gpl: opt-in GPU build under Bazel (Kokkos/CUDA)#10831
Conversation
Registers the Kokkos GPU backends in src/gpl/src/gpu (added via CMake in The-OpenROAD-Project#10511) in the Bazel build, behind an opt-in --config=gpu that mirrors the CMake ENABLE_GPU flow. - bazel/gpu/system_gpu.bzl wraps the system-installed Kokkos, KokkosFFT and CUDA toolkit as external repos (prefixes from KOKKOS_ROOT / KOKKOS_FFT_ROOT / OPENROAD_CUDA_PATH, arch from OPENROAD_CUDA_ARCH). A missing prefix degrades to an empty stub so CPU-only machines and CI are unaffected; an explicitly-set bad path fails fast. - The GPU TUs (the 13 gpu/*.cpp backends plus fft.cpp) compile as CUDA in the hermetic clang's native CUDA mode (-xcuda), with no nvcc or rules_cuda. They live in //src/gpl:gpl_kokkos; fft.cpp moves between :gpl (CPU) and :gpl_kokkos (GPU), matching the LANGUAGE CUDA split in CMakeLists.txt. - Golden tests pin ENABLE_GPU=0 on GPU builds; the GPU-only tests (region01_gpu, region01_gpu_asym, fft_gpu_test, wl_gpu_test) pin ENABLE_GPU=1, are tagged gpu, and are gated with target_compatible_with so plain CPU wildcard runs report them SKIPPED. Validated with bazel test --config=gpu //src/gpl/test/... on aarch64 (NVIDIA GB10) and x86_64 (RTX 5090), both as sm_120. Signed-off-by: Minjae Kim <develop.minjae@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces an opt-in GPU build configuration using Bazel, mirroring the CMake-based GPU flow by wrapping system-installed Kokkos, KokkosFFT, and CUDA toolkits. Feedback highlights two main issues: the system_prefix_repo repository rule needs to declare its environment variable dependencies in the environ attribute to ensure proper cache invalidation, and the fft_gpu_test target is missing a dependency on //src/gpl:gpl_private_hdrs despite including private headers.
| system_prefix_repo = repository_rule( | ||
| implementation = _system_prefix_repo_impl, | ||
| local = True, | ||
| attrs = { |
There was a problem hiding this comment.
The system_prefix_repo repository rule reads environment variables (KOKKOS_ROOT, KOKKOS_FFT_ROOT, OPENROAD_CUDA_PATH, OPENROAD_CUDA_ARCH) via rctx.getenv. However, it does not declare them in the environ attribute of the repository_rule. In Bazel, if a repository rule does not declare its environment variable dependencies in environ, Bazel will not automatically invalidate and refetch the repository when those environment variables change. This can lead to stale builds and unexpected behavior when users switch CUDA architectures or paths.
system_prefix_repo = repository_rule(
implementation = _system_prefix_repo_impl,
local = True,
environ = [
"KOKKOS_ROOT",
"KOKKOS_FFT_ROOT",
"OPENROAD_CUDA_PATH",
"OPENROAD_CUDA_ARCH",
],
attrs = {
| deps = [ | ||
| "//src/gpl", | ||
| "@googletest//:gtest", | ||
| "@googletest//:gtest_main", | ||
| ], |
There was a problem hiding this comment.
The fft_gpu_test target includes private headers from //src/gpl (as noted in the comment # includes private headers), but it does not list //src/gpl:gpl_private_hdrs in its deps. This can cause compilation failures due to missing include paths (since gpl_private_hdrs provides includes = ["src"], which adds src/gpl/src to the include path) or missing header dependencies. It should be added to deps just like it is in gpl_fft_unittest.
deps = [
"//src/gpl",
"//src/gpl:gpl_private_hdrs",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
Adds an opt-in GPU build under Bazel for the Kokkos
gplbackends, complementing the CMakeENABLE_GPUsupport merged in #10511. The default CPU Bazel build is unchanged; the GPU path is enabled with--config=gpu.bazel/gpu/system_gpu.bzlwraps system-installed Kokkos / KokkosFFT / CUDA as external repos (prefixes fromKOKKOS_ROOT/KOKKOS_FFT_ROOT/OPENROAD_CUDA_PATH, arch fromOPENROAD_CUDA_ARCH). A missing prefix degrades to an empty stub, so CPU-only machines and CI are unaffected; an explicitly-set bad path fails fast.gpu/*.cppbackends plusfft.cpp) compile as CUDA in the hermetic clang's native CUDA mode (-xcuda), with no nvcc or rules_cuda. They live in//src/gpl:gpl_kokkos;fft.cppmoves between:gpl(CPU) and:gpl_kokkos(GPU), matching theLANGUAGE CUDAsplit inCMakeLists.txt.ENABLE_GPU=0on GPU builds; the GPU-only tests (region01_gpu,region01_gpu_asym,fft_gpu_test,wl_gpu_test) pinENABLE_GPU=1, are taggedgpu, and are gated withtarget_compatible_withso plain CPU wildcard runs report them SKIPPED.There is no GPU CI runner, so this was validated locally with
bazel test --config=gpu //src/gpl/test/...on aarch64 (NVIDIA GB10) and x86_64 (RTX 5090), both assm_120.