Skip to content

feat(fortran): add the ROCTx Fortran binding to bindings/fortran - #14024

Open
amontoison wants to merge 18 commits into
ROCm:developfrom
amontoison:users/amontoison/roctx-fortran-bindings
Open

amontoison wants to merge 18 commits into
ROCm:developfrom
amontoison:users/amontoison/roctx-fortran-bindings

Conversation

@amontoison

@amontoison amontoison commented Oct 22, 2026 •

Copy link
Copy Markdown

Motivation

Fortran bindings for ROCTx, generated from the ROCTx headers and placed where RFC0015 (as updated in ROCm/TheRock#9433) puts them: in bindings/fortran/, next to the HIP binding, rather than in projects/rocprofiler-sdk/.
This keeps Fortran out of rocprofiler-sdk's build and CI.

This PR takes over #12700 and keeps @Abuudiii's four commits, with their authorship.

Merge after #11923 (HIP binding), which adds bindings/fortran/. This branch contains #11923's branch (merged in), so until #11923 lands the diff also shows the HIP binding.

Technical Details

  • roctx.F90 is regenerated with ROCm/rocm-fortran-generator: X / X_ generics, and every string routine also accepts a character(kind=c_char) string.
  • bindings/fortran/metadata/roctx.toml is the generator's ROCTx metadata, next to hip.toml.
  • bindings/fortran/CMakeLists.txt (project rocm-systems-fortran) keeps the shared options, guard and compiler naming, and includes hip.cmake and roctx.cmake.
    ROCTX_BUILD_FORTRAN_BINDINGS / ROCTX_BUILD_FORTRAN_CLIENTS override the global switches for ROCTx alone, as the HIP_ ones do for HIP.
  • Installs roc::roctx_fortran from a roctx-fortran package, in the same dev component as the HIP binding. The archive has one section per procedure, and the test links with -Wl,--gc-sections.
  • The test passes c_loc(tid) to roctxGetThreadId, whose C argument is a pointer, and also calls the typed string forms.
  • rocprofiler-sdk ends up unchanged relative to develop.

Issue Tracking

JIRA ID: ROCM-31390

Test Plan

Standalone build of bindings/fortran against ROCm 10.2 with gfortran 13.3 and amdflang, each under the three FORTRAN_ARRAY_INTERFACES values, on one gfx1101 GPU.

Test Result

roctx.F90 and metadata/roctx.toml match the output of ROCm/rocm-fortran-generator 9c8b3e4 on this checkout. 42 tests registered (41 HIP + roctx_fortran_roctx; 35 with FORTRAN_ARRAY_INTERFACES=none): all pass in the six configurations against ROCm 10.2, mem_advise, peer_copy and cooperative_launch reporting skipped on this device. Against ROCm 10.1, the HIP tests rdma_flush and library_module do not link (newer HIP entry points) and the rest pass, including ctest --test-dir $PREFIX/bin/roctx-fortran from an install (/opt/rocm/lib on LD_LIBRARY_PATH).

Submission Checklist

cc @Abuudiii: this carries your ROCTx work into bindings/fortran/. Could you take a look, and close #12700 if you agree?

The bindings live in bindings/fortran/, rocm-systems' tree for API consumers, outside the implementation projects (RFC0015): they use only the public API and build standalone against the installed libraries.

@amontoison
amontoison requested a review from a team as a code owner October 22, 2026 14:22
@therock-pr-bot

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

Copy link
Copy Markdown

✅ All Policy Checks Passed

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: bindings/fortran/test/vecadd_kernel.hip.cpp; no test file found
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

🎉 All policy checks passed!

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

🙋 Wish to Override Policy?

Comment thread .github/CODEOWNERS Resolved
Comment thread .github/CODEOWNERS Resolved
amontoison and others added 7 commits November 2, 2026 22:32
Add projects/fortran/hip.F90, the hip module generated from the HIP C
headers by rocm-fortran-generator under RFC0015 (ROCm/TheRock#8122).
projects/fortran is a standalone project for the Fortran bindings of
the rocm-systems libraries. The module is not edited by hand:
.gitattributes marks it linguist-generated, and metadata/ holds what
the C headers cannot express (scalar arguments, optional arguments,
by-value arguments, function pointers), read by the generator when it
runs on this checkout.
Co-authored-by: Alexis Montoison <35051714+amontoison@users.noreply.github.com>
Build projects/fortran/hip.F90 as hip::hip_fortran, a standalone CMake
project built against an installed HIP (find_package(hip)).
BUILD_FORTRAN_BINDINGS (default ${UNIX}), BUILD_FORTRAN_CLIENTS (default
ON) and FORTRAN_ARRAY_INTERFACES (default assumed-shape) control it, and
HIP_BUILD_FORTRAN_* override them. The .mod and the archive install per
compiler under <includedir>/fortran/<compiler> and
<libdir>/fortran/<compiler>, beside a hip-fortran config package.
shared/cmake/ROCmFortran.cmake adds the amdflang-first compiler probe
for rocm-systems projects.

test/ adds 41 CTest tests labelled gpu (39 without a HIP compiler). The
Fortran tests of the rocm-libraries bindings use hip and skip until this
lands.

Refs: ROCm/TheRock#8122 (RFC0015)
RFC0015 puts the HIP and ROCTx bindings in one rocm-systems project,
projects/fortran/, built against the installed runtime, so that
rocprofiler-sdk's build and CI carry no Fortran.

- move roctx.F90, its config package and its test from
  projects/rocprofiler-sdk/fortran/, and drop the rocprofiler-sdk hook,
  its duplicate toolchain files and its CHANGELOG entry;
- regenerate roctx.F90 with rocm-fortran-generator: X / X_ generics and
  typed character(kind=c_char) forms of the string routines;
- split projects/fortran/CMakeLists.txt into the shared options, guard
  and compiler naming, plus hip.cmake and roctx.cmake; ROCTX_ overrides
  sit beside the HIP_ ones, and both libraries install under
  HIP_FORTRAN_INSTALL_COMPONENT;
- the test passes c_loc(tid) to roctxGetThreadId, as the C API takes a
  pointer, and exercises the typed forms.
The binding consumes HIP's public API and builds standalone against an
installed HIP, so it gets its own top-level tree instead of sitting next
to the implementation projects: projects/fortran moves to
bindings/fortran, the layout every monorepo and TheRock use for the
Fortran bindings.

- read HIP's VERSION from projects/hip, now two levels up
- CODEOWNERS: /bindings/fortran/, same owners
- repos-config.json: register bindings/fortran so CI detects changes
  to it, as for emulation/rocjitsu
…s/fortran

The bindings consume the public HIP and ROCTx APIs and build standalone
against the installed libraries, so they get their own top-level tree
instead of sitting next to the implementation projects:
projects/fortran moves to bindings/fortran, the layout every monorepo
and TheRock use for the Fortran bindings.

- read HIP's and rocprofiler-sdk's VERSION from projects/, now two
  levels up
- CODEOWNERS: /bindings/fortran/, same owners
- repos-config.json: register bindings/fortran so CI detects changes
  to it, as for emulation/rocjitsu
- apply gersemi
@amontoison amontoison changed the title feat(fortran): add the ROCTx Fortran binding to projects/fortran feat(fortran): add the ROCTx Fortran binding to bindings/fortran Nov 3, 2026
Install the test executables in bin/, and one CTestTestfile.cmake per
binding in bin/hip-fortran/ and bin/roctx-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 code
object of module_kernel and library_module installs beside the HIP
CTestTestfile.cmake, which they find by a relative path.
Install the test executables in bin/, and a CTestTestfile.cmake in
bin/hip-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 code object of module_kernel and
library_module installs beside it, and they find it by a relative path.
The ROCTx branch already moved both bindings to bindings/fortran and
installed their tests, so the merged tree keeps its split of the HIP
build into hip.cmake next to roctx.cmake.
…ator 9c8b3e4

The generator reads a library's metadata from bindings/fortran/metadata/
once that directory exists, so roctx.toml must sit next to hip.toml.
…object

TheRock's hipcc comes from the HIP install and does not know where the
device libraries are; it passes their path through HIP_FORTRAN_GENCO_FLAGS.

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

github actions Pull requests that update GitHub Actions code organization: ROCm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants