Skip to content

feat(rocblas): add the generated Fortran binding in bindings/fortran/rocblas - #12533

Draft
amontoison wants to merge 8 commits into
ROCm:developfrom
amontoison:users/amontoison/rocblas-fortran-bindings
Draft

amontoison wants to merge 8 commits into
ROCm:developfrom
amontoison:users/amontoison/rocblas-fortran-bindings

Conversation

@amontoison

@amontoison amontoison commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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

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

What lands

  • bindings/fortran/rocblas/rocblas.F90 (168 236 lines, generated with ROCm/rocm-fortran-generator 9c8b3e4 from the rocBLAS headers, marked linguist-generated): one module rocblas with the bind(C) interfaces, the enum constants, the rocblasCheck helper and array overloads for the routines the generator supports.
  • metadata/rocblas.toml: the generator metadata it was generated with.
  • test/: 245 CTest tests, 148 .f03 tests of the C interfaces and 97 .f08 tests of the array overloads (registered as <name>_f2008). They also install: the executables in bin/, and a CTestTestfile.cmake with the same tests and properties in bin/rocblas-fortran/, for ctest --test-dir.
  • The tests are ported from hipFORT's rocBLAS tests.
  • CMakeLists.txt, the rocblas-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/rocblas/ @ROCm/rocm-fortran-maintainers @ROCm/rocblas-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(rocblas-fortran) and links roc::rocblas_fortran. The archive and .mod files install per compiler under lib/fortran/<compiler>/ and include/fortran/<compiler>/; ROCBLAS_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/rocblas as the rocblas-fortran subproject against the rocBLAS it built, with -DBUILD_FORTRAN_BINDINGS=ON -DBUILD_FORTRAN_CLIENTS=${THEROCK_BUILD_TESTING}, ships it in the blas-fortran artifact and runs the installed tests in its rocblas-fortran GPU test job.

Follow-ups

This binding replaces the hand-written library/include/rocblas_module.f90, which stays for now. Deprecating it, then removing it and moving the library's Fortran clients to this binding, come in separate pull requests.

Build and test

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

lib=rocblas
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: 245 tests, 245 pass. From the install tree, ctest --test-dir $PREFIX/bin/rocblas-fortran gives the same result.

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

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

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Sep 24, 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 (69.20%) 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   #12533      +/-   ##
===========================================
+ Coverage    75.95%   76.00%   +0.05%     
===========================================
  Files         2880     2880              
  Lines       479025   479393     +368     
  Branches     71958    72033      +75     
===========================================
+ Hits        363828   364336     +508     
+ Misses       90338    90163     -175     
- Partials     24859    24894      +35     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 48.93% <ø> (ø) Carriedforward from 6004f30
TensileLite-Unit 83.68% <ø> (ø) Carriedforward from 6004f30
hipBLAS 90.62% <ø> (ø) Carriedforward from 6004f30
hipBLASLt 64.43% <ø> (ø) Carriedforward from 6004f30
hipCUB 82.68% <ø> (ø) Carriedforward from 6004f30
hipDNN 86.78% <ø> (ø) Carriedforward from 6004f30
hipFFT 42.00% <ø> (ø) Carriedforward from 6004f30
hipRAND 76.12% <ø> (ø) Carriedforward from 6004f30
hipSOLVER 69.67% <ø> (ø) Carriedforward from 6004f30
hipSPARSE 86.99% <ø> (ø) Carriedforward from 6004f30
rocBLAS 69.20% <ø> (+0.47%) ⬆️
rocFFT 48.10% <ø> (ø) Carriedforward from 6004f30
rocRAND 57.30% <ø> (ø) Carriedforward from 6004f30
rocSOLVER 76.74% <ø> (ø) Carriedforward from 6004f30
rocSPARSE 76.92% <ø> (ø) Carriedforward from 6004f30
rocThrust 93.15% <ø> (ø) Carriedforward from 6004f30

*This pull request uses carry forward flags. Click here to find out more.
see 74 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 force-pushed the users/amontoison/rocblas-fortran-bindings branch 4 times, most recently from 9a0e9f2 to b07f8d7 Compare September 25, 2026 04:17
@amontoison
amontoison force-pushed the users/amontoison/rocblas-fortran-bindings branch 2 times, most recently from f3d55bd to 8c1e0cf Compare September 28, 2026 03:48
@amontoison
amontoison force-pushed the users/amontoison/rocblas-fortran-bindings branch 3 times, most recently from 46b5663 to 535bc58 Compare October 3, 2026 16:50
@amontoison amontoison changed the title feat(rocblas): replace the hand-written Fortran binding with a generated one (RFC0014) feat(rocblas): replace the hand-written Fortran binding with a generated one Oct 4, 2026
@amontoison
amontoison force-pushed the users/amontoison/rocblas-fortran-bindings branch from 535bc58 to 175abbf Compare October 5, 2026 05:12
Add fortran/rocblas.F90, the rocblas 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/rocblas-fortran-bindings branch from 175abbf to dc40b1d Compare October 22, 2026 13:22
…ted one

Build fortran/rocblas.F90 as roc::rocblas_fortran from fortran/, a CMake
project of its own that the root adds. BUILD_FORTRAN_BINDINGS (default
${UNIX}) and FORTRAN_ARRAY_INTERFACES (default assumed-shape) control
it; the existing BUILD_FORTRAN_CLIENTS is forced OFF when no binding is
built. ROCBLAS_BUILD_FORTRAN_* override both per library. The .mod and
the archive install per compiler under <includedir>/fortran/<compiler>
and <libdir>/fortran/<compiler>, beside a rocblas-fortran config
package.

Remove library/include/rocblas_module.f90. Its rocblas_enums module is
folded into rocblas, so use rocblas_enums becomes use rocblas, and
rocblas_create_handle and rocblas_get_stream take their output by
reference. The clients shims and samples use the generated module, and
the trmm sample is fixed and built; there is no fortran/test suite.

Refs: ROCm/TheRock#8122 (RFC0019)
@amontoison
amontoison force-pushed the users/amontoison/rocblas-fortran-bindings branch from dc40b1d to c2b7a02 Compare October 22, 2026 18:13
The rocBLAS Fortran binding consumes rocBLAS's public API and builds
standalone against an installed rocBLAS, so it moves out of the library
into bindings/fortran/rocblas, 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/rocblas reads rocBLAS's version from projects/rocblas
- the binding has its own .gitattributes and CHANGELOG.md
- CODEOWNERS: /bindings/fortran/rocblas/, same owners
- repos-config.json: register bindings/fortran/rocblas 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(rocblas): replace the hand-written Fortran binding with a generated one feat(rocblas): add the generated Fortran binding in bindings/fortran/rocblas Nov 3, 2026
…tests

- regenerate bindings/fortran/rocblas with rocm-fortran-generator 9c8b3e4
- commit its metadata in bindings/fortran/rocblas/metadata/, where the
  generator reads it from a checkout
- add the binding's tests in test/, under BUILD_FORTRAN_CLIENTS, ported
  from hipFORT's rocBLAS tests: the library's own clients still test the
  hand-written module while it is deprecated, so they did not test the
  binding
Install the test executables in bin/, and a CTestTestfile.cmake in
bin/rocblas-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 rocBLAS 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.
…-fortran

The package files went to lib/cmake/rocblas, the C library's directory, with a forwarder in lib/cmake/rocblas-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 rocblas-config.cmake is to include
lib/cmake/rocblas-fortran/rocblas-fortran-config.cmake after its
targets (ROCm/rocm-cmake#303). Skip find_dependency(rocblas) when
rocblas is the package being found, not only when roc::rocblas is
already imported, so that include never re-enters rocblas-config.cmake.

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