Skip to content

fix(rocRAND): give internal kernels hidden visibility - #13363

Merged
amd-mcieslak merged 2 commits into
developfrom
users/amd-mcieslak/rocrand-hidden-kernel-visibility
Oct 10, 2026
Merged

amd-mcieslak merged 2 commits into
developfrom
users/amd-mcieslak/rocrand-hidden-kernel-visibility

Conversation

@amd-mcieslak

Copy link
Copy Markdown
Contributor

JIRA ID : AIPRIMS-247

Motivation

rocRAND's internal kernels leak into the dynamic symbol table of librocrand.so. This exposes implementation details as part of the library's ABI, bloats the symbol table, and risks symbol clashes with other libraries or user code. Of 6,484 dynamic exports, 6,426 were host-side symbols for instantiations of two internal kernel templates.

Technical Details

  • library/CMakeLists.txt already sets CXX_VISIBILITY_PRESET hidden / VISIBILITY_INLINES_HIDDEN ON, and -fvisibility=hidden reaches every compile command.
  • Added ROCRAND_INTERNAL_KERNEL to the internal-only header library/src/rng/common.hpp. It expands to __global__ __attribute__((__visibility__("hidden"))), which mirrors ROCPRIM_KERNEL in rocPRIM's config.hpp. It falls back to plain __global__ for host compilers without GNU attribute support (e.g. nvcc + MSVC).
  • Replaced the bare __global__ on all three internal kernel definitions.

Test Plan

  • Compare dynamic exports before and after: nm -D --defined-only librocrand.so | c++filt
  • Run the full rocRAND test suite (ctest) to confirm the hidden kernels are still found and launched at runtime.

Test Result

  • Dynamic exports: 6,484 before, 58 after. No trampoline_kernel / generate_sobol_kernel symbols remain.
  • ctest: 100% tests passed, 0 tests failed out of 53 (gfx950, 183.58 s).

Submission Checklist

@therock-pr-bot

therock-pr-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rocrand/library/src/rng/common.hpp, projects/rocrand/library/src/rng/sobol.hpp, projects/rocrand/library/src/rng/system.hpp; no test file found
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Pre-commit check failed

⛔ pre-commit failed

Please run locally:

  • python -m pip install pre-commit
  • pre-commit install
  • pre-commit run --all-files --show-diff-on-failure

This repo uses .pre-commit-config.yaml.

JIRA ID : AIPRIMS-247

## Motivation

rocRAND's internal kernels leak into the dynamic symbol table of `librocrand.so`. This exposes implementation details as part of the library's ABI, bloats the symbol table, and risks symbol clashes with other libraries or user code. Of 6,484 dynamic exports, 6,426 were host-side symbols for instantiations of two internal kernel templates.

## Technical Details

- `library/CMakeLists.txt` already sets `CXX_VISIBILITY_PRESET hidden` / `VISIBILITY_INLINES_HIDDEN ON`, and `-fvisibility=hidden` reaches every compile command.
- Added `ROCRAND_INTERNAL_KERNEL` to the internal-only header `library/src/rng/common.hpp`. It expands to `__global__ __attribute__((__visibility__("hidden")))`, which mirrors `ROCPRIM_KERNEL` in rocPRIM's `config.hpp`. It falls back to plain `__global__` for host compilers without GNU attribute support (e.g. nvcc + MSVC).
- Replaced the bare `__global__` on all three internal kernel definitions.

## Test Plan

- Compare dynamic exports before and after: `nm -D --defined-only librocrand.so | c++filt`
- Run the full rocRAND test suite (`ctest`) to confirm the hidden kernels are still found and launched at runtime.

## Test Result

- Dynamic exports: 6,484 before, 58 after. No `trampoline_kernel` / `generate_sobol_kernel` symbols remain.
- `ctest`: 100% tests passed, 0 tests failed out of 53 (gfx950, 183.58 s).

## Submission Checklist

- [x] Look over the contributing guidelines at
    https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
@amd-mcieslak
amd-mcieslak force-pushed the users/amd-mcieslak/rocrand-hidden-kernel-visibility branch from 7e344fc to 6679289 Compare October 8, 2026 22:16
@therock-pr-bot

therock-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #13363      +/-   ##
===========================================
+ Coverage    71.86%   72.16%   +0.30%     
===========================================
  Files         2876     2874       -2     
  Lines       475315   474877     -438     
  Branches     70237    70143      -94     
===========================================
+ Hits        341569   342674    +1105     
+ Misses      109960   108400    -1560     
- Partials     23786    23803      +17     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 49.33% <ø> (-0.35%) ⬇️ Carriedforward from 6679289
TensileLite-Unit 83.33% <ø> (-0.11%) ⬇️ Carriedforward from 6679289
hipBLAS 90.62% <ø> (ø) Carriedforward from 6679289
hipBLASLt 41.97% <ø> (-0.75%) ⬇️ Carriedforward from 6679289
hipCUB 82.68% <ø> (ø) Carriedforward from 6679289
hipDNN 86.66% <ø> (+<0.01%) ⬆️ Carriedforward from 6679289
hipFFT 42.52% <ø> (-0.07%) ⬇️ Carriedforward from 6679289
hipRAND 76.12% <ø> (ø) Carriedforward from 6679289
hipSOLVER 68.96% <ø> (ø) Carriedforward from 6679289
hipSPARSE 86.99% <ø> (ø) Carriedforward from 6679289
rocBLAS 48.17% <ø> (+<0.01%) ⬆️ Carriedforward from 6679289
rocFFT 51.45% <ø> (+4.94%) ⬆️ Carriedforward from 6679289
rocRAND 57.42% <ø> (+0.03%) ⬆️
rocSOLVER 76.83% <ø> (ø) Carriedforward from 6679289
rocSPARSE 74.07% <ø> (+<0.01%) ⬆️ Carriedforward from 6679289
rocThrust 93.15% <ø> (ø) Carriedforward from 6679289

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
projects/rocrand/library/src/rng/common.hpp 33.33% <ø> (ø)
projects/rocrand/library/src/rng/sobol.hpp 76.15% <ø> (ø)
projects/rocrand/library/src/rng/system.hpp 65.38% <ø> (ø)

... and 444 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amd-jmahovsky amd-jmahovsky 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.

LGTM

@amd-mcieslak
amd-mcieslak merged commit c857152 into develop Oct 10, 2026
106 of 107 checks passed
@amd-mcieslak
amd-mcieslak deleted the users/amd-mcieslak/rocrand-hidden-kernel-visibility branch October 10, 2026 17:39
assistant-librarian Bot pushed a commit to ROCm/rocRAND that referenced this pull request Oct 10, 2026
fix(rocRAND): give internal kernels hidden visibility
 (#13363)

JIRA ID : AIPRIMS-247

## Motivation

rocRAND's internal kernels leak into the dynamic symbol table of
`librocrand.so`. This exposes implementation details as part of the
library's ABI, bloats the symbol table, and risks symbol clashes with
other libraries or user code. Of 6,484 dynamic exports, 6,426 were
host-side symbols for instantiations of two internal kernel templates.

## Technical Details

- `library/CMakeLists.txt` already sets `CXX_VISIBILITY_PRESET hidden` /
`VISIBILITY_INLINES_HIDDEN ON`, and `-fvisibility=hidden` reaches every
compile command.
- Added `ROCRAND_INTERNAL_KERNEL` to the internal-only header
`library/src/rng/common.hpp`. It expands to `__global__
__attribute__((__visibility__("hidden")))`, which mirrors
`ROCPRIM_KERNEL` in rocPRIM's `config.hpp`. It falls back to plain
`__global__` for host compilers without GNU attribute support (e.g. nvcc
+ MSVC).
- Replaced the bare `__global__` on all three internal kernel
definitions.

## Test Plan

- Compare dynamic exports before and after: `nm -D --defined-only
librocrand.so | c++filt`
- Run the full rocRAND test suite (`ctest`) to confirm the hidden
kernels are still found and launched at runtime.

## Test Result

- Dynamic exports: 6,484 before, 58 after. No `trampoline_kernel` /
`generate_sobol_kernel` symbols remain.
- `ctest`: 100% tests passed, 0 tests failed out of 53 (gfx950, 183.58
s).

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants