Skip to content

feat(rocrand): add the generated Fortran binding in bindings/fortran/rocrand - #12505

Draft
amontoison wants to merge 10 commits into
ROCm:developfrom
amontoison:users/amontoison/rocrand-fortran-bindings
Draft

amontoison wants to merge 10 commits into
ROCm:developfrom
amontoison:users/amontoison/rocrand-fortran-bindings

Conversation

@amontoison

@amontoison amontoison commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Implements RFC0015, Fortran Bindings Split (update) for rocRAND: bindings/fortran/rocrand/ is a standalone CMake project that builds the generated Fortran binding against an installed rocRAND. The library is untouched: no option, no add_subdirectory, no change to projects/rocrand/.

Draft until ROCm/rocm-systems#11923 (HIP Fortran binding, which the tests use) merges.

What lands

  • bindings/fortran/rocrand/rocrand.F90 (1 013 lines, generated with ROCm/rocm-fortran-generator 9c8b3e4 from the rocRAND headers, marked linguist-generated): one module rocrand with a bind(C) interface for each host entry point of rocrand.h, the enum constants, the uint4 and rocrand_discrete_distribution_st types, the rocrandCheck helper and array overloads.
  • metadata/rocrand.toml: the generator metadata it was generated with.
  • test/: 49 CTest tests: 24 .f03 programs of the C interfaces, 24 .f08 variants of the array overloads (registered as <name>_f2008) and the FRUIT suite. They also install: the executables in bin/, and a CTestTestfile.cmake with the same tests and properties in bin/rocrand-fortran/, for ctest --test-dir.
  • The tests are copied from projects/rocrand/test/fortran/ (which stays until the follow-up) and ported to the generated module: one program per generator and distribution, a version query, and the FRUIT suite as one test. The vendored FRUIT files in test/fruit/ are byte-identical to the originals and excluded from the formatting hooks in .pre-commit-config.yaml.
  • CMakeLists.txt, the rocrand-fortran config template, cmake/ROCmFortranCompiler.cmake (the same in every binding: ROCm's amdflang is preferred over the first compiler on PATH unless CMAKE_Fortran_COMPILER or FC is set), cmake/toolchains/ and the binding's CHANGELOG.md.
  • .github/CODEOWNERS: /bindings/fortran/rocrand/ @ROCm/rocm-fortran-maintainers @ROCm/prims-rands-reviewers.
  • .github/repos-config.json: a bindings/fortran entry, so CI detects changes to the binding. Each binding PR appends its entry at the end of the list, so all but the first to merge need a trivial rebase.

A consumer uses find_package(rocrand-fortran) and links roc::rocrand_fortran. The archive and .mod files install per compiler under lib/fortran/<compiler>/ and include/fortran/<compiler>/; ROCRAND_FORTRAN_COMPILER_DIR names that directory. The archive has one section per procedure, so a program linked with -Wl,--gc-sections keeps only the wrappers it calls.

Options

Option Default Effect
BUILD_FORTRAN_BINDINGS ${UNIX} builds the binding; skipped without a Fortran compiler
BUILD_FORTRAN_CLIENTS ON builds and installs the tests in test/; off under BUILD_ADDRESS_SANITIZER
FORTRAN_ARRAY_INTERFACES assumed-shape none / assumed-shape / assumed-rank array overloads

In TheRock

ROCm/TheRock#9446 builds bindings/fortran/rocrand as the rocrand-fortran subproject against the rocRAND it built, with -DBUILD_FORTRAN_BINDINGS=ON -DBUILD_FORTRAN_CLIENTS=${THEROCK_BUILD_TESTING}, ships it in the rand-fortran artifact and runs the installed tests in its rocrand-fortran GPU test job.

Follow-ups

This binding replaces the hand-written rocrand_m wrapper (library/src/fortran/, behind BUILD_FORTRAN_WRAPPER, deprecated since rocRAND 4.0.0), which stays for now. Removing it and moving the library's Fortran clients and tests to this binding come in separate pull requests.

Build and test

From the repository root, with $PREFIX the install prefix:

lib=rocrand
cmake -S bindings/fortran/$lib -B build/$lib-fortran \
  -DCMAKE_PREFIX_PATH="/opt/rocm;$HIP_FORTRAN_PREFIX" -DCMAKE_INSTALL_PREFIX="$PREFIX"
cmake --build build/$lib-fortran
ctest --test-dir build/$lib-fortran
cmake --install build/$lib-fortran
ctest --test-dir "$PREFIX/bin/$lib-fortran"

$HIP_FORTRAN_PREFIX holds the HIP Fortran binding (hip-fortran) built with the same compiler; without it the tests are skipped.

Verification

Standalone against ROCm 10.1 with amdflang on one GPU: 49 tests, 49 pass.

JIRA ID: ROCM-31390

@therock-pr-bot

therock-pr-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass PR does not contain code files — Unit Test auto-passed
🔎 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

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.

@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch 2 times, most recently from 7d4b156 to 558118c Compare September 24, 2026 02:10
@amontoison amontoison changed the title feat(rocrand): add generated Fortran bindings (RFC0014) feat(rocrand): replace the Fortran wrapper with generated bindings (RFC0014) Sep 24, 2026
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch 3 times, most recently from 542aa70 to bcace51 Compare September 24, 2026 03:32
@therock-pr-bot

therock-pr-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

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

@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch 4 times, most recently from 0e9fbe0 to 4f5a4e8 Compare September 25, 2026 04:22
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch from 4f5a4e8 to e82e12d Compare September 25, 2026 19:08
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch 2 times, most recently from 69100d5 to cb6a8e9 Compare September 28, 2026 03:48
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch 2 times, most recently from 55550f3 to ecba5ce Compare September 30, 2026 17:21
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch from 8731cb3 to 40d15fa Compare October 4, 2026 03:45
@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project check has failed because the head coverage (57.35%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12505      +/-   ##
===========================================
- Coverage    78.17%   78.15%   -0.02%     
===========================================
  Files         2977     2977              
  Lines       508873   508796      -77     
  Branches     79012    79006       -6     
===========================================
- Hits        397805   397639     -166     
- Misses       83888    83926      +38     
- Partials     27180    27231      +51     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 55.69% <ø> (ø) Carriedforward from 7e7fa76
TensileLite-Unit 85.08% <ø> (-0.05%) ⬇️ Carriedforward from 7e7fa76
hipBLAS 90.62% <ø> (ø) Carriedforward from 7e7fa76
hipBLASLt 70.05% <ø> (-0.32%) ⬇️ Carriedforward from 7e7fa76
hipCUB 82.68% <ø> (ø) Carriedforward from 7e7fa76
hipDNN 87.34% <ø> (ø) Carriedforward from 7e7fa76
hipFFT 42.65% <ø> (ø) Carriedforward from 7e7fa76
hipRAND 76.12% <ø> (ø) Carriedforward from 7e7fa76
hipSOLVER 69.67% <ø> (ø) Carriedforward from 7e7fa76
hipSPARSE 87.03% <ø> (ø) Carriedforward from 7e7fa76
rocALUTION 86.47% <ø> (ø) Carriedforward from 7e7fa76
rocBLAS 69.20% <ø> (ø) Carriedforward from 7e7fa76
rocFFT 46.49% <ø> (ø) Carriedforward from 7e7fa76
rocRAND 57.35% <ø> (+0.03%) ⬆️
rocSOLVER 76.66% <ø> (ø) Carriedforward from 7e7fa76
rocSPARSE 83.61% <ø> (ø) Carriedforward from 7e7fa76
rocThrust 93.15% <ø> (ø) Carriedforward from 7e7fa76

*This pull request uses carry forward flags. Click here to find out more.
see 10 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.

@amontoison amontoison changed the title feat(rocrand): replace the Fortran wrapper with generated bindings (RFC0014) feat(rocrand): replace the Fortran wrapper with generated bindings Oct 4, 2026
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch from 40d15fa to c0ab44b Compare October 5, 2026 05:13
Add fortran/rocrand.F90, the rocrand module generated from
the C headers by the rocm-fortran generator under RFC0019
(ROCm/TheRock#8122). It is committed next to the headers, is not
edited by hand, and .gitattributes marks it linguist-generated.
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch 3 times, most recently from 62fdbb2 to 3593575 Compare October 22, 2026 15:31
Build fortran/rocrand.F90 as roc::rocrand_fortran from fortran/, a CMake
project of its own that the root adds. BUILD_FORTRAN_BINDINGS (default
${UNIX}), BUILD_FORTRAN_CLIENTS (default ON) and
FORTRAN_ARRAY_INTERFACES (default assumed-shape) control it, and
ROCRAND_BUILD_FORTRAN_* override per library. The .mod and the archive
install per compiler under <includedir>/fortran/<compiler> and
<libdir>/fortran/<compiler>, beside a rocrand-fortran config package.

Remove the rocrand_m wrapper, its HIP modules and BUILD_FORTRAN_WRAPPER,
deprecated since rocRAND 4.0.0, so use rocrand_m becomes use rocrand.
The FRUIT suite moves to fortran/test/, which adds 25 CTest tests; all
but the version query are labelled gpu, use hip, and skip until
ROCm/rocm-systems#11923 lands.

Refs: ROCm/TheRock#8122 (RFC0019)
@amontoison
amontoison force-pushed the users/amontoison/rocrand-fortran-bindings branch from 3593575 to c67db52 Compare October 22, 2026 18:14
The Fortran binding moves out of the library into bindings/fortran/rocrand
(next commit), so the library goes back to develop: its Fortran wrappers,
FRUIT tests and build options stay as they are until their deprecation.
The content is develop's, byte for byte; the whitespace and cmake-lint
hooks are skipped for this commit only, since projects/rocrand is not
excluded from them and develop's files do not pass them.
The rocRAND Fortran binding consumes rocRAND's public API and builds
standalone against an installed rocRAND, so it moves out of the library
into bindings/fortran/rocrand, the tree every monorepo and TheRock use for
the Fortran bindings (RFC0015). Nothing is wired into the library build
any more: the library is back to its state on develop. Its hand-written
Fortran module stays for now: its deprecation and removal, with the
Fortran clients that use it, follow in separate pull requests.

- bindings/fortran/rocrand reads rocRAND's version from projects/rocrand
- the binding has its own .gitattributes and CHANGELOG.md
- CODEOWNERS: /bindings/fortran/rocrand/, same owners
- repos-config.json: register bindings/fortran/rocrand so CI detects changes
@github-actions github-actions Bot added github actions project: none Does not target any component labels Nov 3, 2026
@amontoison amontoison changed the title feat(rocrand): replace the Fortran wrapper with generated bindings feat(rocrand): add the generated Fortran binding in bindings/fortran/rocrand Nov 3, 2026
Regenerate bindings/fortran/rocrand with rocm-fortran-generator 9c8b3e4, and
commit its metadata in bindings/fortran/rocrand/metadata/, where the generator
reads it from a checkout, instead of the copy kept in the generator.
Install the test executables in bin/, and a CTestTestfile.cmake in
bin/rocrand-fortran/ with the same tests and properties as the build tree,
so that ctest --test-dir runs them from an install, as TheRock's test
jobs do for the libraries.
The binding is built against an installed rocRAND and is never added to the
library's build, so drop what only served that: the per-library
BUILD_FORTRAN_* overrides, the PARENT_SCOPE results, the ROCM_HAVE_FORTRAN
shortcut, the gating on the library's client and test options, and the
comments about the root. Find the Fortran compiler through the
cmake/ROCmFortranCompiler.cmake shared by all the bindings, and require
CMake 3.19.

The version test no longer requires an exact match, which only held in-tree.
…-fortran

The package files went to lib/cmake/rocrand, the C library's directory, with a forwarder in lib/cmake/rocrand-fortran. rocRAND and hipRAND install their own legacy <lib>-fortran-config.cmake there, so the files overlapped. Install the config, targets and version files directly where find_package(<package>) looks, as the HIP and ROCTx bindings do, and drop the forwarder.
…ut recursion

rocm-cmake's generated rocrand-config.cmake is to include
lib/cmake/rocrand-fortran/rocrand-fortran-config.cmake after its
targets (ROCm/rocm-cmake#303). Skip find_dependency(rocrand) when
rocrand is the package being found, not only when roc::rocrand is
already imported, so that include never re-enters rocrand-config.cmake.
Drop the early return() for that same case, which would make the
include a no-op once the legacy rocrand-fortran-config.cmake is no
longer passed via INCLUDE.

This branch has not been deployed

No deployments
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.

1 participant