From c203823e5d8011680c17209725bdeafb6058d9d7 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Thu, 14 Sep 2023 08:32:40 -0700 Subject: [PATCH] build: switch to clang (PROOF-620) (#13) * ci: replace gcc with clang in build env setup ( PROOF-633 ) * ci: undo gcc compiler option removal ( PROOF-633 ) * ci: update the Docker image tag ( PROOF-638 ) * bump bazel version * port base package * migrate base * migrate memory * port cbindings * get cbindings building * fix linking * make linking portable * port benchmarks * migrate examples * fix format * drop legacy cuda rules * fix gpu image * clean up build * rename * clean up bazel rules * clean up bazel options * undo * clean up * clean up * clean up * clean up * clean up * fix --------- Co-authored-by: Jacob Trombetta --- .bazelrc | 50 +- .bazelversion | 2 +- WORKSPACE | 21 +- bazel/sxt_benchmark.bzl | 7 +- bazel/sxt_build_system.bzl | 103 ++ bazel/sxt_component.bzl | 105 -- benchmark/inner_product_proof/BUILD | 6 +- benchmark/multi_commitment/BUILD | 4 - benchmark/multi_exp1/BUILD | 20 +- benchmark/multiprod1/BUILD | 4 - benchmark/reduce2/BUILD | 18 +- benchmark/reduce2/reduce_cpu.cc | 8 +- cbindings/BUILD | 12 +- ci/docker/run_docker_gpu.sh | 2 +- example/exponentiation1/BUILD | 19 +- example/exponentiation1/exponentiate_cpu.cc | 8 +- example/field_arithmetic/BUILD | 29 +- example/multiproduct1/BUILD | 4 - sxt/algorithm/base/BUILD | 2 +- sxt/algorithm/iteration/BUILD | 2 +- sxt/algorithm/reduction/BUILD | 2 +- sxt/base/bit/BUILD | 2 +- sxt/base/concept/BUILD | 2 +- sxt/base/container/BUILD | 2 +- sxt/base/curve/BUILD | 2 +- sxt/base/device/BUILD | 20 +- sxt/base/error/BUILD | 2 +- sxt/base/functional/BUILD | 2 +- sxt/base/iterator/BUILD | 2 +- sxt/base/macro/BUILD | 2 +- sxt/base/macro/cuda_warning.h | 2 +- sxt/base/memory/BUILD | 2 +- sxt/base/num/BUILD | 2 +- sxt/base/profile/BUILD | 2 +- sxt/base/test/BUILD | 2 +- sxt/base/type/BUILD | 2 +- sxt/cbindings/backend/BUILD | 2 +- sxt/curve21/base/BUILD | 2 +- sxt/curve21/constant/BUILD | 2 +- sxt/curve21/operation/BUILD | 2 +- sxt/curve21/property/BUILD | 2 +- sxt/curve21/random/BUILD | 2 +- sxt/curve21/type/BUILD | 2 +- sxt/curve_g1/constant/BUILD | 2 +- sxt/curve_g1/operation/BUILD | 2 +- sxt/curve_g1/property/BUILD | 2 +- sxt/curve_g1/type/BUILD | 2 +- sxt/execution/async/BUILD | 2 +- sxt/execution/device/BUILD | 2 +- sxt/execution/device/event_future.h | 2 +- sxt/execution/kernel/BUILD | 2 +- sxt/execution/schedule/BUILD | 2 +- sxt/field12/base/BUILD | 2 +- sxt/field12/constant/BUILD | 2 +- sxt/field12/operation/BUILD | 2 +- sxt/field12/property/BUILD | 2 +- sxt/field12/random/BUILD | 2 +- sxt/field12/type/BUILD | 2 +- sxt/field51/base/BUILD | 2 +- sxt/field51/constant/BUILD | 2 +- sxt/field51/operation/BUILD | 2 +- sxt/field51/property/BUILD | 2 +- sxt/field51/random/BUILD | 2 +- sxt/field51/type/BUILD | 2 +- sxt/memory/management/BUILD | 2 +- sxt/memory/resource/BUILD | 16 +- sxt/multiexp/base/BUILD | 2 +- sxt/multiexp/bitset_multiprod/BUILD | 2 +- sxt/multiexp/curve/BUILD | 2 +- sxt/multiexp/curve21/BUILD | 2 +- sxt/multiexp/index/BUILD | 2 +- sxt/multiexp/multiproduct_gpu/BUILD | 2 +- sxt/multiexp/pippenger/BUILD | 2 +- .../exponent_aggregates_computation.h | 2 +- sxt/multiexp/pippenger_multiprod/BUILD | 2 +- sxt/multiexp/random/BUILD | 2 +- sxt/multiexp/test/BUILD | 2 +- sxt/proof/inner_product/BUILD | 2 +- sxt/proof/transcript/BUILD | 2 +- sxt/ristretto/base/BUILD | 2 +- sxt/ristretto/operation/BUILD | 2 +- sxt/ristretto/random/BUILD | 2 +- sxt/ristretto/type/BUILD | 2 +- sxt/scalar25/base/BUILD | 2 +- sxt/scalar25/constant/BUILD | 2 +- sxt/scalar25/operation/BUILD | 2 +- sxt/scalar25/property/BUILD | 2 +- sxt/scalar25/random/BUILD | 2 +- sxt/scalar25/type/BUILD | 2 +- sxt/seqcommit/generator/BUILD | 2 +- sxt/seqcommit/test/BUILD | 2 +- third_party/rules_cuda/LICENSE | 202 --- third_party/rules_cuda/README.md | 70 - third_party/rules_cuda/WORKSPACE | 15 - third_party/rules_cuda/gpus/BUILD | 0 .../rules_cuda/gpus/check_cuda_libs.py | 88 -- .../gpus/compress_find_cuda_config.py | 37 - third_party/rules_cuda/gpus/crosstool/BUILD | 0 .../rules_cuda/gpus/crosstool/BUILD.tpl | 144 -- third_party/rules_cuda/gpus/crosstool/LICENSE | 203 --- .../crosstool/cc_toolchain_config.bzl.tpl | 1090 ------------- .../crosstool_wrapper_driver_is_not_gcc.tpl | 413 ----- .../hipcc_cc_toolchain_config.bzl.tpl | 1162 -------------- .../windows/msvc_wrapper_for_nvcc.py.tpl | 214 --- third_party/rules_cuda/gpus/cuda/BUILD | 0 third_party/rules_cuda/gpus/cuda/BUILD.tpl | 216 --- .../rules_cuda/gpus/cuda/BUILD.windows.tpl | 210 --- third_party/rules_cuda/gpus/cuda/LICENSE | 203 --- .../rules_cuda/gpus/cuda/build_defs.bzl.tpl | 106 -- .../rules_cuda/gpus/cuda/cuda_config.h.tpl | 28 - .../rules_cuda/gpus/cuda/cuda_config.py.tpl | 17 - .../rules_cuda/gpus/cuda_configure.bzl | 1350 ----------------- .../rules_cuda/gpus/find_cuda_config.py | 623 -------- .../gpus/find_cuda_config.py.gz.base64 | 1 - third_party/rules_cuda/nccl/BUILD | 0 third_party/rules_cuda/nccl/LICENSE | 30 - third_party/rules_cuda/nccl/archive.BUILD | 100 -- third_party/rules_cuda/nccl/archive.patch | 224 --- .../rules_cuda/nccl/build_defs.bzl.tpl | 408 ----- .../rules_cuda/nccl/nccl_configure.bzl | 156 -- third_party/rules_cuda/nccl/system.BUILD.tpl | 28 - .../rules_cuda/tools/remote_config/BUILD | 0 .../rules_cuda/tools/remote_config/BUILD.tpl | 26 - .../rules_cuda/tools/remote_config/common.bzl | 305 ---- .../remote_platform_configure.bzl | 49 - 125 files changed, 253 insertions(+), 8065 deletions(-) create mode 100644 bazel/sxt_build_system.bzl delete mode 100644 bazel/sxt_component.bzl delete mode 100644 third_party/rules_cuda/LICENSE delete mode 100644 third_party/rules_cuda/README.md delete mode 100644 third_party/rules_cuda/WORKSPACE delete mode 100644 third_party/rules_cuda/gpus/BUILD delete mode 100644 third_party/rules_cuda/gpus/check_cuda_libs.py delete mode 100644 third_party/rules_cuda/gpus/compress_find_cuda_config.py delete mode 100644 third_party/rules_cuda/gpus/crosstool/BUILD delete mode 100644 third_party/rules_cuda/gpus/crosstool/BUILD.tpl delete mode 100644 third_party/rules_cuda/gpus/crosstool/LICENSE delete mode 100644 third_party/rules_cuda/gpus/crosstool/cc_toolchain_config.bzl.tpl delete mode 100755 third_party/rules_cuda/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl delete mode 100644 third_party/rules_cuda/gpus/crosstool/hipcc_cc_toolchain_config.bzl.tpl delete mode 100644 third_party/rules_cuda/gpus/crosstool/windows/msvc_wrapper_for_nvcc.py.tpl delete mode 100644 third_party/rules_cuda/gpus/cuda/BUILD delete mode 100644 third_party/rules_cuda/gpus/cuda/BUILD.tpl delete mode 100644 third_party/rules_cuda/gpus/cuda/BUILD.windows.tpl delete mode 100644 third_party/rules_cuda/gpus/cuda/LICENSE delete mode 100644 third_party/rules_cuda/gpus/cuda/build_defs.bzl.tpl delete mode 100644 third_party/rules_cuda/gpus/cuda/cuda_config.h.tpl delete mode 100644 third_party/rules_cuda/gpus/cuda/cuda_config.py.tpl delete mode 100644 third_party/rules_cuda/gpus/cuda_configure.bzl delete mode 100644 third_party/rules_cuda/gpus/find_cuda_config.py delete mode 100644 third_party/rules_cuda/gpus/find_cuda_config.py.gz.base64 delete mode 100644 third_party/rules_cuda/nccl/BUILD delete mode 100644 third_party/rules_cuda/nccl/LICENSE delete mode 100644 third_party/rules_cuda/nccl/archive.BUILD delete mode 100644 third_party/rules_cuda/nccl/archive.patch delete mode 100644 third_party/rules_cuda/nccl/build_defs.bzl.tpl delete mode 100644 third_party/rules_cuda/nccl/nccl_configure.bzl delete mode 100644 third_party/rules_cuda/nccl/system.BUILD.tpl delete mode 100644 third_party/rules_cuda/tools/remote_config/BUILD delete mode 100644 third_party/rules_cuda/tools/remote_config/BUILD.tpl delete mode 100644 third_party/rules_cuda/tools/remote_config/common.bzl delete mode 100644 third_party/rules_cuda/tools/remote_config/remote_platform_configure.bzl diff --git a/.bazelrc b/.bazelrc index f12bc9f2..9c135830 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,11 +1,31 @@ -build --cxxopt -std=c++20 -build --config=cuda build --experimental_cc_implementation_deps build --copt -fPIC -build:portable_glibc --copt -fPIC build:portable_glibc --define SXT_PORTABLE_GLIBC=1 +build:portable_glibc --action_env=BAZEL_LINKLIBS='-l%:libstdc++.a' +build:portable_glibc --action_env=BAZEL_LINKOPTS='-static-libstdc++ -static-libgcc' + +build --flag_alias=enable_cuda=@rules_cuda//cuda:enable +build --flag_alias=cuda_archs=@rules_cuda//cuda:archs +build --flag_alias=cuda_compiler=@rules_cuda//cuda:compiler +build --flag_alias=cuda_copts=@rules_cuda//cuda:copts +build --flag_alias=cuda_host_copts=@rules_cuda//cuda:host_copts +build --flag_alias=cuda_runtime=@rules_cuda//cuda:runtime + +build --@rules_cuda//cuda:archs=compute_70:compute_70,sm_70 +build --@rules_cuda//cuda:runtime=@local_cuda//:cuda_runtime_static + +build --enable_cuda=True + +# Use --config=clang to build with clang instead of gcc and nvcc. +build:clang --repo_env=CC=clang +build:clang --@rules_cuda//cuda:compiler=clang +build:clang --copt=-stdlib=libstdc++ +build:clang --action_env CC=/usr/bin/clang-18 +build:clang --action_env CXX=/usr/bin/clang++-18 +build --config=clang + build:asan --copt -fsanitize=address build:asan --linkopt -fsanitize=address @@ -22,29 +42,6 @@ build:asan --workspace_status_command=./ci/lsan_hack.sh run:asan --action_env=LSAN_OPTIONS=suppressions=/tmp/sxt-blitzar-lsan.supp test:asan --action_env=LSAN_OPTIONS=suppressions=/tmp/sxt-blitzar-lsan.supp -build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain -build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true --define=using_cuda_clang=false - -build:cuda_clang --crosstool_top=@local_config_cuda//crosstool:toolchain -build:cuda_clang --define=using_cuda=true --define=using_cuda_clang=true - -build:win-cuda --define=using_cuda=true --define=using_cuda_nvcc=true - -build:opt --cxxopt=-march=native --copt=-march=native -build --action_env TF_NEED_CUDA="1" -build --action_env TF_NEED_OPENCL="1" -build --action_env TF_CUDA_CLANG="0" -build --action_env HOST_CXX_COMPILER="/usr/bin/gcc" -build --action_env HOST_C_COMPILER="/usr/bin/gcc" -build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc" - -build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda" -build --action_env PYTHON_BIN_PATH="/usr/bin/python3" -build --action_env TF_CUDA_VERSION="12.2" -build --action_env TF_CUDA_COMPUTE_CAPABILITIES="7.0" -build --action_env COMPUTECPP_TOOLKIT_PATH="/usr/local/computecpp" -build --action_env TMP="/tmp" - # For machines with many cpu cores available, we could not compile # the code. Many times (not always) the following error was launched: # `ptxas /tmp/tmpfxt_00000017_00000000-0, line 1; fatal : Missing .version...` @@ -52,5 +49,6 @@ build --action_env TMP="/tmp" # for more information. # To fix the problem, we added the following line: build --sandbox_add_mount_pair=.:/tmp +build --spawn_strategy local test --test_output=errors diff --git a/.bazelversion b/.bazelversion index 024b066c..91e4a9f2 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.2.1 +6.3.2 diff --git a/WORKSPACE b/WORKSPACE index c69f065b..32d5f0c8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -11,17 +11,20 @@ http_archive( ], ) -local_repository( - name = "build_bazel_rules_cuda", - path = "third_party/rules_cuda", -) - -load("@build_bazel_rules_cuda//gpus:cuda_configure.bzl", "cuda_configure") - -cuda_configure(name = "local_config_cuda") - git_repository( name = "com_github_catchorg_catch2", commit = "6f21a3609cea360846a0ca93be55877cca14c86d", remote = "https://github.com/catchorg/Catch2", ) + +git_repository( + name = "rules_cuda", + commit = "22a46e6", + remote = "https://github.com/bazel-contrib/rules_cuda", +) + +load("@rules_cuda//cuda:repositories.bzl", "register_detected_cuda_toolchains", "rules_cuda_dependencies") + +rules_cuda_dependencies() + +register_detected_cuda_toolchains() diff --git a/bazel/sxt_benchmark.bzl b/bazel/sxt_benchmark.bzl index 33e071b4..543d11bb 100644 --- a/bazel/sxt_benchmark.bzl +++ b/bazel/sxt_benchmark.bzl @@ -1,3 +1,8 @@ +load( + "//bazel:sxt_build_system.bzl", + "sxt_cc_binary", +) + # Taken from https://github.com/bazelbuild/bazel/issues/2670#issuecomment-369674735 # with modifications. def sxt_private_include_copts(includes, is_system = False): @@ -76,7 +81,7 @@ def sxt_cc_benchmark( cmd_bash = "$(location //tools/benchmark:bench_profile) callgrind $$PWD/$(location :%s) $@" % name, ) - native.cc_binary( + sxt_cc_binary( name = name, srcs = srcs, copts = copts + sxt_copts() + select({ diff --git a/bazel/sxt_build_system.bzl b/bazel/sxt_build_system.bzl new file mode 100644 index 00000000..56b3374d --- /dev/null +++ b/bazel/sxt_build_system.bzl @@ -0,0 +1,103 @@ +load("@rules_cuda//cuda:defs.bzl", "cuda_library", "cuda_objects") + +# We add this -std=c++20 flag, because +# benchmarks could not be compiled without it. +# The `build --cxxopt -std=c++20` flag set in the +# `.bazelrc` file was not passed to the compiler. +# However, this flag is relevant to some modules. +def sxt_copts(): + return [ + "-std=c++20", + "-Wno-unknown-cuda-version", + ] + +def sxt_cc_component( + name, + copts = [], + is_cuda = False, + with_test = True, + alwayslink = False, + test_deps = [], + deps = [], + impl_deps = [], + **kwargs): + cuda_objects( + name = name, + hdrs = [ + name + ".h", + ], + srcs = [ + name + ".cc", + ], + copts = sxt_copts(), + deps = deps + impl_deps + [ + "@local_cuda//:cuda_runtime_static", + ], + visibility = ["//visibility:public"], + **kwargs + ) + if with_test: + test_lib = name + ".t-lib" + deps_p = [ + ":" + name, + ] + deps + test_deps + cuda_library( + name = test_lib, + copts = sxt_copts(), + deps = [ + ":" + name, + ] + test_deps, + srcs = [ + name + ".t.cc", + ], + rdc = True, + ) + native.cc_test( + name = name + ".t", + copts = sxt_copts() + copts, + deps = [ + ":" + test_lib, + ] + test_deps + [ + "@com_github_catchorg_catch2//:catch2", + "@com_github_catchorg_catch2//:catch2_main", + ], + visibility = ["//visibility:public"], + **kwargs + ) + +def sxt_cc_library( + name, + copts = [], + deps = [], + impl_deps = [], + **kwargs): + cuda_objects( + name = name, + copts = sxt_copts(), + deps = deps + impl_deps, + visibility = ["//visibility:public"], + **kwargs + ) + +def sxt_cc_binary( + name, + srcs = [], + copts = [], + deps = [], + **kwargs): + libname = name + "-lib" + cuda_library( + name = libname, + srcs = srcs, + copts = sxt_copts() + copts, + deps = deps, + rdc = True, + **kwargs + ) + native.cc_binary( + name = name, + deps = [ + ":" + libname, + ] + deps, + **kwargs + ) diff --git a/bazel/sxt_component.bzl b/bazel/sxt_component.bzl deleted file mode 100644 index 622bfc10..00000000 --- a/bazel/sxt_component.bzl +++ /dev/null @@ -1,105 +0,0 @@ -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library", "cuda_test") -load( - "//bazel:cuda_dlink.bzl", - "cuda_dlink", -) - -# We add this -std=c++20 flag, because -# benchmarks could not be compiled without it. -# The `build --cxxopt -std=c++20` flag set in the -# `.bazelrc` file was not passed to the compiler. -# However, this flag is relevant to some modules. -def sxt_copts(): - return [ - "-std=c++20", - "-fcoroutines", - ] - -def sxt_cc_component( - name, - copts = [], - is_cuda = False, - with_test = True, - alwayslink = False, - test_deps = [], - deps = [], - impl_deps = [], - **kwargs): - if is_cuda: - cuda_library( - name = name, - hdrs = [ - name + ".h", - ], - srcs = [ - name + ".cc", - ], - copts = sxt_copts() + [ - "--device-c", - "-x", - "cuda", - ], - alwayslink = alwayslink, - linkstatic = 1, - deps = deps + impl_deps + [ - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", - ], - visibility = ["//visibility:public"], - **kwargs - ) - else: - native.cc_library( - name = name, - hdrs = [ - name + ".h", - ], - srcs = [ - name + ".cc", - ], - copts = sxt_copts() + copts, - linkstatic = 1, - implementation_deps = impl_deps, - deps = deps, - alwayslink = alwayslink, - visibility = ["//visibility:public"], - linkopts = [ - "-lm", - ], - **kwargs - ) - if with_test: - deps_p = [ - ":" + name, - ] + deps + test_deps - device_test_name = name + "-device.t" - cuda_dlink( - name = device_test_name, - deps = deps_p, - ) - if is_cuda: - cuda_test( - name = name + ".t", - srcs = [ - name + ".t.cc", - ], - copts = sxt_copts() + copts, - deps = deps_p + [ - ":" + device_test_name, - ], - visibility = ["//visibility:public"], - **kwargs - ) - else: - native.cc_test( - name = name + ".t", - srcs = [ - name + ".t.cc", - ], - copts = sxt_copts() + copts, - deps = deps_p + [ - ":" + device_test_name, - ], - visibility = ["//visibility:public"], - **kwargs - ) diff --git a/benchmark/inner_product_proof/BUILD b/benchmark/inner_product_proof/BUILD index fe8c804a..5c43d15b 100644 --- a/benchmark/inner_product_proof/BUILD +++ b/benchmark/inner_product_proof/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) load("//bazel:sxt_benchmark.bzl", "sxt_cc_benchmark") @@ -23,10 +23,6 @@ sxt_cc_benchmark( srcs = [ "benchmark.m.cc", ], - linkopts = [ - "-x", - "cuda", - ], visibility = ["//visibility:public"], deps = [ ":params", diff --git a/benchmark/multi_commitment/BUILD b/benchmark/multi_commitment/BUILD index a9d60437..d99e18d5 100644 --- a/benchmark/multi_commitment/BUILD +++ b/benchmark/multi_commitment/BUILD @@ -5,10 +5,6 @@ sxt_cc_benchmark( srcs = [ "benchmark.m.cc", ], - linkopts = [ - "-x", - "cuda", - ], visibility = ["//visibility:public"], deps = [ "//sxt/base/container:span", diff --git a/benchmark/multi_exp1/BUILD b/benchmark/multi_exp1/BUILD index aabe555b..483db833 100644 --- a/benchmark/multi_exp1/BUILD +++ b/benchmark/multi_exp1/BUILD @@ -1,7 +1,7 @@ load("//bazel:sxt_benchmark.bzl", "sxt_cc_benchmark") -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library") +load("//bazel:sxt_build_system.bzl", "sxt_cc_library") -cc_library( +sxt_cc_library( name = "multiply_add", srcs = [ "multiply_add.cc", @@ -9,11 +9,6 @@ cc_library( hdrs = [ "multiply_add.h", ], - copts = [ - "-x", - "cuda", - "--device-c", - ], deps = [ "//sxt/base/macro:cuda_callable", "//sxt/base/num:fast_random_number_generator", @@ -24,7 +19,7 @@ cc_library( ], ) -cc_library( +sxt_cc_library( name = "multi_exp_cpu", srcs = [ "multi_exp_cpu.cc", @@ -38,7 +33,7 @@ cc_library( ], ) -cuda_library( +sxt_cc_library( name = "multi_exp_gpu", srcs = [ "multi_exp_gpu.cu", @@ -46,9 +41,6 @@ cuda_library( hdrs = [ "multi_exp_gpu.h", ], - copts = [ - "--device-c", - ], deps = [ ":multiply_add", "//sxt/curve21/operation:add", @@ -63,10 +55,6 @@ sxt_cc_benchmark( srcs = [ "benchmark.m.cc", ], - linkopts = [ - "-x", - "cuda", - ], visibility = ["//visibility:public"], deps = [ ":multi_exp_cpu", diff --git a/benchmark/multiprod1/BUILD b/benchmark/multiprod1/BUILD index 8958e0b0..77af8bb6 100644 --- a/benchmark/multiprod1/BUILD +++ b/benchmark/multiprod1/BUILD @@ -5,10 +5,6 @@ sxt_cc_benchmark( srcs = [ "benchmark.m.cc", ], - linkopts = [ - "-x", - "cuda", - ], visibility = ["//visibility:public"], deps = [ "//sxt/base/container:span", diff --git a/benchmark/reduce2/BUILD b/benchmark/reduce2/BUILD index 57b6ac24..20e83359 100644 --- a/benchmark/reduce2/BUILD +++ b/benchmark/reduce2/BUILD @@ -1,7 +1,7 @@ load("//bazel:sxt_benchmark.bzl", "sxt_cc_benchmark") -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library") +load("//bazel:sxt_build_system.bzl", "sxt_cc_library") -cc_library( +sxt_cc_library( name = "reduce_cpu", srcs = [ "reduce_cpu.cc", @@ -9,17 +9,13 @@ cc_library( hdrs = [ "reduce_cpu.h", ], - copts = [ - "-fconcepts", - "-std=c++20", - ], deps = [ "//sxt/curve21/operation:add", "//sxt/curve21/type:element_p3", ], ) -cuda_library( +sxt_cc_library( name = "reduce_gpu", srcs = [ "reduce_gpu.cu", @@ -27,9 +23,6 @@ cuda_library( hdrs = [ "reduce_gpu.h", ], - copts = [ - "--device-c", - ], deps = [ "//sxt/curve21/operation:add", "//sxt/curve21/type:element_p3", @@ -41,11 +34,6 @@ sxt_cc_benchmark( srcs = [ "benchmark.m.cc", ], - linkopts = [ - "-x", - "cuda", - ], - visibility = ["//visibility:public"], deps = [ ":reduce_cpu", ":reduce_gpu", diff --git a/benchmark/reduce2/reduce_cpu.cc b/benchmark/reduce2/reduce_cpu.cc index 03139384..322b7501 100644 --- a/benchmark/reduce2/reduce_cpu.cc +++ b/benchmark/reduce2/reduce_cpu.cc @@ -26,10 +26,10 @@ namespace sxt { void reduce_cpu(c21t::element_p3* res, int m, int n) noexcept { // pretend like g is a random element rather than fixed c21t::element_p3 g{ - .X{3990542415680775, 3398198340507945, 4322667446711068, 2814063955482877, 2839572215813860}, - .Y{1801439850948184, 1351079888211148, 450359962737049, 900719925474099, 1801439850948198}, - .Z{1, 0, 0, 0, 0}, - .T{1841354044333475, 16398895984059, 755974180946558, 900171276175154, 1821297809914039}, + {3990542415680775, 3398198340507945, 4322667446711068, 2814063955482877, 2839572215813860}, + {1801439850948184, 1351079888211148, 450359962737049, 900719925474099, 1801439850948198}, + {1, 0, 0, 0, 0}, + {1841354044333475, 16398895984059, 755974180946558, 900171276175154, 1821297809914039}, }; for (int mi = 0; mi < m; ++mi) { diff --git a/cbindings/BUILD b/cbindings/BUILD index cdcaaffe..570b8a63 100644 --- a/cbindings/BUILD +++ b/cbindings/BUILD @@ -1,14 +1,15 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) load( - "//bazel:cuda_dlink.bzl", - "cuda_dlink", + "@rules_cuda//cuda:defs.bzl", + "cuda_library", ) -cuda_dlink( +cuda_library( name = "cbindings_device", + rdc = 1, deps = [ ":backend", ":get_generators", @@ -16,14 +17,13 @@ cuda_dlink( ":inner_product_proof", ":pedersen", ], + alwayslink = 1, ) cc_binary( name = "libblitzar.so", linkopts = [ "-Wl,--version-script=$(location :libblitzar-export-map.ld)", - "-static-libstdc++", - "-static-libgcc", ], linkshared = 1, visibility = ["//visibility:public"], diff --git a/ci/docker/run_docker_gpu.sh b/ci/docker/run_docker_gpu.sh index a09ce45d..3e65fa66 100755 --- a/ci/docker/run_docker_gpu.sh +++ b/ci/docker/run_docker_gpu.sh @@ -5,4 +5,4 @@ set -e IMAGE=spaceandtimelabs/blitzar:12.2.0-cuda-1.71.1-rust-1 # If you have a GPU instance configured in your machine -docker run --rm -v "$PWD":/src -w /src --gpus all --privileged -it "$IMAGE" /bin/bash -l +docker run -v "$PWD":/src -w /src --gpus all --privileged -it "$IMAGE" /bin/bash -l diff --git a/example/exponentiation1/BUILD b/example/exponentiation1/BUILD index f7f60ec0..e1378047 100644 --- a/example/exponentiation1/BUILD +++ b/example/exponentiation1/BUILD @@ -1,27 +1,21 @@ -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library") +load("//bazel:sxt_build_system.bzl", "sxt_cc_binary", "sxt_cc_library") -cuda_library( +sxt_cc_library( name = "exponentiate_gpu", srcs = ["exponentiate_gpu.cu"], hdrs = ["exponentiate_gpu.h"], - copts = [ - "--device-c", - ], - visibility = ["//visibility:public"], deps = [ "//sxt/base/num:fast_random_number_generator", "//sxt/curve21/operation:scalar_multiply", "//sxt/curve21/type:element_p3", "//sxt/field51/type:element", - "@local_config_cuda//cuda", ], ) -cc_library( +sxt_cc_library( name = "exponentiate_cpu", srcs = ["exponentiate_cpu.cc"], hdrs = ["exponentiate_cpu.h"], - visibility = ["//visibility:public"], deps = [ "//sxt/base/num:fast_random_number_generator", "//sxt/curve21/operation:scalar_multiply", @@ -30,16 +24,11 @@ cc_library( ], ) -cc_binary( +sxt_cc_binary( name = "exponentiate", srcs = [ "main.cc", ], - linkopts = [ - "-x", - "cuda", - "--cudalog", - ], deps = [ ":exponentiate_cpu", ":exponentiate_gpu", diff --git a/example/exponentiation1/exponentiate_cpu.cc b/example/exponentiation1/exponentiate_cpu.cc index e980f705..4bad23cf 100644 --- a/example/exponentiation1/exponentiate_cpu.cc +++ b/example/exponentiation1/exponentiate_cpu.cc @@ -28,10 +28,10 @@ namespace sxt { //-------------------------------------------------------------------------------------------------- void exponentiate_cpu(c21t::element_p3* res, int n) noexcept { c21t::element_p3 g{ - .X{3990542415680775, 3398198340507945, 4322667446711068, 2814063955482877, 2839572215813860}, - .Y{1801439850948184, 1351079888211148, 450359962737049, 900719925474099, 1801439850948198}, - .Z{1, 0, 0, 0, 0}, - .T{1841354044333475, 16398895984059, 755974180946558, 900171276175154, 1821297809914039}, + {3990542415680775, 3398198340507945, 4322667446711068, 2814063955482877, 2839572215813860}, + {1801439850948184, 1351079888211148, 450359962737049, 900719925474099, 1801439850948198}, + {1, 0, 0, 0, 0}, + {1841354044333475, 16398895984059, 755974180946558, 900171276175154, 1821297809914039}, }; for (int i = 0; i < n; ++i) { unsigned char a[32] = {1}; diff --git a/example/field_arithmetic/BUILD b/example/field_arithmetic/BUILD index 989908e3..c246b7bd 100644 --- a/example/field_arithmetic/BUILD +++ b/example/field_arithmetic/BUILD @@ -1,31 +1,16 @@ -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library") +load("//bazel:sxt_build_system.bzl", "sxt_cc_binary") -cuda_library( - name = "reduce1", - srcs = ["reduce1.cu"], - hdrs = ["reduce1.h"], - copts = [ - "--device-c", +sxt_cc_binary( + name = "reduce", + srcs = [ + "reduce.cc", + "reduce1.cu", + "reduce1.h", ], - visibility = ["//visibility:public"], deps = [ "//sxt/field51/base:reduce", "//sxt/field51/operation:add", "//sxt/field51/operation:mul", "//sxt/field51/type:element", - "@local_config_cuda//cuda", - ], -) - -cc_binary( - name = "reduce", - srcs = ["reduce.cc"], - linkopts = [ - "-x", - "cuda", - ], - deps = [ - ":reduce1", - "//sxt/field51/type:element", ], ) diff --git a/example/multiproduct1/BUILD b/example/multiproduct1/BUILD index 80de1f8d..db4c7a8b 100644 --- a/example/multiproduct1/BUILD +++ b/example/multiproduct1/BUILD @@ -5,10 +5,6 @@ sxt_cc_benchmark( srcs = [ "main.cc", ], - linkopts = [ - "-x", - "cuda", - ], deps = [ "//sxt/base/profile:callgrind", "//sxt/curve21/operation:add", diff --git a/sxt/algorithm/base/BUILD b/sxt/algorithm/base/BUILD index f1beda8d..8939f6f2 100644 --- a/sxt/algorithm/base/BUILD +++ b/sxt/algorithm/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/algorithm/iteration/BUILD b/sxt/algorithm/iteration/BUILD index 318668cf..154935ee 100644 --- a/sxt/algorithm/iteration/BUILD +++ b/sxt/algorithm/iteration/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/algorithm/reduction/BUILD b/sxt/algorithm/reduction/BUILD index 8dcf6a66..c81529fa 100644 --- a/sxt/algorithm/reduction/BUILD +++ b/sxt/algorithm/reduction/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/bit/BUILD b/sxt/base/bit/BUILD index 9cb0fe7c..1908ee5d 100644 --- a/sxt/base/bit/BUILD +++ b/sxt/base/bit/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/concept/BUILD b/sxt/base/concept/BUILD index 7e820415..1e3e001c 100644 --- a/sxt/base/concept/BUILD +++ b/sxt/base/concept/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/container/BUILD b/sxt/base/container/BUILD index 670e8a68..40785f29 100644 --- a/sxt/base/container/BUILD +++ b/sxt/base/container/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/curve/BUILD b/sxt/base/curve/BUILD index e95c383b..b04ab265 100644 --- a/sxt/base/curve/BUILD +++ b/sxt/base/curve/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/device/BUILD b/sxt/base/device/BUILD index 8e79ccfa..24b8ba8f 100644 --- a/sxt/base/device/BUILD +++ b/sxt/base/device/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) @@ -37,8 +37,6 @@ sxt_cc_component( ], deps = [ "//sxt/base/type:raw_cuda_event", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], ) @@ -51,8 +49,6 @@ sxt_cc_component( deps = [ "//sxt/base/type:raw_cuda_event", "//sxt/base/type:raw_stream", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], ) @@ -75,8 +71,6 @@ sxt_cc_component( ], deps = [ "//sxt/base/type:raw_stream", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], ) @@ -88,15 +82,11 @@ sxt_cc_component( ":stream", ":state", "//sxt/base/error:panic", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], test_deps = [ ":pointer_attributes", ":state", "//sxt/base/test:unit_test", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], deps = [ "//sxt/base/concept:memcpyable_ranges", @@ -148,8 +138,6 @@ sxt_cc_component( ], deps = [ ":device_map", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], ) @@ -162,10 +150,6 @@ sxt_cc_component( ":property", "//sxt/base/test:unit_test", ], - deps = [ - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", - ], ) sxt_cc_component( @@ -176,7 +160,5 @@ sxt_cc_component( with_test = False, deps = [ "//sxt/base/type:raw_stream", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], ) diff --git a/sxt/base/error/BUILD b/sxt/base/error/BUILD index fa8fecb3..b0a925e5 100644 --- a/sxt/base/error/BUILD +++ b/sxt/base/error/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/functional/BUILD b/sxt/base/functional/BUILD index 34922209..c6efac52 100644 --- a/sxt/base/functional/BUILD +++ b/sxt/base/functional/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/iterator/BUILD b/sxt/base/iterator/BUILD index 36f159cc..317be006 100644 --- a/sxt/base/iterator/BUILD +++ b/sxt/base/iterator/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/macro/BUILD b/sxt/base/macro/BUILD index 071aad4c..9c57c002 100644 --- a/sxt/base/macro/BUILD +++ b/sxt/base/macro/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/macro/cuda_warning.h b/sxt/base/macro/cuda_warning.h index 64ce6091..866110e5 100644 --- a/sxt/base/macro/cuda_warning.h +++ b/sxt/base/macro/cuda_warning.h @@ -16,7 +16,7 @@ */ #pragma once -#ifdef __CUDACC__ +#if defined(__CUDACC__) && !defined(__clang__) #define CUDA_DISABLE_HOSTDEV_WARNING _Pragma("nv_exec_check_disable") #else #define CUDA_DISABLE_HOSTDEV_WARNING diff --git a/sxt/base/memory/BUILD b/sxt/base/memory/BUILD index cc03d06d..c9a407b3 100644 --- a/sxt/base/memory/BUILD +++ b/sxt/base/memory/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/num/BUILD b/sxt/base/num/BUILD index d938c8cf..67e30993 100644 --- a/sxt/base/num/BUILD +++ b/sxt/base/num/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/profile/BUILD b/sxt/base/profile/BUILD index cc2b39b5..2a880e48 100644 --- a/sxt/base/profile/BUILD +++ b/sxt/base/profile/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/test/BUILD b/sxt/base/test/BUILD index 4fd4b1a8..1d9a77eb 100644 --- a/sxt/base/test/BUILD +++ b/sxt/base/test/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/base/type/BUILD b/sxt/base/type/BUILD index 83fe9e4a..05ed6216 100644 --- a/sxt/base/type/BUILD +++ b/sxt/base/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/cbindings/backend/BUILD b/sxt/cbindings/backend/BUILD index 9bf2459d..0ac5bccf 100644 --- a/sxt/cbindings/backend/BUILD +++ b/sxt/cbindings/backend/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve21/base/BUILD b/sxt/curve21/base/BUILD index a6a2383d..31849693 100644 --- a/sxt/curve21/base/BUILD +++ b/sxt/curve21/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve21/constant/BUILD b/sxt/curve21/constant/BUILD index 782d46ed..bd0a6a28 100644 --- a/sxt/curve21/constant/BUILD +++ b/sxt/curve21/constant/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve21/operation/BUILD b/sxt/curve21/operation/BUILD index 9f20356c..73369514 100644 --- a/sxt/curve21/operation/BUILD +++ b/sxt/curve21/operation/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve21/property/BUILD b/sxt/curve21/property/BUILD index aab76790..b49fe6a7 100644 --- a/sxt/curve21/property/BUILD +++ b/sxt/curve21/property/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve21/random/BUILD b/sxt/curve21/random/BUILD index e3fea936..a3af8f75 100644 --- a/sxt/curve21/random/BUILD +++ b/sxt/curve21/random/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve21/type/BUILD b/sxt/curve21/type/BUILD index 76bde292..3b07c9ee 100644 --- a/sxt/curve21/type/BUILD +++ b/sxt/curve21/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve_g1/constant/BUILD b/sxt/curve_g1/constant/BUILD index 55f10c59..615e9c94 100644 --- a/sxt/curve_g1/constant/BUILD +++ b/sxt/curve_g1/constant/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve_g1/operation/BUILD b/sxt/curve_g1/operation/BUILD index 891ac5ba..a8803437 100644 --- a/sxt/curve_g1/operation/BUILD +++ b/sxt/curve_g1/operation/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve_g1/property/BUILD b/sxt/curve_g1/property/BUILD index 4eee3f44..a0262973 100644 --- a/sxt/curve_g1/property/BUILD +++ b/sxt/curve_g1/property/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/curve_g1/type/BUILD b/sxt/curve_g1/type/BUILD index 1aea9a0c..936da14e 100644 --- a/sxt/curve_g1/type/BUILD +++ b/sxt/curve_g1/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/execution/async/BUILD b/sxt/execution/async/BUILD index b987ccb7..d66b0a38 100644 --- a/sxt/execution/async/BUILD +++ b/sxt/execution/async/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/execution/device/BUILD b/sxt/execution/device/BUILD index 38c01dc1..a10a9060 100644 --- a/sxt/execution/device/BUILD +++ b/sxt/execution/device/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/execution/device/event_future.h b/sxt/execution/device/event_future.h index 98217c44..5c4b5cc3 100644 --- a/sxt/execution/device/event_future.h +++ b/sxt/execution/device/event_future.h @@ -38,7 +38,7 @@ template class event_future { ~event_future() noexcept { if (event_) { - xena::future{std::move(*this)}; + (void)xena::future{std::move(*this)}; } } diff --git a/sxt/execution/kernel/BUILD b/sxt/execution/kernel/BUILD index 057b6d64..7f875587 100644 --- a/sxt/execution/kernel/BUILD +++ b/sxt/execution/kernel/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/execution/schedule/BUILD b/sxt/execution/schedule/BUILD index 1db5f3f6..0274aee6 100644 --- a/sxt/execution/schedule/BUILD +++ b/sxt/execution/schedule/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field12/base/BUILD b/sxt/field12/base/BUILD index b075f80d..2133da6a 100644 --- a/sxt/field12/base/BUILD +++ b/sxt/field12/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field12/constant/BUILD b/sxt/field12/constant/BUILD index 5e9320a0..7dd165bb 100644 --- a/sxt/field12/constant/BUILD +++ b/sxt/field12/constant/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field12/operation/BUILD b/sxt/field12/operation/BUILD index 80a15b37..9b176799 100644 --- a/sxt/field12/operation/BUILD +++ b/sxt/field12/operation/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field12/property/BUILD b/sxt/field12/property/BUILD index b686baa9..9a97db28 100644 --- a/sxt/field12/property/BUILD +++ b/sxt/field12/property/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field12/random/BUILD b/sxt/field12/random/BUILD index 82c21a57..2eb61513 100644 --- a/sxt/field12/random/BUILD +++ b/sxt/field12/random/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field12/type/BUILD b/sxt/field12/type/BUILD index 5bef7f20..855d9f3d 100644 --- a/sxt/field12/type/BUILD +++ b/sxt/field12/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field51/base/BUILD b/sxt/field51/base/BUILD index 5ee33cad..b96967d0 100644 --- a/sxt/field51/base/BUILD +++ b/sxt/field51/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field51/constant/BUILD b/sxt/field51/constant/BUILD index b260c949..98439e1f 100644 --- a/sxt/field51/constant/BUILD +++ b/sxt/field51/constant/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field51/operation/BUILD b/sxt/field51/operation/BUILD index 8248fade..7ac4e73b 100644 --- a/sxt/field51/operation/BUILD +++ b/sxt/field51/operation/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field51/property/BUILD b/sxt/field51/property/BUILD index da263b54..4c412fb1 100644 --- a/sxt/field51/property/BUILD +++ b/sxt/field51/property/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field51/random/BUILD b/sxt/field51/random/BUILD index b7d61f26..9e539ff3 100644 --- a/sxt/field51/random/BUILD +++ b/sxt/field51/random/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/field51/type/BUILD b/sxt/field51/type/BUILD index 00eafa63..263381e9 100644 --- a/sxt/field51/type/BUILD +++ b/sxt/field51/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/memory/management/BUILD b/sxt/memory/management/BUILD index 6f63c7f0..5a20db40 100644 --- a/sxt/memory/management/BUILD +++ b/sxt/memory/management/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/memory/resource/BUILD b/sxt/memory/resource/BUILD index e25bc3d2..15cf9b43 100644 --- a/sxt/memory/resource/BUILD +++ b/sxt/memory/resource/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) @@ -14,8 +14,6 @@ sxt_cc_component( with_test = False, deps = [ "//sxt/base/type:raw_stream", - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", ], ) @@ -27,10 +25,6 @@ sxt_cc_component( test_deps = [ "//sxt/base/test:unit_test", ], - deps = [ - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", - ], ) sxt_cc_component( @@ -42,10 +36,6 @@ sxt_cc_component( "//sxt/base/test:unit_test", ], with_test = False, - deps = [ - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", - ], ) sxt_cc_component( @@ -56,8 +46,4 @@ sxt_cc_component( test_deps = [ "//sxt/base/test:unit_test", ], - deps = [ - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", - ], ) diff --git a/sxt/multiexp/base/BUILD b/sxt/multiexp/base/BUILD index 752d5ae4..e1b8e62f 100644 --- a/sxt/multiexp/base/BUILD +++ b/sxt/multiexp/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/bitset_multiprod/BUILD b/sxt/multiexp/bitset_multiprod/BUILD index fdbe198a..d82460f4 100644 --- a/sxt/multiexp/bitset_multiprod/BUILD +++ b/sxt/multiexp/bitset_multiprod/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/curve/BUILD b/sxt/multiexp/curve/BUILD index d6b83dbe..2fb24017 100644 --- a/sxt/multiexp/curve/BUILD +++ b/sxt/multiexp/curve/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/curve21/BUILD b/sxt/multiexp/curve21/BUILD index f44d8190..f28c244e 100644 --- a/sxt/multiexp/curve21/BUILD +++ b/sxt/multiexp/curve21/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/index/BUILD b/sxt/multiexp/index/BUILD index edfdd511..a032f3fb 100644 --- a/sxt/multiexp/index/BUILD +++ b/sxt/multiexp/index/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/multiproduct_gpu/BUILD b/sxt/multiexp/multiproduct_gpu/BUILD index 6992d0bd..06e29477 100644 --- a/sxt/multiexp/multiproduct_gpu/BUILD +++ b/sxt/multiexp/multiproduct_gpu/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/pippenger/BUILD b/sxt/multiexp/pippenger/BUILD index 02983f93..be2d2fdf 100644 --- a/sxt/multiexp/pippenger/BUILD +++ b/sxt/multiexp/pippenger/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/pippenger/exponent_aggregates_computation.h b/sxt/multiexp/pippenger/exponent_aggregates_computation.h index a63b30d9..2366a49f 100644 --- a/sxt/multiexp/pippenger/exponent_aggregates_computation.h +++ b/sxt/multiexp/pippenger/exponent_aggregates_computation.h @@ -21,7 +21,7 @@ #include "sxt/base/container/span.h" namespace sxt::mtxb { -class exponent_sequence; +struct exponent_sequence; } namespace sxt::mtxpi { diff --git a/sxt/multiexp/pippenger_multiprod/BUILD b/sxt/multiexp/pippenger_multiprod/BUILD index 21ac842d..b5288333 100644 --- a/sxt/multiexp/pippenger_multiprod/BUILD +++ b/sxt/multiexp/pippenger_multiprod/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/random/BUILD b/sxt/multiexp/random/BUILD index e3a0669b..9ad4f4a5 100644 --- a/sxt/multiexp/random/BUILD +++ b/sxt/multiexp/random/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/multiexp/test/BUILD b/sxt/multiexp/test/BUILD index b540fd75..700e55e8 100644 --- a/sxt/multiexp/test/BUILD +++ b/sxt/multiexp/test/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/proof/inner_product/BUILD b/sxt/proof/inner_product/BUILD index 9a286f5c..bbaf0a70 100644 --- a/sxt/proof/inner_product/BUILD +++ b/sxt/proof/inner_product/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/proof/transcript/BUILD b/sxt/proof/transcript/BUILD index ffec9b3e..f8aba0fd 100644 --- a/sxt/proof/transcript/BUILD +++ b/sxt/proof/transcript/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/ristretto/base/BUILD b/sxt/ristretto/base/BUILD index 7427a135..b2ce5a9d 100644 --- a/sxt/ristretto/base/BUILD +++ b/sxt/ristretto/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/ristretto/operation/BUILD b/sxt/ristretto/operation/BUILD index f4d1385a..ed5f0e8c 100644 --- a/sxt/ristretto/operation/BUILD +++ b/sxt/ristretto/operation/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/ristretto/random/BUILD b/sxt/ristretto/random/BUILD index 4f595f91..04f0d1be 100644 --- a/sxt/ristretto/random/BUILD +++ b/sxt/ristretto/random/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/ristretto/type/BUILD b/sxt/ristretto/type/BUILD index d2469844..6197f58a 100644 --- a/sxt/ristretto/type/BUILD +++ b/sxt/ristretto/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/scalar25/base/BUILD b/sxt/scalar25/base/BUILD index 82ca59b3..18264afd 100644 --- a/sxt/scalar25/base/BUILD +++ b/sxt/scalar25/base/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/scalar25/constant/BUILD b/sxt/scalar25/constant/BUILD index d1dfaa35..1907672b 100644 --- a/sxt/scalar25/constant/BUILD +++ b/sxt/scalar25/constant/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/scalar25/operation/BUILD b/sxt/scalar25/operation/BUILD index aec27532..396f6d77 100644 --- a/sxt/scalar25/operation/BUILD +++ b/sxt/scalar25/operation/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/scalar25/property/BUILD b/sxt/scalar25/property/BUILD index e6083baf..d7827267 100644 --- a/sxt/scalar25/property/BUILD +++ b/sxt/scalar25/property/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/scalar25/random/BUILD b/sxt/scalar25/random/BUILD index 678dcd35..b2a33527 100644 --- a/sxt/scalar25/random/BUILD +++ b/sxt/scalar25/random/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/scalar25/type/BUILD b/sxt/scalar25/type/BUILD index 7374ac30..5a463e5c 100644 --- a/sxt/scalar25/type/BUILD +++ b/sxt/scalar25/type/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/seqcommit/generator/BUILD b/sxt/seqcommit/generator/BUILD index 4ade7440..49279ac5 100644 --- a/sxt/seqcommit/generator/BUILD +++ b/sxt/seqcommit/generator/BUILD @@ -1,5 +1,5 @@ load( - "//bazel:sxt_component.bzl", + "//bazel:sxt_build_system.bzl", "sxt_cc_component", ) diff --git a/sxt/seqcommit/test/BUILD b/sxt/seqcommit/test/BUILD index 5c55f322..dc6b30e0 100644 --- a/sxt/seqcommit/test/BUILD +++ b/sxt/seqcommit/test/BUILD @@ -1,4 +1,4 @@ -load("//bazel:sxt_component.bzl", "sxt_cc_component") +load("//bazel:sxt_build_system.bzl", "sxt_cc_component") sxt_cc_component( name = "test_generators", diff --git a/third_party/rules_cuda/LICENSE b/third_party/rules_cuda/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/third_party/rules_cuda/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/third_party/rules_cuda/README.md b/third_party/rules_cuda/README.md deleted file mode 100644 index d27b03ef..00000000 --- a/third_party/rules_cuda/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Note: Adopted from https://github.com/liuliu/rules_cuda - -# CUDA Rules for Bazel - -This is an up-to-date set of Bazel rules to configure Linux builds with CUDA. - -It is directly copied from [Tensorflow](https://github.com/tensorflow/tensorflow/tree/master/third_party/gpus) with some updates. Hence, you need to configure `TF_*` environment variables to make it work. - -An example of `.bazelrc` can be found in the root of [this repository](https://github.com/liuliu/rules_cuda/blob/main/.bazelrc). For available configurations, you can find in [`cuda_configure.bzl`](https://github.com/liuliu/rules_cuda/blob/main/gpus/cuda_configure.bzl#L5) - -## How to Use - -To use rules provided in this repository, you can add following to your `WORKSPACE` file: - -``` -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") - -http_archive( - name = "bazel_skylib", - sha256 = "1dde365491125a3db70731e25658dfdd3bc5dbdfd11b840b3e987ecf043c7ca0", - urls = [ - "https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz", - ], -) - -git_repository( - name = "build_bazel_rules_cuda", - remote = "https://github.com/liuliu/rules_cuda.git", - commit = "29f3ced1b7541ae629bbfabe0c07dbfe76f29f4d" -) - -load("@build_bazel_rules_cuda//gpus:cuda_configure.bzl", "cuda_configure") - -cuda_configure(name = "local_config_cuda") -``` - -`cuda_library` will be available after `cuda_configure`. An example `BUILD` file could look like this: - -``` -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library") - -cuda_library( - name = "vectorAdd", - srcs = ["vectorAdd.cu"], - hdrs = ["vectorAdd.h"], - visibility = ["//visibility:public"], - deps = [ - "@local_config_cuda//cuda:cuda", - ], -) - -cc_binary( - name='main', - srcs=['main.cc'], - deps=[':vectorAdd'], -) -``` - -Note that you need to add `@local_config_cuda//cuda:cuda` explicitly for your target. To see a list of available ones, you can query `bazel query "deps(@local_config_cuda//cuda:cuda)"` - -## Updates Differ from TensorFlow - - 1. `.cu` is allowed, `gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl` modified to allow `.cu` suffix (it is already allowed from Bazel); - - 2. Removed `TF_DOWNLOAD_CLANG` option. - -## Acknowledgement - -This repository incorporated TensorFlow's CUDA rules, as well as some elements from Joe Toth's example repository: [https://github.com/joetoth/bazel_cuda](https://github.com/joetoth/bazel_cuda). TensorFlow rules updated from commit bde54d7aeaa23a47e1c5900464a8871d643e2e8e. diff --git a/third_party/rules_cuda/WORKSPACE b/third_party/rules_cuda/WORKSPACE deleted file mode 100644 index 44c87f21..00000000 --- a/third_party/rules_cuda/WORKSPACE +++ /dev/null @@ -1,15 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "bazel_skylib", - sha256 = "1dde365491125a3db70731e25658dfdd3bc5dbdfd11b840b3e987ecf043c7ca0", - urls = [ - "https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz", - ], -) - -load("//gpus:cuda_configure.bzl", "cuda_configure") -load("//nccl:nccl_configure.bzl", "nccl_configure") - -cuda_configure(name = "local_config_cuda") -nccl_configure(name = "local_config_nccl") diff --git a/third_party/rules_cuda/gpus/BUILD b/third_party/rules_cuda/gpus/BUILD deleted file mode 100644 index e69de29b..00000000 diff --git a/third_party/rules_cuda/gpus/check_cuda_libs.py b/third_party/rules_cuda/gpus/check_cuda_libs.py deleted file mode 100644 index 686d36f5..00000000 --- a/third_party/rules_cuda/gpus/check_cuda_libs.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2020 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Verifies that a list of libraries is installed on the system. - -Takes a a list of arguments with every two subsequent arguments being a logical -tuple of (path, check_soname). The path to the library and either True or False -to indicate whether to check the soname field on the shared library. - -Example Usage: -./check_cuda_libs.py /path/to/lib1.so True /path/to/lib2.so False -""" -import os -import os.path -import platform -import subprocess -import sys - -# pylint: disable=g-import-not-at-top,g-importing-member -try: - from shutil import which -except ImportError: - from distutils.spawn import find_executable as which -# pylint: enable=g-import-not-at-top,g-importing-member - - -class ConfigError(Exception): - pass - - -def _is_windows(): - return platform.system() == "Windows" - - -def check_cuda_lib(path, check_soname=True): - """Tests if a library exists on disk and whether its soname matches the filename. - - Args: - path: the path to the library. - check_soname: whether to check the soname as well. - - Raises: - ConfigError: If the library does not exist or if its soname does not match - the filename. - """ - if not os.path.isfile(path): - raise ConfigError("No library found under: " + path) - objdump = which("objdump") - if check_soname and objdump is not None and not _is_windows(): - # Decode is necessary as in py3 the return type changed from str to bytes - output = subprocess.check_output([objdump, "-p", path]).decode("utf-8") - output = [line for line in output.splitlines() if "SONAME" in line] - sonames = [line.strip().split(" ")[-1] for line in output] - if not any(soname == os.path.basename(path) for soname in sonames): - raise ConfigError("None of the libraries match their SONAME: " + path) - - -def main(): - try: - args = [argv for argv in sys.argv[1:]] - if len(args) % 2 == 1: - raise ConfigError("Expected even number of arguments") - checked_paths = [] - for i in range(0, len(args), 2): - path = args[i] - check_cuda_lib(path, check_soname=args[i + 1] == "True") - checked_paths.append(path) - # pylint: disable=superfluous-parens - print(os.linesep.join(checked_paths)) - # pylint: enable=superfluous-parens - except ConfigError as e: - sys.stderr.write(str(e)) - sys.exit(1) - - -if __name__ == "__main__": - main() diff --git a/third_party/rules_cuda/gpus/compress_find_cuda_config.py b/third_party/rules_cuda/gpus/compress_find_cuda_config.py deleted file mode 100644 index 9946140f..00000000 --- a/third_party/rules_cuda/gpus/compress_find_cuda_config.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2020 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Compresses the contents of 'find_cuda.py'. - -The compressed file is what is actually being used. It works around remote -config not being able to upload files yet. -""" -import base64 -import zlib - - -def main(): - with open('find_cuda_config.py', 'rb') as f: - data = f.read() - - compressed = zlib.compress(data) - b64encoded = base64.b64encode(compressed) - - with open('find_cuda_config.py.gz.base64', 'wb') as f: - f.write(b64encoded) - - -if __name__ == '__main__': - main() - diff --git a/third_party/rules_cuda/gpus/crosstool/BUILD b/third_party/rules_cuda/gpus/crosstool/BUILD deleted file mode 100644 index e69de29b..00000000 diff --git a/third_party/rules_cuda/gpus/crosstool/BUILD.tpl b/third_party/rules_cuda/gpus/crosstool/BUILD.tpl deleted file mode 100644 index bc92f91a..00000000 --- a/third_party/rules_cuda/gpus/crosstool/BUILD.tpl +++ /dev/null @@ -1,144 +0,0 @@ -# This file is expanded from a template by cuda_configure.bzl -# Update cuda_configure.bzl#verify_build_defines when adding new variables. - -load(":cc_toolchain_config.bzl", "cc_toolchain_config") - -licenses(["restricted"]) - -package(default_visibility = ["//visibility:public"]) - -toolchain( - name = "toolchain-linux-x86_64", - exec_compatible_with = [ - "@bazel_tools//platforms:linux", - "@bazel_tools//platforms:x86_64", - ], - target_compatible_with = [ - "@bazel_tools//platforms:linux", - "@bazel_tools//platforms:x86_64", - ], - toolchain = ":cc-compiler-local", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain_suite( - name = "toolchain", - toolchains = { - "local|compiler": ":cc-compiler-local", - "darwin|compiler": ":cc-compiler-darwin", - "x64_windows|msvc-cl": ":cc-compiler-windows", - "x64_windows": ":cc-compiler-windows", - "arm": ":cc-compiler-local", - "aarch64": ":cc-compiler-local", - "k8": ":cc-compiler-local", - "piii": ":cc-compiler-local", - "ppc": ":cc-compiler-local", - "darwin": ":cc-compiler-darwin", - }, -) - -cc_toolchain( - name = "cc-compiler-local", - all_files = "%{compiler_deps}", - compiler_files = "%{compiler_deps}", - ar_files = "%{compiler_deps}", - as_files = "%{compiler_deps}", - dwp_files = ":empty", - linker_files = "%{compiler_deps}", - objcopy_files = ":empty", - strip_files = ":empty", - # To support linker flags that need to go to the start of command line - # we need the toolchain to support parameter files. Parameter files are - # last on the command line and contain all shared libraries to link, so all - # regular options will be left of them. - supports_param_files = 1, - toolchain_identifier = "local_linux", - toolchain_config = ":cc-compiler-local-config", -) - -cc_toolchain_config( - name = "cc-compiler-local-config", - cpu = "local", - builtin_include_directories = [%{cxx_builtin_include_directories}], - extra_no_canonical_prefixes_flags = [%{extra_no_canonical_prefixes_flags}], - host_compiler_path = "%{host_compiler_path}", - host_compiler_prefix = "%{host_compiler_prefix}", - host_compiler_warnings = [%{host_compiler_warnings}], - host_unfiltered_compile_flags = [%{unfiltered_compile_flags}], - linker_bin_path = "%{linker_bin_path}", - builtin_sysroot = "%{builtin_sysroot}", - cuda_path = "%{cuda_toolkit_path}", - compiler = "%{compiler}", -) - -cc_toolchain( - name = "cc-compiler-darwin", - all_files = "%{compiler_deps}", - compiler_files = "%{compiler_deps}", - ar_files = "%{compiler_deps}", - as_files = "%{compiler_deps}", - dwp_files = ":empty", - linker_files = "%{compiler_deps}", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_identifier = "local_darwin", - toolchain_config = ":cc-compiler-local-darwin", -) - -cc_toolchain_config( - name = "cc-compiler-local-darwin", - cpu = "darwin", - builtin_include_directories = [%{cxx_builtin_include_directories}], - extra_no_canonical_prefixes_flags = [%{extra_no_canonical_prefixes_flags}], - host_compiler_path = "%{host_compiler_path}", - host_compiler_prefix = "%{host_compiler_prefix}", - host_compiler_warnings = [%{host_compiler_warnings}], - host_unfiltered_compile_flags = [%{unfiltered_compile_flags}], - linker_bin_path = "%{linker_bin_path}", -) - -cc_toolchain( - name = "cc-compiler-windows", - all_files = "%{win_compiler_deps}", - compiler_files = "%{win_compiler_deps}", - ar_files = "%{win_compiler_deps}", - as_files = "%{win_compiler_deps}", - dwp_files = ":empty", - linker_files = "%{win_compiler_deps}", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, - toolchain_identifier = "local_windows", - toolchain_config = ":cc-compiler-windows-config", -) - -cc_toolchain_config( - name = "cc-compiler-windows-config", - cpu = "x64_windows", - builtin_include_directories = [%{cxx_builtin_include_directories}], - msvc_cl_path = "%{msvc_cl_path}", - msvc_env_include = "%{msvc_env_include}", - msvc_env_lib = "%{msvc_env_lib}", - msvc_env_path = "%{msvc_env_path}", - msvc_env_tmp = "%{msvc_env_tmp}", - msvc_lib_path = "%{msvc_lib_path}", - msvc_link_path = "%{msvc_link_path}", - msvc_ml_path = "%{msvc_ml_path}", - compiler = "msvc", -) - -filegroup( - name = "empty", - srcs = [], -) - -filegroup( - name = "crosstool_wrapper_driver_is_not_gcc", - srcs = ["clang/bin/crosstool_wrapper_driver_is_not_gcc"], -) - -filegroup( - name = "windows_msvc_wrapper_files", - srcs = glob(["windows/msvc_*"]), -) diff --git a/third_party/rules_cuda/gpus/crosstool/LICENSE b/third_party/rules_cuda/gpus/crosstool/LICENSE deleted file mode 100644 index d3da2284..00000000 --- a/third_party/rules_cuda/gpus/crosstool/LICENSE +++ /dev/null @@ -1,203 +0,0 @@ -Copyright 2015 The TensorFlow Authors. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2015, The TensorFlow Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/third_party/rules_cuda/gpus/crosstool/cc_toolchain_config.bzl.tpl b/third_party/rules_cuda/gpus/crosstool/cc_toolchain_config.bzl.tpl deleted file mode 100644 index afc8132b..00000000 --- a/third_party/rules_cuda/gpus/crosstool/cc_toolchain_config.bzl.tpl +++ /dev/null @@ -1,1090 +0,0 @@ -"""cc_toolchain_config rule for configuring CUDA toolchains on Linux, Mac, and Windows.""" - -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "artifact_name_pattern", - "env_entry", - "env_set", - "feature", - "feature_set", - "flag_group", - "flag_set", - "tool", - "tool_path", - "variable_with_value", - "with_feature_set", -) -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") - -def all_assembly_actions(): - return [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ] - -def all_compile_actions(): - return [ - ACTION_NAMES.assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ] - -def all_c_compile_actions(): - return [ - ACTION_NAMES.c_compile, - ] - -def all_cpp_compile_actions(): - return [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.linkstamp_compile, - ] - -def all_preprocessed_actions(): - return [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ] - -def all_link_actions(): - return [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ] - -def all_executable_link_actions(): - return [ - ACTION_NAMES.cpp_link_executable, - ] - -def all_shared_library_link_actions(): - return [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ] - -def all_archive_actions(): - return [ACTION_NAMES.cpp_link_static_library] - -def all_strip_actions(): - return [ACTION_NAMES.strip] - -def _library_to_link(flag_prefix, value, iterate = None): - return flag_group( - flags = [ - "{}%{{libraries_to_link.{}}}".format( - flag_prefix, - iterate if iterate else "name", - ), - ], - iterate_over = ("libraries_to_link." + iterate if iterate else None), - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = value, - ), - ) - -def _surround_static_library(prefix, suffix): - return [ - flag_group( - flags = [prefix, "%{libraries_to_link.name}", suffix], - expand_if_true = "libraries_to_link.is_whole_archive", - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_false = "libraries_to_link.is_whole_archive", - ), - ] - -def _prefix_static_library(prefix): - return [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_false = "libraries_to_link.is_whole_archive", - ), - flag_group( - flags = [prefix + "%{libraries_to_link.name}"], - expand_if_true = "libraries_to_link.is_whole_archive", - ), - ] - -def _static_library_to_link(alwayslink_prefix, alwayslink_suffix = None): - if alwayslink_suffix: - flag_groups = _surround_static_library(alwayslink_prefix, alwayslink_suffix) - else: - flag_groups = _prefix_static_library(alwayslink_prefix) - return flag_group( - flag_groups = flag_groups, - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ) - -def _iterate_flag_group(iterate_over, flags = [], flag_groups = []): - return flag_group( - iterate_over = iterate_over, - expand_if_available = iterate_over, - flag_groups = flag_groups, - flags = flags, - ) - -def _libraries_to_link_group(flavour): - if flavour == "linux": - return _iterate_flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["-Wl,--start-lib"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - _library_to_link("", "object_file_group", "object_files"), - flag_group( - flags = ["-Wl,--end-lib"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - _library_to_link("", "object_file"), - _library_to_link("", "interface_library"), - _static_library_to_link("-Wl,-whole-archive", "-Wl,-no-whole-archive"), - _library_to_link("-l", "dynamic_library"), - _library_to_link("-l:", "versioned_dynamic_library"), - ], - ) - elif flavour == "darwin": - return _iterate_flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - _library_to_link("", "object_file_group", "object_files"), - _library_to_link("", "object_file"), - _library_to_link("", "interface_library"), - _static_library_to_link("-Wl,-force_load,"), - _library_to_link("-l", "dynamic_library"), - _library_to_link("-l:", "versioned_dynamic_library"), - ], - ) - elif flavour == "msvc": - return _iterate_flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - _library_to_link("", "object_file_group", "object_files"), - _library_to_link("", "object_file"), - _library_to_link("", "interface_library"), - _static_library_to_link("/WHOLEARCHIVE:"), - ], - ) - -def _action_configs_with_tool(path, actions): - return [ - action_config( - action_name = name, - enabled = True, - tools = [tool(path = path)], - ) - for name in actions - ] - -def _action_configs(assembly_path, c_compiler_path, cc_compiler_path, archiver_path, linker_path, strip_path): - return _action_configs_with_tool( - assembly_path, - all_assembly_actions(), - ) + _action_configs_with_tool( - c_compiler_path, - all_c_compile_actions(), - ) + _action_configs_with_tool( - cc_compiler_path, - all_cpp_compile_actions(), - ) + _action_configs_with_tool( - archiver_path, - all_archive_actions(), - ) + _action_configs_with_tool( - linker_path, - all_link_actions(), - ) + _action_configs_with_tool( - strip_path, - all_strip_actions(), - ) - -def _tool_paths(cpu, ctx): - if cpu in ["local", "darwin"]: - return [ - tool_path(name = "gcc", path = ctx.attr.host_compiler_path), - tool_path(name = "ar", path = ctx.attr.host_compiler_prefix + ( - "/ar" if cpu == "local" else "/libtool" - )), - tool_path(name = "compat-ld", path = ctx.attr.host_compiler_prefix + "/ld"), - tool_path(name = "cpp", path = ctx.attr.host_compiler_prefix + "/cpp"), - tool_path(name = "dwp", path = ctx.attr.host_compiler_prefix + "/dwp"), - tool_path(name = "gcov", path = ctx.attr.host_compiler_prefix + "/gcov"), - tool_path(name = "ld", path = ctx.attr.host_compiler_prefix + "/ld"), - tool_path(name = "nm", path = ctx.attr.host_compiler_prefix + "/nm"), - tool_path(name = "objcopy", path = ctx.attr.host_compiler_prefix + "/objcopy"), - tool_path(name = "objdump", path = ctx.attr.host_compiler_prefix + "/objdump"), - tool_path(name = "strip", path = ctx.attr.host_compiler_prefix + "/strip"), - ] - elif cpu == "x64_windows": - return [ - tool_path(name = "ar", path = ctx.attr.msvc_lib_path), - tool_path(name = "ml", path = ctx.attr.msvc_ml_path), - tool_path(name = "cpp", path = ctx.attr.msvc_cl_path), - tool_path(name = "gcc", path = ctx.attr.msvc_cl_path), - tool_path(name = "gcov", path = "wrapper/bin/msvc_nop.bat"), - tool_path(name = "ld", path = ctx.attr.msvc_link_path), - tool_path(name = "nm", path = "wrapper/bin/msvc_nop.bat"), - tool_path( - name = "objcopy", - path = "wrapper/bin/msvc_nop.bat", - ), - tool_path( - name = "objdump", - path = "wrapper/bin/msvc_nop.bat", - ), - tool_path( - name = "strip", - path = "wrapper/bin/msvc_nop.bat", - ), - ] - else: - fail("Unreachable") - -def _sysroot_group(): - return flag_group( - flags = ["--sysroot=%{sysroot}"], - expand_if_available = "sysroot", - ) - -def _no_canonical_prefixes_group(extra_flags): - return flag_group( - flags = [ - "-no-canonical-prefixes", - ] + extra_flags, - ) - -def _cuda_set(cuda_path, actions): - if cuda_path: - return [flag_set( - actions = actions, - flag_groups = [ - flag_group( - flags = ["--cuda-path=" + cuda_path], - ), - ], - )] - else: - return [] - -def _nologo(): - return flag_group(flags = ["/nologo"]) - -def _features(cpu, compiler, ctx): - if cpu in ["local", "darwin"]: - return [ - feature(name = "no_legacy_features"), - feature( - name = "all_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions(), - flag_groups = [ - flag_group( - flags = ["-MD", "-MF", "%{dependency_file}"], - expand_if_available = "dependency_file", - ), - flag_group( - flags = ["-gsplit-dwarf"], - expand_if_available = "per_object_debug_info_file", - ), - ], - ), - flag_set( - actions = all_preprocessed_actions(), - flag_groups = [ - flag_group( - flags = ["-frandom-seed=%{output_file}"], - expand_if_available = "output_file", - ), - _iterate_flag_group( - flags = ["-D%{preprocessor_defines}"], - iterate_over = "preprocessor_defines", - ), - _iterate_flag_group( - flags = ["-include", "%{includes}"], - iterate_over = "includes", - ), - _iterate_flag_group( - flags = ["-iquote", "%{quote_include_paths}"], - iterate_over = "quote_include_paths", - ), - _iterate_flag_group( - flags = ["-I%{include_paths}"], - iterate_over = "include_paths", - ), - _iterate_flag_group( - flags = ["-isystem", "%{system_include_paths}"], - iterate_over = "system_include_paths", - ), - _iterate_flag_group( - flags = ["-F", "%{framework_include_paths}"], - iterate_over = "framework_include_paths", - ), - ], - ), - flag_set( - actions = all_cpp_compile_actions(), - flag_groups = [ - flag_group(flags = ["-fexperimental-new-pass-manager"]), - ] if compiler == "clang" else [], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [ - flag_group( - flags = [ - "-Wno-builtin-macro-redefined", - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - ], - ), - flag_group( - flags = ["-fPIC"], - expand_if_available = "pic", - ), - flag_group( - flags = ["-fPIE"], - expand_if_not_available = "pic", - ), - flag_group( - flags = [ - "-U_FORTIFY_SOURCE", - "-D_FORTIFY_SOURCE=1", - "-fstack-protector", - "-Wall", - ] + ctx.attr.host_compiler_warnings + [ - "-fno-omit-frame-pointer", - ], - ), - _no_canonical_prefixes_group( - ctx.attr.extra_no_canonical_prefixes_flags, - ), - ], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["-DNDEBUG"])], - with_features = [with_feature_set(features = ["disable-assertions"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [ - flag_group( - flags = [ - "-g0", - "-O2", - "-ffunction-sections", - "-fdata-sections", - ], - ), - ], - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["-g"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - ] + _cuda_set( - ctx.attr.cuda_path, - all_compile_actions(), - ) + [ - flag_set( - actions = all_compile_actions(), - flag_groups = [ - _iterate_flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - ), - _sysroot_group(), - flag_group( - expand_if_available = "source_file", - flags = ["-c", "%{source_file}"], - ), - flag_group( - expand_if_available = "output_assembly_file", - flags = ["-S"], - ), - flag_group( - expand_if_available = "output_preprocess_file", - flags = ["-E"], - ), - flag_group( - expand_if_available = "output_file", - flags = ["-o", "%{output_file}"], - ), - ], - ), - ], - ), - feature( - name = "all_archive_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_archive_actions(), - flag_groups = [ - flag_group( - expand_if_available = "linker_param_file", - flags = ["@%{linker_param_file}"], - ), - flag_group(flags = ["rcsD"]), - flag_group( - flags = ["%{output_execpath}"], - expand_if_available = "output_execpath", - ), - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - ], - ), - feature( - name = "all_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_shared_library_link_actions(), - flag_groups = [flag_group(flags = ["-shared"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [ - flag_group(flags = ( - ["-Wl,-no-as-needed"] if cpu == "local" else [] - ) + [ - "-B" + ctx.attr.linker_bin_path, - ]), - flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - ), - _iterate_flag_group( - flags = ["%{linkstamp_paths}"], - iterate_over = "linkstamp_paths", - ), - flag_group( - flags = ["-o", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - _iterate_flag_group( - flags = ["-L%{library_search_directories}"], - iterate_over = "library_search_directories", - ), - _iterate_flag_group( - iterate_over = "runtime_library_search_directories", - flags = [ - "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", - ] if cpu == "local" else [ - "-Wl,-rpath,@loader_path/%{runtime_library_search_directories}", - ], - ), - _libraries_to_link_group("darwin" if cpu == "darwin" else "linux"), - _iterate_flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - ), - flag_group( - flags = ["-Wl,--gdb-index"], - expand_if_available = "is_using_fission", - ), - flag_group( - flags = ["-Wl,-S"], - expand_if_available = "strip_debug_symbols", - ), - flag_group(flags = ["-lc++" if cpu == "darwin" else "-lstdc++"]), - _no_canonical_prefixes_group( - ctx.attr.extra_no_canonical_prefixes_flags, - ), - ], - ), - flag_set( - actions = all_executable_link_actions(), - flag_groups = [flag_group(flags = ["-pie"])], - ), - ] + ([ - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = [ - "-Wl,-z,relro,-z,now", - ])], - ), - ] if cpu == "local" else []) + ([ - flag_set( - actions = all_link_actions(), - flag_groups = [ - flag_group(flags = ["-Wl,--gc-sections"]), - flag_group( - flags = ["-Wl,--build-id=md5", "-Wl,--hash-style=gnu"], - ), - ], - ), - ] if cpu == "local" else []) + ([ - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = ["-undefined", "dynamic_lookup"])], - ), - ] if cpu == "darwin" else []) + _cuda_set( - ctx.attr.cuda_path, - all_link_actions(), - ) + [ - flag_set( - actions = all_link_actions(), - flag_groups = [ - _sysroot_group(), - ], - ), - ], - ), - feature(name = "disable-assertions"), - feature( - name = "opt", - implies = ["disable-assertions"], - ), - feature(name = "fastbuild"), - feature(name = "dbg"), - feature(name = "supports_dynamic_linker", enabled = True), - feature(name = "pic", enabled = True), - feature(name = "supports_pic", enabled = True), - feature(name = "has_configured_linker_path", enabled = True), - ] - elif cpu == "x64_windows": - return [ - feature(name = "no_legacy_features"), - feature( - name = "common_flags", - enabled = True, - env_sets = [ - env_set( - actions = all_compile_actions() + all_link_actions() + all_archive_actions(), - env_entries = [ - env_entry(key = "PATH", value = ctx.attr.msvc_env_path), - env_entry(key = "INCLUDE", value = ctx.attr.msvc_env_include), - env_entry(key = "LIB", value = ctx.attr.msvc_env_lib), - env_entry(key = "TMP", value = ctx.attr.msvc_env_tmp), - env_entry(key = "TEMP", value = ctx.attr.msvc_env_tmp), - ], - ), - ], - ), - feature( - name = "all_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions(), - flag_groups = [ - flag_group( - flags = [ - "-B", - "external/local_config_cuda/crosstool/windows/msvc_wrapper_for_nvcc.py", - ], - ), - _nologo(), - flag_group( - flags = [ - "/DCOMPILER_MSVC", - "/DNOMINMAX", - "/D_WIN32_WINNT=0x0600", - "/D_CRT_SECURE_NO_DEPRECATE", - "/D_CRT_SECURE_NO_WARNINGS", - "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS", - "/bigobj", - "/Zm500", - "/J", - "/Gy", - "/GF", - "/EHsc", - "/wd4351", - "/wd4291", - "/wd4250", - "/wd4996", - ], - ), - _iterate_flag_group( - flags = ["/I%{quote_include_paths}"], - iterate_over = "quote_include_paths", - ), - _iterate_flag_group( - flags = ["/I%{include_paths}"], - iterate_over = "include_paths", - ), - _iterate_flag_group( - flags = ["/I%{system_include_paths}"], - iterate_over = "system_include_paths", - ), - _iterate_flag_group( - flags = ["/D%{preprocessor_defines}"], - iterate_over = "preprocessor_defines", - ), - ], - ), - flag_set( - actions = all_preprocessed_actions(), - flag_groups = [flag_group(flags = ["/showIncludes"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/MT"])], - with_features = [with_feature_set(features = ["static_link_msvcrt_no_debug"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/MD"])], - with_features = [with_feature_set(features = ["dynamic_link_msvcrt_no_debug"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/MTd"])], - with_features = [with_feature_set(features = ["static_link_msvcrt_debug"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/MDd"])], - with_features = [with_feature_set(features = ["dynamic_link_msvcrt_debug"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/Od", "/Z7", "/DDEBUG"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/Od", "/Z7", "/DDEBUG"])], - with_features = [with_feature_set(features = ["fastbuild"])], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [flag_group(flags = ["/O2", "/DNDEBUG"])], - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_preprocessed_actions(), - flag_groups = [ - _iterate_flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - ), - ] + ([ - flag_group(flags = ctx.attr.host_unfiltered_compile_flags), - ] if ctx.attr.host_unfiltered_compile_flags else []), - ), - flag_set( - actions = [ACTION_NAMES.assemble], - flag_groups = [ - flag_group( - flag_groups = [ - flag_group( - flags = ["/Fo%{output_file}", "/Zi"], - expand_if_not_available = "output_preprocess_file", - ), - ], - expand_if_available = "output_file", - expand_if_not_available = "output_assembly_file", - ), - ], - ), - flag_set( - actions = all_preprocessed_actions(), - flag_groups = [ - flag_group( - flag_groups = [ - flag_group( - flags = ["/Fo%{output_file}"], - expand_if_not_available = "output_preprocess_file", - ), - ], - expand_if_available = "output_file", - expand_if_not_available = "output_assembly_file", - ), - flag_group( - flag_groups = [ - flag_group( - flags = ["/Fa%{output_file}"], - expand_if_available = "output_assembly_file", - ), - ], - expand_if_available = "output_file", - ), - flag_group( - flag_groups = [ - flag_group( - flags = ["/P", "/Fi%{output_file}"], - expand_if_available = "output_preprocess_file", - ), - ], - expand_if_available = "output_file", - ), - ], - ), - flag_set( - actions = all_compile_actions(), - flag_groups = [ - flag_group( - flags = ["/c", "%{source_file}"], - expand_if_available = "source_file", - ), - ], - ), - ], - ), - feature( - name = "all_archive_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_archive_actions(), - flag_groups = [ - _nologo(), - flag_group( - flags = ["/OUT:%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ), - feature( - name = "all_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_shared_library_link_actions(), - flag_groups = [flag_group(flags = ["/DLL"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [ - _nologo(), - _iterate_flag_group( - flags = ["%{linkstamp_paths}"], - iterate_over = "linkstamp_paths", - ), - flag_group( - flags = ["/OUT:%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - flag_set( - actions = all_shared_library_link_actions(), - flag_groups = [ - flag_group( - flags = ["/IMPLIB:%{interface_library_output_path}"], - expand_if_available = "interface_library_output_path", - ), - ], - ), - flag_set( - actions = all_link_actions() + - all_archive_actions(), - flag_groups = [ - _libraries_to_link_group("msvc"), - ], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [ - flag_group(flags = ["/SUBSYSTEM:CONSOLE"]), - _iterate_flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - ), - flag_group(flags = ["/MACHINE:X64"]), - ], - ), - flag_set( - actions = all_link_actions() + - all_archive_actions(), - flag_groups = [ - flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - ), - ], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmt.lib"])], - with_features = [with_feature_set(features = ["static_link_msvcrt_no_debug"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrt.lib"])], - with_features = [with_feature_set(features = ["dynamic_link_msvcrt_no_debug"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmtd.lib"])], - with_features = [with_feature_set(features = ["static_link_msvcrt_debug"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrtd.lib"])], - with_features = [with_feature_set(features = ["dynamic_link_msvcrt_debug"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [flag_group(flags = ["/DEBUG:FULL", "/INCREMENTAL:NO"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [ - flag_group(flags = ["/DEBUG:FASTLINK", "/INCREMENTAL:NO"]), - ], - with_features = [with_feature_set(features = ["fastbuild"])], - ), - flag_set( - actions = all_link_actions(), - flag_groups = [ - flag_group( - flags = ["/DEF:%{def_file_path}", "/ignore:4070"], - expand_if_available = "def_file_path", - ), - ], - ), - ], - ), - feature(name = "parse_showincludes", enabled = True), - feature(name = "no_stripping", enabled = True), - feature( - name = "targets_windows", - enabled = True, - implies = ["copy_dynamic_libraries_to_binary"], - ), - feature(name = "copy_dynamic_libraries_to_binary"), - feature( - name = "generate_pdb_file", - requires = [ - feature_set(features = ["dbg"]), - feature_set(features = ["fastbuild"]), - ], - ), - feature(name = "static_link_msvcrt"), - feature( - name = "static_link_msvcrt_no_debug", - requires = [ - feature_set(features = ["fastbuild"]), - feature_set(features = ["opt"]), - ], - ), - feature( - name = "dynamic_link_msvcrt_no_debug", - requires = [ - feature_set(features = ["fastbuild"]), - feature_set(features = ["opt"]), - ], - ), - feature( - name = "static_link_msvcrt_debug", - requires = [feature_set(features = ["dbg"])], - ), - feature( - name = "dynamic_link_msvcrt_debug", - requires = [feature_set(features = ["dbg"])], - ), - feature( - name = "dbg", - implies = ["generate_pdb_file"], - ), - feature( - name = "fastbuild", - implies = ["generate_pdb_file"], - ), - feature( - name = "opt", - ), - feature(name = "windows_export_all_symbols"), - feature(name = "no_windows_export_all_symbols"), - feature(name = "supports_dynamic_linker", enabled = True), - feature( - name = "supports_interface_shared_libraries", - enabled = True, - ), - feature(name = "has_configured_linker_path", enabled = True), - ] - else: - fail("Unreachable") - -def _impl(ctx): - cpu = ctx.attr.cpu - compiler = ctx.attr.compiler - - if (cpu == "darwin"): - toolchain_identifier = "local_darwin" - target_cpu = "darwin" - target_libc = "macosx" - compiler = "compiler" - action_configs = _action_configs( - assembly_path = ctx.attr.host_compiler_path, - c_compiler_path = ctx.attr.host_compiler_path, - cc_compiler_path = ctx.attr.host_compiler_path, - archiver_path = ctx.attr.host_compiler_prefix + "/libtool", - linker_path = ctx.attr.host_compiler_path, - strip_path = ctx.attr.host_compiler_prefix + "/strip", - ) - artifact_name_patterns = [] - elif (cpu == "local"): - toolchain_identifier = "local_linux" - target_cpu = "local" - target_libc = "local" - compiler = "compiler" - action_configs = _action_configs( - assembly_path = ctx.attr.host_compiler_path, - c_compiler_path = ctx.attr.host_compiler_path, - cc_compiler_path = ctx.attr.host_compiler_path, - archiver_path = ctx.attr.host_compiler_prefix + "/ar", - linker_path = ctx.attr.host_compiler_path, - strip_path = ctx.attr.host_compiler_prefix + "/strip", - ) - artifact_name_patterns = [] - elif (cpu == "x64_windows"): - toolchain_identifier = "local_windows" - target_cpu = "x64_windows" - target_libc = "msvcrt" - compiler = "msvc-cl" - action_configs = _action_configs( - assembly_path = ctx.attr.msvc_ml_path, - c_compiler_path = ctx.attr.msvc_cl_path, - cc_compiler_path = ctx.attr.msvc_cl_path, - archiver_path = ctx.attr.msvc_lib_path, - linker_path = ctx.attr.msvc_link_path, - strip_path = "fake_tool_strip_not_supported", - ) - artifact_name_patterns = [ - artifact_name_pattern( - category_name = "object_file", - prefix = "", - extension = ".obj", - ), - artifact_name_pattern( - category_name = "static_library", - prefix = "", - extension = ".lib", - ), - artifact_name_pattern( - category_name = "alwayslink_static_library", - prefix = "", - extension = ".lo.lib", - ), - artifact_name_pattern( - category_name = "executable", - prefix = "", - extension = ".exe", - ), - artifact_name_pattern( - category_name = "dynamic_library", - prefix = "", - extension = ".dll", - ), - artifact_name_pattern( - category_name = "interface_library", - prefix = "", - extension = ".if.lib", - ), - ] - else: - fail("Unreachable") - - out = ctx.actions.declare_file(ctx.label.name) - ctx.actions.write(out, "Fake executable") - return [ - cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = _features(cpu, compiler, ctx), - action_configs = action_configs, - artifact_name_patterns = artifact_name_patterns, - cxx_builtin_include_directories = ctx.attr.builtin_include_directories, - toolchain_identifier = toolchain_identifier, - host_system_name = "local", - target_system_name = "local", - target_cpu = target_cpu, - target_libc = target_libc, - compiler = compiler, - abi_version = "local", - abi_libc_version = "local", - tool_paths = _tool_paths(cpu, ctx), - make_variables = [], - builtin_sysroot = ctx.attr.builtin_sysroot, - cc_target_os = None, - ), - DefaultInfo( - executable = out, - ), - ] - -cc_toolchain_config = rule( - implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True, values = ["darwin", "local", "x64_windows"]), - "compiler": attr.string(values = ["clang", "msvc", "unknown"], default = "unknown"), - "builtin_include_directories": attr.string_list(), - "extra_no_canonical_prefixes_flags": attr.string_list(), - "host_compiler_path": attr.string(), - "host_compiler_prefix": attr.string(), - "host_compiler_warnings": attr.string_list(), - "host_unfiltered_compile_flags": attr.string_list(), - "linker_bin_path": attr.string(), - "builtin_sysroot": attr.string(), - "cuda_path": attr.string(), - "msvc_cl_path": attr.string(default = "msvc_not_used"), - "msvc_env_include": attr.string(default = "msvc_not_used"), - "msvc_env_lib": attr.string(default = "msvc_not_used"), - "msvc_env_path": attr.string(default = "msvc_not_used"), - "msvc_env_tmp": attr.string(default = "msvc_not_used"), - "msvc_lib_path": attr.string(default = "msvc_not_used"), - "msvc_link_path": attr.string(default = "msvc_not_used"), - "msvc_ml_path": attr.string(default = "msvc_not_used"), - }, - provides = [CcToolchainConfigInfo], - executable = True, -) diff --git a/third_party/rules_cuda/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl b/third_party/rules_cuda/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl deleted file mode 100755 index 0f16af98..00000000 --- a/third_party/rules_cuda/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl +++ /dev/null @@ -1,413 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2015 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Crosstool wrapper for compiling CUDA programs. - -SYNOPSIS: - crosstool_wrapper_is_not_gcc [options passed in by cc_library() - or cc_binary() rule] - -DESCRIPTION: - This script is expected to be called by the cc_library() or cc_binary() bazel - rules. When the option "-x cuda" is present in the list of arguments passed - to this script, it invokes the nvcc CUDA compiler. Most arguments are passed - as is as a string to --compiler-options of nvcc. When "-x cuda" is not - present, this wrapper invokes hybrid_driver_is_not_gcc with the input - arguments as is. - -NOTES: - Changes to the contents of this file must be propagated from - //third_party/gpus/crosstool/crosstool_wrapper_is_not_gcc to - //third_party/gpus/crosstool/v*/*/clang/bin/crosstool_wrapper_is_not_gcc -""" - -from __future__ import print_function - -__author__ = 'keveman@google.com (Manjunath Kudlur)' - -from argparse import ArgumentParser -import contextlib -import os -import subprocess -import re -import sys -import pipes -import tempfile - -# Template values set by cuda_autoconf. -CPU_COMPILER = ('%{cpu_compiler}') -CPU_CXX_COMPILER = ('%{cpu_cxx_compiler}') -GCC_HOST_COMPILER_PATH = ('%{gcc_host_compiler_path}') - -NVCC_PATH = '%{nvcc_path}' -PREFIX_DIR = os.path.dirname(GCC_HOST_COMPILER_PATH) -NVCC_VERSION = '%{cuda_version}' - -def Log(s): - print('gpus/crosstool: {0}'.format(s)) - -@contextlib.contextmanager -def ClosingFileDescriptor(fd): - try: - yield fd - finally: - os.close(fd) - - -def NormalizeArgs(args): - result = [] - for arg in args: - if arg.startswith('@'): - with open(arg[1:], 'r') as f: - result += [line[:-1] for line in f.readlines()] - else: - result.append(arg) - return result - - -def GetOptionValue(argv, option): - """Extract the list of values for option from the argv list. - - Args: - argv: A list of strings, possibly the argv passed to main(). - option: The option whose value to extract, with the leading '-'. - - Returns: - A list of values, either directly following the option, - (eg., -opt val1 val2) or values collected from multiple occurrences of - the option (eg., -opt val1 -opt val2). - """ - - parser = ArgumentParser() - parser.add_argument(option, nargs='*', action='append') - option = option.lstrip('-').replace('-', '_') - args, _ = parser.parse_known_args(argv) - if not args or not vars(args)[option]: - return [] - else: - return sum(vars(args)[option], []) - - -def GetHostCompilerOptions(argv): - """Collect the -isystem, -iquote, and --sysroot option values from argv. - - Args: - argv: A list of strings, possibly the argv passed to main(). - - Returns: - The string that can be used as the --compiler-options to nvcc. - """ - - parser = ArgumentParser() - parser.add_argument('-isystem', nargs='*', action='append') - parser.add_argument('-iquote', nargs='*', action='append') - parser.add_argument('--sysroot', nargs=1) - parser.add_argument('-g', nargs='*', action='append') - parser.add_argument('-fno-canonical-system-headers', action='store_true') - parser.add_argument('-no-canonical-prefixes', action='store_true') - - args, _ = parser.parse_known_args(argv) - - opts = '' - - if args.isystem: - opts += ' -isystem ' + ' -isystem '.join(sum(args.isystem, [])) - if args.iquote: - opts += ' -iquote ' + ' -iquote '.join(sum(args.iquote, [])) - if args.g: - opts += ' -g' + ' -g'.join(sum(args.g, [])) - if args.fno_canonical_system_headers: - opts += ' -fno-canonical-system-headers' - if args.no_canonical_prefixes: - opts += ' -no-canonical-prefixes' - if args.sysroot: - opts += ' --sysroot ' + args.sysroot[0] - - return opts - -def _update_options(nvcc_options): - if NVCC_VERSION in ("7.0",): - return nvcc_options - - update_options = { "relaxed-constexpr" : "expt-relaxed-constexpr" } - return [ update_options[opt] if opt in update_options else opt - for opt in nvcc_options ] - -def GetNvccOptions(argv): - """Collect the -nvcc_options values from argv. - - Args: - argv: A list of strings, possibly the argv passed to main(). - - Returns: - The string that can be passed directly to nvcc. - """ - - parser = ArgumentParser() - parser.add_argument('-nvcc_options', nargs='*', action='append') - - args, _ = parser.parse_known_args(argv) - - if args.nvcc_options: - options = _update_options(sum(args.nvcc_options, [])) - return ' '.join(['--'+a for a in options]) - return '' - -def system(cmd): - """Invokes cmd with os.system(). - - Args: - cmd: The command. - - Returns: - The exit code if the process exited with exit() or -signal - if the process was terminated by a signal. - """ - retv = os.system(cmd) - if os.WIFEXITED(retv): - return os.WEXITSTATUS(retv) - else: - return -os.WTERMSIG(retv) - -def CompileNvcc(argv, log=False, device_c=False): - """Compile with nvcc using arguments assembled from argv. - - Args: - argv: A list of strings, possibly the argv passed to main(). - log: True if logging is requested. - - Returns: - The return value of calling system('nvcc ' + args) - """ - - host_compiler_options = GetHostCompilerOptions(argv) - host_compiler_options += ' -fcoroutines' - nvcc_compiler_options = GetNvccOptions(argv) - opt_option = GetOptionValue(argv, '-O') - m_options = GetOptionValue(argv, '-m') - m_options = ''.join([' -m' + m for m in m_options if m in ['32', '64']]) - include_options = GetOptionValue(argv, '-I') - out_file = GetOptionValue(argv, '-o') - depfiles = GetOptionValue(argv, '-MF') - defines = GetOptionValue(argv, '-D') - defines = ''.join([' -D' + define for define in defines]) - undefines = GetOptionValue(argv, '-U') - undefines = ''.join([' -U' + define for define in undefines]) - std_options = GetOptionValue(argv, '-std') - # Supported -std flags as of CUDA 9.0. Only keep last to mimic gcc/clang. - nvcc_allowed_std_options = ["c++03", "c++11", "c++14", "c++17", "c++20"] - std_options = ''.join([' -std=' + define - for define in std_options if define in nvcc_allowed_std_options][-1:]) - fatbin_options = ''.join([' --fatbin-options=' + option - for option in GetOptionValue(argv, '-Xcuda-fatbinary')]) - - # The list of source files get passed after the -c option. I don't know of - # any other reliable way to just get the list of source files to be compiled. - src_files = GetOptionValue(argv, '-c') - - # Pass -w through from host to nvcc, but don't do anything fancier with - # warnings-related flags, since they're not necessarily the same across - # compilers. - warning_options = ' -w' if '-w' in argv else '' - - if len(src_files) == 0: - return 1 - if len(out_file) != 1: - return 1 - - opt = (' -O2' if (len(opt_option) > 0 and int(opt_option[0]) > 0) - else ' -g') - - includes = (' -I ' + ' -I '.join(include_options) - if len(include_options) > 0 - else '') - - # Unfortunately, there are other options that have -c prefix too. - # So allowing only those look like C/C++ files. - src_files = [f for f in src_files if - re.search('\.cpp$|\.cc$|\.cu$|\.c$|\.cxx$|\.C$', f)] - srcs = ' '.join(src_files) - out = ' -o ' + out_file[0] - - # We add this -std=c++17 flag, because - # benchmarks could not be compiled without it. - # The `build --cxxopt -std=c++17` flag set in the - # `.bazelrc` file was not passed to the compiler. - # However, this flag is relevant to some modules. - nvccopts = '-std=c++20 ' - - nvccopts += '-D_FORCE_INLINES ' - for capability in GetOptionValue(argv, "--cuda-gpu-arch"): - capability = capability[len('sm_'):] - nvccopts += r'-gencode=arch=compute_%s,\"code=sm_%s\" ' % (capability, - capability) - for capability in GetOptionValue(argv, '--cuda-include-ptx'): - capability = capability[len('sm_'):] - nvccopts += r'-gencode=arch=compute_%s,\"code=compute_%s\" ' % (capability, - capability) - nvccopts += nvcc_compiler_options - nvccopts += ' --keep' # Doesn't actively remove files under /tmp, it causes compilation errors sometimes. - nvccopts += ' --allow-unsupported-compiler' # Allow any version of clang / gcc. - nvccopts += undefines - nvccopts += defines - nvccopts += std_options - nvccopts += m_options - nvccopts += warning_options - nvccopts += fatbin_options - nvccopts += ' --extended-lambda' - nvccopts += ' --expt-relaxed-constexpr' - - if device_c: - nvccopts += ' --device-c' - - if depfiles: - # Generate the dependency file - depfile = depfiles[0] - cmd = (NVCC_PATH + ' ' + nvccopts + - ' --compiler-options "' + host_compiler_options + '"' + - ' --compiler-bindir=' + GCC_HOST_COMPILER_PATH + - ' -I .' + - ' -x cu ' + opt + includes + ' ' + srcs + ' -M -o ' + depfile) - if log: Log(cmd) - exit_status = system(cmd) - if exit_status != 0: - return exit_status - - cmd = (NVCC_PATH + ' ' + nvccopts + - ' --compiler-options "' + host_compiler_options + ' -fPIC"' + - ' --compiler-bindir=' + GCC_HOST_COMPILER_PATH + - ' -I .' + - ' -x cu ' + opt + includes + ' -c ' + srcs + out) - - # TODO(zhengxq): for some reason, 'gcc' needs this help to find 'as'. - # Need to investigate and fix. - cmd = 'PATH=' + PREFIX_DIR + ':$PATH ' + cmd - if log: Log(cmd) - return system(cmd) - -def ProcessLinkArgs(args_fd, argv): - nargs = len(argv) - args = [] - index = 0 - while index < nargs: - arg = argv[index] - if arg == '-o' and index + 1 < nargs: - args += ['-o', argv[index+1]] - index += 1 - elif arg.startswith('-x'): - index += 1 - pass - elif arg == '--cudalog': - pass - elif arg == '-dlink': - args.append(arg) - elif arg.startswith('-'): - os.write(args_fd, str.encode(arg + '\n')) - else: - args.append(arg) - index += 1 - return args - -def LinkNvcc(argv, log=False): - """Link with nvcc using arguments assembled from argv. - - Args: - argv: A list of strings, possibly the argv passed to main(). - log: True if logging is requested. - """ - args_fd, args_path = tempfile.mkstemp(dir='./', suffix='.params') - with ClosingFileDescriptor(args_fd): - args = ProcessLinkArgs(args_fd, argv) - args = [ - '--compiler-options', - '@%s' % args_path - ] + args - # Work around for silencing nvlink warnings - args.append('--gpu-architecture=sm_70') - cmd = [NVCC_PATH] + args - return subprocess.call(cmd) - -def SanitizeFlagfile(in_path, out_fd): - with open(in_path, "r") as in_fp: - for line in in_fp: - if line != "-lstdc++\n": - os.write(out_fd, bytearray(line, 'utf8')) - -def RewriteStaticLinkArgs(argv): - prev_argv = list(argv) - argv = [] - for arg in prev_argv: - if arg == "-lstdc++": - pass - elif arg.startswith("-Wl,@"): - # tempfile.mkstemp will write to the out-of-sandbox tempdir - # unless the user has explicitly set environment variables - # before starting Bazel. But here in $PWD is the Bazel sandbox, - # which will be deleted automatically after the compiler exits. - (flagfile_fd, flagfile_path) = tempfile.mkstemp( - dir='./', suffix=".linker-params") - with ClosingFileDescriptor(flagfile_fd): - SanitizeFlagfile(arg[len("-Wl,@"):], flagfile_fd) - argv.append("-Wl,@" + flagfile_path) - elif arg.startswith("@"): - # tempfile.mkstemp will write to the out-of-sandbox tempdir - # unless the user has explicitly set environment variables - # before starting Bazel. But here in $PWD is the Bazel sandbox, - # which will be deleted automatically after the compiler exits. - (flagfile_fd, flagfile_path) = tempfile.mkstemp( - dir='./', suffix=".linker-params") - with ClosingFileDescriptor(flagfile_fd): - SanitizeFlagfile(arg[len("@"):], flagfile_fd) - argv.append("@" + flagfile_path) - else: - argv.append(arg) - return argv - -def main(): - parser = ArgumentParser() - parser.add_argument('-x', nargs=1) - parser.add_argument('--cuda_log', action='store_true') - parser.add_argument('--device-c', dest='device_c', action='store_true') - normalized_args = NormalizeArgs(sys.argv[1:]) - - args, leftover = parser.parse_known_args(normalized_args) - - if args.x and args.x[0] == 'cuda': - if args.cuda_log: Log('-x cuda') - leftover = [pipes.quote(s) for s in leftover] - if args.cuda_log: Log('using nvcc') - if '-c' in leftover: - return CompileNvcc(leftover, log=args.cuda_log, device_c=args.device_c) - else: - return LinkNvcc(normalized_args, log=args.cuda_log) - - # Strip our flags before passing through to the CPU compiler for files which - # are not -x cuda. We can't just pass 'leftover' because it also strips -x. - # We not only want to pass -x to the CPU compiler, but also keep it in its - # relative location in the argv list (the compiler is actually sensitive to - # this). - cpu_compiler_flags = [flag for flag in sys.argv[1:] - if not flag.startswith(('--cuda_log'))] - - compiler = CPU_COMPILER - if '-static-libstdc++' in normalized_args: - compiler = CPU_CXX_COMPILER - cpu_compiler_flags = RewriteStaticLinkArgs(cpu_compiler_flags) - - return subprocess.call([compiler] + cpu_compiler_flags) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/third_party/rules_cuda/gpus/crosstool/hipcc_cc_toolchain_config.bzl.tpl b/third_party/rules_cuda/gpus/crosstool/hipcc_cc_toolchain_config.bzl.tpl deleted file mode 100644 index e0541def..00000000 --- a/third_party/rules_cuda/gpus/crosstool/hipcc_cc_toolchain_config.bzl.tpl +++ /dev/null @@ -1,1162 +0,0 @@ -"""cc_toolchain_config rule for configuring ROCm toolchain on Linux.""" - -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "feature", - "feature_set", - "flag_group", - "flag_set", - "tool_path", - "variable_with_value", - "with_feature_set", -) -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") - -all_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, -] - -preprocessor_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.clif_match, -] - -codegen_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.lto_backend, -] - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -lto_index_actions = [ - ACTION_NAMES.lto_index_for_executable, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, -] - -def _impl(ctx): - tool_paths = [ - tool_path(name = "gcc", path = ctx.attr.host_compiler_path), - tool_path(name = "ar", path = ctx.attr.host_compiler_prefix + "/ar"), - tool_path(name = "compat-ld", path = ctx.attr.host_compiler_prefix + "/ld"), - tool_path(name = "cpp", path = ctx.attr.host_compiler_prefix + "/cpp"), - tool_path(name = "dwp", path = ctx.attr.host_compiler_prefix + "/dwp"), - tool_path(name = "gcov", path = ctx.attr.host_compiler_prefix + "/gcov"), - tool_path(name = "ld", path = ctx.attr.host_compiler_prefix + "/ld"), - tool_path(name = "nm", path = ctx.attr.host_compiler_prefix + "/nm"), - tool_path(name = "objcopy", path = ctx.attr.host_compiler_prefix + "/objcopy"), - tool_path(name = "objdump", path = ctx.attr.host_compiler_prefix + "/objdump"), - tool_path(name = "strip", path = ctx.attr.host_compiler_prefix + "/strip"), - ] - - action_configs = [] - - supports_pic_feature = feature( - name = "supports_pic", - enabled = True, - ) - supports_start_end_lib_feature = feature( - name = "supports_start_end_lib", - enabled = True, - ) - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.compile_flags, - ), - ] if ctx.attr.compile_flags else []), - ), - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.dbg_compile_flags, - ), - ] if ctx.attr.dbg_compile_flags else []), - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.opt_compile_flags, - ), - ] if ctx.attr.opt_compile_flags else []), - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend], - flag_groups = ([ - flag_group( - flags = ctx.attr.cxx_flags, - ), - ] if ctx.attr.cxx_flags else []), - ), - ], - ) - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.link_flags, - ), - ] if ctx.attr.link_flags else []), - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.opt_link_flags, - ), - ] if ctx.attr.opt_link_flags else []), - with_features = [with_feature_set(features = ["opt"])], - ), - ], - ) - - dbg_feature = feature(name = "dbg") - - opt_feature = feature(name = "opt") - - sysroot_feature = feature( - name = "sysroot", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.lto_backend, - ACTION_NAMES.clif_match, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["--sysroot=%{sysroot}"], - expand_if_available = "sysroot", - ), - ], - ), - ], - ) - - fdo_optimize_feature = feature( - name = "fdo_optimize", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = [ - "-fprofile-use=%{fdo_profile_path}", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.unfiltered_compile_flags, - ), - ] if ctx.attr.unfiltered_compile_flags else []), - ), - ], - ) - - library_search_directories_feature = feature( - name = "library_search_directories", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-L%{library_search_directories}"], - iterate_over = "library_search_directories", - expand_if_available = "library_search_directories", - ), - ], - ), - ], - ) - - static_libgcc_feature = feature( - name = "static_libgcc", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.lto_index_for_executable, - ACTION_NAMES.lto_index_for_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-static-libgcc"])], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - ], - ) - - pic_feature = feature( - name = "pic", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group(flags = ["-fPIC"], expand_if_available = "pic"), - ], - ), - ], - ) - - per_object_debug_info_feature = feature( - name = "per_object_debug_info", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["-gsplit-dwarf"], - expand_if_available = "per_object_debug_info_file", - ), - ], - ), - ], - ) - - preprocessor_defines_feature = feature( - name = "preprocessor_defines", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["-D%{preprocessor_defines}"], - iterate_over = "preprocessor_defines", - ), - ], - ), - ], - ) - - cs_fdo_optimize_feature = feature( - name = "cs_fdo_optimize", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.lto_backend], - flag_groups = [ - flag_group( - flags = [ - "-fprofile-use=%{fdo_profile_path}", - "-Xclang-only=-Wno-profile-instr-unprofiled", - "-Xclang-only=-Wno-profile-instr-out-of-date", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["csprofile"], - ) - - autofdo_feature = feature( - name = "autofdo", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = [ - "-fauto-profile=%{fdo_profile_path}", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}", - ], - expand_if_true = "is_cc_test", - ), - flag_group( - flags = [ - "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", - ], - expand_if_false = "is_cc_test", - ), - ], - expand_if_available = - "runtime_library_search_directories", - ), - ], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", - ], - ), - ], - expand_if_available = - "runtime_library_search_directories", - ), - ], - with_features = [ - with_feature_set( - not_features = ["static_link_cpp_runtimes"], - ), - ], - ), - ], - ) - - fission_support_feature = feature( - name = "fission_support", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,--gdb-index"], - expand_if_available = "is_using_fission", - ), - ], - ), - ], - ) - - shared_flag_feature = feature( - name = "shared_flag", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-shared"])], - ), - ], - ) - - random_seed_feature = feature( - name = "random_seed", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group( - flags = ["-frandom-seed=%{output_file}"], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - includes_feature = feature( - name = "includes", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.clif_match, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = ["-include", "%{includes}"], - iterate_over = "includes", - expand_if_available = "includes", - ), - ], - ), - ], - ) - - fdo_instrument_feature = feature( - name = "fdo_instrument", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = [ - "-fprofile-generate=%{fdo_instrument_path}", - "-fno-data-sections", - ], - expand_if_available = "fdo_instrument_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - cs_fdo_instrument_feature = feature( - name = "cs_fdo_instrument", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.lto_backend, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = [ - "-fcs-profile-generate=%{cs_fdo_instrument_path}", - ], - expand_if_available = "cs_fdo_instrument_path", - ), - ], - ), - ], - provides = ["csprofile"], - ) - - include_paths_feature = feature( - name = "include_paths", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.clif_match, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = ["-iquote", "%{quote_include_paths}"], - iterate_over = "quote_include_paths", - ), - flag_group( - flags = ["-I%{include_paths}"], - iterate_over = "include_paths", - ), - flag_group( - flags = ["-isystem", "%{system_include_paths}"], - iterate_over = "system_include_paths", - ), - ], - ), - ], - ) - - symbol_counts_feature = feature( - name = "symbol_counts", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = [ - "-Wl,--print-symbol-counts=%{symbol_counts_output}", - ], - expand_if_available = "symbol_counts_output", - ), - ], - ), - ], - ) - - llvm_coverage_map_format_feature = feature( - name = "llvm_coverage_map_format", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = [ - "-fprofile-instr-generate", - "-fcoverage-mapping", - ], - ), - ], - ), - flag_set( - actions = all_link_actions + lto_index_actions + [ - "objc-executable", - "objc++-executable", - ], - flag_groups = [ - flag_group(flags = ["-fprofile-instr-generate"]), - ], - ), - ], - requires = [feature_set(features = ["coverage"])], - provides = ["profile"], - ) - - strip_debug_symbols_feature = feature( - name = "strip_debug_symbols", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,-S"], - expand_if_available = "strip_debug_symbols", - ), - ], - ), - ], - ) - - build_interface_libraries_feature = feature( - name = "build_interface_libraries", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [ - "%{generate_interface_library}", - "%{interface_library_builder_path}", - "%{interface_library_input_path}", - "%{interface_library_output_path}", - ], - expand_if_available = "generate_interface_library", - ), - ], - with_features = [ - with_feature_set( - features = ["supports_interface_shared_libraries"], - ), - ], - ), - ], - ) - - libraries_to_link_feature = feature( - name = "libraries_to_link", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["-Wl,--start-lib"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["-Wl,-whole-archive"], - expand_if_true = - "libraries_to_link.is_whole_archive", - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "interface_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["-l%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "dynamic_library", - ), - ), - flag_group( - flags = ["-l:%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "versioned_dynamic_library", - ), - ), - flag_group( - flags = ["-Wl,-no-whole-archive"], - expand_if_true = "libraries_to_link.is_whole_archive", - ), - flag_group( - flags = ["-Wl,--end-lib"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - flag_group( - flags = ["-Wl,@%{thinlto_param_file}"], - expand_if_true = "thinlto_param_file", - ), - ], - ), - ], - ) - - user_link_flags_feature = feature( - name = "user_link_flags", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - expand_if_available = "user_link_flags", - ), - ] + ([flag_group(flags = ctx.attr.link_libs)] if ctx.attr.link_libs else []), - ), - ], - ) - - fdo_prefetch_hints_feature = feature( - name = "fdo_prefetch_hints", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.lto_backend, - ], - flag_groups = [ - flag_group( - flags = [ - "-Xclang-only=-mllvm", - "-Xclang-only=-prefetch-hints-file=%{fdo_prefetch_hints_path}", - ], - expand_if_available = "fdo_prefetch_hints_path", - ), - ], - ), - ], - ) - - linkstamps_feature = feature( - name = "linkstamps", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["%{linkstamp_paths}"], - iterate_over = "linkstamp_paths", - expand_if_available = "linkstamp_paths", - ), - ], - ), - ], - ) - - gcc_coverage_map_format_feature = feature( - name = "gcc_coverage_map_format", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - "objc-executable", - "objc++-executable", - ], - flag_groups = [ - flag_group( - flags = ["-fprofile-arcs", "-ftest-coverage"], - expand_if_available = "gcov_gcno_file", - ), - ], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [flag_group(flags = ["--coverage"])], - ), - ], - requires = [feature_set(features = ["coverage"])], - provides = ["profile"], - ) - - archiver_flags_feature = feature( - name = "archiver_flags", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group(flags = ["rcsD"]), - flag_group( - flags = ["%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - ], - ) - - force_pic_flags_feature = feature( - name = "force_pic_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.lto_index_for_executable, - ], - flag_groups = [ - flag_group( - flags = ["-pie"], - expand_if_available = "force_pic", - ), - ], - ), - ], - ) - - dependency_file_feature = feature( - name = "dependency_file", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["-MD", "-MF", "%{dependency_file}"], - expand_if_available = "dependency_file", - ), - ], - ), - ], - ) - - dynamic_library_linker_tool_path = tool_paths - dynamic_library_linker_tool_feature = feature( - name = "dynamic_library_linker_tool", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [" + cppLinkDynamicLibraryToolPath + "], - expand_if_available = "generate_interface_library", - ), - ], - with_features = [ - with_feature_set( - features = ["supports_interface_shared_libraries"], - ), - ], - ), - ], - ) - - output_execpath_flags_feature = feature( - name = "output_execpath_flags", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-o", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - # Note that we also set --coverage for c++-link-nodeps-dynamic-library. The - # generated code contains references to gcov symbols, and the dynamic linker - # can't resolve them unless the library is linked against gcov. - coverage_feature = feature( - name = "coverage", - provides = ["profile"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = ([ - flag_group(flags = ctx.attr.coverage_compile_flags), - ] if ctx.attr.coverage_compile_flags else []), - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group(flags = ctx.attr.coverage_link_flags), - ] if ctx.attr.coverage_link_flags else []), - ), - ], - ) - - build_id_feature = feature( - name = "build-id", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,--build-id=md5", "-Wl,--hash-style=gnu"], - ), - ], - ), - ], - ) - - no_canonical_prefixes_feature = feature( - name = "no-canonical-prefixes", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [ - "-no-canonical-prefixes", - "-fno-canonical-system-headers", - ] - ), - ], - ), - ], - ) - - linker_bin_path_feature = feature( - name = "linker-bin-path", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-B" + ctx.attr.linker_bin_path])], - ), - ], - ) - - features = [ - dependency_file_feature, - random_seed_feature, - pic_feature, - per_object_debug_info_feature, - preprocessor_defines_feature, - includes_feature, - include_paths_feature, - fdo_instrument_feature, - cs_fdo_instrument_feature, - cs_fdo_optimize_feature, - fdo_prefetch_hints_feature, - autofdo_feature, - build_interface_libraries_feature, - dynamic_library_linker_tool_feature, - symbol_counts_feature, - shared_flag_feature, - linkstamps_feature, - output_execpath_flags_feature, - runtime_library_search_directories_feature, - library_search_directories_feature, - archiver_flags_feature, - force_pic_flags_feature, - fission_support_feature, - strip_debug_symbols_feature, - coverage_feature, - supports_pic_feature, - ] + ( - [ - supports_start_end_lib_feature, - ] if ctx.attr.supports_start_end_lib else [] - ) + [ - default_compile_flags_feature, - default_link_flags_feature, - libraries_to_link_feature, - user_link_flags_feature, - static_libgcc_feature, - fdo_optimize_feature, - supports_dynamic_linker_feature, - dbg_feature, - opt_feature, - user_compile_flags_feature, - sysroot_feature, - unfiltered_compile_flags_feature, - build_id_feature, - no_canonical_prefixes_feature, - linker_bin_path_feature, - ] - - return cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = features, - action_configs = action_configs, - cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, - toolchain_identifier = ctx.attr.toolchain_identifier, - host_system_name = ctx.attr.host_system_name, - target_system_name = ctx.attr.target_system_name, - target_cpu = ctx.attr.cpu, - target_libc = ctx.attr.target_libc, - compiler = ctx.attr.compiler, - abi_version = ctx.attr.abi_version, - abi_libc_version = ctx.attr.abi_libc_version, - tool_paths = tool_paths, - ) - -cc_toolchain_config = rule( - implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True), - "compiler": attr.string(mandatory = True), - "toolchain_identifier": attr.string(mandatory = True), - "host_system_name": attr.string(mandatory = True), - "target_system_name": attr.string(mandatory = True), - "target_libc": attr.string(mandatory = True), - "abi_version": attr.string(mandatory = True), - "abi_libc_version": attr.string(mandatory = True), - "cxx_builtin_include_directories": attr.string_list(), - "compile_flags": attr.string_list(), - "dbg_compile_flags": attr.string_list(), - "opt_compile_flags": attr.string_list(), - "cxx_flags": attr.string_list(), - "link_flags": attr.string_list(), - "link_libs": attr.string_list(), - "opt_link_flags": attr.string_list(), - "unfiltered_compile_flags": attr.string_list(), - "coverage_compile_flags": attr.string_list(), - "coverage_link_flags": attr.string_list(), - "supports_start_end_lib": attr.bool(), - "host_compiler_path": attr.string(), - "host_compiler_prefix": attr.string(), - "linker_bin_path": attr.string(), - }, - provides = [CcToolchainConfigInfo], -) - diff --git a/third_party/rules_cuda/gpus/crosstool/windows/msvc_wrapper_for_nvcc.py.tpl b/third_party/rules_cuda/gpus/crosstool/windows/msvc_wrapper_for_nvcc.py.tpl deleted file mode 100644 index 7e067496..00000000 --- a/third_party/rules_cuda/gpus/crosstool/windows/msvc_wrapper_for_nvcc.py.tpl +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/env python -# Copyright 2015 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Crosstool wrapper for compiling CUDA programs with nvcc on Windows. - -DESCRIPTION: - This script is the Windows version of //third_party/gpus/crosstool/crosstool_wrapper_is_not_gcc -""" - -from __future__ import print_function - -from argparse import ArgumentParser -import os -import subprocess -import re -import sys -import pipes -import tempfile - -# Template values set by cuda_autoconf. -CPU_COMPILER = ('%{cpu_compiler}') -GCC_HOST_COMPILER_PATH = ('%{gcc_host_compiler_path}') - -NVCC_PATH = '%{nvcc_path}' -NVCC_VERSION = '%{cuda_version}' -NVCC_TEMP_DIR = "%{nvcc_tmp_dir}" - -def Log(s): - print('gpus/crosstool: {0}'.format(s)) - - -def GetOptionValue(argv, option): - """Extract the list of values for option from options. - - Args: - option: The option whose value to extract. - - Returns: - 1. A list of values, either directly following the option, - (eg., /opt val1 val2) or values collected from multiple occurrences of - the option (eg., /opt val1 /opt val2). - 2. The leftover options. - """ - - parser = ArgumentParser(prefix_chars='-/') - parser.add_argument(option, nargs='*', action='append') - option = option.lstrip('-/').replace('-', '_') - args, leftover = parser.parse_known_args(argv) - if args and vars(args)[option]: - return (sum(vars(args)[option], []), leftover) - return ([], leftover) - -def _update_options(nvcc_options): - if NVCC_VERSION in ("7.0",): - return nvcc_options - - update_options = { "relaxed-constexpr" : "expt-relaxed-constexpr" } - return [ update_options[opt] if opt in update_options else opt - for opt in nvcc_options ] - -def GetNvccOptions(argv): - """Collect the -nvcc_options values from argv. - - Args: - argv: A list of strings, possibly the argv passed to main(). - - Returns: - 1. The string that can be passed directly to nvcc. - 2. The leftover options. - """ - - parser = ArgumentParser() - parser.add_argument('-nvcc_options', nargs='*', action='append') - - args, leftover = parser.parse_known_args(argv) - - if args.nvcc_options: - options = _update_options(sum(args.nvcc_options, [])) - return (['--' + a for a in options], leftover) - return ([], leftover) - - -def InvokeNvcc(argv, log=False): - """Call nvcc with arguments assembled from argv. - - Args: - argv: A list of strings, possibly the argv passed to main(). - log: True if logging is requested. - - Returns: - The return value of calling os.system('nvcc ' + args) - """ - - src_files = [f for f in argv if - re.search('\.cpp$|\.cc$|\.c$|\.cxx$|\.C$', f)] - if len(src_files) == 0: - raise Error('No source files found for cuda compilation.') - - out_file = [ f for f in argv if f.startswith('/Fo') ] - if len(out_file) != 1: - raise Error('Please specify exactly one output file for cuda compilation.') - out = ['-o', out_file[0][len('/Fo'):]] - - nvcc_compiler_options, argv = GetNvccOptions(argv) - - opt_option, argv = GetOptionValue(argv, '/O') - opt = ['-g'] - if (len(opt_option) > 0 and opt_option[0] != 'd'): - opt = ['-O2'] - - include_options, argv = GetOptionValue(argv, '/I') - includes = ["-I " + include for include in include_options] - - defines, argv = GetOptionValue(argv, '/D') - defines = ['-D' + define for define in defines] - - undefines, argv = GetOptionValue(argv, '/U') - undefines = ['-U' + define for define in undefines] - - fatbin_options, argv = GetOptionValue(argv, '-Xcuda-fatbinary') - fatbin_options = ['--fatbin-options=' + option for option in fatbin_options] - - # The rest of the unrecognized options should be passed to host compiler - host_compiler_options = [option for option in argv if option not in (src_files + out_file)] - - m_options = ["-m64"] - - nvccopts = ['-D_FORCE_INLINES'] - compute_capabilities, argv = GetOptionValue(argv, "--cuda-gpu-arch") - for capability in compute_capabilities: - capability = capability[len('sm_'):] - nvccopts += [ - r'-gencode=arch=compute_%s,"code=sm_%s"' % (capability, capability) - ] - compute_capabilities, argv = GetOptionValue(argv, '--cuda-include-ptx') - for capability in compute_capabilities: - capability = capability[len('sm_'):] - nvccopts += [ - r'-gencode=arch=compute_%s,"code=compute_%s"' % (capability, capability) - ] - _, argv = GetOptionValue(argv, '--no-cuda-include-ptx') - - nvccopts += nvcc_compiler_options - nvccopts += undefines - nvccopts += defines - nvccopts += m_options - nvccopts += fatbin_options - nvccopts += ['--compiler-options=' + ",".join(host_compiler_options)] - nvccopts += ['-x', 'cu'] + opt + includes + out + ['-c'] + src_files - # Specify a unique temp directory for nvcc to generate intermediate files, - # then Bazel can ignore files under NVCC_TEMP_DIR during dependency check - # http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#options-for-guiding-compiler-driver - # Different actions are sharing NVCC_TEMP_DIR, so we cannot remove it if the directory already exists. - if os.path.isfile(NVCC_TEMP_DIR): - os.remove(NVCC_TEMP_DIR) - if not os.path.exists(NVCC_TEMP_DIR): - os.makedirs(NVCC_TEMP_DIR) - # Provide a unique dir for each compiling action to avoid conflicts. - tempdir = tempfile.mkdtemp(dir = NVCC_TEMP_DIR) - nvccopts += ['--keep', '--keep-dir', tempdir] - if log: - Log([NVCC_PATH] + nvccopts) - - # Store command line options in a file to avoid hitting the character limit. - optsfile = tempfile.NamedTemporaryFile(mode='w', dir=tempdir, delete=False) - optsfile.write("\n".join(nvccopts)) - optsfile.close() - - proc = subprocess.Popen([NVCC_PATH, "--options-file", optsfile.name], - stdout=sys.stdout, - stderr=sys.stderr, - env=os.environ.copy(), - shell=True) - proc.wait() - return proc.returncode - -def main(): - parser = ArgumentParser() - parser.add_argument('-x', nargs=1) - parser.add_argument('--cuda_log', action='store_true') - args, leftover = parser.parse_known_args(sys.argv[1:]) - - if args.x and args.x[0] == 'cuda': - if args.cuda_log: Log('-x cuda') - leftover = [pipes.quote(s) for s in leftover] - if args.cuda_log: Log('using nvcc') - return InvokeNvcc(leftover, log=args.cuda_log) - - # Strip our flags before passing through to the CPU compiler for files which - # are not -x cuda. We can't just pass 'leftover' because it also strips -x. - # We not only want to pass -x to the CPU compiler, but also keep it in its - # relative location in the argv list (the compiler is actually sensitive to - # this). - cpu_compiler_flags = [flag for flag in sys.argv[1:] - if not flag.startswith(('--cuda_log')) - and not flag.startswith(('-nvcc_options'))] - - return subprocess.call([CPU_COMPILER] + cpu_compiler_flags) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/third_party/rules_cuda/gpus/cuda/BUILD b/third_party/rules_cuda/gpus/cuda/BUILD deleted file mode 100644 index e69de29b..00000000 diff --git a/third_party/rules_cuda/gpus/cuda/BUILD.tpl b/third_party/rules_cuda/gpus/cuda/BUILD.tpl deleted file mode 100644 index 7df100a5..00000000 --- a/third_party/rules_cuda/gpus/cuda/BUILD.tpl +++ /dev/null @@ -1,216 +0,0 @@ -load(":build_defs.bzl", "cuda_header_library") -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -licenses(["restricted"]) # MPL2, portions GPL v3, LGPL v3, BSD-like - -package(default_visibility = ["//visibility:public"]) - -config_setting( - name = "using_nvcc", - values = { - "define": "using_cuda_nvcc=true", - }, -) - -config_setting( - name = "using_clang", - values = { - "define": "using_cuda_clang=true", - }, -) - -# Equivalent to using_clang && -c opt. -config_setting( - name = "using_clang_opt", - values = { - "define": "using_cuda_clang=true", - "compilation_mode": "opt", - }, -) - -config_setting( - name = "darwin", - values = {"cpu": "darwin"}, -) - -config_setting( - name = "freebsd", - values = {"cpu": "freebsd"}, -) - -cuda_header_library( - name = "cuda_headers", - hdrs = [ - "cuda/cuda_config.h", - ":cuda-include" - ], - include_prefix = "third_party/gpus", - includes = [ - ".", # required to include cuda/cuda/cuda_config.h as cuda/config.h - "cuda/include", - ], -) - -cc_library( - name = "cudart_static", - srcs = ["cuda/lib/%{cudart_static_lib}"], - linkopts = select({ - ":freebsd": [], - "//conditions:default": ["-ldl"], - }) + [ - "-lpthread", - %{cudart_static_linkopt} - ], -) - -cc_library( - name = "cuda_driver", - srcs = ["cuda/lib/%{cuda_driver_lib}"], -) - -cc_library( - name = "cudart", - srcs = ["cuda/lib/%{cudart_lib}"], - data = ["cuda/lib/%{cudart_lib}"], - linkstatic = 1, -) - -cuda_header_library( - name = "cublas_headers", - hdrs = [":cublas-include"], - include_prefix = "third_party/gpus/cuda/include", - strip_include_prefix = "cublas/include", - deps = [":cuda_headers"], - includes = ["cublas/include"], -) - -cuda_header_library( - name = "cusolver_headers", - hdrs = [":cusolver-include"], - include_prefix = "third_party/gpus/cuda/include", - strip_include_prefix = "cusolver/include", - deps = [":cuda_headers"], - includes = ["cusolver/include"], -) - -cuda_header_library( - name = "cufft_headers", - hdrs = [":cufft-include"], - include_prefix = "third_party/gpus/cuda/include", - strip_include_prefix = "cufft/include", - deps = [":cuda_headers"], - includes = ["cufft/include"], -) - -cuda_header_library( - name = "cusparse_headers", - hdrs = [":cusparse-include"], - include_prefix = "third_party/gpus/cuda/include", - strip_include_prefix = "cusparse/include", - deps = [":cuda_headers"], - includes = ["cusparse/include"], -) - -cuda_header_library( - name = "curand_headers", - hdrs = [":curand-include"], - include_prefix = "third_party/gpus/cuda/include", - strip_include_prefix = "curand/include", - deps = [":cuda_headers"], - includes = ["curand/include"], -) - -cc_library( - name = "cublas", - srcs = ["cuda/lib/%{cublas_lib}"], - data = ["cuda/lib/%{cublas_lib}"], - linkstatic = 1, -) - -cc_library( - name = "cusolver", - srcs = ["cuda/lib/%{cusolver_lib}"], - data = ["cuda/lib/%{cusolver_lib}"], - linkopts = ["-lgomp"], - linkstatic = 1, -) - -cc_library( - name = "cufft", - srcs = ["cuda/lib/%{cufft_lib}"], - data = ["cuda/lib/%{cufft_lib}"], - linkstatic = 1, -) - -cc_library( - name = "curand", - srcs = ["cuda/lib/%{curand_lib}"], - data = ["cuda/lib/%{curand_lib}"], - linkstatic = 1, -) - -cc_library( - name = "cuda", - deps = [ - ":cublas", - ":cuda_headers", - ":cudart", - ":cufft", - ":curand", - ], -) - -alias( - name = "cub_headers", - actual = "%{cub_actual}" -) - -cuda_header_library( - name = "cupti_headers", - hdrs = [":cuda-extras"], - include_prefix="third_party/gpus", - includes = ["cuda/extras/CUPTI/include/"], - deps = [":cuda_headers"], -) - -cc_library( - name = "cupti_dsos", - data = ["cuda/lib/%{cupti_lib}"], -) - -cc_library( - name = "cusparse", - srcs = ["cuda/lib/%{cusparse_lib}"], - data = ["cuda/lib/%{cusparse_lib}"], - linkopts = ["-lgomp"], - linkstatic = 1, -) - -cc_library( - name = "libdevice_root", - data = [":cuda-nvvm"], -) - -filegroup( - name = "cuda_root", - srcs = [ - "cuda/bin/fatbinary", - "cuda/bin/bin2c", - ], -) - -bzl_library( - name = "build_defs_bzl", - srcs = ["build_defs.bzl"], - deps = [ - "@bazel_skylib//lib:selects", - ], -) - -py_library( - name = "cuda_config_py", - srcs = ["cuda/cuda_config.py"] -) - -%{copy_rules} - diff --git a/third_party/rules_cuda/gpus/cuda/BUILD.windows.tpl b/third_party/rules_cuda/gpus/cuda/BUILD.windows.tpl deleted file mode 100644 index 4f9e67c9..00000000 --- a/third_party/rules_cuda/gpus/cuda/BUILD.windows.tpl +++ /dev/null @@ -1,210 +0,0 @@ -load(":build_defs.bzl", "cuda_header_library") -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -licenses(["restricted"]) # MPL2, portions GPL v3, LGPL v3, BSD-like - -package(default_visibility = ["//visibility:public"]) - -config_setting( - name = "using_nvcc", - values = { - "define": "using_cuda_nvcc=true", - }, -) - -config_setting( - name = "using_clang", - values = { - "define": "using_cuda_clang=true", - }, -) - -# Equivalent to using_clang && -c opt. -config_setting( - name = "using_clang_opt", - values = { - "define": "using_cuda_clang=true", - "compilation_mode": "opt", - }, -) - -config_setting( - name = "darwin", - values = {"cpu": "darwin"}, -) - -config_setting( - name = "freebsd", - values = {"cpu": "freebsd"}, -) - -# Provides CUDA headers for '#include "third_party/gpus/cuda/include/cuda.h"' -# All clients including TensorFlow should use these directives. -cuda_header_library( - name = "cuda_headers", - hdrs = [ - "cuda/cuda_config.h", - ":cuda-include" - ], - include_prefix = "third_party/gpus", - includes = [ - ".", # required to include cuda/cuda/cuda_config.h as cuda/config.h - "cuda/include", - ], -) - -cc_import( - name = "cudart_static", - # /WHOLEARCHIVE:cudart_static.lib will cause a - # "Internal error during CImplib::EmitThunk" error. - # Treat this library as interface library to avoid being whole archived when - # linking a DLL that depends on this. - # TODO(pcloudy): Remove this rule after b/111278841 is resolved. - interface_library = "cuda/lib/%{cudart_static_lib}", - system_provided = 1, -) - -cc_import( - name = "cuda_driver", - interface_library = "cuda/lib/%{cuda_driver_lib}", - system_provided = 1, -) - -cc_import( - name = "cudart", - interface_library = "cuda/lib/%{cudart_lib}", - system_provided = 1, -) - -cuda_header_library( - name = "cublas_headers", - hdrs = [":cublas-include"], - include_prefix = "third_party/gpus/cuda/include", - includes = ["cublas/include"], - strip_include_prefix = "cublas/include", - deps = [":cuda_headers"], -) - -cuda_header_library( - name = "cusolver_headers", - hdrs = [":cusolver-include"], - include_prefix = "third_party/gpus/cuda/include", - includes = ["cusolver/include"], - strip_include_prefix = "cusolver/include", - deps = [":cuda_headers"], -) - -cuda_header_library( - name = "cufft_headers", - hdrs = [":cufft-include"], - include_prefix = "third_party/gpus/cuda/include", - includes = ["cufft/include"], - strip_include_prefix = "cufft/include", - deps = [":cuda_headers"], -) - -cuda_header_library( - name = "cusparse_headers", - hdrs = [":cusparse-include"], - include_prefix = "third_party/gpus/cuda/include", - includes = ["cusparse/include"], - strip_include_prefix = "cusparse/include", - deps = [":cuda_headers"], -) - -cuda_header_library( - name = "curand_headers", - hdrs = [":curand-include"], - include_prefix = "third_party/gpus/cuda/include", - includes = ["curand/include"], - strip_include_prefix = "curand/include", - deps = [":cuda_headers"], -) - -cc_import( - name = "cublas", - interface_library = "cuda/lib/%{cublas_lib}", - system_provided = 1, -) - -cc_import( - name = "cusolver", - interface_library = "cuda/lib/%{cusolver_lib}", - system_provided = 1, -) - -cc_import( - name = "cufft", - interface_library = "cuda/lib/%{cufft_lib}", - system_provided = 1, -) - -cc_import( - name = "curand", - interface_library = "cuda/lib/%{curand_lib}", - system_provided = 1, -) - -cc_library( - name = "cuda", - deps = [ - ":cublas", - ":cuda_headers", - ":cudart", - ":cufft", - ":curand", - ], -) - -alias( - name = "cub_headers", - actual = "%{cub_actual}" -) - -cuda_header_library( - name = "cupti_headers", - hdrs = [":cuda-extras"], - include_prefix="third_party/gpus", - includes = ["cuda/extras/CUPTI/include/"], - deps = [":cuda_headers"], -) - -cc_import( - name = "cupti_dsos", - interface_library = "cuda/lib/%{cupti_lib}", - system_provided = 1, -) - -cc_import( - name = "cusparse", - interface_library = "cuda/lib/%{cusparse_lib}", - system_provided = 1, -) - -cc_library( - name = "libdevice_root", - data = [":cuda-nvvm"], -) - -filegroup( - name = "cuda_root", - srcs = [ - "cuda/bin/fatbinary.exe", - "cuda/bin/bin2c.exe", - ], -) - -bzl_library( - name = "build_defs_bzl", - srcs = ["build_defs.bzl"], - deps = [ - "@bazel_skylib//lib:selects", - ], -) - -py_library( - name = "cuda_config_py", - srcs = ["cuda/cuda_config.py"] -) - -%{copy_rules} diff --git a/third_party/rules_cuda/gpus/cuda/LICENSE b/third_party/rules_cuda/gpus/cuda/LICENSE deleted file mode 100644 index d3da2284..00000000 --- a/third_party/rules_cuda/gpus/cuda/LICENSE +++ /dev/null @@ -1,203 +0,0 @@ -Copyright 2015 The TensorFlow Authors. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2015, The TensorFlow Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/third_party/rules_cuda/gpus/cuda/build_defs.bzl.tpl b/third_party/rules_cuda/gpus/cuda/build_defs.bzl.tpl deleted file mode 100644 index 3011d38d..00000000 --- a/third_party/rules_cuda/gpus/cuda/build_defs.bzl.tpl +++ /dev/null @@ -1,106 +0,0 @@ -# Macros for building CUDA code. -def if_cuda(if_true, if_false = []): - """Shorthand for select()'ing on whether we're building with CUDA. - - Returns a select statement which evaluates to if_true if we're building - with CUDA enabled. Otherwise, the select statement evaluates to if_false. - - """ - return select({ - "@local_config_cuda//cuda:using_nvcc": if_true, - "@local_config_cuda//cuda:using_clang": if_true, - "//conditions:default": if_false, - }) - -def if_cuda_clang(if_true, if_false = []): - """Shorthand for select()'ing on wheteher we're building with cuda-clang. - - Returns a select statement which evaluates to if_true if we're building - with cuda-clang. Otherwise, the select statement evaluates to if_false. - - """ - return select({ - "@local_config_cuda//cuda:using_clang": if_true, - "//conditions:default": if_false - }) - -def if_cuda_clang_opt(if_true, if_false = []): - """Shorthand for select()'ing on wheteher we're building with cuda-clang - in opt mode. - - Returns a select statement which evaluates to if_true if we're building - with cuda-clang in opt mode. Otherwise, the select statement evaluates to - if_false. - - """ - return select({ - "@local_config_cuda//cuda:using_clang_opt": if_true, - "//conditions:default": if_false - }) - -def cuda_default_copts(): - """Default options for all CUDA compilations.""" - return if_cuda([ - "-x", "cuda", - "-DGOOGLE_CUDA=1", - "-Xcuda-fatbinary=--compress-all", - "--no-cuda-include-ptx=all" - ] + %{cuda_extra_copts}) + if_cuda_clang_opt( - # Some important CUDA optimizations are only enabled at O3. - ["-O3"] - ) - -def cuda_is_configured(): - """Returns true if CUDA was enabled during the configure process.""" - return %{cuda_is_configured} - -def cuda_gpu_architectures(): - """Returns a list of supported GPU architectures.""" - return %{cuda_gpu_architectures} - -def if_cuda_is_configured(x): - """Tests if the CUDA was enabled during the configure process. - - Unlike if_cuda(), this does not require that we are building with - --config=cuda. Used to allow non-CUDA code to depend on CUDA libraries. - """ - if cuda_is_configured(): - return select({"//conditions:default": x}) - return select({"//conditions:default": []}) - -def cuda_header_library( - name, - hdrs, - include_prefix = None, - strip_include_prefix = None, - deps = [], - **kwargs): - """Generates a cc_library containing both virtual and system include paths. - - Generates both a header-only target with virtual includes plus the full - target without virtual includes. This works around the fact that bazel can't - mix 'includes' and 'include_prefix' in the same target.""" - - native.cc_library( - name = name + "_virtual", - hdrs = hdrs, - include_prefix = include_prefix, - strip_include_prefix = strip_include_prefix, - deps = deps, - visibility = ["//visibility:private"], - ) - - native.cc_library( - name = name, - textual_hdrs = hdrs, - deps = deps + [":%s_virtual" % name], - **kwargs - ) - -def cuda_library(copts = [], **kwargs): - """Wrapper over cc_library which adds default CUDA options.""" - native.cc_library(copts = cuda_default_copts() + copts, **kwargs) - -def cuda_test(copts = [], **kwargs): - """Wrapper over cc_library which adds default CUDA options.""" - native.cc_test(copts = cuda_default_copts() + copts, **kwargs) diff --git a/third_party/rules_cuda/gpus/cuda/cuda_config.h.tpl b/third_party/rules_cuda/gpus/cuda/cuda_config.h.tpl deleted file mode 100644 index 8e59acad..00000000 --- a/third_party/rules_cuda/gpus/cuda/cuda_config.h.tpl +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -#ifndef CUDA_CUDA_CONFIG_H_ -#define CUDA_CUDA_CONFIG_H_ - -#define TF_CUDA_VERSION "%{cuda_version}" -#define TF_CUBLAS_VERSION "%{cublas_version}" -#define TF_CUSOLVER_VERSION "%{cusolver_version}" -#define TF_CURAND_VERSION "%{curand_version}" -#define TF_CUFFT_VERSION "%{cufft_version}" -#define TF_CUSPARSE_VERSION "%{cusparse_version}" - -#define TF_CUDA_TOOLKIT_PATH "%{cuda_toolkit_path}" - -#endif // CUDA_CUDA_CONFIG_H_ diff --git a/third_party/rules_cuda/gpus/cuda/cuda_config.py.tpl b/third_party/rules_cuda/gpus/cuda/cuda_config.py.tpl deleted file mode 100644 index eb041a17..00000000 --- a/third_party/rules_cuda/gpus/cuda/cuda_config.py.tpl +++ /dev/null @@ -1,17 +0,0 @@ -# Lint as: python3 -# Copyright 2019 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -config = %{cuda_config} diff --git a/third_party/rules_cuda/gpus/cuda_configure.bzl b/third_party/rules_cuda/gpus/cuda_configure.bzl deleted file mode 100644 index 68afa7a4..00000000 --- a/third_party/rules_cuda/gpus/cuda_configure.bzl +++ /dev/null @@ -1,1350 +0,0 @@ -"""Repository rule for CUDA autoconfiguration. - -`cuda_configure` depends on the following environment variables: - - * `TF_NEED_CUDA`: Whether to enable building with CUDA. - * `GCC_HOST_COMPILER_PATH`: The GCC host compiler path - * `TF_CUDA_CLANG`: Whether to use clang as a cuda compiler. - * `CLANG_CUDA_COMPILER_PATH`: The clang compiler path that will be used for - both host and device code compilation if TF_CUDA_CLANG is 1. - * `TF_SYSROOT`: The sysroot to use when compiling. - compiler and use it to build tensorflow. When this option is set - CLANG_CUDA_COMPILER_PATH is ignored. - * `TF_CUDA_PATHS`: The base paths to look for CUDA. Default is - `/usr/local/cuda,usr/`. - * `CUDA_TOOLKIT_PATH` (deprecated): The path to the CUDA toolkit. Default is - `/usr/local/cuda`. - * `TF_CUDA_VERSION`: The version of the CUDA toolkit. If this is blank, then - use the system default.. - * `TF_CUDA_COMPUTE_CAPABILITIES`: The CUDA compute capabilities. Default is - `3.5,5.2`. - * `PYTHON_BIN_PATH`: The python binary path -""" - -load( - "@bazel_tools//tools/cpp:lib_cc_configure.bzl", - "auto_configure_warning", - "escape_string", - "get_env_var", -) -load( - "@bazel_tools//tools/cpp:windows_cc_configure.bzl", - "find_msvc_tool", - "find_vc_path", - "setup_vc_env_vars", -) -load( - "//tools/remote_config:common.bzl", - "config_repo_label", - "err_out", - "execute", - "get_bash_bin", - "get_cpu_value", - "get_host_environ", - "get_python_bin", - "is_windows", - "raw_exec", - "read_dir", - "realpath", - "which", -) -load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", - "find_cc", -) - -_GCC_HOST_COMPILER_PATH = "GCC_HOST_COMPILER_PATH" -_GCC_HOST_COMPILER_PREFIX = "GCC_HOST_COMPILER_PREFIX" -_CLANG_CUDA_COMPILER_PATH = "CLANG_CUDA_COMPILER_PATH" -_TF_SYSROOT = "TF_SYSROOT" -_CUDA_TOOLKIT_PATH = "CUDA_TOOLKIT_PATH" -_TF_CUDA_VERSION = "TF_CUDA_VERSION" -_TF_CUDA_COMPUTE_CAPABILITIES = "TF_CUDA_COMPUTE_CAPABILITIES" -_TF_CUDA_CONFIG_REPO = "TF_CUDA_CONFIG_REPO" -_PYTHON_BIN_PATH = "PYTHON_BIN_PATH" - -def _is_clang(repository_ctx, cc): - return "clang" in repository_ctx.execute([cc, "-v"]).stderr - -def _find_generic(repository_ctx, name, env_name, overriden_tools, warn = False, silent = False): - """Find a generic C++ toolchain tool. Doesn't %-escape the result.""" - - if name in overriden_tools: - return overriden_tools[name] - - result = name - env_value = repository_ctx.os.environ.get(env_name) - env_value_with_paren = "" - if env_value != None: - env_value = env_value.strip() - if env_value: - result = env_value - env_value_with_paren = " (%s)" % env_value - if result.startswith("/"): - # Absolute path, maybe we should make this suported by our which function. - return result - result = repository_ctx.which(result) - if result == None: - msg = ("Cannot find %s or %s%s; either correct your path or set the %s" + - " environment variable") % (name, env_name, env_value_with_paren, env_name) - if warn: - if not silent: - auto_configure_warning(msg) - else: - auto_configure_fail(msg) - return result - -def to_list_of_strings(elements): - """Convert the list of ["a", "b", "c"] into '"a", "b", "c"'. - - This is to be used to put a list of strings into the bzl file templates - so it gets interpreted as list of strings in Starlark. - - Args: - elements: list of string elements - - Returns: - single string of elements wrapped in quotes separated by a comma.""" - quoted_strings = ["\"" + element + "\"" for element in elements] - return ", ".join(quoted_strings) - -def verify_build_defines(params): - """Verify all variables that crosstool/BUILD.tpl expects are substituted. - - Args: - params: dict of variables that will be passed to the BUILD.tpl template. - """ - missing = [] - for param in [ - "cxx_builtin_include_directories", - "extra_no_canonical_prefixes_flags", - "host_compiler_path", - "host_compiler_prefix", - "host_compiler_warnings", - "linker_bin_path", - "compiler_deps", - "msvc_cl_path", - "msvc_env_include", - "msvc_env_lib", - "msvc_env_path", - "msvc_env_tmp", - "msvc_lib_path", - "msvc_link_path", - "msvc_ml_path", - "unfiltered_compile_flags", - "win_compiler_deps", - ]: - if ("%{" + param + "}") not in params: - missing.append(param) - - if missing: - auto_configure_fail( - "BUILD.tpl template is missing these variables: " + - str(missing) + - ".\nWe only got: " + - str(params) + - ".", - ) - -def _get_nvcc_tmp_dir_for_windows(repository_ctx): - """Return the Windows tmp directory for nvcc to generate intermediate source files.""" - escaped_tmp_dir = escape_string( - get_env_var(repository_ctx, "TMP", "C:\\Windows\\Temp").replace( - "\\", - "\\\\", - ), - ) - return escaped_tmp_dir + "\\\\nvcc_inter_files_tmp_dir" - -def _get_msvc_compiler(repository_ctx): - vc_path = find_vc_path(repository_ctx) - return find_msvc_tool(repository_ctx, vc_path, "cl.exe").replace("\\", "/") - -def _get_win_cuda_defines(repository_ctx): - """Return CROSSTOOL defines for Windows""" - - # If we are not on Windows, return fake vaules for Windows specific fields. - # This ensures the CROSSTOOL file parser is happy. - if not is_windows(repository_ctx): - return { - "%{msvc_env_tmp}": "msvc_not_used", - "%{msvc_env_path}": "msvc_not_used", - "%{msvc_env_include}": "msvc_not_used", - "%{msvc_env_lib}": "msvc_not_used", - "%{msvc_cl_path}": "msvc_not_used", - "%{msvc_ml_path}": "msvc_not_used", - "%{msvc_link_path}": "msvc_not_used", - "%{msvc_lib_path}": "msvc_not_used", - } - - vc_path = find_vc_path(repository_ctx) - if not vc_path: - auto_configure_fail( - "Visual C++ build tools not found on your machine." + - "Please check your installation following https://docs.bazel.build/versions/master/windows.html#using", - ) - return {} - - env = setup_vc_env_vars(repository_ctx, vc_path) - escaped_paths = escape_string(env["PATH"]) - escaped_include_paths = escape_string(env["INCLUDE"]) - escaped_lib_paths = escape_string(env["LIB"]) - escaped_tmp_dir = escape_string( - get_env_var(repository_ctx, "TMP", "C:\\Windows\\Temp").replace( - "\\", - "\\\\", - ), - ) - - msvc_cl_path = get_python_bin(repository_ctx) - msvc_ml_path = find_msvc_tool(repository_ctx, vc_path, "ml64.exe").replace( - "\\", - "/", - ) - msvc_link_path = find_msvc_tool(repository_ctx, vc_path, "link.exe").replace( - "\\", - "/", - ) - msvc_lib_path = find_msvc_tool(repository_ctx, vc_path, "lib.exe").replace( - "\\", - "/", - ) - - # nvcc will generate some temporary source files under %{nvcc_tmp_dir} - # The generated files are guaranteed to have unique name, so they can share - # the same tmp directory - escaped_cxx_include_directories = [ - _get_nvcc_tmp_dir_for_windows(repository_ctx), - "C:\\\\botcode\\\\w", - ] - for path in escaped_include_paths.split(";"): - if path: - escaped_cxx_include_directories.append(path) - - return { - "%{msvc_env_tmp}": escaped_tmp_dir, - "%{msvc_env_path}": escaped_paths, - "%{msvc_env_include}": escaped_include_paths, - "%{msvc_env_lib}": escaped_lib_paths, - "%{msvc_cl_path}": msvc_cl_path, - "%{msvc_ml_path}": msvc_ml_path, - "%{msvc_link_path}": msvc_link_path, - "%{msvc_lib_path}": msvc_lib_path, - "%{cxx_builtin_include_directories}": to_list_of_strings( - escaped_cxx_include_directories, - ), - } - -# Find a good path for the C++ compiler, by hooking into Bazel's C compiler -# detection. Uses `$CXX` if found, otherwise defaults to `g++` because Bazel -# defaults to `gcc`. -def _find_cxx(repository_ctx, overriden_tools): - cc = _find_generic(repository_ctx, "g++", "CXX", overriden_tools) - if _is_clang(repository_ctx, cc): - # If clang is run through a symlink with -no-canonical-prefixes, it does - # not find its own include directory, which includes the headers for - # libc++. Resolving the potential symlink here prevents this. - result = repository_ctx.execute(["readlink", "-f", cc]) - if result.return_code == 0: - return result.stdout.strip() - return cc - -_INC_DIR_MARKER_BEGIN = "#include <...>" - -# OSX add " (framework directory)" at the end of line, strip it. -_OSX_FRAMEWORK_SUFFIX = " (framework directory)" -_OSX_FRAMEWORK_SUFFIX_LEN = len(_OSX_FRAMEWORK_SUFFIX) - -def _cxx_inc_convert(path): - """Convert path returned by cc -E xc++ in a complete path.""" - path = path.strip() - if path.endswith(_OSX_FRAMEWORK_SUFFIX): - path = path[:-_OSX_FRAMEWORK_SUFFIX_LEN].strip() - return path - -def _normalize_include_path(repository_ctx, path): - """Normalizes include paths before writing them to the crosstool. - - If path points inside the 'crosstool' folder of the repository, a relative - path is returned. - If path points outside the 'crosstool' folder, an absolute path is returned. - """ - path = str(repository_ctx.path(path)) - crosstool_folder = str(repository_ctx.path(".").get_child("crosstool")) - - if path.startswith(crosstool_folder): - # We drop the path to "$REPO/crosstool" and a trailing path separator. - return path[len(crosstool_folder) + 1:] - return path - -def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp, tf_sysroot): - """Compute the list of default C or C++ include directories.""" - if lang_is_cpp: - lang = "c++" - else: - lang = "c" - sysroot = [] - if tf_sysroot: - sysroot += ["--sysroot", tf_sysroot] - result = raw_exec(repository_ctx, [cc, "-E", "-x" + lang, "-", "-v"] + - sysroot) - stderr = err_out(result) - index1 = stderr.find(_INC_DIR_MARKER_BEGIN) - if index1 == -1: - return [] - index1 = stderr.find("\n", index1) - if index1 == -1: - return [] - index2 = stderr.rfind("\n ") - if index2 == -1 or index2 < index1: - return [] - index2 = stderr.find("\n", index2 + 1) - if index2 == -1: - inc_dirs = stderr[index1 + 1:] - else: - inc_dirs = stderr[index1 + 1:index2].strip() - - return [ - _normalize_include_path(repository_ctx, _cxx_inc_convert(p)) - for p in inc_dirs.split("\n") - ] - -def get_cxx_inc_directories(repository_ctx, cc, tf_sysroot): - """Compute the list of default C and C++ include directories.""" - - # For some reason `clang -xc` sometimes returns include paths that are - # different from the ones from `clang -xc++`. (Symlink and a dir) - # So we run the compiler with both `-xc` and `-xc++` and merge resulting lists - includes_cpp = _get_cxx_inc_directories_impl( - repository_ctx, - cc, - True, - tf_sysroot, - ) - includes_c = _get_cxx_inc_directories_impl( - repository_ctx, - cc, - False, - tf_sysroot, - ) - - return includes_cpp + [ - inc - for inc in includes_c - if inc not in includes_cpp - ] - -def auto_configure_fail(msg): - """Output failure message when cuda configuration fails.""" - red = "\033[0;31m" - no_color = "\033[0m" - fail("\n%sCuda Configuration Error:%s %s\n" % (red, no_color, msg)) - -# END cc_configure common functions (see TODO above). - -def _cuda_include_path(repository_ctx, cuda_config): - """Generates the Starlark string with cuda include directories. - - Args: - repository_ctx: The repository context. - cc: The path to the gcc host compiler. - - Returns: - A list of the gcc host compiler include directories. - """ - nvcc_path = repository_ctx.path("%s/bin/nvcc%s" % ( - cuda_config.cuda_toolkit_path, - ".exe" if cuda_config.cpu_value == "Windows" else "", - )) - - # The expected exit code of this command is non-zero. Bazel remote execution - # only caches commands with zero exit code. So force a zero exit code. - cmd = "%s -v /dev/null -o /dev/null ; [ $? -eq 1 ]" % str(nvcc_path) - result = raw_exec(repository_ctx, [get_bash_bin(repository_ctx), "-c", cmd]) - target_dir = "" - for one_line in err_out(result).splitlines(): - if one_line.startswith("#$ _TARGET_DIR_="): - target_dir = ( - cuda_config.cuda_toolkit_path + "/" + one_line.replace( - "#$ _TARGET_DIR_=", - "", - ) + "/include" - ) - inc_entries = [] - if target_dir != "": - inc_entries.append(realpath(repository_ctx, target_dir)) - inc_entries.append(realpath(repository_ctx, cuda_config.cuda_toolkit_path + "/include")) - return inc_entries - -def enable_cuda(repository_ctx): - """Returns whether to build with CUDA support.""" - return int(get_host_environ(repository_ctx, "TF_NEED_CUDA", False)) - -def matches_version(environ_version, detected_version): - """Checks whether the user-specified version matches the detected version. - - This function performs a weak matching so that if the user specifies only - the - major or major and minor versions, the versions are still considered - matching - if the version parts match. To illustrate: - - environ_version detected_version result - ----------------------------------------- - 5.1.3 5.1.3 True - 5.1 5.1.3 True - 5 5.1 True - 5.1.3 5.1 False - 5.2.3 5.1.3 False - - Args: - environ_version: The version specified by the user via environment - variables. - detected_version: The version autodetected from the CUDA installation on - the system. - Returns: True if user-specified version matches detected version and False - otherwise. - """ - environ_version_parts = environ_version.split(".") - detected_version_parts = detected_version.split(".") - if len(detected_version_parts) < len(environ_version_parts): - return False - for i, part in enumerate(detected_version_parts): - if i >= len(environ_version_parts): - break - if part != environ_version_parts[i]: - return False - return True - -_NVCC_VERSION_PREFIX = "Cuda compilation tools, release " - -def compute_capabilities(repository_ctx): - """Returns a list of strings representing cuda compute capabilities. - - Args: - repository_ctx: the repo rule's context. - Returns: list of cuda architectures to compile for. 'compute_xy' refers to - both PTX and SASS, 'sm_xy' refers to SASS only. - """ - capabilities = get_host_environ( - repository_ctx, - _TF_CUDA_COMPUTE_CAPABILITIES, - "compute_35,compute_52", - ).split(",") - - # Map old 'x.y' capabilities to 'compute_xy'. - for i, capability in enumerate(capabilities): - parts = capability.split(".") - if len(parts) != 2: - continue - capabilities[i] = "compute_%s%s" % (parts[0], parts[1]) - - # Make list unique - capabilities = dict(zip(capabilities, capabilities)).keys() - - # Validate capabilities. - for capability in capabilities: - if not capability.startswith(("compute_", "sm_")): - auto_configure_fail("Invalid compute capability: %s" % capability) - for prefix in ["compute_", "sm_"]: - if not capability.startswith(prefix): - continue - if len(capability) == len(prefix) + 2 and capability[-2:].isdigit(): - continue - auto_configure_fail("Invalid compute capability: %s" % capability) - - return capabilities - -def lib_name(base_name, cpu_value, version = None, static = False): - """Constructs the platform-specific name of a library. - - Args: - base_name: The name of the library, such as "cudart" - cpu_value: The name of the host operating system. - version: The version of the library. - static: True the library is static or False if it is a shared object. - - Returns: - The platform-specific name of the library. - """ - version = "" if not version else "." + version - if cpu_value in ("Linux", "FreeBSD"): - if static: - return "lib%s.a" % base_name - return "lib%s.so%s" % (base_name, version) - elif cpu_value == "Windows": - return "%s.lib" % base_name - elif cpu_value == "Darwin": - if static: - return "lib%s.a" % base_name - return "lib%s%s.dylib" % (base_name, version) - else: - auto_configure_fail("Invalid cpu_value: %s" % cpu_value) - -def _lib_path(lib, cpu_value, basedir, version, static): - file_name = lib_name(lib, cpu_value, version, static) - return "%s/%s" % (basedir, file_name) - -def _should_check_soname(version, static): - return version and not static - -def _check_cuda_lib_params(lib, cpu_value, basedir, version, static = False): - return ( - _lib_path(lib, cpu_value, basedir, version, static), - _should_check_soname(version, static), - ) - -def _check_cuda_libs(repository_ctx, script_path, libs): - python_bin = get_python_bin(repository_ctx) - contents = repository_ctx.read(script_path).splitlines() - - cmd = "from os import linesep;" - cmd += "f = open('script.py', 'w');" - for line in contents: - cmd += "f.write('%s' + linesep);" % line - cmd += "f.close();" - cmd += "from os import system;" - args = " ".join(["\"" + path + "\" " + str(check) for path, check in libs]) - cmd += "system('%s script.py %s');" % (python_bin, args) - - all_paths = [path for path, _ in libs] - checked_paths = execute(repository_ctx, [python_bin, "-c", cmd]).stdout.splitlines() - - # Filter out empty lines from splitting on '\r\n' on Windows - checked_paths = [path for path in checked_paths if len(path) > 0] - if all_paths != checked_paths: - auto_configure_fail("Error with installed CUDA libs. Expected '%s'. Actual '%s'." % (all_paths, checked_paths)) - -def _find_libs(repository_ctx, check_cuda_libs_script, cuda_config): - """Returns the CUDA libraries on the system. - - Also, verifies that the script actually exist. - - Args: - repository_ctx: The repository context. - check_cuda_libs_script: The path to a script verifying that the cuda - libraries exist on the system. - cuda_config: The CUDA config as returned by _get_cuda_config - - Returns: - Map of library names to structs of filename and path. - """ - cpu_value = cuda_config.cpu_value - stub_dir = "" if is_windows(repository_ctx) else "/stubs" - - check_cuda_libs_params = { - "cuda": _check_cuda_lib_params( - "cuda", - cpu_value, - cuda_config.config["cuda_library_dir"] + stub_dir, - version = None, - static = False, - ), - "cudart": _check_cuda_lib_params( - "cudart", - cpu_value, - cuda_config.config["cuda_library_dir"], - version = None, - static = False, - ), - "cudart_static": _check_cuda_lib_params( - "cudart_static", - cpu_value, - cuda_config.config["cuda_library_dir"], - cuda_config.cuda_version, - static = True, - ), - "cublas": _check_cuda_lib_params( - "cublas", - cpu_value, - cuda_config.config["cublas_library_dir"], - cuda_config.cublas_version, - static = False, - ), - "curand": _check_cuda_lib_params( - "curand", - cpu_value, - cuda_config.config["curand_library_dir"], - cuda_config.curand_version, - static = False, - ), - "cufft": _check_cuda_lib_params( - "cufft", - cpu_value, - cuda_config.config["cufft_library_dir"], - cuda_config.cufft_version, - static = False, - ), - "cusparse": _check_cuda_lib_params( - "cusparse", - cpu_value, - cuda_config.config["cusparse_library_dir"], - cuda_config.cusparse_version, - static = False, - ), - } - - # Verify that the libs actually exist at their locations. - _check_cuda_libs(repository_ctx, check_cuda_libs_script, check_cuda_libs_params.values()) - - paths = {filename: v[0] for (filename, v) in check_cuda_libs_params.items()} - return paths - -def _cudart_static_linkopt(cpu_value): - """Returns additional platform-specific linkopts for cudart.""" - return "" if cpu_value == "Darwin" else "\"-lrt\"," - -def _exec_find_cuda_config(repository_ctx, script_path, cuda_libraries): - python_bin = get_python_bin(repository_ctx) - - # If used with remote execution then repository_ctx.execute() can't - # access files from the source tree. A trick is to read the contents - # of the file in Starlark and embed them as part of the command. In - # this case the trick is not sufficient as the find_cuda_config.py - # script has more than 8192 characters. 8192 is the command length - # limit of cmd.exe on Windows. Thus we additionally need to compress - # the contents locally and decompress them as part of the execute(). - compressed_contents = repository_ctx.read(script_path) - decompress_and_execute_cmd = ( - "from zlib import decompress;" + - "from base64 import b64decode;" + - "from os import system;" + - "script = decompress(b64decode('%s'));" % compressed_contents + - "f = open('script.py', 'wb');" + - "f.write(script);" + - "f.close();" + - "system('\"%s\" script.py %s');" % (python_bin, " ".join(cuda_libraries)) - ) - - return execute(repository_ctx, [python_bin, "-c", decompress_and_execute_cmd]) - -# TODO(csigg): Only call once instead of from here, tensorrt_configure.bzl, -# and nccl_configure.bzl. -def find_cuda_config(repository_ctx, script_path, cuda_libraries): - """Returns CUDA config dictionary from running find_cuda_config.py""" - exec_result = _exec_find_cuda_config(repository_ctx, script_path, cuda_libraries) - if exec_result.return_code: - auto_configure_fail("Failed to run find_cuda_config.py: %s" % err_out(exec_result)) - - # Parse the dict from stdout. - return dict([tuple(x.split(": ")) for x in exec_result.stdout.splitlines()]) - -def _get_cuda_config(repository_ctx, find_cuda_config_script): - """Detects and returns information about the CUDA installation on the system. - - Args: - repository_ctx: The repository context. - - Returns: - A struct containing the following fields: - cuda_toolkit_path: The CUDA toolkit installation directory. - cuda_version: The version of CUDA on the system. - compute_capabilities: A list of the system's CUDA compute capabilities. - cpu_value: The name of the host operating system. - """ - config = find_cuda_config(repository_ctx, find_cuda_config_script, ["cuda"]) - cpu_value = get_cpu_value(repository_ctx) - toolkit_path = config["cuda_toolkit_path"] - - is_windows = cpu_value == "Windows" - cuda_version = config["cuda_version"].split(".") - cuda_major = cuda_version[0] - cuda_minor = cuda_version[1] - - cuda_version = ("64_%s%s" if is_windows else "%s.%s") % (cuda_major, cuda_minor) - - if int(cuda_major) >= 11: - cublas_version = ("64_%s" if is_windows else "%s") % config["cublas_version"].split(".")[0] - cusolver_version = ("64_%s" if is_windows else "%s") % config["cusolver_version"].split(".")[0] - curand_version = ("64_%s" if is_windows else "%s") % config["curand_version"].split(".")[0] - cufft_version = ("64_%s" if is_windows else "%s") % config["cufft_version"].split(".")[0] - cusparse_version = ("64_%s" if is_windows else "%s") % config["cusparse_version"].split(".")[0] - elif (int(cuda_major), int(cuda_minor)) >= (10, 1): - # cuda_lib_version is for libraries like cuBLAS, cuFFT, cuSOLVER, etc. - # It changed from 'x.y' to just 'x' in CUDA 10.1. - cuda_lib_version = ("64_%s" if is_windows else "%s") % cuda_major - cublas_version = cuda_lib_version - cusolver_version = cuda_lib_version - curand_version = cuda_lib_version - cufft_version = cuda_lib_version - cusparse_version = cuda_lib_version - else: - cublas_version = cuda_version - cusolver_version = cuda_version - curand_version = cuda_version - cufft_version = cuda_version - cusparse_version = cuda_version - - return struct( - cuda_toolkit_path = toolkit_path, - cuda_version = cuda_version, - cuda_version_major = cuda_major, - cublas_version = cublas_version, - cusolver_version = cusolver_version, - curand_version = curand_version, - cufft_version = cufft_version, - cusparse_version = cusparse_version, - compute_capabilities = compute_capabilities(repository_ctx), - cpu_value = cpu_value, - config = config, - ) - -def _tpl(repository_ctx, tpl, substitutions = {}, out = None): - if not out: - out = tpl.replace(":", "/") - repository_ctx.template( - out, - Label("//gpus/%s.tpl" % tpl), - substitutions, - ) - -def _file(repository_ctx, label): - repository_ctx.template( - label.replace(":", "/"), - Label("//gpus/%s.tpl" % label), - {}, - ) - -_DUMMY_CROSSTOOL_BZL_FILE = """ -def error_gpu_disabled(): - fail("ERROR: Building with --config=cuda but TensorFlow is not configured " + - "to build with GPU support. Please re-run ./configure and enter 'Y' " + - "at the prompt to build with GPU support.") - - native.genrule( - name = "error_gen_crosstool", - outs = ["CROSSTOOL"], - cmd = "echo 'Should not be run.' && exit 1", - ) - - native.filegroup( - name = "crosstool", - srcs = [":CROSSTOOL"], - output_licenses = ["unencumbered"], - ) -""" - -_DUMMY_CROSSTOOL_BUILD_FILE = """ -load("//crosstool:error_gpu_disabled.bzl", "error_gpu_disabled") - -error_gpu_disabled() -""" - -def _create_dummy_repository(repository_ctx): - cpu_value = get_cpu_value(repository_ctx) - - # Set up BUILD file for cuda/. - _tpl( - repository_ctx, - "cuda:build_defs.bzl", - { - "%{cuda_is_configured}": "False", - "%{cuda_extra_copts}": "[]", - "%{cuda_gpu_architectures}": "[]", - }, - ) - _tpl( - repository_ctx, - "cuda:BUILD", - { - "%{cuda_driver_lib}": lib_name("cuda", cpu_value), - "%{cudart_static_lib}": lib_name( - "cudart_static", - cpu_value, - static = True, - ), - "%{cudart_static_linkopt}": _cudart_static_linkopt(cpu_value), - "%{cudart_lib}": lib_name("cudart", cpu_value), - "%{cublas_lib}": lib_name("cublas", cpu_value), - "%{cusolver_lib}": lib_name("cusolver", cpu_value), - "%{cufft_lib}": lib_name("cufft", cpu_value), - "%{curand_lib}": lib_name("curand", cpu_value), - "%{cupti_lib}": lib_name("cupti", cpu_value), - "%{cusparse_lib}": lib_name("cusparse", cpu_value), - "%{cub_actual}": ":cuda_headers", - "%{copy_rules}": """ -filegroup(name="cuda-include") -filegroup(name="cublas-include") -filegroup(name="cusolver-include") -filegroup(name="cufft-include") -filegroup(name="cusparse-include") -filegroup(name="curand-include") -""", - }, - ) - - # Create dummy files for the CUDA toolkit since they are still required by - # tensorflow/core/platform/default/build_config:cuda. - repository_ctx.file("cuda/cuda/include/cuda.h") - repository_ctx.file("cuda/cuda/include/cublas.h") - repository_ctx.file("cuda/cuda/extras/CUPTI/include/cupti.h") - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cuda", cpu_value)) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cudart", cpu_value)) - repository_ctx.file( - "cuda/cuda/lib/%s" % lib_name("cudart_static", cpu_value), - ) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cublas", cpu_value)) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cusolver", cpu_value)) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("curand", cpu_value)) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cufft", cpu_value)) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cupti", cpu_value)) - repository_ctx.file("cuda/cuda/lib/%s" % lib_name("cusparse", cpu_value)) - - # Set up cuda_config.h, which is used by - # tensorflow/stream_executor/dso_loader.cc. - _tpl( - repository_ctx, - "cuda:cuda_config.h", - { - "%{cuda_version}": "", - "%{cublas_version}": "", - "%{cusolver_version}": "", - "%{curand_version}": "", - "%{cufft_version}": "", - "%{cusparse_version}": "", - "%{cuda_toolkit_path}": "", - }, - "cuda/cuda/cuda_config.h", - ) - - # Set up cuda_config.py, which is used by gen_build_info to provide - # static build environment info to the API - _tpl( - repository_ctx, - "cuda:cuda_config.py", - _py_tmpl_dict({}), - "cuda/cuda/cuda_config.py", - ) - - # If cuda_configure is not configured to build with GPU support, and the user - # attempts to build with --config=cuda, add a dummy build rule to intercept - # this and fail with an actionable error message. - repository_ctx.file( - "crosstool/error_gpu_disabled.bzl", - _DUMMY_CROSSTOOL_BZL_FILE, - ) - repository_ctx.file("crosstool/BUILD", _DUMMY_CROSSTOOL_BUILD_FILE) - -def _norm_path(path): - """Returns a path with '/' and remove the trailing slash.""" - path = path.replace("\\", "/") - if path[-1] == "/": - path = path[:-1] - return path - -def make_copy_files_rule(repository_ctx, name, srcs, outs): - """Returns a rule to copy a set of files.""" - cmds = [] - - # Copy files. - for src, out in zip(srcs, outs): - cmds.append('cp -f "%s" "$(location %s)"' % (src, out)) - outs = [(' "%s",' % out) for out in outs] - return """genrule( - name = "%s", - outs = [ -%s - ], - cmd = \"""%s \""", -)""" % (name, "\n".join(outs), " && \\\n".join(cmds)) - -def make_copy_dir_rule(repository_ctx, name, src_dir, out_dir, exceptions = None): - """Returns a rule to recursively copy a directory. - If exceptions is not None, it must be a list of files or directories in - 'src_dir'; these will be excluded from copying. - """ - src_dir = _norm_path(src_dir) - out_dir = _norm_path(out_dir) - outs = read_dir(repository_ctx, src_dir) - post_cmd = "" - if exceptions != None: - outs = [x for x in outs if not any([ - x.startswith(src_dir + "/" + y) - for y in exceptions - ])] - outs = [(' "%s",' % out.replace(src_dir, out_dir)) for out in outs] - - # '@D' already contains the relative path for a single file, see - # http://docs.bazel.build/versions/master/be/make-variables.html#predefined_genrule_variables - out_dir = "$(@D)/%s" % out_dir if len(outs) > 1 else "$(@D)" - if exceptions != None: - for x in exceptions: - post_cmd += " ; rm -fR " + out_dir + "/" + x - return """genrule( - name = "%s", - outs = [ -%s - ], - cmd = \"""cp -rLf "%s/." "%s/" %s\""", -)""" % (name, "\n".join(outs), src_dir, out_dir, post_cmd) - -def _flag_enabled(repository_ctx, flag_name): - return get_host_environ(repository_ctx, flag_name) == "1" - -def _use_cuda_clang(repository_ctx): - return _flag_enabled(repository_ctx, "TF_CUDA_CLANG") - -def _tf_sysroot(repository_ctx): - return get_host_environ(repository_ctx, _TF_SYSROOT, "") - -def _compute_cuda_extra_copts(repository_ctx, compute_capabilities): - copts = [] - for capability in compute_capabilities: - if capability.startswith("compute_"): - capability = capability.replace("compute_", "sm_") - copts.append("--cuda-include-ptx=%s" % capability) - copts.append("--cuda-gpu-arch=%s" % capability) - - return str(copts) - -def _tpl_path(repository_ctx, filename): - return repository_ctx.path(Label("//gpus/%s.tpl" % filename)) - -def _basename(repository_ctx, path_str): - """Returns the basename of a path of type string. - - This method is different from path.basename in that it also works if - the host platform is different from the execution platform - i.e. linux -> windows. - """ - - num_chars = len(path_str) - is_win = is_windows(repository_ctx) - for i in range(num_chars): - r_i = num_chars - 1 - i - if (is_win and path_str[r_i] == "\\") or path_str[r_i] == "/": - return path_str[r_i + 1:] - return path_str - -def _create_local_cuda_repository(repository_ctx): - """Creates the repository containing files set up to build with CUDA.""" - - # Resolve all labels before doing any real work. Resolving causes the - # function to be restarted with all previous state being lost. This - # can easily lead to a O(n^2) runtime in the number of labels. - # See https://github.com/tensorflow/tensorflow/commit/62bd3534525a036f07d9851b3199d68212904778 - tpl_paths = {filename: _tpl_path(repository_ctx, filename) for filename in [ - "cuda:build_defs.bzl", - "crosstool:clang/bin/crosstool_wrapper_driver_is_not_gcc", - "crosstool:windows/msvc_wrapper_for_nvcc.py", - "crosstool:BUILD", - "crosstool:cc_toolchain_config.bzl", - "cuda:cuda_config.h", - "cuda:cuda_config.py", - ]} - tpl_paths["cuda:BUILD"] = _tpl_path(repository_ctx, "cuda:BUILD.windows" if is_windows(repository_ctx) else "cuda:BUILD") - find_cuda_config_script = repository_ctx.path(Label("//gpus:find_cuda_config.py.gz.base64")) - - cuda_config = _get_cuda_config(repository_ctx, find_cuda_config_script) - - cuda_include_path = cuda_config.config["cuda_include_dir"] - cublas_include_path = cuda_config.config["cublas_include_dir"] - cupti_header_dir = cuda_config.config["cupti_include_dir"] - nvvm_libdevice_dir = cuda_config.config["nvvm_library_dir"] - - # Create genrule to copy files from the installed CUDA toolkit into execroot. - copy_rules = [ - make_copy_dir_rule( - repository_ctx, - name = "cuda-include", - src_dir = cuda_include_path, - out_dir = "cuda/include", - ), - make_copy_dir_rule( - repository_ctx, - name = "cuda-nvvm", - src_dir = nvvm_libdevice_dir, - out_dir = "cuda/nvvm/libdevice", - ), - make_copy_dir_rule( - repository_ctx, - name = "cuda-extras", - src_dir = cupti_header_dir, - out_dir = "cuda/extras/CUPTI/include", - ), - ] - - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "cublas-include", - srcs = [ - cublas_include_path + "/cublas.h", - cublas_include_path + "/cublas_v2.h", - cublas_include_path + "/cublas_api.h", - ], - outs = [ - "cublas/include/cublas.h", - "cublas/include/cublas_v2.h", - "cublas/include/cublas_api.h", - ], - )) - - cusolver_include_path = cuda_config.config["cusolver_include_dir"] - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "cusolver-include", - srcs = [ - cusolver_include_path + "/cusolver_common.h", - cusolver_include_path + "/cusolverDn.h", - ], - outs = [ - "cusolver/include/cusolver_common.h", - "cusolver/include/cusolverDn.h", - ], - )) - - cufft_include_path = cuda_config.config["cufft_include_dir"] - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "cufft-include", - srcs = [ - cufft_include_path + "/cufft.h", - ], - outs = [ - "cufft/include/cufft.h", - ], - )) - - cusparse_include_path = cuda_config.config["cusparse_include_dir"] - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "cusparse-include", - srcs = [ - cusparse_include_path + "/cusparse.h", - ], - outs = [ - "cusparse/include/cusparse.h", - ], - )) - - curand_include_path = cuda_config.config["curand_include_dir"] - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "curand-include", - srcs = [ - curand_include_path + "/curand.h", - ], - outs = [ - "curand/include/curand.h", - ], - )) - - check_cuda_libs_script = repository_ctx.path(Label("//gpus:check_cuda_libs.py")) - cuda_libs = _find_libs(repository_ctx, check_cuda_libs_script, cuda_config) - cuda_lib_srcs = [] - cuda_lib_outs = [] - for path in cuda_libs.values(): - cuda_lib_srcs.append(path) - cuda_lib_outs.append("cuda/lib/" + _basename(repository_ctx, path)) - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "cuda-lib", - srcs = cuda_lib_srcs, - outs = cuda_lib_outs, - )) - - # copy files mentioned in nccl/build_defs.bzl.tpl - file_ext = ".exe" if is_windows(repository_ctx) else "" - copy_rules.append(make_copy_files_rule( - repository_ctx, - name = "cuda-bin", - srcs = [ - cuda_config.cuda_toolkit_path + "/bin/" + "crt/link.stub", - cuda_config.cuda_toolkit_path + "/bin/" + "nvlink" + file_ext, - cuda_config.cuda_toolkit_path + "/bin/" + "fatbinary" + file_ext, - cuda_config.cuda_toolkit_path + "/bin/" + "bin2c" + file_ext, - ], - outs = [ - "cuda/bin/" + "crt/link.stub", - "cuda/bin/" + "nvlink" + file_ext, - "cuda/bin/" + "fatbinary" + file_ext, - "cuda/bin/" + "bin2c" + file_ext, - ], - )) - - # Set up BUILD file for cuda/ - repository_ctx.template( - "cuda/build_defs.bzl", - tpl_paths["cuda:build_defs.bzl"], - { - "%{cuda_is_configured}": "True", - "%{cuda_extra_copts}": _compute_cuda_extra_copts( - repository_ctx, - cuda_config.compute_capabilities, - ), - "%{cuda_gpu_architectures}": str(cuda_config.compute_capabilities), - }, - ) - - cub_actual = "@cub_archive//:cub" - if int(cuda_config.cuda_version_major) >= 11: - cub_actual = ":cuda_headers" - - repository_ctx.template( - "cuda/BUILD", - tpl_paths["cuda:BUILD"], - { - "%{cuda_driver_lib}": _basename(repository_ctx, cuda_libs["cuda"]), - "%{cudart_static_lib}": _basename(repository_ctx, cuda_libs["cudart_static"]), - "%{cudart_static_linkopt}": _cudart_static_linkopt(cuda_config.cpu_value), - "%{cudart_lib}": _basename(repository_ctx, cuda_libs["cudart"]), - "%{cublas_lib}": _basename(repository_ctx, cuda_libs["cublas"]), - "%{cufft_lib}": _basename(repository_ctx, cuda_libs["cufft"]), - "%{curand_lib}": _basename(repository_ctx, cuda_libs["curand"]), - "%{cusparse_lib}": _basename(repository_ctx, cuda_libs["cusparse"]), - "%{cub_actual}": cub_actual, - "%{copy_rules}": "\n".join(copy_rules), - }, - ) - - is_cuda_clang = _use_cuda_clang(repository_ctx) - tf_sysroot = _tf_sysroot(repository_ctx) - - # Set up crosstool/ - cc = find_cc(repository_ctx, {}) - cc = str(cc) - cc_fullpath = cc - - cxx = _find_cxx(repository_ctx, {}) - - host_compiler_includes = get_cxx_inc_directories( - repository_ctx, - cc_fullpath, - tf_sysroot, - ) - cuda_defines = {} - cuda_defines["%{builtin_sysroot}"] = tf_sysroot - cuda_defines["%{cuda_toolkit_path}"] = "" - cuda_defines["%{compiler}"] = "unknown" - if is_cuda_clang: - cuda_defines["%{cuda_toolkit_path}"] = cuda_config.config["cuda_toolkit_path"] - cuda_defines["%{compiler}"] = "clang" - - host_compiler_prefix = get_host_environ(repository_ctx, _GCC_HOST_COMPILER_PREFIX) - if not host_compiler_prefix: - host_compiler_prefix = "/usr/bin" - - cuda_defines["%{host_compiler_prefix}"] = host_compiler_prefix - - # Bazel sets '-B/usr/bin' flag to workaround build errors on RHEL (see - # https://github.com/bazelbuild/bazel/issues/760). - # However, this stops our custom clang toolchain from picking the provided - # LLD linker, so we're only adding '-B/usr/bin' when using non-downloaded - # toolchain. - # TODO: when bazel stops adding '-B/usr/bin' by default, remove this - # flag from the CROSSTOOL completely (see - # https://github.com/bazelbuild/bazel/issues/5634) - cuda_defines["%{linker_bin_path}"] = host_compiler_prefix - - cuda_defines["%{extra_no_canonical_prefixes_flags}"] = "" - cuda_defines["%{unfiltered_compile_flags}"] = "" - if is_cuda_clang: - cuda_defines["%{host_compiler_path}"] = str(cc) - cuda_defines["%{host_compiler_warnings}"] = """ - # Some parts of the codebase set -Werror and hit this warning, so - # switch it off for now. - "-Wno-invalid-partial-specialization" - """ - cuda_defines["%{cxx_builtin_include_directories}"] = to_list_of_strings(host_compiler_includes) - cuda_defines["%{compiler_deps}"] = ":empty" - cuda_defines["%{win_compiler_deps}"] = ":empty" - repository_ctx.file( - "crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc", - "", - ) - repository_ctx.file("crosstool/windows/msvc_wrapper_for_nvcc.py", "") - else: - cuda_defines["%{host_compiler_path}"] = "clang/bin/crosstool_wrapper_driver_is_not_gcc" - cuda_defines["%{host_compiler_warnings}"] = "" - - # nvcc has the system include paths built in and will automatically - # search them; we cannot work around that, so we add the relevant cuda - # system paths to the allowed compiler specific include paths. - cuda_defines["%{cxx_builtin_include_directories}"] = to_list_of_strings( - host_compiler_includes + _cuda_include_path( - repository_ctx, - cuda_config, - ) + [cupti_header_dir], - ) - - # For gcc, do not canonicalize system header paths; some versions of gcc - # pick the shortest possible path for system includes when creating the - # .d file - given that includes that are prefixed with "../" multiple - # time quickly grow longer than the root of the tree, this can lead to - # bazel's header check failing. - if 'gcc' in cc: - cuda_defines["%{extra_no_canonical_prefixes_flags}"] = "\"-fno-canonical-system-headers\"" - - file_ext = ".exe" if is_windows(repository_ctx) else "" - nvcc_path = "%s/nvcc%s" % (cuda_config.config["cuda_binary_dir"], file_ext) - cuda_defines["%{compiler_deps}"] = ":crosstool_wrapper_driver_is_not_gcc" - cuda_defines["%{win_compiler_deps}"] = ":windows_msvc_wrapper_files" - - wrapper_defines = { - "%{cpu_compiler}": str(cc), - "%{cpu_cxx_compiler}": str(cxx), - "%{cuda_version}": cuda_config.cuda_version, - "%{nvcc_path}": nvcc_path, - "%{gcc_host_compiler_path}": str(cc), - "%{nvcc_tmp_dir}": _get_nvcc_tmp_dir_for_windows(repository_ctx), - } - repository_ctx.template( - "crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc", - tpl_paths["crosstool:clang/bin/crosstool_wrapper_driver_is_not_gcc"], - wrapper_defines, - ) - repository_ctx.template( - "crosstool/windows/msvc_wrapper_for_nvcc.py", - tpl_paths["crosstool:windows/msvc_wrapper_for_nvcc.py"], - wrapper_defines, - ) - - cuda_defines.update(_get_win_cuda_defines(repository_ctx)) - - verify_build_defines(cuda_defines) - - # Only expand template variables in the BUILD file - repository_ctx.template( - "crosstool/BUILD", - tpl_paths["crosstool:BUILD"], - cuda_defines, - ) - - # No templating of cc_toolchain_config - use attributes and templatize the - # BUILD file. - repository_ctx.template( - "crosstool/cc_toolchain_config.bzl", - tpl_paths["crosstool:cc_toolchain_config.bzl"], - {}, - ) - - # Set up cuda_config.h, which is used by - # tensorflow/stream_executor/dso_loader.cc. - repository_ctx.template( - "cuda/cuda/cuda_config.h", - tpl_paths["cuda:cuda_config.h"], - { - "%{cuda_version}": cuda_config.cuda_version, - "%{cublas_version}": cuda_config.cublas_version, - "%{cusolver_version}": cuda_config.cusolver_version, - "%{curand_version}": cuda_config.curand_version, - "%{cufft_version}": cuda_config.cufft_version, - "%{cusparse_version}": cuda_config.cusparse_version, - "%{cuda_toolkit_path}": cuda_config.cuda_toolkit_path, - }, - ) - - # Set up cuda_config.py, which is used by gen_build_info to provide - # static build environment info to the API - repository_ctx.template( - "cuda/cuda/cuda_config.py", - tpl_paths["cuda:cuda_config.py"], - _py_tmpl_dict({ - "cuda_version": cuda_config.cuda_version, - "cuda_compute_capabilities": cuda_config.compute_capabilities, - "cpu_compiler": str(cc), - "cpu_cxx_compiler": str(cxx), - }), - ) - -def _py_tmpl_dict(d): - return {"%{cuda_config}": str(d)} - -def _create_remote_cuda_repository(repository_ctx, remote_config_repo): - """Creates pointers to a remotely configured repo set up to build with CUDA.""" - _tpl( - repository_ctx, - "cuda:build_defs.bzl", - { - "%{cuda_is_configured}": "True", - "%{cuda_extra_copts}": _compute_cuda_extra_copts( - repository_ctx, - compute_capabilities(repository_ctx), - ), - }, - ) - repository_ctx.template( - "cuda/BUILD", - config_repo_label(remote_config_repo, "cuda:BUILD"), - {}, - ) - repository_ctx.template( - "cuda/build_defs.bzl", - config_repo_label(remote_config_repo, "cuda:build_defs.bzl"), - {}, - ) - repository_ctx.template( - "cuda/cuda/cuda_config.h", - config_repo_label(remote_config_repo, "cuda:cuda/cuda_config.h"), - {}, - ) - repository_ctx.template( - "cuda/cuda/cuda_config.py", - config_repo_label(remote_config_repo, "cuda:cuda/cuda_config.py"), - _py_tmpl_dict({}), - ) - - repository_ctx.template( - "crosstool/BUILD", - config_repo_label(remote_config_repo, "crosstool:BUILD"), - {}, - ) - - repository_ctx.template( - "crosstool/cc_toolchain_config.bzl", - config_repo_label(remote_config_repo, "crosstool:cc_toolchain_config.bzl"), - {}, - ) - - repository_ctx.template( - "crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc", - config_repo_label(remote_config_repo, "crosstool:clang/bin/crosstool_wrapper_driver_is_not_gcc"), - {}, - ) - -def _cuda_autoconf_impl(repository_ctx): - """Implementation of the cuda_autoconf repository rule.""" - if not enable_cuda(repository_ctx): - _create_dummy_repository(repository_ctx) - elif get_host_environ(repository_ctx, _TF_CUDA_CONFIG_REPO) != None: - has_cuda_version = get_host_environ(repository_ctx, _TF_CUDA_VERSION) != None - if not has_cuda_version: - auto_configure_fail("%s must also be set if %s is specified" % - (_TF_CUDA_VERSION, _TF_CUDA_CONFIG_REPO)) - _create_remote_cuda_repository( - repository_ctx, - get_host_environ(repository_ctx, _TF_CUDA_CONFIG_REPO), - ) - else: - _create_local_cuda_repository(repository_ctx) - -_ENVIRONS = [ - _GCC_HOST_COMPILER_PATH, - _GCC_HOST_COMPILER_PREFIX, - _CLANG_CUDA_COMPILER_PATH, - "TF_NEED_CUDA", - "TF_CUDA_CLANG", - _CUDA_TOOLKIT_PATH, - _TF_CUDA_VERSION, - _TF_CUDA_COMPUTE_CAPABILITIES, - "NVVMIR_LIBRARY_DIR", - _PYTHON_BIN_PATH, - "TMP", - "TMPDIR", - "TF_CUDA_PATHS", -] - -cuda_configure = repository_rule( - implementation = _cuda_autoconf_impl, - environ = _ENVIRONS + [_TF_CUDA_CONFIG_REPO], -) -"""Detects and configures the local CUDA toolchain. - -Add the following to your WORKSPACE FILE: - -```python -cuda_configure(name = "local_config_cuda") -``` - -Args: - name: A unique name for this workspace rule. -""" diff --git a/third_party/rules_cuda/gpus/find_cuda_config.py b/third_party/rules_cuda/gpus/find_cuda_config.py deleted file mode 100644 index 5cbd3e6f..00000000 --- a/third_party/rules_cuda/gpus/find_cuda_config.py +++ /dev/null @@ -1,623 +0,0 @@ -# Copyright 2019 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Prints CUDA library and header directories and versions found on the system. - -The script searches for CUDA library and header files on the system, inspects -them to determine their version and prints the configuration to stdout. -The paths to inspect and the required versions are specified through environment -variables. If no valid configuration is found, the script prints to stderr and -returns an error code. - -The list of libraries to find is specified as arguments. Supported libraries are -CUDA (includes cuBLAS), NCCL, and TensorRT. - -The script takes a list of base directories specified by the TF_CUDA_PATHS -environment variable as comma-separated glob list. The script looks for headers -and library files in a hard-coded set of subdirectories from these base paths. -If TF_CUDA_PATHS is not specified, a OS specific default is used: - - Linux: /usr/local/cuda, /usr, and paths from 'ldconfig -p'. - Windows: CUDA_PATH environment variable, or - C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\* - -For backwards compatibility, some libraries also use alternative base -directories from other environment variables if they are specified. List of -library-specific environment variables: - - Library Version env variable Additional base directories - ---------------------------------------------------------------- - CUDA TF_CUDA_VERSION CUDA_TOOLKIT_PATH - cuBLAS TF_CUBLAS_VERSION CUDA_TOOLKIT_PATH - NCCL TF_NCCL_VERSION NCCL_INSTALL_PATH, NCCL_HDR_PATH - TensorRT TF_TENSORRT_VERSION TENSORRT_INSTALL_PATH - -Versions environment variables can be of the form 'x' or 'x.y' to request a -specific version, empty or unspecified to accept any version. - -The output of a found library is of the form: -tf__version: x.y.z -tf__header_dir: ... -tf__library_dir: ... -""" - -import io -import os -import glob -import platform -import re -import subprocess -import sys - -# pylint: disable=g-import-not-at-top -try: - from shutil import which -except ImportError: - from distutils.spawn import find_executable as which -# pylint: enable=g-import-not-at-top - - -class ConfigError(Exception): - pass - - -def _is_linux(): - return platform.system() == "Linux" - - -def _is_windows(): - return platform.system() == "Windows" - - -def _is_macos(): - return platform.system() == "Darwin" - - -def _matches_version(actual_version, required_version): - """Checks whether some version meets the requirements. - - All elements of the required_version need to be present in the - actual_version. - - required_version actual_version result - ----------------------------------------- - 1 1.1 True - 1.2 1 False - 1.2 1.3 False - 1 True - - Args: - required_version: The version specified by the user. - actual_version: The version detected from the CUDA installation. - Returns: Whether the actual version matches the required one. - """ - if actual_version is None: - return False - - # Strip spaces from the versions. - actual_version = actual_version.strip() - required_version = required_version.strip() - return actual_version.startswith(required_version) - - -def _at_least_version(actual_version, required_version): - actual = [int(v) for v in actual_version.split(".")] - required = [int(v) for v in required_version.split(".")] - return actual >= required - - -def _get_header_version(path, name): - """Returns preprocessor defines in C header file.""" - for line in io.open(path, "r", encoding="utf-8").readlines(): - match = re.match("#define %s +(\d+)" % name, line) - if match: - return match.group(1) - return "" - - -def _cartesian_product(first, second): - """Returns all path combinations of first and second.""" - return [os.path.join(f, s) for f in first for s in second] - - -def _get_ld_config_paths(): - """Returns all directories from 'ldconfig -p'.""" - if not _is_linux(): - return [] - ldconfig_path = which("ldconfig") or "/sbin/ldconfig" - output = subprocess.check_output([ldconfig_path, "-p"]) - pattern = re.compile(".* => (.*)") - result = set() - for line in output.splitlines(): - try: - match = pattern.match(line.decode("ascii")) - except UnicodeDecodeError: - match = False - if match: - result.add(os.path.dirname(match.group(1))) - return sorted(list(result)) - - -def _get_default_cuda_paths(cuda_version): - if not cuda_version: - cuda_version = "*" - elif not "." in cuda_version: - cuda_version = cuda_version + ".*" - - if _is_windows(): - return [ - os.environ.get( - "CUDA_PATH", - "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v%s\\" % - cuda_version) - ] - return ["/usr/local/cuda-%s" % cuda_version, "/usr/local/cuda", "/usr"] + _get_ld_config_paths() - - -def _header_paths(): - """Returns hard-coded set of relative paths to look for header files.""" - return [ - "", - "include", - "include/cuda", - "include/*-linux-gnu", - "extras/CUPTI/include", - "include/cuda/CUPTI", - "local/cuda/extras/CUPTI/include" - ] - - -def _library_paths(): - """Returns hard-coded set of relative paths to look for library files.""" - return [ - "", - "lib64", - "lib", - "lib/*-linux-gnu", - "lib/x64", - "extras/CUPTI/*", - "local/cuda/lib64", - "local/cuda/extras/CUPTI/lib64", - ] - - -def _not_found_error(base_paths, relative_paths, filepattern): - base_paths = "".join(["\n '%s'" % path for path in sorted(base_paths)]) - relative_paths = "".join(["\n '%s'" % path for path in relative_paths]) - return ConfigError( - "Could not find any %s in any subdirectory:%s\nof:%s\n" % - (filepattern, relative_paths, base_paths)) - - -def _find_file(base_paths, relative_paths, filepattern): - for path in _cartesian_product(base_paths, relative_paths): - for file in glob.glob(os.path.join(path, filepattern)): - return file - raise _not_found_error(base_paths, relative_paths, filepattern) - - -def _find_library(base_paths, library_name, required_version): - """Returns first valid path to the requested library.""" - if _is_windows(): - filepattern = library_name + ".lib" - elif _is_macos(): - filepattern = "%s*.dylib" % (".".join(["lib" + library_name] + - required_version.split(".")[:1])) - else: - filepattern = ".".join(["lib" + library_name, "so"] + - required_version.split(".")[:1]) + "*" - return _find_file(base_paths, _library_paths(), filepattern) - - -def _find_versioned_file(base_paths, relative_paths, filepatterns, - required_version, get_version): - """Returns first valid path to a file that matches the requested version.""" - if type(filepatterns) not in [list, tuple]: - filepatterns = [filepatterns] - for path in _cartesian_product(base_paths, relative_paths): - for filepattern in filepatterns: - for file in glob.glob(os.path.join(path, filepattern)): - actual_version = get_version(file) - if _matches_version(actual_version, required_version): - return file, actual_version - raise _not_found_error( - base_paths, relative_paths, - ", ".join(filepatterns) + " matching version '%s'" % required_version) - - -def _find_header(base_paths, header_name, required_version, get_version): - """Returns first valid path to a header that matches the requested version.""" - return _find_versioned_file(base_paths, _header_paths(), header_name, - required_version, get_version) - - -def _find_cuda_config(base_paths, required_version): - - def get_header_version(path): - version = int(_get_header_version(path, "CUDA_VERSION")) - if not version: - return None - return "%d.%d" % (version // 1000, version % 1000 // 10) - - cuda_header_path, header_version = _find_header(base_paths, "cuda.h", - required_version, - get_header_version) - cuda_version = header_version # x.y, see above. - - cuda_library_path = _find_library(base_paths, "cudart", cuda_version) - - def get_nvcc_version(path): - pattern = "Cuda compilation tools, release \d+\.\d+, V(\d+\.\d+\.\d+)" - for line in subprocess.check_output([path, "--version"]).splitlines(): - match = re.match(pattern, line.decode("ascii")) - if match: - return match.group(1) - return None - - nvcc_name = "nvcc.exe" if _is_windows() else "nvcc" - nvcc_path, nvcc_version = _find_versioned_file(base_paths, [ - "", - "bin", - "local/cuda/bin", - ], nvcc_name, cuda_version, get_nvcc_version) - - nvvm_path = _find_file(base_paths, [ - "nvvm/libdevice", - "share/cuda", - "lib/nvidia-cuda-toolkit/libdevice", - "local/cuda/nvvm/libdevice", - ], "libdevice*.10.bc") - - cupti_header_path = _find_file(base_paths, _header_paths(), "cupti.h") - cupti_library_path = _find_library(base_paths, "cupti", required_version) - - cuda_binary_dir = os.path.dirname(nvcc_path) - nvvm_library_dir = os.path.dirname(nvvm_path) - - # XLA requires the toolkit path to find ptxas and libdevice. - # TODO(csigg): pass in both directories instead. - cuda_toolkit_paths = ( - os.path.normpath(os.path.join(cuda_binary_dir, "..")), - os.path.normpath(os.path.join(nvvm_library_dir, "../..")), - ) - if cuda_toolkit_paths[0] != cuda_toolkit_paths[1]: - raise ConfigError("Inconsistent CUDA toolkit path: %s vs %s" % - cuda_toolkit_paths) - - return { - "cuda_version": cuda_version, - "cuda_include_dir": os.path.dirname(cuda_header_path), - "cuda_library_dir": os.path.dirname(cuda_library_path), - "cuda_binary_dir": cuda_binary_dir, - "nvvm_library_dir": nvvm_library_dir, - "cupti_include_dir": os.path.dirname(cupti_header_path), - "cupti_library_dir": os.path.dirname(cupti_library_path), - "cuda_toolkit_path": cuda_toolkit_paths[0], - } - - -def _find_cublas_config(base_paths, required_version, cuda_version): - - if _at_least_version(cuda_version, "10.1"): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("CUBLAS_VER_MAJOR", "CUBLAS_VER_MINOR", - "CUBLAS_VER_PATCH")) - return ".".join(version) - - header_path, header_version = _find_header(base_paths, "cublas_api.h", - required_version, - get_header_version) - # cuBLAS uses the major version only. - cublas_version = header_version.split(".")[0] - - else: - # There is no version info available before CUDA 10.1, just find the file. - header_version = cuda_version - header_path = _find_file(base_paths, _header_paths(), "cublas_api.h") - # cuBLAS version is the same as CUDA version (x.y). - cublas_version = required_version - - library_path = _find_library(base_paths, "cublas", cublas_version) - - return { - "cublas_version": header_version, - "cublas_include_dir": os.path.dirname(header_path), - "cublas_library_dir": os.path.dirname(library_path), - } - - -def _find_cusolver_config(base_paths, required_version, cuda_version): - - if _at_least_version(cuda_version, "11.0"): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("CUSOLVER_VER_MAJOR", "CUSOLVER_VER_MINOR", - "CUSOLVER_VER_PATCH")) - return ".".join(version) - - header_path, header_version = _find_header(base_paths, "cusolver_common.h", - required_version, - get_header_version) - cusolver_version = header_version.split(".")[0] - - else: - header_version = cuda_version - header_path = _find_file(base_paths, _header_paths(), "cusolver_common.h") - cusolver_version = required_version - - library_path = _find_library(base_paths, "cusolver", cusolver_version) - - return { - "cusolver_version": header_version, - "cusolver_include_dir": os.path.dirname(header_path), - "cusolver_library_dir": os.path.dirname(library_path), - } - - -def _find_curand_config(base_paths, required_version, cuda_version): - - if _at_least_version(cuda_version, "11.0"): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("CURAND_VER_MAJOR", "CURAND_VER_MINOR", - "CURAND_VER_PATCH")) - return ".".join(version) - - header_path, header_version = _find_header(base_paths, "curand.h", - required_version, - get_header_version) - curand_version = header_version.split(".")[0] - - else: - header_version = cuda_version - header_path = _find_file(base_paths, _header_paths(), "curand.h") - curand_version = required_version - - library_path = _find_library(base_paths, "curand", curand_version) - - return { - "curand_version": header_version, - "curand_include_dir": os.path.dirname(header_path), - "curand_library_dir": os.path.dirname(library_path), - } - - -def _find_cufft_config(base_paths, required_version, cuda_version): - - if _at_least_version(cuda_version, "11.0"): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("CUFFT_VER_MAJOR", "CUFFT_VER_MINOR", "CUFFT_VER_PATCH")) - return ".".join(version) - - header_path, header_version = _find_header(base_paths, "cufft.h", - required_version, - get_header_version) - cufft_version = header_version.split(".")[0] - - else: - header_version = cuda_version - header_path = _find_file(base_paths, _header_paths(), "cufft.h") - cufft_version = required_version - - library_path = _find_library(base_paths, "cufft", cufft_version) - - return { - "cufft_version": header_version, - "cufft_include_dir": os.path.dirname(header_path), - "cufft_library_dir": os.path.dirname(library_path), - } - - -def _find_cusparse_config(base_paths, required_version, cuda_version): - - if _at_least_version(cuda_version, "11.0"): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("CUSPARSE_VER_MAJOR", "CUSPARSE_VER_MINOR", - "CUSPARSE_VER_PATCH")) - return ".".join(version) - - header_path, header_version = _find_header(base_paths, "cusparse.h", - required_version, - get_header_version) - cusparse_version = header_version.split(".")[0] - - else: - header_version = cuda_version - header_path = _find_file(base_paths, _header_paths(), "cusparse.h") - cusparse_version = required_version - - library_path = _find_library(base_paths, "cusparse", cusparse_version) - - return { - "cusparse_version": header_version, - "cusparse_include_dir": os.path.dirname(header_path), - "cusparse_library_dir": os.path.dirname(library_path), - } - - -def _find_nccl_config(base_paths, required_version): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("NCCL_MAJOR", "NCCL_MINOR", "NCCL_PATCH")) - return ".".join(version) - - header_path, header_version = _find_header(base_paths, "nccl.h", - required_version, - get_header_version) - nccl_version = header_version.split(".")[0] - - library_path = _find_library(base_paths, "nccl", nccl_version) - - return { - "nccl_version": nccl_version, - "nccl_include_dir": os.path.dirname(header_path), - "nccl_library_dir": os.path.dirname(library_path), - } - - -def _find_tensorrt_config(base_paths, required_version): - - def get_header_version(path): - version = ( - _get_header_version(path, name) - for name in ("NV_TENSORRT_MAJOR", "NV_TENSORRT_MINOR", - "NV_TENSORRT_PATCH")) - # `version` is a generator object, so we convert it to a list before using - # it (muitiple times below). - version = list(version) - if not all(version): - return None # Versions not found, make _matches_version returns False. - return ".".join(version) - - try: - header_path, header_version = _find_header(base_paths, "NvInfer.h", - required_version, - get_header_version) - except ConfigError: - # TensorRT 6 moved the version information to NvInferVersion.h. - header_path, header_version = _find_header(base_paths, "NvInferVersion.h", - required_version, - get_header_version) - - tensorrt_version = header_version.split(".")[0] - library_path = _find_library(base_paths, "nvinfer", tensorrt_version) - - return { - "tensorrt_version": tensorrt_version, - "tensorrt_include_dir": os.path.dirname(header_path), - "tensorrt_library_dir": os.path.dirname(library_path), - } - - -def _list_from_env(env_name, default=[]): - """Returns comma-separated list from environment variable.""" - if env_name in os.environ: - return os.environ[env_name].split(",") - return default - - -def _get_legacy_path(env_name, default=[]): - """Returns a path specified by a legacy environment variable. - - NCCL_INSTALL_PATH, TENSORRT_INSTALL_PATH set to - '/usr/lib/x86_64-linux-gnu' would previously find both library and header - paths. Detect those and return '/usr', otherwise forward to _list_from_env(). - """ - if env_name in os.environ: - match = re.match("^(/[^/ ]*)+/lib/\w+-linux-gnu/?$", os.environ[env_name]) - if match: - return [match.group(1)] - return _list_from_env(env_name, default) - - -def _normalize_path(path): - """Returns normalized path, with forward slashes on Windows.""" - path = os.path.realpath(path) - if _is_windows(): - path = path.replace("\\", "/") - return path - - -def find_cuda_config(): - """Returns a dictionary of CUDA library and header file paths.""" - libraries = [argv.lower() for argv in sys.argv[1:]] - cuda_version = os.environ.get("TF_CUDA_VERSION", "") - base_paths = _list_from_env("CUDA_PATHS", - _get_default_cuda_paths(cuda_version)) - base_paths = [path for path in base_paths if os.path.exists(path)] - - result = {} - if "cuda" in libraries: - cuda_paths = _list_from_env("CUDA_TOOLKIT_PATH", base_paths) - result.update(_find_cuda_config(cuda_paths, cuda_version)) - - cuda_version = result["cuda_version"] - cublas_paths = base_paths - if tuple(int(v) for v in cuda_version.split(".")) < (10, 1): - # Before CUDA 10.1, cuBLAS was in the same directory as the toolkit. - cublas_paths = cuda_paths - cublas_version = os.environ.get("TF_CUBLAS_VERSION", "") - result.update( - _find_cublas_config(cublas_paths, cublas_version, cuda_version)) - - cusolver_paths = base_paths - if tuple(int(v) for v in cuda_version.split(".")) < (11, 0): - cusolver_paths = cuda_paths - cusolver_version = os.environ.get("TF_CUSOLVER_VERSION", "") - result.update( - _find_cusolver_config(cusolver_paths, cusolver_version, cuda_version)) - - curand_paths = base_paths - if tuple(int(v) for v in cuda_version.split(".")) < (11, 0): - curand_paths = cuda_paths - curand_version = os.environ.get("TF_CURAND_VERSION", "") - result.update( - _find_curand_config(curand_paths, curand_version, cuda_version)) - - cufft_paths = base_paths - if tuple(int(v) for v in cuda_version.split(".")) < (11, 0): - cufft_paths = cuda_paths - cufft_version = os.environ.get("TF_CUFFT_VERSION", "") - result.update(_find_cufft_config(cufft_paths, cufft_version, cuda_version)) - - cusparse_paths = base_paths - if tuple(int(v) for v in cuda_version.split(".")) < (11, 0): - cusparse_paths = cuda_paths - cusparse_version = os.environ.get("TF_CUSPARSE_VERSION", "") - result.update( - _find_cusparse_config(cusparse_paths, cusparse_version, cuda_version)) - - if "nccl" in libraries: - nccl_paths = _get_legacy_path("NCCL_INSTALL_PATH", base_paths) - nccl_version = os.environ.get("TF_NCCL_VERSION", "") - result.update(_find_nccl_config(nccl_paths, nccl_version)) - - if "tensorrt" in libraries: - tensorrt_paths = _get_legacy_path("TENSORRT_INSTALL_PATH", base_paths) - tensorrt_version = os.environ.get("TF_TENSORRT_VERSION", "") - result.update(_find_tensorrt_config(tensorrt_paths, tensorrt_version)) - - for k, v in result.items(): - if k.endswith("_dir") or k.endswith("_path"): - result[k] = _normalize_path(v) - - return result - - -def main(): - try: - for key, value in sorted(find_cuda_config().items()): - print("%s: %s" % (key, value)) - except ConfigError as e: - sys.stderr.write(str(e)) - sys.exit(1) - - -if __name__ == "__main__": - main() diff --git a/third_party/rules_cuda/gpus/find_cuda_config.py.gz.base64 b/third_party/rules_cuda/gpus/find_cuda_config.py.gz.base64 deleted file mode 100644 index 85a97195..00000000 --- a/third_party/rules_cuda/gpus/find_cuda_config.py.gz.base64 +++ /dev/null @@ -1 +0,0 @@ -eJzdPGtT40iS3/0r6tRHINNGwOzGxJ5vmQsGum/Y5aAD3D23AV5vIZWNpmVJJ8kG78b+98vMqpJKJckG0z3bMURMjyVVZmVm5bNeb9hpkq6ycPZQsO8Oj/6DjR4EG4k4T7L3UfLIThbFQ5LlHjuJInaNzXJ2LXKRLUXg9d703rCL0IfmImCLOBAZKwD+JOU+/E99GbBPIsvDJGbfeYfMxQaO+uT0/xMwrJIFm/MVi5OCLXIBKMKcTcNIMPHki7RgYcz8ZJ5GIY99wR7D4oG6UUiADPYXhSK5Lzi05tA+haep2Y7xggjGv4eiSIcHB4+Pjx4nYr0kmx1EsmF+cHF++u7y5t0+EEwgH+NI5DnLxP8twgxYvV8xngI9Pr8HKiP+yJKM8Vkm4FuRIL2PWViE8WzA8mRaPPJMAJYgzIssvF8UNWFp6oBnswGIi8fMOblh5zcO+/Hk5vxmADh+Ph/9dPVxxH4+ub4+uRydv7thV9fs9Ory7Hx0fnUJT+/ZyeVf2J/PL88GTICooBvxlGZIPxAZohhp6NiNEDUCpokkKE+FH05DH/iKZws+E2yWLEUWAzssFdk8zHEwcyAvACxROA8LXtCbBlPYzfEX/es5jvMhC2NQw9OPZyfQ/X3GsxUSwx4Ex/4DGCK/SLJQEI1sKbUPVCoBAlGwxOUqL8Tc6/VQ4XM/C0HPcsEz0IWcRNGFHhUzr2MZwIij1Iq8By/nqAKBKFBUMYk4zDQRhCiV9CO8n8TTcLbISIAIlxdBsig8oirlxUMu9YmwEzBClXpYsgYKpscNVfAhSxazBybiZZgl8VzERW/JsxC1FUz5fAqmxpY8CgOLgFAJaSCZk1LR5BJxIsto4DNRLDJSAgavQFx+EgglzQjUGG1PCg+HAWCnIRAP+CsqOZI9WyB1QNTNIk2TDDW/AkOzoWFww9iPFgG88hc/Xpzc9Afw4+zycsAuT08vBiQY6bSuR/UhLfhnRFTSdM9B000NqegBo0auR+8n2Ofkw8nop5ueIUKmRYiUgz+a8/1cpBxEB8CzKLmnTjxm9B4lyWepTVJ58h5SqpVKahK5qweeBfsowgCUkAjNF/cmmdMsmSN5QD2xQLrh9WAoa/SihNGNllyBbNjVTWXTgZjyRVRgO3C1wbDXY2Cs8eJpCF7xYJFnB1Hi8+jAXwR8QC+kdKUuEhW7USC1hu2nux7A/wxDmzzmQ1bSwdrENgD/02PV3+nw7u5DlswyPmfvURR3d5efzs/OT9h/f/gIYWmeLtCFslGSRJ/D4u4O0d/d7fV670Gg99z/DH41oKEA6sL7MAqLFTrcuTB1KMoTiio8AouMoeFSirDXEG8inWUL6TBKFEpWdUPzQHSkVj01pPulnFuxKGnL0WdlWIS2lW6xkyAI0Rh51FBWgN5/5R+gIIuiP606n95d30Dw0OOCr0ZXVxd/Ph/RaAKMNLsSBh9qUO0wYKFGP5eX9Y7kq/PLm9HJxYUGQnsuicMHizh6ZcJIFzD56exao9COgFCMII5fXV+PDDTlq1rXvU/al7YrgA+e7l7olAJMGgzhaRdD6u6Tt9pFF4duWYA+8F6pBspBQySep8UKWy9iw08njPuU4fB4pdsq/wVRAPQf++MqcGm3AaZrUDHsFdPJH9W3HyYKyZABUd7f69+kD5qAQg2Z53n1j+pH9RUCba8H6QI4ZRYm+leS61/o8fTvNOIFEqOfwW+rX+DG0izxIfso36zyHqQF6SqCsDLEnAcFfDzbl9/3wX3t82K/SNJeka2GMKBknPkDeIOIKSSPD6H/0FPp4Tm9e4dhqGyOqRQC5F6e8sdYw2EUmogn4S8K7cklqoogEXfS0+v5EYc86pTcH3XoviMaQOR97DuFz9AMvCybhDkIFTyrS19kwCwl5cnMwe1DfoTpMLRzDMBH6VKfAaqcrwk8537yHNAznkE/JeScF5j8aBVyuV8seDQpVVhnHfoNdQBacvog/M8oR0H+k/yvTnfmQqhMR0HLaN9TcQCLChHJl1qp7W5YrLJqsD5MY9EsQ8q+FJI6nSVu/GvgshpjixzCoQHyEk+q/46Y/Xfk1d+NsoUwAbzvbADr+T3ErQ0Q3u/WQjT/7D6IKD0S2SwfltC23IaU1GihNVImCK+ZVwLXRVwHxbTYx3xJ5zMyGkGCW/AooiRUI7qWGeaQ/awUC1tL3JV6SZWtJ8VJLDypmfAvxG1ryMF9XkITyayyDyk7eANVEVRgKbDIfSPrKhNtRGzhO7YVEGu41O33WtTvuPGq1ppoaWDjWZFjzes2DFBbLi8mkeB58TLTVbI8Zrfg99xln/LUJeWjFglQMhau4zn9scFUG2CTOwvU4JD9UElDMzIThY5SmhVMPAcs5nOh/Y1SDHQGKrRA9wAOxRZl06dmpeZJNUAKI6zG4HuYeEkqNGYncyA6x5B7Q6557CyK6f4fnL6XAQoEUH6USVWjAfTop+u8kX2ynZy9de+Ct32H7RChA+qqT2Cgf9Rc25YSAb3zZlCmpe6RMfhO6Y19GHaRhzyeAJPBwi/caZjlBeS3ArLvwBYGWA/l6JgN34exKsjBpRIUpfASUAlE9Xeb5B6Ceb8kYexOAbsczSkKSoLiI8lVwo/NsYqCiSwFJlQfuG1UNdLsev1QmimWLVbMrMhE7dFg1BeMBAVu19GvnT6mV85BDuwflC8BTmVSx0Yu4vkYsybyi3tbwwwqsZ864z5F8wJrBjnqWGaAQoEy77HjH5jr7fUdOXIYQRC9KMiOTV2TPUgzqKmTSm1MzVK9KfXC1l4gsCZ0HZ77Yej0pUqprOdjHOLHM2pSJj8mwioiNLUQafZ4ELhaAWCYUHfdumb2Dd3MqTx3sch1JYJ+31QGVVpOsHRU+kA/TZ+jxtl8L2ky3wDpzh6OnIhUe3AgNAm4Caz2+BbAAI3stZFUVbpVBi4Qhcr9PeDHrcVSp6xtnYH1YbsydrkDDcFj1JDV5EVfDLd561j1+f5Oji7HBALltRo56pVJttUmjp0xSKvdovUIK7fcbufN6YtMRLLULiexcC7EmAqRsx+WN1IkOiWxjpr4abxQvNlv9/bJfezP4kX1UTwVGc8PTj9+GJ0frEUo21TfKjEetCLp4QApAekC6gtIqDZBtFFE0Pr739ceaw/tMsEPTyZYjb+9VhHYHXUIp2pWygZseEJF7IQmC12c2JCCGpRy0M/ItHKFJMSqLfoFR0aqW+cu1tq8u5Pvoh1QWEDx0Y+wdFgVgv5YujOzw5cirUOPDf9oVoVaRqfJIgrIhdH8J5b5O3LKD34ZU3yrIbiDOJnS/yqv4BrCaErKYKw0UypwEepFMjYZbMk8ulEpV0opAy7YADzOC3j4j1vLLWRoNTvuWzkRfkNp8jAX26tMTRDKkGrA2k5lptZV1Gq7lTmQnCsnCYGd6mpD5NV09apKZFpCjUEg6JtJAUUpNFkd7qwC3oZ1dvI9L1ghBGgnZtZad+nV2xpy8OprC8L635rk/XZ4NKZUQEBG0UrWWjogBOWJs4GaTd2jpPYMT9ih6rYfXqMdqiPxMoPJB91c2DwMGMbUF6gWl2ZUPPCiUdxKddPSKdWtWKXC9BOQwaO/AUu8xVRtwIpFGolxY9TQ892az+Mv6Ai0ZoRxrUtt8a/zFy0luCFmkkW/bBpuO7NVjWnpnQZWx93eSsGvUSkdIcA2VPFVG0JQdqkAmDpqPnVQ6pwIILWW+VVtrFTy1u7ytlBSlcI9W01rJrvG7Kwss074Ble2nq2ahChjlmmupdINPYBOEa5jYkIpSqWHOCHSPYvhmKstupxTJU6trCklhjNVZrHi7ATeTkCuX3d6cMCODg8PByUVO/Qs3/eRAWLXkGwp1oruTs1xENh7cDZJ/1kjsgWOpiz7vUbZZ7HD3uDqB86UCMbvk6XwSimYwaFkuy1LIL6zwhlYNZmhD/HS99u0wYiKpwDL5MSBXuFPIukLBK7t3QVv7zz4Z8A+ufo3/dN3SneqpxI6Zy/0pMW+osUZ91smHFpmsMrEsnuuoTl10D2FVVdaeEECoiQHRIEPnngSTiNFoqRCNnA0lJr1MyRcjtYa99FSHN2HcWvFot+PBxWZA6uUtge5L5lazuvq000GtsVyKBDL0DdKzhyqQbuCxYIsXoZByPepti/kdEEbuMFGSw/AkVO+2fOODr1731F+IC1C0xF0s9BwxA4BgyPol4heYkvQ3mnxr6Vd4pSlXHwETPaUVKkRfS1/Y7Gytb0aor6c0v/fixPdtQxTSrZlQKPaLC2euNwwVErPI/DR1dmV6+fhbNYf0gIfWuN9AqDm1CYuYYDMPM2R6qMsMnVKoImNkwy3LTzUsx5LGJgcQP7bHzwL2BYNQR+UCPoyX2xSd3s4Zv923PbhSKWNMssxC1znPIYAmkOCietxtIhjSnWIZe4yZzRD1eH2m/3ReCkn8g+t7aZNOsO6idbaqEkZ5Bza2UphB8F+HdgQWxewqe8WdDVimkJjDE1vYPXTGLEKK1rYJo4sc+5b4Jt4so3YYsocGs2WrTcI8U8rt7qPeP6c7MoKrUM9U9tYzbImOMGjHTmy+XOSMzM9M+d0Nyw2GS0xClMYA7t3nWr3y+R/Tv50de1QXle9O7/Ed12pjtn0w8no9Kcq0uoUT5fSppNkbPv8jcaDp+E2WdyrU7j2/A3dqtpStMiVU57zX5Jqn2QSRyu5EqwY6Mr2zGmCw3GvNkfxBteeMyE3xZWow3gKNcySQ06GW0DuBYyvWodG1RqwXxa5mq+jTTa4imgOQftygz1IL4utxhhZ8jGWrWlPJuohV5tf9TcX0t1+h7TsEUQJvSRyIzrKgk28HY7abAIeoy6vgdVuvXPrcGsEud6vNTya7Z/yJAKSvqqHOvIO/6Ue6ubqAh2M5aPMtxu9lNH4V/JT5bjM52DW35KzKmnbxgl9Ra9hS6yT2tc6AYmQ3EAdd4cjqDda5wpUy62cgYJ9pTvIeBz8pp3B9cnlme0KqncbHUHZ9FdyAzge35j1k4p8Y7avxNRB4msNHtGRuZt4O4zdbLLO1KndVoZOkK808+m0+E1b+fv3I9vIy1fSxs1Xv5Itg9C/MVNGNfjGLFkKqZ3A19oxYCMzNrB2WLHRYp0RY7OtbBgBX2nCQRx/nVWbagvYc+3Ptj48yWJYHj1WVoePZHEX7z69u5B7YbuNDv2N+o0zczQ7rqfUtzPFl5mP65Co0XCZ/FkaCKjpC5G90pQ7l38qop5hxi9a9YljuehT9dA1LVm1kNNj1fOg3morg0HA11a6Kc+Aud9y2Lv5cHJ9865R6RpvN1e6VeNfq9KlcfnGIqNSlm8sOJai6iTz1bUtIZS1bQ13V21ba7S2tpUtt6ttJeyrHEDs+9HXCZiV7W4XMOnIZmmv8kmHS3qqGeI6M9zWCFE2LzfArxLNaJi+RjBDxCBRE3+rTpsNcFHKeBzU2myhyQT3Ki0u6Dhv9qzq7V+gyZ+qI8aVQpsv18WfWsuazr9hf1NE/A2n/jkwFIuMF9B5cv+L8PEgUMIe6QYJaFiwsJBbs+iiA7WmscjDeKbQwXd3vgiLMMX9heFc5NAqSh7VukElETrfUYsNaocSjyK3krM2iHLHB3bySX6WdxComyTm/LNobMFj+v4IOqPibTTz8rjMtvZ+uTyPpyL7hmKuOsZjLKqXi1b6APv3bJ4sRWCeQKTVq2xe3hei+PqkE3TvS0ipxPaNCAsVQHuBZzrKF/nJZYhcg+XavbS6S7sRuDT71aDRdgvXWcJu6z7Rkid45G4i4qUL/6ldTuqg1vHt2N7tad9qQs6EDu21XYpQ7UHWuOnIW3mKqnbMqnp9q1uP9ZgNHOMYhaKudsxQzLgvOXwWG1zu7KmdUwbPSFjaOcFxbt5HMWi7bqL1+gg61FMkgGVXnq3C4zV/+H7y/e+rwze77JFOg6SZWIbJIo9WcpGZthI1LxrqMXXJCzujQ9PgBRK8xgQaKElRV7sDeW/JYyivcMI7UdAxWKPfrx2JXjdezYOuf3UPbv96wMZ7/bfE2N3j24qrg//6dzCcttFdewD2tr590Djmtklt+9WhIvCDUfh3achVeDcUoWwiNy8P5N1hWkp5xPMHeZeTukVBabRyGdrSMsGjqote1yEPBaVA0oj7wnXu7ugAnqng2EDx0NiN3NTkIPTpNpiMrjNbdymVUhfJQnUBzjG75dls6UGsB3cvj/fiC9pTuso9/H17NByPe419tdaBSMe6LwY5I8ZqR7Ss8asOTt5sjCbPOkba6JA2wNZOLhifYaj0MIonICyXgziWjl2d3P3HP+Wg0r4nOmlais84ZrqWQfPuG6d2NEs5QTpwu0gD8Ktucxd61YE1E6PmGqyBkehu63vjxqol7ZHQxFaEaGuk4yCufXLfxGSE0j77I3OPDgfsqEz53rAfGztm1F6VR56rqznkPpXydBvuWDE2XuorHixaKyGYnGxQR/MqolIhbYFXSX7LHjWTCnujS9doqKXnLyplkONhKeVGFw3hNBb5W8VTbeN4mYDqm2Tq1DS3AXSJiRbuvqaQah00RGQtirYKSC9vv0w85qYBkwp7ybRLMLga8jXlYuJviKW+xNQqFbVOuFYoLSurRsfWqlOnIcl5rq9qSPUumoZkzyi2G1I5S/xCQ6rNwdepac45tolJBaY47ohMcVyFJjtbdppJbUt0stdT2uN+dX/bRpUwVuoMAu1llZI7mqhqYY4mj7p5ayTnLaxZk2stnJmXzG1gzJxQrWizZthKrnT91sZZWdt1c9daZ7Rw2FIZt3Bp34O3gVN70q1Ob0uhTFyjeX4e6KuACGtYiHmZIYNUPgNlgbzOyKGClm5tqb3FLhxjholSnc9jFJKV8i/N+lzd5CUT6zkPY9lrOXNExInVAA8zLoRxP0AzCddUl0TQFaius5MP5YkG5laY+u2TOZjyqOURzLLl1akeXgss3LzIXKEm+vAjZKYFnqHq9bCyoHJnMqEr2iYT5GQycRCTZKr3/4K5Yeo= \ No newline at end of file diff --git a/third_party/rules_cuda/nccl/BUILD b/third_party/rules_cuda/nccl/BUILD deleted file mode 100644 index e69de29b..00000000 diff --git a/third_party/rules_cuda/nccl/LICENSE b/third_party/rules_cuda/nccl/LICENSE deleted file mode 100644 index b9585181..00000000 --- a/third_party/rules_cuda/nccl/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ - - Copyright (c) 2015-2018, NVIDIA CORPORATION. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of NVIDIA CORPORATION, Lawrence Berkeley National - Laboratory, the U.S. Department of Energy, nor the names of their - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - The U.S. Department of Energy funded the development of this software - under subcontract 7078610 with Lawrence Berkeley National Laboratory. diff --git a/third_party/rules_cuda/nccl/archive.BUILD b/third_party/rules_cuda/nccl/archive.BUILD deleted file mode 100644 index 028b348c..00000000 --- a/third_party/rules_cuda/nccl/archive.BUILD +++ /dev/null @@ -1,100 +0,0 @@ -# NVIDIA NCCL 2 -# A package of optimized primitives for collective multi-GPU communication. - -licenses(["notice"]) - -exports_files(["LICENSE.txt"]) - -load( - "@local_config_nccl//:build_defs.bzl", - "cuda_rdc_library", - "gen_device_srcs", -) - -cc_library( - name = "src_hdrs", - hdrs = [ - "src/include/collectives.h", - "src/nccl.h", - ], - strip_include_prefix = "src", -) - -cc_library( - name = "include_hdrs", - hdrs = glob(["src/include/*.h"]), - strip_include_prefix = "src/include", - deps = ["@local_config_cuda//cuda:cuda_headers"], -) - -cc_library( - name = "device_hdrs", - hdrs = glob(["src/collectives/device/*.h"]), - strip_include_prefix = "src/collectives/device", -) - -# NCCL compiles the same source files with different NCCL_OP/NCCL_TYPE defines. -# RDC compilation requires that each compiled module has a unique ID. Clang -# derives the module ID from the path only so we need to copy the files to get -# different IDs for different parts of compilation. NVCC does not have that -# problem because it generates IDs based on preprocessed content. -gen_device_srcs( - name = "device_srcs", - srcs = [ - "src/collectives/device/all_gather.cu.cc", - "src/collectives/device/all_reduce.cu.cc", - "src/collectives/device/broadcast.cu.cc", - "src/collectives/device/reduce.cu.cc", - "src/collectives/device/reduce_scatter.cu.cc", - "src/collectives/device/sendrecv.cu.cc", - ], -) - -cuda_rdc_library( - name = "device", - srcs = [ - "src/collectives/device/functions.cu.cc", - ":device_srcs", - ] + glob([ - # Required for header inclusion checking, see below for details. - "src/collectives/device/*.h", - "src/nccl.h", - ]), - deps = [ - ":device_hdrs", - ":include_hdrs", - ":src_hdrs", - "@local_config_cuda//cuda:cuda_headers", - ], -) - -# Primary NCCL target. -cc_library( - name = "nccl", - srcs = glob( - include = [ - "src/**/*.cc", - # Required for header inclusion checking, see below for details. - "src/graph/*.h", - ], - # Exclude device-library code. - exclude = ["src/collectives/device/**"], - ) + [ - # Required for header inclusion checking (see - # http://docs.bazel.build/versions/master/be/c-cpp.html#hdrs). - # Files in src/ which #include "nccl.h" load it from there rather than - # from the virtual includes directory. - "src/include/collectives.h", - "src/nccl.h", - ], - hdrs = ["src/nccl.h"], - include_prefix = "third_party/nccl", - linkopts = ["-lrt"], - strip_include_prefix = "src", - visibility = ["//visibility:public"], - deps = [ - ":device", - ":include_hdrs", - ":src_hdrs", - ], -) diff --git a/third_party/rules_cuda/nccl/archive.patch b/third_party/rules_cuda/nccl/archive.patch deleted file mode 100644 index 9dfe432d..00000000 --- a/third_party/rules_cuda/nccl/archive.patch +++ /dev/null @@ -1,224 +0,0 @@ -diff --git a/src/collectives/device/all_gather.cu b/src/collectives/device/all_gather.cu.cc -similarity index 100% -rename from src/collectives/device/all_gather.cu -rename to src/collectives/device/all_gather.cu.cc -diff --git a/src/collectives/device/all_reduce.cu b/src/collectives/device/all_reduce.cu.cc -similarity index 100% -rename from src/collectives/device/all_reduce.cu -rename to src/collectives/device/all_reduce.cu.cc -diff --git a/src/collectives/device/broadcast.cu b/src/collectives/device/broadcast.cu.cc -similarity index 100% -rename from src/collectives/device/broadcast.cu -rename to src/collectives/device/broadcast.cu.cc -diff --git a/src/collectives/device/functions.cu b/src/collectives/device/functions.cu.cc -similarity index 100% -rename from src/collectives/device/functions.cu -rename to src/collectives/device/functions.cu.cc -diff --git a/src/collectives/device/reduce.cu b/src/collectives/device/reduce.cu.cc -similarity index 100% -rename from src/collectives/device/reduce.cu -rename to src/collectives/device/reduce.cu.cc -diff --git a/src/collectives/device/reduce_scatter.cu b/src/collectives/device/reduce_scatter.cu.cc -similarity index 100% -rename from src/collectives/device/reduce_scatter.cu -rename to src/collectives/device/reduce_scatter.cu.cc -diff --git a/src/collectives/device/sendrecv.cu b/src/collectives/device/sendrecv.cu.cc -similarity index 100% -rename from src/collectives/device/sendrecv.cu -rename to src/collectives/device/sendrecv.cu.cc -diff --git a/src/nccl.h.in b/src/nccl.h -similarity index 98% -rename from src/nccl.h.in -rename to src/nccl.h -index 985274e..7ebb1e1 100644 ---- a/src/nccl.h.in -+++ b/src/nccl.h -@@ -10,12 +10,12 @@ - #include - #include - --#define NCCL_MAJOR ${nccl:Major} --#define NCCL_MINOR ${nccl:Minor} --#define NCCL_PATCH ${nccl:Patch} --#define NCCL_SUFFIX "${nccl:Suffix}" -+#define NCCL_MAJOR 2 -+#define NCCL_MINOR 7 -+#define NCCL_PATCH 3 -+#define NCCL_SUFFIX "" - --#define NCCL_VERSION_CODE ${nccl:Version} -+#define NCCL_VERSION_CODE 2703 - #define NCCL_VERSION(X,Y,Z) ((X) * 1000 + (Y) * 100 + (Z)) - - #ifdef __cplusplus -See https://github.com/NVIDIA/nccl/pull/322.patch -From 410d341bd4569f60282576daa5c991717dbd560e Mon Sep 17 00:00:00 2001 -From: Danilo -Date: Tue, 14 Apr 2020 14:52:42 +0200 -Subject: [PATCH 1/2] Fix memory leak in xml.cc. - -This patch fixes the memory leak documented in -https://github.com/NVIDIA/nccl/issues/321, where one of the buffers -allocated by realpath(), inside getPciPath() is not freed. - -The memory management aspect of this function also seemed odd and -unecessary, as the realpath() function is documented to only write up to -PATH_MAX bytes to the buffer passed to it, meaning we don't need dynamic -memory allocation at all. I also changed the function signature of -getPciPath to enforce the use of a fixed-size buffer. ---- - src/graph/xml.cc | 23 ++++++++++++----------- - 1 file changed, 12 insertions(+), 11 deletions(-) - -diff --git a/src/graph/xml.cc b/src/graph/xml.cc -index 550cfcd0c..8fea91950 100644 ---- a/src/graph/xml.cc -+++ b/src/graph/xml.cc -@@ -323,12 +323,14 @@ ncclResult_t ncclTopoGetXmlFromFile(const char* xmlTopoFile, struct ncclXml* xml - static void memcpylower(char* dst, const char* src, const size_t size) { - for (int i=0; iparent; - if (parent == NULL) { -- if (path == NULL) NCCLCHECK(getPciPath(busId, &path)); -+ NCCLCHECK(getPciPath(busId, path)); - - // Save that for later in case next step is a CPU - char numaIdStr[MAX_STR_LEN]; -@@ -544,7 +546,6 @@ ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* - } else if (strcmp(parent->name, "cpu") == 0) { - NCCLCHECK(ncclTopoGetXmlFromCpu(parent, xml)); - } -- free(path); - return ncclSuccess; - } - -@@ -644,8 +644,8 @@ ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvm - // Remote NVLink device is not visible inside this VM. Assume NVSwitch. - NCCLCHECK(xmlSetAttr(sub, "tclass", "0x068000")); - } else { -- char* path; -- NCCLCHECK(getPciPath(busId, &path)); -+ char path[PATH_MAX+1]; -+ NCCLCHECK(getPciPath(busId, path)); - NCCLCHECK(ncclTopoSetAttrFromSys(sub, path, "class", "tclass")); - } - } - -From f02d51952ac587237ea5f7c607a5b379381d09d7 Mon Sep 17 00:00:00 2001 -From: Danilo -Date: Tue, 14 Apr 2020 22:17:49 +0200 -Subject: [PATCH 2/2] Performance tweaks in ncclTopoGetXmlFromSys. - -Reduce the number of getPciPath calls to a single one per invocation -and split the function in two so that the large `path` buffer does -not linger the in the stack during recursive calls. ---- - src/graph/xml.cc | 17 +++++++++++------ - 1 file changed, 11 insertions(+), 6 deletions(-) - -diff --git a/src/graph/xml.cc b/src/graph/xml.cc -index 8fea91950..42eb68a4b 100644 ---- a/src/graph/xml.cc -+++ b/src/graph/xml.cc -@@ -460,20 +460,21 @@ int checkBDFFormat(char* bdf) { - return 1; - } - --ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* xml) { -+ncclResult_t ncclTopoGetXmlNodeFromSys(struct ncclXmlNode* pciNode, -+ struct ncclXml* xml, -+ struct ncclXmlNode** return_parent) { - // Fill info, then parent - const char* busId; - NCCLCHECK(xmlGetAttr(pciNode, "busid", &busId)); - char path[PATH_MAX+1]; -+ NCCLCHECK(getPciPath(busId, path)); - int index; - NCCLCHECK(xmlGetAttrIndex(pciNode, "class", &index)); - if (index == -1) { -- NCCLCHECK(getPciPath(busId, path)); - NCCLCHECK(ncclTopoSetAttrFromSys(pciNode, path, "class", "class")); - } - NCCLCHECK(xmlGetAttrIndex(pciNode, "link_speed", &index)); - if (index == -1) { -- NCCLCHECK(getPciPath(busId, path)); - char deviceSpeedStr[MAX_STR_LEN]; - float deviceSpeed; - NCCLCHECK(ncclTopoGetStrFromSys(path, "max_link_speed", deviceSpeedStr)); -@@ -486,7 +487,6 @@ ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* - } - NCCLCHECK(xmlGetAttrIndex(pciNode, "link_width", &index)); - if (index == -1) { -- NCCLCHECK(getPciPath(busId, path)); - char strValue[MAX_STR_LEN]; - NCCLCHECK(ncclTopoGetStrFromSys(path, "max_link_width", strValue)); - int deviceWidth = strtol(strValue, NULL, 0); -@@ -496,8 +496,6 @@ ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* - } - struct ncclXmlNode* parent = pciNode->parent; - if (parent == NULL) { -- NCCLCHECK(getPciPath(busId, path)); -- - // Save that for later in case next step is a CPU - char numaIdStr[MAX_STR_LEN]; - NCCLCHECK(ncclTopoGetStrFromSys(path, "numa_node", numaIdStr)); -@@ -541,6 +539,13 @@ ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* - pciNode->parent = parent; - parent->subs[parent->nSubs++] = pciNode; - } -+ *return_parent = parent; -+ return ncclSuccess; -+} -+ -+ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* xml) { -+ struct ncclXmlNode* parent; -+ ncclTopoGetXmlNodeFromSys(pciNode, xml, &parent); - if (strcmp(parent->name, "pci") == 0) { - NCCLCHECK(ncclTopoGetXmlFromSys(parent, xml)); - } else if (strcmp(parent->name, "cpu") == 0) { diff --git a/third_party/rules_cuda/nccl/build_defs.bzl.tpl b/third_party/rules_cuda/nccl/build_defs.bzl.tpl deleted file mode 100644 index 7dd6ea58..00000000 --- a/third_party/rules_cuda/nccl/build_defs.bzl.tpl +++ /dev/null @@ -1,408 +0,0 @@ -"""Repository rule for NCCL.""" - -load("@local_config_cuda//cuda:build_defs.bzl", "cuda_default_copts", "cuda_gpu_architectures") -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") - -def _gen_device_srcs_impl(ctx): - ops = ["sum", "prod", "min", "max"] - types = ["i8", "u8", "i32", "u32", "i64", "u64", "f16", "f32", "f64"] - hdr_tail = "****************************************/" - defines = "\n\n#define NCCL_OP %d\n#define NCCL_TYPE %d" - - files = [] - for NCCL_OP, op in enumerate(ops): - for NCCL_TYPE, dt in enumerate(types): - substitutions = { - hdr_tail: hdr_tail + defines % (NCCL_OP, NCCL_TYPE), - } - for src in ctx.files.srcs: - name = "%s_%s_%s" % (op, dt, src.basename) - file = ctx.actions.declare_file(name, sibling = src) - ctx.actions.expand_template( - output = file, - template = src, - substitutions = substitutions, - ) - files.append(file) - return [DefaultInfo(files = depset(files))] - -gen_device_srcs = rule( - implementation = _gen_device_srcs_impl, - attrs = { - "srcs": attr.label_list(allow_files = True), - }, -) -"""Adds prefix to each file name in srcs and adds #define NCCL_OP.""" - -def _rdc_copts(): - """Returns copts for compiling relocatable device code.""" - - # The global functions can not have a lower register count than the - # device functions. This is enforced by setting a fixed register count. - # https://github.com/NVIDIA/nccl/blob/f93fe9bfd94884cec2ba711897222e0df5569a53/makefiles/common.mk#L48 - maxrregcount = "-maxrregcount=96" - - return cuda_default_copts() + select({ - "@local_config_cuda//cuda:using_nvcc": [ - "-nvcc_options", - "relocatable-device-code=true", - "-nvcc_options", - "ptxas-options=" + maxrregcount, - ], - "@local_config_cuda//cuda:using_clang": [ - "-fcuda-rdc", - "-Xcuda-ptxas", - maxrregcount, - ], - "//conditions:default": [], - }) - -def _lookup_file(filegroup, path): - """Extracts file at (relative) path in filegroup.""" - for file in filegroup.files: - if file.path.endswith(path): - return file - return None - -def _pic_only(files): - """Returns the PIC files if there are any in 'files', otherwise 'files'.""" - pic_only = [f for f in files if f.basename.find(".pic.") >= 0] - return pic_only if pic_only else files - -def _device_link_impl(ctx): - if not ctx.attr.gpu_archs: - fail("No GPU architecture specified. NCCL requires --config=cuda or similar.") - - inputs = [] - for dep in ctx.attr.deps: - inputs += dep.files.to_list() - inputs = _pic_only(inputs) - - # Device-link to cubins for each architecture. - name = ctx.attr.name - register_h = None - cubins = [] - images = [] - for arch in ctx.attr.gpu_archs: - arch = arch.replace("compute_", "sm_") # PTX is JIT-linked at runtime. - cubin = ctx.actions.declare_file("%s_%s.cubin" % (name, arch)) - register_h = ctx.actions.declare_file("%s_register_%s.h" % (name, arch)) - ctx.actions.run( - outputs = [register_h, cubin], - inputs = inputs, - executable = ctx.file._nvlink, - arguments = ctx.attr.nvlink_args + [ - "--arch=%s" % arch, - "--register-link-binaries=%s" % register_h.path, - "--output-file=%s" % cubin.path, - ] + [file.path for file in inputs], - mnemonic = "nvlink", - ) - cubins.append(cubin) - images.append("--image=profile=%s,file=%s" % (arch, cubin.path)) - - # Generate fatbin header from all cubins. - tmp_fatbin = ctx.actions.declare_file("%s.fatbin" % name) - fatbin_h = ctx.actions.declare_file("%s_fatbin.h" % name) - bin2c = ctx.file._bin2c - arguments_list = [ - "-64", - "--cmdline=--compile-only", - "--link", - "--compress-all", - "--create=%s" % tmp_fatbin.path, - "--embedded-fatbin=%s" % fatbin_h.path, - ] - if %{use_bin2c_path}: - arguments_list.append("--bin2c-path=%s" % bin2c.dirname) - ctx.actions.run( - outputs = [tmp_fatbin, fatbin_h], - inputs = cubins, - executable = ctx.file._fatbinary, - arguments = arguments_list + images, - tools = [bin2c], - mnemonic = "fatbinary", - ) - - # Generate the source file #including the headers generated above. - ctx.actions.expand_template( - output = ctx.outputs.out, - template = ctx.file._link_stub, - substitutions = { - "REGISTERLINKBINARYFILE": '"%s"' % register_h.short_path, - "FATBINFILE": '"%s"' % fatbin_h.short_path, - }, - ) - - return [DefaultInfo(files = depset([register_h, fatbin_h]))] - -_device_link = rule( - implementation = _device_link_impl, - attrs = { - "deps": attr.label_list(), - "out": attr.output(mandatory = True), - "gpu_archs": attr.string_list(), - "nvlink_args": attr.string_list(), - "_nvlink": attr.label( - default = Label("@local_config_cuda//cuda:cuda/bin/nvlink"), - allow_single_file = True, - executable = True, - cfg = "host", - ), - "_fatbinary": attr.label( - default = Label("@local_config_cuda//cuda:cuda/bin/fatbinary"), - allow_single_file = True, - executable = True, - cfg = "host", - ), - "_bin2c": attr.label( - default = Label("@local_config_cuda//cuda:cuda/bin/bin2c"), - allow_single_file = True, - executable = True, - cfg = "host", - ), - "_link_stub": attr.label( - default = Label("@local_config_cuda//cuda:cuda/bin/crt/link.stub"), - allow_single_file = True, - ), - }, -) -"""Links device code and generates source code for kernel registration.""" - -def _prune_relocatable_code_impl(ctx): - """Clears __nv_relfatbin section containing relocatable device code.""" - empty_file = ctx.actions.declare_file(ctx.attr.name + "__nv_relfatbin") - ctx.actions.write(empty_file, "") - - # Parse 'objcopy --version' and update section if it's at least v2.26. - # Otherwise, simply copy the file without changing it. - # TODO(csigg): version parsing is brittle, can we do better? - command = r""" - objcopy=$1 \ - section=$2 \ - input=$3 \ - output=$4 \ - args="" \ - pattern='([0-9])\.([0-9]+)'; \ - if [[ $($objcopy --version) =~ $pattern ]] && { \ - [ ${BASH_REMATCH[1]} -gt 2 ] || \ - [ ${BASH_REMATCH[2]} -ge 26 ]; }; then \ - args="--update-section __nv_relfatbin=$section"; \ - fi; \ - $objcopy $args $input $output - """ - cc_toolchain = find_cpp_toolchain(ctx) - outputs = [] - for src in ctx.files.srcs: - out = ctx.actions.declare_file("pruned_" + src.basename, sibling = src) - ctx.actions.run_shell( - inputs = [empty_file] + ctx.files.srcs, # + ctx.files._crosstool, - outputs = [out], - arguments = [ - cc_toolchain.objcopy_executable, - empty_file.path, - src.path, - out.path, - ], - command = command, - ) - outputs.append(out) - return DefaultInfo(files = depset(outputs)) - -_prune_relocatable_code = rule( - implementation = _prune_relocatable_code_impl, - attrs = { - "srcs": attr.label_list(mandatory = True, allow_files = True), - "_cc_toolchain": attr.label( - default = "@bazel_tools//tools/cpp:current_cc_toolchain", - ), - # "_crosstool": attr.label_list( - # cfg = "host", - # default = ["@bazel_tools//tools/cpp:crosstool"] - # ), - }, -) - -def _merge_archive_impl(ctx): - # Generate an mri script to the merge archives in srcs and pass it to 'ar'. - # See https://stackoverflow.com/a/23621751. - files = _pic_only(ctx.files.srcs) - mri_script = "create " + ctx.outputs.out.path - for f in files: - mri_script += r"\naddlib " + f.path - mri_script += r"\nsave\nend" - - cc_toolchain = find_cpp_toolchain(ctx) - ctx.actions.run_shell( - inputs = ctx.files.srcs, # + ctx.files._crosstool, - outputs = [ctx.outputs.out], - command = "echo -e \"%s\" | %s -M" % (mri_script, cc_toolchain.ar_executable), - ) - -_merge_archive = rule( - implementation = _merge_archive_impl, - attrs = { - "srcs": attr.label_list(mandatory = True, allow_files = True), - "_cc_toolchain": attr.label( - default = "@bazel_tools//tools/cpp:current_cc_toolchain", - ), - # "_crosstool": attr.label_list( - # cfg = "host", - # default = ["@bazel_tools//tools/cpp:crosstool"] - # ), - }, - outputs = {"out": "lib%{name}.a"}, -) -"""Merges srcs into a single archive.""" - -def cuda_rdc_library(name, hdrs = None, copts = None, linkstatic = True, **kwargs): - r"""Produces a cuda_library using separate compilation and linking. - - CUDA separate compilation and linking allows device function calls across - translation units. This is different from the normal whole program - compilation where each translation unit contains all device code. For more - background, see - https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/, - https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-options-for-separate-compilation - - During separate compilation, the different CUDA source files are compiled - to 'relocatable device code' (RDC) and embedded in the host object files. - When using nvcc, linking the device code for each supported GPU - architecture and generating kernel registration code for the CUDA runtime - is handled automatically. Clang supports generating relocatable device - code, but it can't link it. We therefore rely on tools provided by the CUDA - SDK to link the device code and generate the host code to register the - kernels. - - The nvlink tool extracts the RDC code from the object files and links it - into cubin files, one per GPU architecture. It also produces a header file - with a list of kernel names to register. The cubins are merged into a - binary blob using the fatbinary tool, and converted to a C header file with - the help of the bin2c tool. The registration header file, the fatbinary - header file, and the link.stub file (shipped with the CUDA SDK) are - compiled as ordinary host code. - - Here is a diagram of the CUDA separate compilation trajectory: - - x.cu.cc y.cu.cc - \ / cc_library (compile RDC and archive) - xy.a - / \ * nvlink - register.h xy.cubin - : | * fatbinary and bin2c - : xy.fatbin.h - : : * #include - dlink.cc * Expanded from crt/dlink.stub template - | cc_library (host compile and archive) - dlink.a - - The steps marked with '*' are implemented in the _device_link rule. - - The intermediate relocatable device code in xy.a is no longer needed at - this point and the corresponding section is replaced with an empty one using - objcopy. We do not remove the section completely because it is referenced by - relocations, and removing those as well breaks fatbin registration. - - The object files in both xy.a and dlink.a reference symbols defined in the - other archive. The separate archives are a side effect of using two - cc_library targets to implement a single compilation trajectory. We could - fix this once bazel supports C++ sandwich. For now, we just merge the two - archives to avoid unresolved symbols: - - xy.a - | objcopy --update-section __nv_relfatbin='' - dlink.a xy_pruned.a - \ / merge archive - xy_merged.a - | cc_library (or alternatively, cc_import) - final target - - Another complication is that cc_library produces (depending on the - configuration) both PIC and non-PIC archives, but the distinction - is hidden from Starlark until C++ sandwich becomes available. We work - around this by dropping the non-PIC files if PIC files are available. - - Args: - name: Target name. - hdrs: Header files. - copts: Compiler options. - linkstatic: Must be true. - **kwargs: Any other arguments. - """ - - if not hdrs: - hdrs = [] - if not copts: - copts = [] - - # Compile host and device code into library. - lib = name + "_lib" - native.cc_library( - name = lib, - hdrs = hdrs, - copts = _rdc_copts() + copts, - linkstatic = linkstatic, - **kwargs - ) - - # Generate source file containing linked device code. - dlink_hdrs = name + "_dlink_hdrs" - dlink_cc = name + "_dlink.cc" - _device_link( - name = dlink_hdrs, - deps = [lib], - out = dlink_cc, - gpu_archs = cuda_gpu_architectures(), - nvlink_args = select({ - "@org_tensorflow//tensorflow:linux_x86_64": ["--cpu-arch=X86_64"], - "@org_tensorflow//tensorflow:linux_ppc64le": ["--cpu-arch=PPC64LE"], - "//conditions:default": [], - }), - ) - - # Compile the source file into a library. - dlink = name + "_dlink" - native.cc_library( - name = dlink, - srcs = [dlink_cc], - textual_hdrs = [dlink_hdrs], - deps = [ - "@local_config_cuda//cuda:cuda_headers", - ], - defines = [ - # Silence warning about including internal header. - "__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__", - # Macros that need to be defined starting with CUDA 10. - "__NV_EXTRA_INITIALIZATION=", - "__NV_EXTRA_FINALIZATION=", - ], - linkstatic = linkstatic, - ) - - # Remove intermediate relocatable device code. - pruned = name + "_pruned" - _prune_relocatable_code( - name = pruned, - srcs = [lib], - ) - - # Repackage the two libs into a single archive. This is required because - # both libs reference symbols defined in the other one. For details, see - # https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking - merged = name + "_merged" - _merge_archive( - name = merged, - - # TODO(b/166662245): We're deliberately not using `pruned` here. - # Pruning __nv_relfatbin also seems to prune out the PTX shipped with - # NCCL. - srcs = [lib, dlink], - ) - - # Create cc target from archive. - native.cc_library( - name = name, - srcs = [merged], - hdrs = hdrs, - linkstatic = linkstatic, - ) diff --git a/third_party/rules_cuda/nccl/nccl_configure.bzl b/third_party/rules_cuda/nccl/nccl_configure.bzl deleted file mode 100644 index b1a34b55..00000000 --- a/third_party/rules_cuda/nccl/nccl_configure.bzl +++ /dev/null @@ -1,156 +0,0 @@ -"""Repository rule for NCCL configuration. - -`nccl_configure` depends on the following environment variables: - - * `TF_NCCL_VERSION`: Installed NCCL version or empty to build from source. - * `NCCL_INSTALL_PATH` (deprecated): The installation path of the NCCL library. - * `NCCL_HDR_PATH` (deprecated): The installation path of the NCCL header - files. - * `TF_CUDA_PATHS`: The base paths to look for CUDA. Default is - `/usr/local/cuda,usr/`. - -""" - -load( - "//gpus:cuda_configure.bzl", - "enable_cuda", - "find_cuda_config", -) -load( - "//tools/remote_config:common.bzl", - "config_repo_label", - "get_cpu_value", - "get_host_environ", -) - -_CUDA_TOOLKIT_PATH = "CUDA_TOOLKIT_PATH" -_NCCL_HDR_PATH = "NCCL_HDR_PATH" -_NCCL_INSTALL_PATH = "NCCL_INSTALL_PATH" -_TF_CUDA_COMPUTE_CAPABILITIES = "TF_CUDA_COMPUTE_CAPABILITIES" -_TF_NCCL_VERSION = "TF_NCCL_VERSION" -_TF_NEED_CUDA = "TF_NEED_CUDA" - -_DEFINE_NCCL_MAJOR = "#define NCCL_MAJOR" -_DEFINE_NCCL_MINOR = "#define NCCL_MINOR" -_DEFINE_NCCL_PATCH = "#define NCCL_PATCH" - -_NCCL_DUMMY_BUILD_CONTENT = """ -filegroup( - name = "LICENSE", - visibility = ["//visibility:public"], -) - -cc_library( - name = "nccl", - visibility = ["//visibility:public"], -) -""" - -_NCCL_ARCHIVE_BUILD_CONTENT = """ -filegroup( - name = "LICENSE", - data = ["@nccl_archive//:LICENSE.txt"], - visibility = ["//visibility:public"], -) - -alias( - name = "nccl", - actual = "@nccl_archive//:nccl", - visibility = ["//visibility:public"], -) -""" - -def _label(file): - return Label("//nccl:{}".format(file)) - -def _create_local_nccl_repository(repository_ctx): - # Resolve all labels before doing any real work. Resolving causes the - # function to be restarted with all previous state being lost. This - # can easily lead to a O(n^2) runtime in the number of labels. - # See https://github.com/tensorflow/tensorflow/commit/62bd3534525a036f07d9851b3199d68212904778 - find_cuda_config_path = repository_ctx.path(Label("//gpus:find_cuda_config.py.gz.base64")) - - nccl_version = get_host_environ(repository_ctx, _TF_NCCL_VERSION, "") - if nccl_version: - nccl_version = nccl_version.split(".")[0] - - cuda_config = find_cuda_config(repository_ctx, find_cuda_config_path, ["cuda"]) - cuda_version = cuda_config["cuda_version"].split(".") - cuda_major = cuda_version[0] - cuda_minor = cuda_version[1] - - if nccl_version == "": - # Alias to open source build from @nccl_archive. - repository_ctx.file("BUILD", _NCCL_ARCHIVE_BUILD_CONTENT) - - config_wrap = { - "%{use_bin2c_path}": "False", - } - if (int(cuda_major), int(cuda_minor)) <= (10, 1): - config_wrap["%{use_bin2c_path}"] = "True" - - repository_ctx.template( - "build_defs.bzl", - _label("build_defs.bzl.tpl"), - config_wrap, - ) - else: - # Create target for locally installed NCCL. - config = find_cuda_config(repository_ctx, find_cuda_config_path, ["nccl"]) - config_wrap = { - "%{nccl_version}": config["nccl_version"], - "%{nccl_header_dir}": config["nccl_include_dir"], - "%{nccl_library_dir}": config["nccl_library_dir"], - } - repository_ctx.template("BUILD", _label("system.BUILD.tpl"), config_wrap) - -def _create_remote_nccl_repository(repository_ctx, remote_config_repo): - repository_ctx.template( - "BUILD", - config_repo_label(remote_config_repo, ":BUILD"), - {}, - ) - - nccl_version = get_host_environ(repository_ctx, _TF_NCCL_VERSION, "") - if nccl_version == "": - repository_ctx.template( - "build_defs.bzl", - config_repo_label(remote_config_repo, ":build_defs.bzl"), - {}, - ) - -def _nccl_autoconf_impl(repository_ctx): - if (not enable_cuda(repository_ctx) or - get_cpu_value(repository_ctx) not in ("Linux", "FreeBSD")): - # Add a dummy build file to make bazel query happy. - repository_ctx.file("BUILD", _NCCL_DUMMY_BUILD_CONTENT) - elif get_host_environ(repository_ctx, "TF_NCCL_CONFIG_REPO") != None: - _create_remote_nccl_repository(repository_ctx, get_host_environ(repository_ctx, "TF_NCCL_CONFIG_REPO")) - else: - _create_local_nccl_repository(repository_ctx) - -_ENVIRONS = [ - _CUDA_TOOLKIT_PATH, - _NCCL_HDR_PATH, - _NCCL_INSTALL_PATH, - _TF_NCCL_VERSION, - _TF_CUDA_COMPUTE_CAPABILITIES, - _TF_NEED_CUDA, - "TF_CUDA_PATHS", -] - -nccl_configure = repository_rule( - implementation = _nccl_autoconf_impl, - environ = _ENVIRONS, -) -"""Detects and configures the NCCL configuration. - -Add the following to your WORKSPACE FILE: - -```python -nccl_configure(name = "local_config_nccl") -``` - -Args: - name: A unique name for this workspace rule. -""" diff --git a/third_party/rules_cuda/nccl/system.BUILD.tpl b/third_party/rules_cuda/nccl/system.BUILD.tpl deleted file mode 100644 index b970aeec..00000000 --- a/third_party/rules_cuda/nccl/system.BUILD.tpl +++ /dev/null @@ -1,28 +0,0 @@ -filegroup( - name = "LICENSE", - visibility = ["//visibility:public"], -) - -cc_library( - name = "nccl", - srcs = ["libnccl.so.%{nccl_version}"], - hdrs = ["nccl.h"], - include_prefix = "third_party/nccl", - visibility = ["//visibility:public"], - deps = [ - "@local_config_cuda//cuda:cuda_headers", - ], -) - -genrule( - name = "nccl-files", - outs = [ - "libnccl.so.%{nccl_version}", - "nccl.h", - ], - cmd = """ -cp "%{nccl_header_dir}/nccl.h" "$(@D)/nccl.h" && -cp "%{nccl_library_dir}/libnccl.so.%{nccl_version}" \ - "$(@D)/libnccl.so.%{nccl_version}" -""", -) diff --git a/third_party/rules_cuda/tools/remote_config/BUILD b/third_party/rules_cuda/tools/remote_config/BUILD deleted file mode 100644 index e69de29b..00000000 diff --git a/third_party/rules_cuda/tools/remote_config/BUILD.tpl b/third_party/rules_cuda/tools/remote_config/BUILD.tpl deleted file mode 100644 index 15a3b3bf..00000000 --- a/third_party/rules_cuda/tools/remote_config/BUILD.tpl +++ /dev/null @@ -1,26 +0,0 @@ -# Each platform creates a constraint @//:platform_constraint that -# is listed in its constraint_values; rule that want to select a specific -# platform to run on can put @//:platform_constraing into their -# exec_compatible_with attribute. -# Toolchains can similarly be marked with target_compatible_with or -# exec_compatible_with to bind them to this platform. -constraint_setting( - name = "platform_setting" -) - -constraint_value( - name = "platform_constraint", - constraint_setting = ":platform_setting", - visibility = ["//visibility:public"], -) - -platform( - name = "platform", - visibility = ["//visibility:public"], - constraint_values = [ - "@bazel_tools//platforms:%{cpu}", - "@bazel_tools//platforms:%{platform}", - ":platform_constraint", - ], - exec_properties = %{exec_properties}, -) diff --git a/third_party/rules_cuda/tools/remote_config/common.bzl b/third_party/rules_cuda/tools/remote_config/common.bzl deleted file mode 100644 index 2d627e26..00000000 --- a/third_party/rules_cuda/tools/remote_config/common.bzl +++ /dev/null @@ -1,305 +0,0 @@ -"""Functions common across configure rules.""" - -BAZEL_SH = "BAZEL_SH" -PYTHON_BIN_PATH = "PYTHON_BIN_PATH" -PYTHON_LIB_PATH = "PYTHON_LIB_PATH" -TF_PYTHON_CONFIG_REPO = "TF_PYTHON_CONFIG_REPO" - -def auto_config_fail(msg): - """Output failure message when auto configuration fails.""" - red = "\033[0;31m" - no_color = "\033[0m" - fail("%sConfiguration Error:%s %s\n" % (red, no_color, msg)) - -def which(repository_ctx, program_name): - """Returns the full path to a program on the execution platform. - - Args: - repository_ctx: the repository_ctx - program_name: name of the program on the PATH - - Returns: - The full path to a program on the execution platform. - """ - if is_windows(repository_ctx): - if not program_name.endswith(".exe"): - program_name = program_name + ".exe" - result = execute(repository_ctx, ["C:\\Windows\\System32\\where.exe", program_name]) - else: - result = execute(repository_ctx, ["which", program_name]) - return result.stdout.rstrip() - -def get_python_bin(repository_ctx): - """Gets the python bin path. - - Args: - repository_ctx: the repository_ctx - - Returns: - The python bin path. - """ - python_bin = get_host_environ(repository_ctx, PYTHON_BIN_PATH) - if python_bin != None: - return python_bin - python_bin_path = which(repository_ctx, "python") - if python_bin_path == None: - auto_config_fail("Cannot find python in PATH, please make sure " + - "python is installed and add its directory in PATH, or --define " + - "%s='/something/else'.\nPATH=%s" % ( - PYTHON_BIN_PATH, - get_environ("PATH", ""), - )) - return python_bin_path - -def get_bash_bin(repository_ctx): - """Gets the bash bin path. - - Args: - repository_ctx: the repository_ctx - - Returns: - The bash bin path. - """ - bash_bin = get_host_environ(repository_ctx, BAZEL_SH) - if bash_bin != None: - return bash_bin - bash_bin_path = which(repository_ctx, "bash") - if bash_bin_path == None: - auto_config_fail("Cannot find bash in PATH, please make sure " + - "bash is installed and add its directory in PATH, or --define " + - "%s='/path/to/bash'.\nPATH=%s" % ( - BAZEL_SH, - get_environ("PATH", ""), - )) - return bash_bin_path - -def read_dir(repository_ctx, src_dir): - """Returns a sorted list with all files in a directory. - - Finds all files inside a directory, traversing subfolders and following - symlinks. - - Args: - repository_ctx: the repository_ctx - src_dir: the directory to traverse - - Returns: - A sorted list with all files in a directory. - """ - if is_windows(repository_ctx): - src_dir = src_dir.replace("/", "\\") - find_result = execute( - repository_ctx, - ["C:\\Windows\\System32\\cmd.exe", "/c", "dir", src_dir, "/b", "/s", "/a-d"], - empty_stdout_fine = True, - ) - - # src_files will be used in genrule.outs where the paths must - # use forward slashes. - result = find_result.stdout.replace("\\", "/") - else: - find_result = execute( - repository_ctx, - ["find", src_dir, "-follow", "-type", "f"], - empty_stdout_fine = True, - ) - result = find_result.stdout - return sorted(result.splitlines()) - -def get_environ(repository_ctx, name, default_value = None): - """Returns the value of an environment variable on the execution platform. - - Args: - repository_ctx: the repository_ctx - name: the name of environment variable - default_value: the value to return if not set - - Returns: - The value of the environment variable 'name' on the execution platform - or 'default_value' if it's not set. - """ - if is_windows(repository_ctx): - result = execute( - repository_ctx, - ["C:\\Windows\\System32\\cmd.exe", "/c", "echo", "%" + name + "%"], - empty_stdout_fine = True, - ) - else: - cmd = "echo -n \"$%s\"" % name - result = execute( - repository_ctx, - [get_bash_bin(repository_ctx), "-c", cmd], - empty_stdout_fine = True, - ) - if len(result.stdout) == 0: - return default_value - return result.stdout - -def get_host_environ(repository_ctx, name, default_value = None): - """Returns the value of an environment variable on the host platform. - - The host platform is the machine that Bazel runs on. - - Args: - repository_ctx: the repository_ctx - name: the name of environment variable - - Returns: - The value of the environment variable 'name' on the host platform. - """ - if name in repository_ctx.os.environ: - return repository_ctx.os.environ.get(name).strip() - - if hasattr(repository_ctx.attr, "environ") and name in repository_ctx.attr.environ: - return repository_ctx.attr.environ.get(name).strip() - - return default_value - -def is_windows(repository_ctx): - """Returns true if the execution platform is Windows. - - Args: - repository_ctx: the repository_ctx - - Returns: - If the execution platform is Windows. - """ - os_name = "" - if hasattr(repository_ctx.attr, "exec_properties") and "OSFamily" in repository_ctx.attr.exec_properties: - os_name = repository_ctx.attr.exec_properties["OSFamily"] - else: - os_name = repository_ctx.os.name - - return os_name.lower().find("windows") != -1 - -def get_cpu_value(repository_ctx): - """Returns the name of the host operating system. - - Args: - repository_ctx: The repository context. - Returns: - A string containing the name of the host operating system. - """ - if is_windows(repository_ctx): - return "Windows" - result = raw_exec(repository_ctx, ["uname", "-s"]) - return result.stdout.strip() - -def execute( - repository_ctx, - cmdline, - error_msg = None, - error_details = None, - empty_stdout_fine = False): - """Executes an arbitrary shell command. - - Args: - repository_ctx: the repository_ctx object - cmdline: list of strings, the command to execute - error_msg: string, a summary of the error if the command fails - error_details: string, details about the error or steps to fix it - empty_stdout_fine: bool, if True, an empty stdout result is fine, - otherwise it's an error - Returns: - The result of repository_ctx.execute(cmdline) - """ - result = raw_exec(repository_ctx, cmdline) - if result.stderr or not (empty_stdout_fine or result.stdout): - fail( - "\n".join([ - error_msg.strip() if error_msg else "Repository command failed", - result.stderr.strip(), - error_details if error_details else "", - ]), - ) - return result - -def raw_exec(repository_ctx, cmdline): - """Executes a command via repository_ctx.execute() and returns the result. - - This method is useful for debugging purposes. For example, to print all - commands executed as well as their return code. - - Args: - repository_ctx: the repository_ctx - cmdline: the list of args - - Returns: - The 'exec_result' of repository_ctx.execute(). - """ - return repository_ctx.execute(cmdline) - -def files_exist(repository_ctx, paths, bash_bin = None): - """Checks which files in paths exists. - - Args: - repository_ctx: the repository_ctx - paths: a list of paths - bash_bin: path to the bash interpreter - - Returns: - Returns a list of Bool. True means that the path at the - same position in the paths list exists. - """ - if bash_bin == None: - bash_bin = get_bash_bin(repository_ctx) - - cmd_tpl = "[ -e \"%s\" ] && echo True || echo False" - cmds = [cmd_tpl % path for path in paths] - cmd = " ; ".join(cmds) - - stdout = execute(repository_ctx, [bash_bin, "-c", cmd]).stdout.strip() - return [val == "True" for val in stdout.splitlines()] - -def realpath(repository_ctx, path, bash_bin = None): - """Returns the result of "realpath path". - - Args: - repository_ctx: the repository_ctx - path: a path on the file system - bash_bin: path to the bash interpreter - - Returns: - Returns the result of "realpath path" - """ - if bash_bin == None: - bash_bin = get_bash_bin(repository_ctx) - - return execute(repository_ctx, [bash_bin, "-c", "realpath \"%s\"" % path]).stdout.strip() - -def err_out(result): - """Returns stderr if set, else stdout. - - This function is a workaround for a bug in RBE where stderr is returned as stdout. Instead - of using result.stderr use err_out(result) instead. - - Args: - result: the exec_result. - - Returns: - The stderr if set, else stdout - """ - if len(result.stderr) == 0: - return result.stdout - return result.stderr - -def config_repo_label(config_repo, target): - """Construct a label from config_repo and target. - - This function exists to ease the migration from preconfig to remote config. In preconfig - the TF_*_CONFIG_REPO environ variables are set to packages in the main repo while in - remote config they will point to remote repositories. - - Args: - config_repo: a remote repository or package. - target: a target - Returns: - A label constructed from config_repo and target. - """ - if config_repo.startswith("@") and not config_repo.find("//") > 0: - # remote config is being used. - return Label(config_repo + "//" + target) - elif target.startswith(":"): - return Label(config_repo + target) - else: - return Label(config_repo + "/" + target) diff --git a/third_party/rules_cuda/tools/remote_config/remote_platform_configure.bzl b/third_party/rules_cuda/tools/remote_config/remote_platform_configure.bzl deleted file mode 100644 index 386ad603..00000000 --- a/third_party/rules_cuda/tools/remote_config/remote_platform_configure.bzl +++ /dev/null @@ -1,49 +0,0 @@ -"""Repository rule to create a platform for a docker image to be used with RBE.""" - -def _remote_platform_configure_impl(repository_ctx): - platform = repository_ctx.attr.platform - if platform == "local": - os = repository_ctx.os.name.lower() - if os.startswith("windows"): - platform = "windows" - elif os.startswith("mac os"): - platform = "osx" - else: - platform = "linux" - - cpu = "x86_64" - machine_type = repository_ctx.execute(["bash", "-c", "echo $MACHTYPE"]).stdout - if (machine_type.startswith("ppc") or - machine_type.startswith("powerpc")): - cpu = "ppc" - elif machine_type.startswith("s390x"): - cpu = "s390x" - elif machine_type.startswith("aarch64"): - cpu = "aarch64" - elif machine_type.startswith("arm"): - cpu = "arm" - - exec_properties = repository_ctx.attr.platform_exec_properties - - serialized_exec_properties = "{" - for k, v in exec_properties.items(): - serialized_exec_properties += "\"%s\" : \"%s\"," % (k, v) - serialized_exec_properties += "}" - - repository_ctx.template( - "BUILD", - Label("@org_tensorflow//third_party/remote_config:BUILD.tpl"), - { - "%{platform}": platform, - "%{exec_properties}": serialized_exec_properties, - "%{cpu}": cpu, - }, - ) - -remote_platform_configure = repository_rule( - implementation = _remote_platform_configure_impl, - attrs = { - "platform_exec_properties": attr.string_dict(mandatory = True), - "platform": attr.string(default = "linux", values = ["linux", "windows", "local"]), - }, -)