Skip to content

[Sandbox] Move the Fortran bindings to per-library modules, with hipfftxt beside hipfft (ROCm only) - #540

Open
amontoison wants to merge 6 commits into
developfrom
rocm-fortran
Open

amontoison wants to merge 6 commits into
developfrom
rocm-fortran

Conversation

@amontoison

@amontoison amontoison commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

A sandbox preview, not for merge. It shows what the Fortran bindings look like once they move into the bindings/fortran/ tree of rocm-systems and rocm-libraries, apart from the libraries they wrap, so the shape can be tried before anything lands. lib/rocm-systems/bindings/fortran/ and lib/rocm-libraries/bindings/fortran/ mirror those trees, with one project per library (the monorepos build HIP with ROCTx, and hipFFT with hipFFTW, from one project). The bindings are generated from the ROCm 10.2 headers with rocm-fortran-generator main, and are byte-identical to those of the per-library pull requests below. The HIP module of rocm-systems#11923 is generated from the headers of rocm-systems develop (HIP 7.18), so it also has hipExtMemcpyBatchAsync and hipKernelSetCacheConfig, which ROCm 10.2 does not export; the sandbox keeps the ROCm 10.2 one.

The real pull requests are one per library. This branch is where you can build the whole set at once.

Library Pull request
HIP rocm-systems#11923
ROCTx rocm-systems#14024
rocBLAS rocm-libraries#12533
hipBLAS rocm-libraries#12370
rocSOLVER rocm-libraries#12582
hipSOLVER rocm-libraries#12581
rocSPARSE rocm-libraries#12514
hipSPARSE rocm-libraries#12368
rocFFT rocm-libraries#12366
hipFFT, hipFFTW rocm-libraries#12367
rocRAND rocm-libraries#12505
hipRAND rocm-libraries#12506

Status (2026-11-07)

All the binding pull requests are up to date and green, locally and in TheRock CI (rocm-libraries#15008, a test-only PR that merges the ten rocm-libraries bindings with ROCm/TheRock#9446: 1271 binding tests pass on MI300). The ten rocm-libraries PRs are still drafts until the RFC is approved.

Pull request What State
ROCm/TheRock#9433 RFC0015 update up to date, to be approved
rocm-systems#11923, #14024 HIP, ROCTx bindings up to date, in review; #14024 contains #11923 and merges after it
the ten rocm-libraries PRs above math-library bindings up to date, draft
ROCm/TheRock#9446 TheRock builds and tests the bindings (fortran-bindings stage, one GPU test job per binding) up to date, in review
ROCm/rocm-cmake#303 find_package(<lib>) also loads <lib>-fortran when installed up to date, in review; the bindings work without it
hipfort#548 migration guides (hipFORT, in-tree modules, CUDA Fortran) and hipFORT deprecation draft until the RFC is approved

Each binding installs its CMake package in <libdir>/cmake/<lib>-fortran/ and is ready for the rocm-cmake hook (hipfft-fortran also loads hipfftw-fortran).

Merge order: rocm-systems#11923, then #14024, then the ten rocm-libraries PRs (each appends its entry to .github/repos-config.json, so they rebase in turn, regenerating the bindings), then ROCm/TheRock#9446.

After the merge:

  • packaging in TheRock: one amdrocm-<family>-fortran-devel package per family and the amdrocm-fortran metapackage, which also removes the *-fortran entries from KNOWN_UNCOVERED_COMPONENTS;
  • deprecation of the hand-written modules: rocRAND and hipRAND (their legacy <lib>-fortran-config.cmake, whose removal enables the rocm-cmake hook for them), hipSOLVER (EXPORT_FORTRAN_BINDINGS OFF by default), rocSPARSE docs;
  • before the bindings ship: let the HIP arguments that C requires to be NULL take c_null_ptr (hipStreamBeginCaptureToGraph, hipModuleLaunchKernel/hipDrvLaunchKernelEx, hipGraphAddMemFreeNode);
  • in TheRock, when the pins include the bindings: regenerate the consumer graph so a C library change runs its binding's tests.

What changes

lib/hipfort, a flat directory of 35 files, becomes 13 directories, one per library, laid out as in the repository each will be committed to:

lib/rocm-systems/bindings/fortran/{hip,roctx}
lib/rocm-libraries/bindings/fortran/{rocblas,hipblas,rocsolver,hipsolver,rocsparse,hipsparse,rocfft,hipfft,hipfftw,rocrand,hiprand}

Each is one self-contained module named after its library, with the enums, types, handles and the <lib>Check helper folded in. use hipfort_rocblas becomes use rocblas. hipFFT is the one library with two modules, see below: 14 modules in all.

hipFFT: hipfft and hipfftxt

As CUDA Fortran's cufft and cufftXt, the hipFFT binding has two modules, built into the same libhipfft_fortran.a (hip::hipfft_fortran, find_package(hipfft-fortran)):

Module File Lines Contents
hipfft lib/rocm-libraries/bindings/fortran/hipfft/hipfft.F90 1683 the plans, hipfftExec*, the work area and stream routines
hipfftxt lib/rocm-libraries/bindings/fortran/hipfft/hipfftxt.F90 651 every hipfftXt* and hipfftMp* function, hipfftXtSetWorkArea included, with the hipXtDesc/hipLibXtDesc types and the Xt enums; it uses and re-exports hipfft

A program calling the Xt or multi-process API writes use hipfftxt (the Xt tests do); any other keeps use hipfft. rocm_add_fortran_binding takes several SOURCE files for this and installs one .mod per source. The files are byte-identical to rocm-libraries#12367. hipFORT itself has the same split (hipfort_hipfftxt).

Each also builds its own archive and config package, the way its binding project will:

target roc::rocblas_fortran, hip::hipfft_fortran
archive librocblas_fortran.a
module rocblas.mod (hipFFT: hipfft.mod, hipfftxt.mod)
package find_package(rocblas-fortran)

The .mod and the archive install under include/fortran/<compiler> and lib/fortran/<compiler>, because a .mod is not portable across compilers.

find_package(hipfort) and the single libhipfort-amdgcn.a are gone, as they are after the split. So is the CUDA backend.

Try it

cmake -S . -B build -DCMAKE_Fortran_COMPILER=amdflang
cmake --build build -j$(nproc)
ctest --test-dir build

1296 tests, on by default, the same set as develop (fewer with FORTRAN_ARRAY_INTERFACES=none or assumed-rank, which skip the f2008 tests). They need a GPU to pass.

Build one binding on its own, against the installed library, as TheRock and a user with another compiler do:

cmake -S lib/rocm-libraries/bindings/fortran/rocblas -B build-rocblas -DCMAKE_Fortran_COMPILER=amdflang -DCMAKE_PREFIX_PATH=/opt/rocm
cmake --build build-rocblas

Install and consume it, which is what a user does:

cmake --install build --prefix /tmp/rocm-fortran
find_package(rocblas-fortran REQUIRED)   # find_dependency()s rocblas itself
find_package(hip-fortran REQUIRED)
target_link_libraries(app PRIVATE roc::rocblas_fortran hip::hip_fortran)
cmake -S your-app -B build-app -DCMAKE_PREFIX_PATH="/tmp/rocm-fortran;/opt/rocm"

Without CMake:

amdflang app.f90 -I/tmp/rocm-fortran/include/fortran/amdflang -L/tmp/rocm-fortran/lib/fortran/amdflang -lrocblas_fortran -L/opt/rocm/lib -lrocblas -lamdhip64 -o app

Options

Option Default Notes
BUILD_FORTRAN_BINDINGS ON skipped, not an error, when no Fortran compiler is found
BUILD_FORTRAN_CLIENTS ON each binding's test/; BUILD_TESTING is honoured once, with a warning
FORTRAN_ARRAY_INTERFACES assumed-shape none / assumed-shape / assumed-rank
BUILD_FORTRAN_CLIENT_SAMPLES OFF the libraries' own samples, see below

The libraries' own samples

test/rocm-libraries/ holds the 18 Fortran samples rocBLAS and rocSPARSE ship in clients/samples/, copied verbatim and compiled unedited. They open with use rocblas and use rocsparse, the names the generated bindings provide, so building them is what shows the generated module is a drop-in for the hand-written one it replaces.

cmake -S . -B build -DBUILD_FORTRAN_CLIENTS=ON -DBUILD_FORTRAN_CLIENT_SAMPLES=ON
cmake --build build --target hipfort_sample_rocblas_example_fortran_axpy

OFF by default because 16 of the 18 still need one line each: a use <lib>_enums to delete for two of them, and a c_loc() around the character buffer passed to the revision helpers for the fourteen rocSPARSE ones, each of which opens by printing the revision. Details in test/rocm-libraries/README.md.

@amontoison
amontoison force-pushed the rocm-fortran branch 2 times, most recently from 7794245 to ab3686f Compare September 20, 2026 16:04
@amontoison amontoison changed the title Split the Fortran bindings into one directory per library [Sandbox] Move the Fortran bindings to one module per library (ROCm only) Sep 20, 2026
@amontoison
amontoison force-pushed the rocm-fortran branch 2 times, most recently from bf7a1d1 to fd2fee6 Compare September 20, 2026 22:55
@amontoison
amontoison requested a review from a team as a code owner September 20, 2026 22:55
@amontoison
amontoison force-pushed the rocm-fortran branch 2 times, most recently from 6e02bff to c0c5a93 Compare September 21, 2026 01:24
@amontoison
amontoison force-pushed the rocm-fortran branch 3 times, most recently from 3a12e1f to da31ee7 Compare September 27, 2026 16:37
amontoison added a commit that referenced this pull request Sep 29, 2026
Document the move from hipFORT to the bindings that ship inside ROCm
(rocm-systems and rocm-libraries), in the spirit of the layout previewed
in #540: one self-contained module per library, ROCm only.

The guide covers the two edits a consumer has to make (the `use`
statement rename, with a sed recipe and the cases it deliberately leaves
to review; and the per-library Fortran archive and CMake target), the
build options, the per-compiler install layout and how to rebuild a
binding for a non-amdflang compiler, what does not change, and an FAQ
covering the old/new coexistence.

Wire the page into the docs index and the Sphinx TOC.
@amontoison
amontoison force-pushed the rocm-fortran branch 5 times, most recently from 8299c6d to 2fbf0f6 Compare September 30, 2026 03:23
amontoison added a commit to amontoison/rocm-systems that referenced this pull request Sep 30, 2026
Every file the bindings commit added carried either no licence header at all
or hipfort's older "[MITx11 License]" banner, which names no SPDX identifier.
The review on rocm-systems#11923 flagged the one C++ source,
projects/hip/fortran/test/vecadd_kernel.hip.cpp, but the same gap ran through
the whole directory, so it is closed everywhere rather than on the single file
that happened to be noticed.

The Fortran sources take the MIT block hipfort now emits, byte-identical to
the one in ROCm/hipfort#540, so that regenerating hip.F90 does not re-churn
the header it just gained. The CMake and C++ files take the three-line form
already used across projects/hip: hip_profile.h, FindHIP/run_make2cmake.cmake
and hipamd/CMakeLists.txt all open that way.

No code changes. The diff is 699 comment lines added and the six lines of the
old hipfort banner in hip.F90 removed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@amontoison
amontoison force-pushed the rocm-fortran branch 2 times, most recently from dbdff10 to 3cb9c27 Compare October 2, 2026 02:57
amontoison added a commit to amontoison/rocm-systems that referenced this pull request Oct 2, 2026
Every file the bindings commit added carried either no licence header at all
or hipfort's older "[MITx11 License]" banner, which names no SPDX identifier.
The review on rocm-systems#11923 flagged the one C++ source,
projects/hip/fortran/test/vecadd_kernel.hip.cpp, but the same gap ran through
the whole directory, so it is closed everywhere rather than on the single file
that happened to be noticed.

The Fortran sources take the MIT block hipfort now emits, byte-identical to
the one in ROCm/hipfort#540, so that regenerating hip.F90 does not re-churn
the header it just gained. The CMake and C++ files take the three-line form
already used across projects/hip: hip_profile.h, FindHIP/run_make2cmake.cmake
and hipamd/CMakeLists.txt all open that way.

No code changes. The diff is 699 comment lines added and the six lines of the
old hipfort banner in hip.F90 removed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
amontoison added a commit that referenced this pull request Oct 17, 2026
Document the move from hipFORT to the bindings that ship inside ROCm
(rocm-systems and rocm-libraries), in the spirit of the layout previewed
in #540: one self-contained module per library, ROCm only.

The guide covers the two edits a consumer has to make (the `use`
statement rename, with a sed recipe and the cases it deliberately leaves
to review; and the per-library Fortran archive and CMake target), the
build options, the per-compiler install layout and how to rebuild a
binding for a non-amdflang compiler, what does not change, and an FAQ
covering the old/new coexistence.

Wire the page into the docs index and the Sphinx TOC.
amontoison added a commit that referenced this pull request Oct 20, 2026
Document the move from hipFORT to the bindings that ship inside ROCm
(rocm-systems and rocm-libraries), in the spirit of the layout previewed
in #540: one self-contained module per library, ROCm only.

The guide covers the two edits a consumer has to make (the `use`
statement rename, with a sed recipe and the cases it deliberately leaves
to review; and the per-library Fortran archive and CMake target), the
build options, the per-compiler install layout and how to rebuild a
binding for a non-amdflang compiler, what does not change, and an FAQ
covering the old/new coexistence.

Wire the page into the docs index and the Sphinx TOC.
@amontoison
amontoison force-pushed the rocm-fortran branch 2 times, most recently from 6bb0a12 to abb688f Compare October 20, 2026 22:19
@amontoison
amontoison force-pushed the rocm-fortran branch 3 times, most recently from 5b5f636 to 5ecef27 Compare October 21, 2026 18:25
amontoison added a commit that referenced this pull request Oct 21, 2026
Document the move from hipFORT to the bindings that ship inside ROCm
(rocm-systems and rocm-libraries), in the spirit of the layout previewed
in #540: one self-contained module per library, ROCm only.

The guide covers the two edits a consumer has to make (the `use`
statement rename, with a sed recipe and the cases it deliberately leaves
to review; and the per-library Fortran archive and CMake target), the
build options, the per-compiler install layout and how to rebuild a
binding for a non-amdflang compiler, what does not change, and an FAQ
covering the old/new coexistence.

Wire the page into the docs index and the Sphinx TOC.
…nly)

lib/hipfort becomes one directory per library, grouped by the repository
each binding will be committed to: lib/rocm-systems/{hip,roctx} and
lib/rocm-libraries/<lib>. Each is a single module named after its
library (use rocblas), with the enums, types, handles and the <lib>Check
helper folded in, and builds its own archive and CMake package
(roc::rocblas_fortran, find_package(rocblas-fortran)), installed under
include/fortran/<compiler> and lib/fortran/<compiler>.

The array tiers are selected by FORTRAN_ARRAY_INTERFACES (none,
assumed-shape, assumed-rank). find_package(hipfort), the single
libhipfort-amdgcn archive and the CUDA backend are gone, as they are
after the split. The tests use the new modules, and the docs describe
the per-library packages.

Each archive is compiled with one section per procedure, and the tests
link with -Wl,--gc-sections, so a test keeps only the wrappers it calls
and still links against a library older than the headers the bindings
were generated from.
Regenerated with rocm-fortran-generator public 625cb01 from the headers
of ROCm 10.2, as hipfort develop: the metadata is now one TOML file per
library, with defaults derived from the C signature, so the modules gain
the same forms as develop (the _devptr twins, the _strided_rank
overloads, the nullable scalars, the routines added in 10.2) and use
each module once, with IMPORT in the interface bodies.
@amontoison
amontoison requested a review from a team as a code owner November 3, 2026 04:07
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Security scan found no critical or high findings on lines changed by this pull request

2 medium, low, or unrated finding(s) are not listed; the scan run has them.

View the security scan run for complete reports.

“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta.

amontoison added a commit that referenced this pull request Nov 3, 2026
Document the move from hipFORT to the bindings that ship inside ROCm
(rocm-systems and rocm-libraries), in the spirit of the layout previewed
in #540: one self-contained module per library, ROCm only.

The guide covers the two edits a consumer has to make (the `use`
statement rename, with a sed recipe and the cases it deliberately leaves
to review; and the per-library Fortran archive and CMake target), the
build options, the per-compiler install layout and how to rebuild a
binding for a non-amdflang compiler, what does not change, and an FAQ
covering the old/new coexistence.

Wire the page into the docs index and the Sphinx TOC.
The bindings moved out of the library projects into a top-level
bindings/fortran tree in rocm-systems and rocm-libraries. Mirror it:
lib/rocm-<repo>/<lib>/fortran becomes lib/rocm-<repo>/bindings/fortran/<lib>,
with the module path, the docs globs and the comments that named the old
location. The sandbox keeps one project per module, so HIP and ROCTx, and
hipFFT and hipFFTW, stay in separate directories where the monorepos build
each pair from one.
Mirror rocm-libraries#12367: hipfft.F90 and the new hipfftxt.F90 are the
files of its branch, generated by rocm-fortran-generator#17. As CUDA
Fortran's cufft and cufftXt, every hipfftXt* and hipfftMp* function,
hipfftXtSetWorkArea included, is in hipfftxt, which uses and re-exports
hipfft. Both modules build into libhipfft_fortran.a and install with the
hipfft-fortran package: rocm_add_fortran_binding takes several SOURCE
files and installs one .mod per source. The Xt tests and the hipFFT
examples use hipfftxt.
@amontoison amontoison changed the title [Sandbox] Move the Fortran bindings to one module per library (ROCm only) [Sandbox] Move the Fortran bindings to per-library modules, with hipfftxt beside hipfft (ROCm only) Nov 7, 2026

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants