Skip to content

gpl: opt-in GPU build under Bazel (Kokkos/CUDA)#10831

Open
dev-minjae wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
dev-minjae:gpl-gpu-bazel
Open

gpl: opt-in GPU build under Bazel (Kokkos/CUDA)#10831
dev-minjae wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
dev-minjae:gpl-gpu-bazel

Conversation

@dev-minjae

Copy link
Copy Markdown
Contributor

Adds an opt-in GPU build under Bazel for the Kokkos gpl backends, complementing the CMake ENABLE_GPU support merged in #10511. The default CPU Bazel build is unchanged; the GPU path is enabled with --config=gpu.

  • bazel/gpu/system_gpu.bzl wraps system-installed Kokkos / KokkosFFT / CUDA 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.

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 as sm_120.

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>
@dev-minjae dev-minjae requested review from a team as code owners July 6, 2026 20:13
@github-actions github-actions Bot added the size/L label Jul 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bazel/gpu/system_gpu.bzl
Comment on lines +250 to +253
system_prefix_repo = repository_rule(
implementation = _system_prefix_repo_impl,
local = True,
attrs = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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 = {

Comment thread src/gpl/test/BUILD
Comment on lines +190 to +194
deps = [
"//src/gpl",
"@googletest//:gtest",
"@googletest//:gtest_main",
],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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",
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant