From b7887dd731bf6fac76beff0d5881ebe04f91e2c4 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Sun, 13 Oct 2024 09:37:48 +0800 Subject: [PATCH] refactor: split monolithic BUILD.local_cuda into template fragments --- cuda/private/repositories.bzl | 59 +- cuda/private/template_helper.bzl | 82 +++ cuda/private/templates/BUILD.cccl | 22 + cuda/private/templates/BUILD.cublas | 37 ++ cuda/private/templates/BUILD.cudart | 95 +++ cuda/private/templates/BUILD.cufft | 36 ++ cuda/private/templates/BUILD.cufile | 0 cuda/private/templates/BUILD.cupti | 84 +++ cuda/private/templates/BUILD.curand | 22 + cuda/private/templates/BUILD.cusolver | 22 + cuda/private/templates/BUILD.cusparse | 22 + .../templates/BUILD.local_cuda_build_setting | 4 + .../templates}/BUILD.local_cuda_disabled | 0 .../templates/BUILD.local_cuda_headers | 14 + .../private/templates/BUILD.local_cuda_shared | 6 + .../templates/BUILD.local_toolchain_clang | 0 .../templates/BUILD.local_toolchain_disabled | 0 .../templates/BUILD.local_toolchain_nvcc | 0 .../templates/BUILD.local_toolchain_nvcc_msvc | 0 cuda/private/templates/BUILD.npp | 61 ++ cuda/private/templates/BUILD.nvcc | 50 ++ cuda/private/templates/BUILD.nvidia_fs | 0 cuda/private/templates/BUILD.nvjitlink | 0 cuda/private/templates/BUILD.nvjpeg | 0 cuda/private/templates/BUILD.nvml | 23 + cuda/private/templates/BUILD.nvprof | 0 cuda/private/templates/BUILD.nvrtc | 22 + cuda/private/templates/BUILD.nvtx | 22 + cuda/private/templates/README.md | 31 + cuda/private/templates/defs.bzl.tpl | 6 + cuda/private/templates/registry.bzl | 21 + cuda/runtime/BUILD.local_cuda | 575 ------------------ 32 files changed, 703 insertions(+), 613 deletions(-) create mode 100644 cuda/private/template_helper.bzl create mode 100644 cuda/private/templates/BUILD.cccl create mode 100644 cuda/private/templates/BUILD.cublas create mode 100644 cuda/private/templates/BUILD.cudart create mode 100644 cuda/private/templates/BUILD.cufft create mode 100644 cuda/private/templates/BUILD.cufile create mode 100644 cuda/private/templates/BUILD.cupti create mode 100644 cuda/private/templates/BUILD.curand create mode 100644 cuda/private/templates/BUILD.cusolver create mode 100644 cuda/private/templates/BUILD.cusparse create mode 100644 cuda/private/templates/BUILD.local_cuda_build_setting rename cuda/{runtime => private/templates}/BUILD.local_cuda_disabled (100%) create mode 100644 cuda/private/templates/BUILD.local_cuda_headers create mode 100644 cuda/private/templates/BUILD.local_cuda_shared rename cuda/{ => private}/templates/BUILD.local_toolchain_clang (100%) rename cuda/{ => private}/templates/BUILD.local_toolchain_disabled (100%) rename cuda/{ => private}/templates/BUILD.local_toolchain_nvcc (100%) rename cuda/{ => private}/templates/BUILD.local_toolchain_nvcc_msvc (100%) create mode 100644 cuda/private/templates/BUILD.npp create mode 100644 cuda/private/templates/BUILD.nvcc create mode 100644 cuda/private/templates/BUILD.nvidia_fs create mode 100644 cuda/private/templates/BUILD.nvjitlink create mode 100644 cuda/private/templates/BUILD.nvjpeg create mode 100644 cuda/private/templates/BUILD.nvml create mode 100644 cuda/private/templates/BUILD.nvprof create mode 100644 cuda/private/templates/BUILD.nvrtc create mode 100644 cuda/private/templates/BUILD.nvtx create mode 100644 cuda/private/templates/README.md create mode 100644 cuda/private/templates/defs.bzl.tpl create mode 100644 cuda/private/templates/registry.bzl delete mode 100644 cuda/runtime/BUILD.local_cuda diff --git a/cuda/private/repositories.bzl b/cuda/private/repositories.bzl index fc04d0fc..bc6cd698 100644 --- a/cuda/private/repositories.bzl +++ b/cuda/private/repositories.bzl @@ -2,6 +2,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("//cuda/private:template_helper.bzl", "template_helper") def _to_forward_slash(s): return s.replace("\\", "/") @@ -103,9 +104,10 @@ def config_cuda_toolkit_and_nvcc(repository_ctx, cuda): cuda: The struct returned from detect_cuda_toolkit """ - # Generate @local_cuda//BUILD and @local_cuda//defs.bzl - defs_bzl_content = "" - defs_if_local_cuda = "def if_local_cuda(if_true, if_false = []):\n return %s\n" + # True: locally installed cuda toolkit + # False: hermatic cuda toolkit (components) + # None: cuda toolkit is not presented + is_local_cuda = None if cuda.path != None: # When using a special cuda toolkit path install, need to manually fix up the lib64 links if cuda.path == "/usr/lib/nvidia-cuda-toolkit": @@ -113,32 +115,23 @@ def config_cuda_toolkit_and_nvcc(repository_ctx, cuda): repository_ctx.symlink("/usr/lib/x86_64-linux-gnu", "cuda/lib64") else: repository_ctx.symlink(cuda.path, "cuda") - repository_ctx.symlink(Label("//cuda:runtime/BUILD.local_cuda"), "BUILD") - defs_bzl_content += defs_if_local_cuda % "if_true" + is_local_cuda = True + + # Generate @local_cuda//BUILD + if is_local_cuda == None: + repository_ctx.symlink(Label("//cuda/private:templates/BUILD.local_cuda_disabled"), "BUILD") + elif is_local_cuda: + libpath = "lib64" if _is_linux(repository_ctx) else "lib" + template_helper.generate_build(repository_ctx, libpath) else: - repository_ctx.symlink(Label("//cuda:runtime/BUILD.local_cuda_disabled"), "BUILD") - defs_bzl_content += defs_if_local_cuda % "if_false" - repository_ctx.file("defs.bzl", defs_bzl_content) + # raise NotImplementedError("hermatic cuda toolchain is not implemented") + pass + + # Generate @local_cuda//defs.bzl + template_helper.generate_defs_bzl(repository_ctx, is_local_cuda) # Generate @local_cuda//toolchain/BUILD - tpl_label = Label( - "//cuda:templates/BUILD.local_toolchain_" + - ("nvcc" if _is_linux(repository_ctx) else "nvcc_msvc"), - ) - substitutions = { - "%{cuda_path}": _to_forward_slash(cuda.path) if cuda.path else "cuda-not-found", - "%{cuda_version}": "{}.{}".format(cuda.version_major, cuda.version_minor), - "%{nvcc_version_major}": str(cuda.nvcc_version_major), - "%{nvcc_version_minor}": str(cuda.nvcc_version_minor), - "%{nvlink_label}": cuda.nvlink_label, - "%{link_stub_label}": cuda.link_stub_label, - "%{bin2c_label}": cuda.bin2c_label, - "%{fatbinary_label}": cuda.fatbinary_label, - } - env_tmp = repository_ctx.os.environ.get("TMP", repository_ctx.os.environ.get("TEMP", None)) - if env_tmp != None: - substitutions["%{env_tmp}"] = _to_forward_slash(env_tmp) - repository_ctx.template("toolchain/BUILD", tpl_label, substitutions = substitutions, executable = False) + template_helper.generate_toolchain_build(repository_ctx, cuda) def detect_clang(repository_ctx): """Detect local clang installation. @@ -178,20 +171,10 @@ def config_clang(repository_ctx, cuda, clang_path): cuda: The struct returned from `detect_cuda_toolkit` clang_path: Path to clang executable returned from `detect_clang` """ - tpl_label = Label("//cuda:templates/BUILD.local_toolchain_clang") - substitutions = { - "%{clang_path}": _to_forward_slash(clang_path) if clang_path else "cuda-clang-not-found", - "%{cuda_path}": _to_forward_slash(cuda.path) if cuda.path else "cuda-not-found", - "%{cuda_version}": "{}.{}".format(cuda.version_major, cuda.version_minor), - "%{nvlink_label}": cuda.nvlink_label, - "%{link_stub_label}": cuda.link_stub_label, - "%{bin2c_label}": cuda.bin2c_label, - "%{fatbinary_label}": cuda.fatbinary_label, - } - repository_ctx.template("toolchain/clang/BUILD", tpl_label, substitutions = substitutions, executable = False) + template_helper.generate_toolchain_clang_build(repository_ctx, cuda, clang_path) def config_disabled(repository_ctx): - repository_ctx.symlink(Label("//cuda:templates/BUILD.local_toolchain_disabled"), "toolchain/disabled/BUILD") + repository_ctx.symlink(Label("//cuda/private:templates/BUILD.local_toolchain_disabled"), "toolchain/disabled/BUILD") def _local_cuda_impl(repository_ctx): cuda = detect_cuda_toolkit(repository_ctx) diff --git a/cuda/private/template_helper.bzl b/cuda/private/template_helper.bzl new file mode 100644 index 00000000..8a0a34f9 --- /dev/null +++ b/cuda/private/template_helper.bzl @@ -0,0 +1,82 @@ +load("//cuda/private:templates/registry.bzl", "REGISTRY") + +def _to_forward_slash(s): + return s.replace("\\", "/") + +def _is_linux(ctx): + return ctx.os.name.startswith("linux") + +def _is_windows(ctx): + return ctx.os.name.lower().startswith("windows") + +def _generate_build(repository_ctx, libpath): + # stitch template fragment + fragments = [ + Label("//cuda/private:templates/BUILD.local_cuda_shared"), + Label("//cuda/private:templates/BUILD.local_cuda_headers"), + Label("//cuda/private:templates/BUILD.local_cuda_build_setting"), + ] + fragments.extend([Label("//cuda/private:templates/BUILD.{}".format(c)) for c in REGISTRY if len(REGISTRY[c]) > 0]) + + template_content = [] + for frag in fragments: + template_content.append("# Generated from fragment " + str(frag)) + template_content.append(repository_ctx.read(frag)) + + template_content = "\n".join(template_content) + + template_path = repository_ctx.path("BUILD.tpl") + repository_ctx.file(template_path, content = template_content, executable = False) + + substitutions = { + "%{component_name}": "cuda", + "%{libpath}": libpath, + } + repository_ctx.template("BUILD", template_path, substitutions = substitutions, executable = False) + +def _generate_defs_bzl(repository_ctx, is_local_cuda): + tpl_label = Label("//cuda/private:templates/defs.bzl.tpl") + substitutions = { + "%{is_local_cuda}": str(is_local_cuda), + } + repository_ctx.template("defs.bzl", tpl_label, substitutions = substitutions, executable = False) + +def _generate_toolchain_build(repository_ctx, cuda): + tpl_label = Label( + "//cuda/private:templates/BUILD.local_toolchain_" + + ("nvcc" if _is_linux(repository_ctx) else "nvcc_msvc"), + ) + substitutions = { + "%{cuda_path}": _to_forward_slash(cuda.path) if cuda.path else "cuda-not-found", + "%{cuda_version}": "{}.{}".format(cuda.version_major, cuda.version_minor), + "%{nvcc_version_major}": str(cuda.nvcc_version_major), + "%{nvcc_version_minor}": str(cuda.nvcc_version_minor), + "%{nvlink_label}": cuda.nvlink_label, + "%{link_stub_label}": cuda.link_stub_label, + "%{bin2c_label}": cuda.bin2c_label, + "%{fatbinary_label}": cuda.fatbinary_label, + } + env_tmp = repository_ctx.os.environ.get("TMP", repository_ctx.os.environ.get("TEMP", None)) + if env_tmp != None: + substitutions["%{env_tmp}"] = _to_forward_slash(env_tmp) + repository_ctx.template("toolchain/BUILD", tpl_label, substitutions = substitutions, executable = False) + +def _generate_toolchain_clang_build(repository_ctx, cuda, clang_path): + tpl_label = Label("//cuda/private:templates/BUILD.local_toolchain_clang") + substitutions = { + "%{clang_path}": _to_forward_slash(clang_path) if clang_path else "cuda-clang-not-found", + "%{cuda_path}": _to_forward_slash(cuda.path) if cuda.path else "cuda-not-found", + "%{cuda_version}": "{}.{}".format(cuda.version_major, cuda.version_minor), + "%{nvlink_label}": cuda.nvlink_label, + "%{link_stub_label}": cuda.link_stub_label, + "%{bin2c_label}": cuda.bin2c_label, + "%{fatbinary_label}": cuda.fatbinary_label, + } + repository_ctx.template("toolchain/clang/BUILD", tpl_label, substitutions = substitutions, executable = False) + +template_helper = struct( + generate_build = _generate_build, + generate_defs_bzl = _generate_defs_bzl, + generate_toolchain_build = _generate_toolchain_build, + generate_toolchain_clang_build = _generate_toolchain_clang_build, +) diff --git a/cuda/private/templates/BUILD.cccl b/cuda/private/templates/BUILD.cccl new file mode 100644 index 00000000..20be0b3e --- /dev/null +++ b/cuda/private/templates/BUILD.cccl @@ -0,0 +1,22 @@ +cc_library( + name = "cub", + hdrs = glob( + ["%{component_name}/include/cub/**"], + allow_empty = True, + ), + includes = [ + "%{component_name}/include", + ], +) + +cc_library( + name = "thrust", + hdrs = glob( + ["%{component_name}/include/thrust/**"], + allow_empty = True, + ), + includes = [ + "%{component_name}/include", + ], + deps = [":cub"], +) diff --git a/cuda/private/templates/BUILD.cublas b/cuda/private/templates/BUILD.cublas new file mode 100644 index 00000000..0b79fd95 --- /dev/null +++ b/cuda/private/templates/BUILD.cublas @@ -0,0 +1,37 @@ + +cc_import_versioned_sos( + name = "cublas_so", + shared_library = "%{component_name}/%{libpath}/libcublas.so", +) + +cc_import_versioned_sos( + name = "cublasLt_so", + shared_library = "%{component_name}/%{libpath}/libcublasLt.so", +) + +cc_import( + name = "cublas_lib", + interface_library = "%{component_name}/%{libpath}/x64/cublas.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_import( + name = "cublasLt_lib", + interface_library = "%{component_name}/%{libpath}/x64/cublasLt.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "cublas", + deps = [ + ":headers", + ] + if_linux([ + ":cublasLt_so", + ":cublas_so", + ]) + if_windows([ + ":cublasLt_lib", + ":cublas_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.cudart b/cuda/private/templates/BUILD.cudart new file mode 100644 index 00000000..fda4e1f8 --- /dev/null +++ b/cuda/private/templates/BUILD.cudart @@ -0,0 +1,95 @@ +cc_import_versioned_sos( + name = "cudart_so", + shared_library = "%{component_name}/%{libpath}/libcudart.so", +) + +cc_library( + name = "cudadevrt_a", + srcs = ["%{component_name}/%{libpath}/libcudadevrt.a"], + target_compatible_with = ["@platforms//os:linux"], +) + +cc_import( + name = "cudart_lib", + interface_library = "%{component_name}/%{libpath}/x64/cudart.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_import( + name = "cudadevrt_lib", + interface_library = "%{component_name}/%{libpath}/x64/cudadevrt.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +# Note: do not use this target directly, use the configurable label_flag +# @rules_cuda//cuda:runtime instead. +cc_library( + name = "cuda_runtime", + linkopts = if_linux([ + "-ldl", + "-lpthread", + "-lrt", + ]), + deps = [ + ":headers", + ] + if_linux([ + # devrt is required for jit linking when rdc is enabled + ":cudadevrt_a", + ":cudart_so", + ]) + if_windows([ + # devrt is required for jit linking when rdc is enabled + ":cudadevrt_lib", + ":cudart_lib", + ]), + # FIXME: + # visibility = ["@rules_cuda//cuda:__pkg__"], +) + +# Note: do not use this target directly, use the configurable label_flag +# @rules_cuda//cuda:runtime instead. +cc_library( + name = "cuda_runtime_static", + srcs = ["%{component_name}/%{libpath}/libcudart_static.a"], + hdrs = [":_cuda_header_files"], + includes = ["%{component_name}/include"], + linkopts = if_linux([ + "-ldl", + "-lpthread", + "-lrt", + ]), + deps = [":cudadevrt_a"], + # FIXME: + # visibility = ["@rules_cuda//cuda:__pkg__"], +) + +cc_library( + name = "no_cuda_runtime", + # FIXME: + # visibility = ["@rules_cuda//cuda:__pkg__"], +) + +cc_import( + name = "cuda_so", + shared_library = "%{component_name}/%{libpath}/stubs/libcuda.so", + target_compatible_with = ["@platforms//os:linux"], +) + +cc_import( + name = "cuda_lib", + interface_library = "%{component_name}/%{libpath}/x64/cuda.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "cuda", + deps = [ + ":headers", + ] + if_linux([ + ":cuda_so", + ]) + if_windows([ + ":cuda_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.cufft b/cuda/private/templates/BUILD.cufft new file mode 100644 index 00000000..4e63a70b --- /dev/null +++ b/cuda/private/templates/BUILD.cufft @@ -0,0 +1,36 @@ +cc_import_versioned_sos( + name = "cufft_so", + shared_library = "%{component_name}/%{libpath}/libcufft.so", +) + +cc_import( + name = "cufft_lib", + interface_library = "%{component_name}/%{libpath}/x64/cufft.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_import_versioned_sos( + name = "cufftw_so", + shared_library = "%{component_name}/%{libpath}/libcufftw.so", +) + +cc_import( + name = "cufftw_lib", + interface_library = "%{component_name}/%{libpath}/x64/cufftw.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "cufft", + deps = [ + ":headers", + ] + if_linux([ + ":cufft_so", + ":cufftw_so", + ]) + if_windows([ + ":cufft_lib", + ":cufftw_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.cufile b/cuda/private/templates/BUILD.cufile new file mode 100644 index 00000000..e69de29b diff --git a/cuda/private/templates/BUILD.cupti b/cuda/private/templates/BUILD.cupti new file mode 100644 index 00000000..84457c8c --- /dev/null +++ b/cuda/private/templates/BUILD.cupti @@ -0,0 +1,84 @@ +# CUPTI +cc_import_versioned_sos( + name = "cupti_so", + shared_library = "%{component_name}/**/%{libpath}/libcupti.so", +) + +cc_import( + name = "cupti_lib", + interface_library = "%{component_name}/extras/CUPTI/lib64/cupti.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "cupti_headers", + hdrs = glob( + ["%{component_name}/extras/CUPTI/include/*.h"], + allow_empty = True, + ), + includes = ["%{component_name}/extras/CUPTI/include"], +) + +cc_library( + name = "cupti", + deps = [ + ":headers", + ] + if_linux([ + ":cupti_so", + ]) + if_windows([ + ":cupti_headers", + ":cupti_lib", + ]), +) + +# nvperf +cc_import( + name = "nvperf_host_so", + shared_library = "%{component_name}/%{libpath}/libnvperf_host.so", + target_compatible_with = ["@platforms//os:linux"], +) + +cc_import( + name = "nvperf_host_lib", + interface_library = "%{component_name}/extras/CUPTI/lib64/nvperf_host.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "nvperf_host", + deps = [ + ":headers", + ] + if_linux([ + ":nvperf_host_so", + ]) + if_windows([ + ":cupti_headers", + ":nvperf_host_lib", + ]), +) + +cc_import( + name = "nvperf_target_so", + shared_library = "%{component_name}/%{libpath}/libnvperf_target.so", + target_compatible_with = ["@platforms//os:linux"], +) + +cc_import( + name = "nvperf_target_lib", + interface_library = "%{component_name}/extras/CUPTI/lib64/nvperf_target.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "nvperf_target", + deps = [ + ":headers", + ] + if_linux([ + ":nvperf_target_so", + ]) + if_windows([ + ":cupti_headers", + ":nvperf_target_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.curand b/cuda/private/templates/BUILD.curand new file mode 100644 index 00000000..9ac34992 --- /dev/null +++ b/cuda/private/templates/BUILD.curand @@ -0,0 +1,22 @@ +cc_import_versioned_sos( + name = "curand_so", + shared_library = "%{component_name}/%{libpath}/libcurand.so", +) + +cc_import( + name = "curand_lib", + interface_library = "%{component_name}/%{libpath}/x64/curand.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "curand", + deps = [ + ":headers", + ] + if_linux([ + ":curand_so", + ]) + if_windows([ + ":curand_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.cusolver b/cuda/private/templates/BUILD.cusolver new file mode 100644 index 00000000..0b22151a --- /dev/null +++ b/cuda/private/templates/BUILD.cusolver @@ -0,0 +1,22 @@ +cc_import_versioned_sos( + name = "cusolver_so", + shared_library = "%{component_name}/%{libpath}/libcusolver.so", +) + +cc_import( + name = "cusolver_lib", + interface_library = "%{component_name}/%{libpath}/x64/cusolver.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "cusolver", + deps = [ + ":headers", + ] + if_linux([ + ":cusolver_so", + ]) + if_windows([ + ":cusolver_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.cusparse b/cuda/private/templates/BUILD.cusparse new file mode 100644 index 00000000..00afb9a7 --- /dev/null +++ b/cuda/private/templates/BUILD.cusparse @@ -0,0 +1,22 @@ +cc_import_versioned_sos( + name = "cusparse_so", + shared_library = "%{component_name}/%{libpath}/libcusparse.so", +) + +cc_import( + name = "cusparse_lib", + interface_library = "%{component_name}/%{libpath}/x64/cusparse.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "cusparse", + deps = [ + ":headers", + ] + if_linux([ + ":cusparse_so", + ]) + if_windows([ + ":cusparse_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.local_cuda_build_setting b/cuda/private/templates/BUILD.local_cuda_build_setting new file mode 100644 index 00000000..b2744f3e --- /dev/null +++ b/cuda/private/templates/BUILD.local_cuda_build_setting @@ -0,0 +1,4 @@ +bool_setting( + name = "valid_toolchain_found", + build_setting_default = True, +) diff --git a/cuda/runtime/BUILD.local_cuda_disabled b/cuda/private/templates/BUILD.local_cuda_disabled similarity index 100% rename from cuda/runtime/BUILD.local_cuda_disabled rename to cuda/private/templates/BUILD.local_cuda_disabled diff --git a/cuda/private/templates/BUILD.local_cuda_headers b/cuda/private/templates/BUILD.local_cuda_headers new file mode 100644 index 00000000..b212ed59 --- /dev/null +++ b/cuda/private/templates/BUILD.local_cuda_headers @@ -0,0 +1,14 @@ +filegroup( + name = "_header_files", + srcs = glob( + ["%{component_name}/include/**"], + allow_empty = True, + ), + visibility = ["//visibility:private"], +) + +cc_library( + name = "headers", + hdrs = [":_header_files"], + includes = ["%{component_name}/include"], +) diff --git a/cuda/private/templates/BUILD.local_cuda_shared b/cuda/private/templates/BUILD.local_cuda_shared new file mode 100644 index 00000000..af548866 --- /dev/null +++ b/cuda/private/templates/BUILD.local_cuda_shared @@ -0,0 +1,6 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_setting") # @unused +load("@rules_cuda//cuda:defs.bzl", "cc_import_versioned_sos", "if_linux", "if_windows") # @unused + +package( + default_visibility = ["//visibility:public"], +) diff --git a/cuda/templates/BUILD.local_toolchain_clang b/cuda/private/templates/BUILD.local_toolchain_clang similarity index 100% rename from cuda/templates/BUILD.local_toolchain_clang rename to cuda/private/templates/BUILD.local_toolchain_clang diff --git a/cuda/templates/BUILD.local_toolchain_disabled b/cuda/private/templates/BUILD.local_toolchain_disabled similarity index 100% rename from cuda/templates/BUILD.local_toolchain_disabled rename to cuda/private/templates/BUILD.local_toolchain_disabled diff --git a/cuda/templates/BUILD.local_toolchain_nvcc b/cuda/private/templates/BUILD.local_toolchain_nvcc similarity index 100% rename from cuda/templates/BUILD.local_toolchain_nvcc rename to cuda/private/templates/BUILD.local_toolchain_nvcc diff --git a/cuda/templates/BUILD.local_toolchain_nvcc_msvc b/cuda/private/templates/BUILD.local_toolchain_nvcc_msvc similarity index 100% rename from cuda/templates/BUILD.local_toolchain_nvcc_msvc rename to cuda/private/templates/BUILD.local_toolchain_nvcc_msvc diff --git a/cuda/private/templates/BUILD.npp b/cuda/private/templates/BUILD.npp new file mode 100644 index 00000000..1a1a01e9 --- /dev/null +++ b/cuda/private/templates/BUILD.npp @@ -0,0 +1,61 @@ +_NPP_LIBS = { + "nppc": [ + "npp.h", + "nppcore.h", + "nppdefs.h", + ], + "nppial": ["nppi_arithmetic_and_logical_operations.h"], + "nppicc": ["nppi_color_conversion.h"], + "nppidei": ["nppi_data_exchange_and_initialization.h"], + "nppif": ["nppi_filtering_functions.h"], + "nppig": ["nppi_geometry_transforms.h"], + "nppim": ["nppi_morphological_operations.h"], + "nppist": [ + "nppi_statistics_functions.h", + "nppi_linear_transforms.h", + ], + "nppisu": ["nppi_support_functions.h"], + "nppitc": ["nppi_threshold_and_compare_operations.h"], + "npps": [ + "npps_arithmetic_and_logical_operations.h", + "npps_conversion_functions.h", + "npps_filtering_functions.h", + "npps.h", + "npps_initialization.h", + "npps_statistics_functions.h", + "npps_support_functions.h", + ], +} + +[ + cc_import_versioned_sos( + name = name + "_so", + shared_library = "%{component_name}/%{libpath}/lib{}.so".format(name), + ) + for name in _NPP_LIBS.keys() +] + +[ + cc_import( + name = name + "_lib", + interface_library = "%{component_name}/%{libpath}/x64/{}.lib".format(name), + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], + ) + for name in _NPP_LIBS.keys() +] + +[ + cc_library( + name = name, + hdrs = ["%{component_name}/include/" + hdr for hdr in hdrs], + includes = ["%{component_name}/include"], + visibility = ["//visibility:public"], + deps = ([":nppc"] if name != "nppc" else []) + if_linux([ + ":{}_so".format(name), + ]) + if_windows([ + ":{}_lib".format(name), + ]), + ) + for name, hdrs in _NPP_LIBS.items() +] diff --git a/cuda/private/templates/BUILD.nvcc b/cuda/private/templates/BUILD.nvcc new file mode 100644 index 00000000..2f95676b --- /dev/null +++ b/cuda/private/templates/BUILD.nvcc @@ -0,0 +1,50 @@ +filegroup( + name = "compiler_deps", + srcs = [ + ":_cuda_header_files", + ] + glob( + [ + "%{component_name}/version.json", + "%{component_name}/version.txt", + "%{component_name}/bin/**", + "%{component_name}/%{libpath}/**", + "%{component_name}/nvvm/**", + ], + allow_empty = True, + ), +) + +cc_import( + name = "nvptxcompiler_so", + static_library = "%{component_name}/%{libpath}/libnvptxcompiler_static.a", + target_compatible_with = ["@platforms//os:linux"], +) + +cc_import( + name = "nvptxcompiler_lib", + interface_library = "%{component_name}/%{libpath}/x64/nvptxcompiler_static.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "nvptxcompiler", + srcs = [], + hdrs = glob( + [ + "%{component_name}/include/fatbinary_section.h", + "%{component_name}/include/nvPTXCompiler.h", + "%{component_name}/include/crt/*", + ], + allow_empty = True, + ), + includes = [ + "%{component_name}/include", + ], + visibility = ["//visibility:public"], + deps = [] + if_linux([ + ":nvptxcompiler_so", + ]) + if_windows([ + ":nvptxcompiler_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.nvidia_fs b/cuda/private/templates/BUILD.nvidia_fs new file mode 100644 index 00000000..e69de29b diff --git a/cuda/private/templates/BUILD.nvjitlink b/cuda/private/templates/BUILD.nvjitlink new file mode 100644 index 00000000..e69de29b diff --git a/cuda/private/templates/BUILD.nvjpeg b/cuda/private/templates/BUILD.nvjpeg new file mode 100644 index 00000000..e69de29b diff --git a/cuda/private/templates/BUILD.nvml b/cuda/private/templates/BUILD.nvml new file mode 100644 index 00000000..f92bca00 --- /dev/null +++ b/cuda/private/templates/BUILD.nvml @@ -0,0 +1,23 @@ +cc_import( + name = "nvidia-ml_so", + shared_library = "%{component_name}/%{libpath}/stubs/libnvidia-ml.so", + target_compatible_with = ["@platforms//os:linux"], +) + +cc_import( + name = "nvml_lib", + interface_library = "%{component_name}/%{libpath}/x64/nvml.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "nvml", + deps = [ + ":headers", + ] + if_linux([ + ":nvidia-ml_so", + ]) + if_windows([ + ":nvml_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.nvprof b/cuda/private/templates/BUILD.nvprof new file mode 100644 index 00000000..e69de29b diff --git a/cuda/private/templates/BUILD.nvrtc b/cuda/private/templates/BUILD.nvrtc new file mode 100644 index 00000000..082a6550 --- /dev/null +++ b/cuda/private/templates/BUILD.nvrtc @@ -0,0 +1,22 @@ +cc_import_versioned_sos( + name = "nvrtc_so", + shared_library = "%{component_name}/%{libpath}/libnvrtc.so", +) + +cc_import( + name = "nvrtc_lib", + interface_library = "%{component_name}/%{libpath}/x64/nvrtc.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "nvrtc", + deps = [ + ":headers", + ] + if_linux([ + ":nvrtc_so", + ]) + if_windows([ + ":nvrtc_lib", + ]), +) diff --git a/cuda/private/templates/BUILD.nvtx b/cuda/private/templates/BUILD.nvtx new file mode 100644 index 00000000..40232f82 --- /dev/null +++ b/cuda/private/templates/BUILD.nvtx @@ -0,0 +1,22 @@ +cc_import_versioned_sos( + name = "nvtx_so", + shared_library = "%{component_name}/%{libpath}/libnvToolsExt.so", +) + +cc_import( + name = "nvtx_lib", + interface_library = "%{component_name}/%{libpath}/x64/libnvToolsExt.lib", + system_provided = 1, + target_compatible_with = ["@platforms//os:windows"], +) + +cc_library( + name = "nvtx", + deps = [ + ":headers", + ] + if_linux([ + ":nvtx_so", + ]) + if_windows([ + ":nvtx_lib", + ]), +) diff --git a/cuda/private/templates/README.md b/cuda/private/templates/README.md new file mode 100644 index 00000000..746960d7 --- /dev/null +++ b/cuda/private/templates/README.md @@ -0,0 +1,31 @@ +- `BUILD.local_cuda_shared`: For local_cuda repo (CTK + toolchain) or local_cuda_%{component_name} +- `BUILD.local_cuda_headers`: For local_cuda repo (CTK + toolchain) or local_cuda_%{component_name} headers +- `BUILD.local_cuda_build_setting`: For local_cuda repo (CTK + toolchain) build_setting +- `BUILD.local_cuda_disabled`: For creating a dummy local configuration. +- `BUILD.local_toolchain_nvcc`: +- `BUILD.local_toolchain_nvcc_msvc`: +- `BUILD.local_toolchain_nvcc`: +- Otherwise, each `BUILD.*` corresponds to a component in CUDA Toolkit. + +We organize the generated repo as follows +``` + # bazel unconditionally create a directory for us +├── %{component_name} # placeholder +│ ├── include/ # +│ ├── %{libpath}/ # placeholder +│ └── version.json # copy redistrib json to it if not exist and is a deliverable +├── defs.bzl # generated +├── BUILD # generated from BUILD.local_cuda and one/all of the component(s) +└── WORKSPACE # generated +``` + +If the repo is `local_cuda`, we additionally generate toolchain config as follows +``` + +└── toolchain + ├── BUILD # the default nvcc toolchain + ├── clang # the optional clang toolchain + │ └── BUILD # + └── disabled # the fallback toolchain + └── BUILD # +``` diff --git a/cuda/private/templates/defs.bzl.tpl b/cuda/private/templates/defs.bzl.tpl new file mode 100644 index 00000000..012f03ec --- /dev/null +++ b/cuda/private/templates/defs.bzl.tpl @@ -0,0 +1,6 @@ +def if_local_cuda(if_true, if_false = []): + is_local_cuda = %{is_local_cuda} + if is_local_cuda: + return if_true + else: + return if_false diff --git a/cuda/private/templates/registry.bzl b/cuda/private/templates/registry.bzl new file mode 100644 index 00000000..cf9d6afc --- /dev/null +++ b/cuda/private/templates/registry.bzl @@ -0,0 +1,21 @@ +# map component name to consumable targets +REGISTRY = { + "cudart": ["cuda", "cuda_runtime", "cuda_runtime_static"], + "nvcc": ["compiler_deps", "nvptxcompiler"], + "cccl": ["cub", "thrust"], + "cublas": ["cublas"], + "cufft": ["cufft"], + "cufile": [], + "cupti": ["cupti", "nvperf_host", "nvperf_target"], + "curand": ["curand"], + "cusolver": ["cusolver"], + "cusparse": ["cusparse"], + "npp": ["nppc", "nppial", "nppicc", "nppidei", "nppif", "nppig", "nppim", "nppist", "nppisu", "nppitc", "npps"], + "nvidia_fs": [], + "nvjitlink": [], + "nvjpeg": [], + "nvml": ["nvml"], + "nvprof": [], + "nvrtc": [], + "nvtx": ["nvtx"], +} diff --git a/cuda/runtime/BUILD.local_cuda b/cuda/runtime/BUILD.local_cuda deleted file mode 100644 index c4b1dace..00000000 --- a/cuda/runtime/BUILD.local_cuda +++ /dev/null @@ -1,575 +0,0 @@ -load("@bazel_skylib//rules:common_settings.bzl", "bool_setting") -load("@rules_cuda//cuda:defs.bzl", "cc_import_versioned_sos", "if_linux", "if_windows") - -package( - default_visibility = ["//visibility:public"], -) - -bool_setting( - name = "valid_toolchain_found", - build_setting_default = True, -) - -filegroup( - name = "compiler_deps", - srcs = [ - ":_cuda_header_files", - ] + glob( - [ - "cuda/version.json", - "cuda/version.txt", - "cuda/bin/**", - "cuda/lib64/**", - "cuda/nvvm/**", - ], - allow_empty = True, - ), -) - -filegroup( - name = "_cuda_header_files", - srcs = glob( - ["cuda/include/**"], - allow_empty = True, - ), - visibility = ["//visibility:private"], -) - -cc_library( - name = "cuda_headers", - hdrs = [":_cuda_header_files"], - includes = ["cuda/include"], -) - -cc_library( - name = "cuda_stub", - srcs = ["cuda/lib64/stubs/libcuda.so"], - linkopts = if_linux([ - "-ldl", - "-lpthread", - "-lrt", - ]), -) - -cc_import_versioned_sos( - name = "cudart_so", - shared_library = "cuda/lib64/libcudart.so", -) - -cc_library( - name = "cudadevrt_a", - srcs = ["cuda/lib64/libcudadevrt.a"], - target_compatible_with = ["@platforms//os:linux"], -) - -cc_import( - name = "cudart_lib", - interface_library = "cuda/lib/x64/cudart.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_import( - name = "cudadevrt_lib", - interface_library = "cuda/lib/x64/cudadevrt.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -# Note: do not use this target directly, use the configurable label_flag -# @rules_cuda//cuda:runtime instead. -cc_library( - name = "cuda_runtime", - linkopts = if_linux([ - "-ldl", - "-lpthread", - "-lrt", - ]), - deps = [ - ":cuda_headers", - ] + if_linux([ - # devrt is require for jit linking when rdc is enabled - ":cudadevrt_a", - ":cudart_so", - ]) + if_windows([ - # devrt is require for jit linking when rdc is enabled - ":cudadevrt_lib", - ":cudart_lib", - ]), - # FIXME: - # visibility = ["@rules_cuda//cuda:__pkg__"], -) - -# Note: do not use this target directly, use the configurable label_flag -# @rules_cuda//cuda:runtime instead. -cc_library( - name = "cuda_runtime_static", - srcs = ["cuda/lib64/libcudart_static.a"], - hdrs = [":_cuda_header_files"], - includes = ["cuda/include"], - linkopts = if_linux([ - "-ldl", - "-lpthread", - "-lrt", - ]), - deps = [":cudadevrt_a"], - # FIXME: - # visibility = ["@rules_cuda//cuda:__pkg__"], -) - -cc_library( - name = "no_cuda_runtime", - # FIXME: - # visibility = ["@rules_cuda//cuda:__pkg__"], -) - -cc_import( - name = "cuda_so", - shared_library = "cuda/lib64/stubs/libcuda.so", - target_compatible_with = ["@platforms//os:linux"], -) - -cc_import( - name = "cuda_lib", - interface_library = "cuda/lib/x64/cuda.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "cuda", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":cuda_so", - ]) + if_windows([ - ":cuda_lib", - ]), -) - -cc_import_versioned_sos( - name = "cublas_so", - shared_library = "cuda/lib64/libcublas.so", -) - -cc_import_versioned_sos( - name = "cublasLt_so", - shared_library = "cuda/lib64/libcublasLt.so", -) - -cc_import( - name = "cublas_lib", - interface_library = "cuda/lib/x64/cublas.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_import( - name = "cublasLt_lib", - interface_library = "cuda/lib/x64/cublasLt.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "cublas", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":cublasLt_so", - ":cublas_so", - ]) + if_windows([ - ":cublasLt_lib", - ":cublas_lib", - ]), -) - -cc_library( - name = "cub", - hdrs = glob( - ["cuda/include/cub/**"], - allow_empty = True, - ), - includes = [ - "cuda/include", - ], -) - -cc_library( - name = "thrust", - hdrs = glob( - ["cuda/include/thrust/**"], - allow_empty = True, - ), - includes = [ - "cuda/include", - ], - deps = [":cub"], -) - -# CUPTI -cc_import_versioned_sos( - name = "cupti_so", - shared_library = "cuda/**/lib64/libcupti.so", -) - -cc_import( - name = "cupti_lib", - interface_library = "cuda/extras/CUPTI/lib64/cupti.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "cupti_headers", - hdrs = glob( - ["cuda/extras/CUPTI/include/*.h"], - allow_empty = True, - ), - includes = ["cuda/extras/CUPTI/include"], -) - -cc_library( - name = "cupti", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":cupti_so", - ]) + if_windows([ - ":cupti_headers", - ":cupti_lib", - ]), -) - -# nvperf -cc_import( - name = "nvperf_host_so", - shared_library = "cuda/lib64/libnvperf_host.so", - target_compatible_with = ["@platforms//os:linux"], -) - -cc_import( - name = "nvperf_host_lib", - interface_library = "cuda/extras/CUPTI/lib64/nvperf_host.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "nvperf_host", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":nvperf_host_so", - ]) + if_windows([ - ":cupti_headers", - ":nvperf_host_lib", - ]), -) - -cc_import( - name = "nvperf_target_so", - shared_library = "cuda/lib64/libnvperf_target.so", - target_compatible_with = ["@platforms//os:linux"], -) - -cc_import( - name = "nvperf_target_lib", - interface_library = "cuda/extras/CUPTI/lib64/nvperf_target.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "nvperf_target", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":nvperf_target_so", - ]) + if_windows([ - ":cupti_headers", - ":nvperf_target_lib", - ]), -) - -# NVML -cc_import( - name = "nvidia-ml_so", - shared_library = "cuda/lib64/stubs/libnvidia-ml.so", - target_compatible_with = ["@platforms//os:linux"], -) - -cc_import( - name = "nvml_lib", - interface_library = "cuda/lib/x64/nvml.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "nvml", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":nvidia-ml_so", - ]) + if_windows([ - ":nvml_lib", - ]), -) - -# NVRTC -cc_import_versioned_sos( - name = "nvrtc_so", - shared_library = "cuda/lib64/libnvrtc.so", -) - -cc_import( - name = "nvrtc_lib", - interface_library = "cuda/lib/x64/nvrtc.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "nvrtc", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":nvrtc_so", - ]) + if_windows([ - ":nvrtc_lib", - ]), -) - -# curand -cc_import_versioned_sos( - name = "curand_so", - shared_library = "cuda/lib64/libcurand.so", -) - -cc_import( - name = "curand_lib", - interface_library = "cuda/lib/x64/curand.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "curand", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":curand_so", - ]) + if_windows([ - ":curand_lib", - ]), -) - -# nvptxcompiler -cc_import( - name = "nvptxcompiler_so", - static_library = "cuda/lib64/libnvptxcompiler_static.a", - target_compatible_with = ["@platforms//os:linux"], -) - -cc_import( - name = "nvptxcompiler_lib", - interface_library = "cuda/lib/x64/nvptxcompiler_static.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "nvptxcompiler", - srcs = [], - hdrs = glob( - [ - "cuda/include/fatbinary_section.h", - "cuda/include/nvPTXCompiler.h", - "cuda/include/crt/*", - ], - allow_empty = True, - ), - includes = [ - "cuda/include", - ], - visibility = ["//visibility:public"], - deps = [] + if_linux([ - ":nvptxcompiler_so", - ]) + if_windows([ - ":nvptxcompiler_lib", - ]), -) - -# cufft -cc_import_versioned_sos( - name = "cufft_so", - shared_library = "cuda/lib64/libcufft.so", -) - -cc_import( - name = "cufft_lib", - interface_library = "cuda/lib/x64/cufft.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_import_versioned_sos( - name = "cufftw_so", - shared_library = "cuda/lib64/libcufftw.so", -) - -cc_import( - name = "cufftw_lib", - interface_library = "cuda/lib/x64/cufftw.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "cufft", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":cufft_so", - ":cufftw_so", - ]) + if_windows([ - ":cufft_lib", - ":cufftw_lib", - ]), -) - -# cusolver -cc_import_versioned_sos( - name = "cusolver_so", - shared_library = "cuda/lib64/libcusolver.so", -) - -cc_import( - name = "cusolver_lib", - interface_library = "cuda/lib/x64/cusolver.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "cusolver", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":cusolver_so", - ]) + if_windows([ - ":cusolver_lib", - ]), -) - -# cusparse -cc_import_versioned_sos( - name = "cusparse_so", - shared_library = "cuda/lib64/libcusparse.so", -) - -cc_import( - name = "cusparse_lib", - interface_library = "cuda/lib/x64/cusparse.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "cusparse", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":cusparse_so", - ]) + if_windows([ - ":cusparse_lib", - ]), -) - -# nvtx -cc_import_versioned_sos( - name = "nvtx_so", - shared_library = "cuda/lib64/libnvToolsExt.so", -) - -cc_import( - name = "nvtx_lib", - interface_library = "cuda/lib/x64/libnvToolsExt.lib", - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], -) - -cc_library( - name = "nvtx", - deps = [ - ":cuda_headers", - ] + if_linux([ - ":nvtx_so", - ]) + if_windows([ - ":nvtx_lib", - ]), -) - -# NPP -_NPP_LIBS = { - "nppc": [ - "npp.h", - "nppcore.h", - "nppdefs.h", - ], - "nppial": ["nppi_arithmetic_and_logical_operations.h"], - "nppicc": ["nppi_color_conversion.h"], - "nppidei": ["nppi_data_exchange_and_initialization.h"], - "nppif": ["nppi_filtering_functions.h"], - "nppig": ["nppi_geometry_transforms.h"], - "nppim": ["nppi_morphological_operations.h"], - "nppist": [ - "nppi_statistics_functions.h", - "nppi_linear_transforms.h", - ], - "nppisu": ["nppi_support_functions.h"], - "nppitc": ["nppi_threshold_and_compare_operations.h"], - "npps": [ - "npps_arithmetic_and_logical_operations.h", - "npps_conversion_functions.h", - "npps_filtering_functions.h", - "npps.h", - "npps_initialization.h", - "npps_statistics_functions.h", - "npps_support_functions.h", - ], -} - -[ - cc_import_versioned_sos( - name = name + "_so", - shared_library = "cuda/lib64/lib{}.so".format(name), - ) - for name in _NPP_LIBS.keys() -] - -[ - cc_import( - name = name + "_lib", - interface_library = "cuda/lib/x64/{}.lib".format(name), - system_provided = 1, - target_compatible_with = ["@platforms//os:windows"], - ) - for name in _NPP_LIBS.keys() -] - -[ - cc_library( - name = name, - hdrs = ["cuda/include/" + hdr for hdr in hdrs], - includes = ["cuda/include"], - visibility = ["//visibility:public"], - deps = ([":nppc"] if name != "nppc" else []) + if_linux([ - ":{}_so".format(name), - ]) + if_windows([ - ":{}_lib".format(name), - ]), - ) - for name, hdrs in _NPP_LIBS.items() -]