Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8bd295f
feat(fortran): add the generated HIP Fortran binding module
amontoison Oct 16, 2026
708cb93
feat(rocprofiler-sdk): package the rocTX Fortran bindings
Abuudiii Oct 2, 2026
aaa9a30
Update projects/rocprofiler-sdk/CHANGELOG.md
Abuudiii Oct 5, 2026
3f49494
fix(rocprofiler-sdk): address review of the rocTX Fortran bindings
Abuudiii Oct 5, 2026
9551b72
fix(rocprofiler-sdk): keep the rocTX Fortran test within the API cont…
Abuudiii Oct 5, 2026
630c5bf
feat(fortran): build and test the HIP Fortran bindings
amontoison Oct 16, 2026
54ce31a
refactor(fortran): move the ROCTx binding into projects/fortran
amontoison Oct 22, 2026
2d2ac65
refactor(fortran): move the HIP Fortran binding to bindings/fortran
amontoison Nov 3, 2026
5e8f428
style(fortran): apply gersemi to bindings/fortran/CMakeLists.txt
amontoison Nov 3, 2026
153e64a
refactor(fortran): move the HIP and ROCTx Fortran bindings to binding…
amontoison Nov 3, 2026
93e8528
feat(fortran): install the HIP and ROCTx binding tests
amontoison Nov 4, 2026
b4b5b36
feat(fortran): install the HIP binding tests
amontoison Nov 4, 2026
f152297
docs(fortran): point the ROCmFortran.cmake mirror comment at bindings…
amontoison Nov 4, 2026
b802455
Merge the HIP Fortran binding branch (#11923) into the ROCTx one
amontoison Nov 4, 2026
a3c90cc
feat(fortran): add the ROCTx binding metadata from rocm-fortran-gener…
amontoison Nov 4, 2026
7a4faa8
style(fortran): name the project rocm-systems-fortran and spell ROCTx…
amontoison Nov 4, 2026
840ba82
fix(fortran): let the build pass extra hipcc flags for the test code …
amontoison Nov 4, 2026
5cadd71
Merge branch 'users/amontoison/hip-fortran-bindings' into users/amont…
amontoison Nov 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
# Profilers
/profilers/profiler-hub @ROCm/rocm-profiler-hub

# Bindings
/bindings/fortran/ @ROCm/rocm-fortran-maintainers @ROCm/hip-reviewers

# Documentation-specific ownership by project (last to take precedence)

/projects/clr/**/*.md @ROCm/clr-reviewers @ROCm/lrt-docs-reviewers
Expand Down
9 changes: 9 additions & 0 deletions .github/repos-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
"auto_subtree_push": true,
"monorepo_source_of_truth": true
},
{
"name": "fortran",
"url": "ROCm/rocm-systems",
"branch": "develop",
"category": "bindings",
"auto_subtree_pull": false,
"auto_subtree_push": false,
"monorepo_source_of_truth": true
},
{
"name": "rocjitsu",
"url": "ROCm/rocm-systems",
Expand Down
3 changes: 3 additions & 0 deletions bindings/fortran/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by rocm-fortran-generator
/hip.F90 linguist-generated=true
/roctx.F90 linguist-generated=true
16 changes: 16 additions & 0 deletions bindings/fortran/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog for the rocm-systems Fortran bindings

## Unreleased

### Added
* Generated Fortran bindings for the HIP runtime API, as a single `hip` module: `use hip`, link
`hip::hip_fortran`. A standalone CMake project, built against an installed HIP. Controlled by
`BUILD_FORTRAN_BINDINGS` (`ON` on Linux, `OFF` on Windows, where ROCm ships no Fortran
compiler), `BUILD_FORTRAN_CLIENTS` and `FORTRAN_ARRAY_INTERFACES` (`none`, `assumed-shape`,
`assumed-rank`). Found with `find_package(hip-fortran)`; installed per compiler, the archive
under `<libdir>/fortran/<compiler>` and the `.mod` files under `<includedir>/fortran/<compiler>`.
The archive has one section per procedure: link with `-Wl,--gc-sections` to keep only the wrappers
you call.
* Generated Fortran bindings for the ROCTx API, as a single `roctx` module: `use roctx`, link
`roc::roctx_fortran`, found with `find_package(roctx-fortran)`. Built and installed with the HIP
bindings, against an installed `rocprofiler-sdk-roctx`.
220 changes: 220 additions & 0 deletions bindings/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# Fortran bindings for the rocm-systems libraries: the `hip` and `roctx` modules.
# hip.F90 and roctx.F90 are generated from the HIP and ROCTx headers by
# rocm-fortran-generator; do not edit them by hand. A standalone project, built
# against an installed HIP (find_package(hip)) and ROCTx
# (find_package(rocprofiler-sdk-roctx)).

cmake_minimum_required(VERSION 3.19)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(rocm-systems-fortran LANGUAGES NONE)
endif()

# "${UNIX}": ROCm ships no Fortran compiler on Windows, where the probe would
# pick up a stray gfortran that enable_language(Fortran) then rejects.
option(
BUILD_FORTRAN_BINDINGS
"Build the HIP and ROCTx Fortran bindings"
"${UNIX}"
)

option(BUILD_FORTRAN_CLIENTS "Build the HIP and ROCTx Fortran binding tests" ON)

# Both options are shared by every library in the monorepo; the HIP_ and ROCTX_
# names win for their library.
foreach(_lib IN ITEMS HIP ROCTX)
set(_${_lib}_bindings ${BUILD_FORTRAN_BINDINGS})
if(DEFINED ${_lib}_BUILD_FORTRAN_BINDINGS)
set(_${_lib}_bindings ${${_lib}_BUILD_FORTRAN_BINDINGS})
endif()
set(_${_lib}_clients ${BUILD_FORTRAN_CLIENTS})
if(DEFINED ${_lib}_BUILD_FORTRAN_CLIENTS)
set(_${_lib}_clients ${${_lib}_BUILD_FORTRAN_CLIENTS})
endif()
endforeach()

set(FORTRAN_ARRAY_INTERFACES
"assumed-shape"
CACHE STRING
"Array-argument overloads to expose: none, assumed-shape, or assumed-rank"
)
set_property(
CACHE FORTRAN_ARRAY_INTERFACES
PROPERTY STRINGS none assumed-shape assumed-rank
)

if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(HIP_HAVE_FORTRAN_BINDINGS FALSE PARENT_SCOPE)
set(ROCTX_HAVE_FORTRAN_BINDINGS FALSE PARENT_SCOPE)
endif()

if(NOT _HIP_bindings AND NOT _ROCTX_bindings)
return()
endif()

# A deliberate ROCM_HAVE_FORTRAN=OFF must not be overridden by a fresh probe.
if(NOT DEFINED ROCM_HAVE_FORTRAN)
if(NOT DEFINED ROCM_SYSTEMS_ROOT)
get_filename_component(
ROCM_SYSTEMS_ROOT
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
ABSOLUTE
)
endif()
include("${ROCM_SYSTEMS_ROOT}/shared/cmake/ROCmFortran.cmake" OPTIONAL)
endif()

# Fallback for a build extracted from the monorepo, where the shared module is
# absent. Mirrors shared/cmake/ROCmFortran.cmake; keep the two in sync.
if(DEFINED ROCM_HAVE_FORTRAN)
set(_have_fortran ${ROCM_HAVE_FORTRAN})
else()
include(CheckLanguage)

set(_rocm_warn_toolchain_var "${ROCM_WARN_TOOLCHAIN_VAR}")
set(_rocm_error_toolchain_var "${ROCM_ERROR_TOOLCHAIN_VAR}")
set(ROCM_WARN_TOOLCHAIN_VAR OFF)
set(ROCM_ERROR_TOOLCHAIN_VAR OFF)

if(NOT CMAKE_Fortran_COMPILER AND NOT DEFINED ENV{FC})
set(_rocm_fc_hints)
foreach(
_rocm_fc_cc
"${CMAKE_CXX_COMPILER}"
"${CMAKE_C_COMPILER}"
"${CMAKE_HIP_COMPILER}"
)
if(_rocm_fc_cc)
get_filename_component(_rocm_fc_dir "${_rocm_fc_cc}" DIRECTORY)
list(APPEND _rocm_fc_hints "${_rocm_fc_dir}")
endif()
endforeach()
foreach(_rocm_fc_root "${ROCM_PATH}" "$ENV{ROCM_PATH}" "/opt/rocm")
if(_rocm_fc_root)
list(
APPEND _rocm_fc_hints
"${_rocm_fc_root}/bin"
"${_rocm_fc_root}/lib/llvm/bin"
)
endif()
endforeach()
unset(_rocm_amdflang CACHE)
find_program(
_rocm_amdflang
NAMES amdflang
HINTS ${_rocm_fc_hints}
NO_DEFAULT_PATH
)
if(_rocm_amdflang)
execute_process(
COMMAND "${_rocm_amdflang}" --version
RESULT_VARIABLE _rocm_fc_rc
OUTPUT_QUIET
ERROR_QUIET
)
if(_rocm_fc_rc EQUAL 0)
set(CMAKE_Fortran_COMPILER
"${_rocm_amdflang}"
CACHE FILEPATH
"Fortran compiler used for the ROCm Fortran bindings"
FORCE
)
endif()
unset(_rocm_fc_rc)
endif()
unset(_rocm_amdflang CACHE)
unset(_rocm_fc_hints)
unset(_rocm_fc_cc)
unset(_rocm_fc_dir)
unset(_rocm_fc_root)
endif()

check_language(Fortran)
set(ROCM_WARN_TOOLCHAIN_VAR "${_rocm_warn_toolchain_var}")
set(ROCM_ERROR_TOOLCHAIN_VAR "${_rocm_error_toolchain_var}")
unset(_rocm_warn_toolchain_var)
unset(_rocm_error_toolchain_var)

if(CMAKE_Fortran_COMPILER)
set(_have_fortran TRUE)
else()
set(_have_fortran FALSE)
endif()
endif()

if(NOT _have_fortran)
message(
STATUS
"HIP, ROCTx: no Fortran compiler found, skipping the Fortran bindings"
)
return()
endif()

enable_language(Fortran)

include(GNUInstallDirs)

if(NOT FORTRAN_ARRAY_INTERFACES MATCHES "^(none|assumed-shape|assumed-rank)$")
message(
FATAL_ERROR
"FORTRAN_ARRAY_INTERFACES must be none, assumed-shape or assumed-rank, "
"not '${FORTRAN_ARRAY_INTERFACES}'."
)
endif()

# A .mod is compiler-specific, so artifacts install per compiler, named as the
# user types it. Must match the mapping in hip-fortran-config.cmake.in and
# roctx-fortran-config.cmake.in.
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(_fc_name "gfortran")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Flang") # Flang, LLVMFlang
set(_fc_name "amdflang")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
set(_fc_name "ftn")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(_fc_name "ifx")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(_fc_name "ifort")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
set(_fc_name "nvfortran")
else()
get_filename_component(_fc_name "${CMAKE_Fortran_COMPILER}" NAME_WE)
string(TOLOWER "${_fc_name}" _fc_name)
endif()

include(CMakePackageConfigHelpers)

# One section per procedure (see hip.cmake), with the compilers that take the
# flags: the amdflang of ROCm 7.13 rejects them.
include(CheckFortranCompilerFlag)
check_fortran_compiler_flag(
-ffunction-sections
ROCM_FORTRAN_HAVE_FUNCTION_SECTIONS
)
check_fortran_compiler_flag(-fdata-sections ROCM_FORTRAN_HAVE_DATA_SECTIONS)

# dev: the component HIP's headers and CMake config install under.
set(HIP_FORTRAN_INSTALL_COMPONENT
"dev"
CACHE STRING
"Install component of the HIP and ROCTx Fortran bindings"
)

if(_HIP_bindings)
include("${CMAKE_CURRENT_SOURCE_DIR}/hip.cmake")
endif()
if(_ROCTX_bindings)
include("${CMAKE_CURRENT_SOURCE_DIR}/roctx.cmake")
endif()

if(
(TARGET hip_fortran AND _HIP_clients)
OR (TARGET roctx_fortran AND _ROCTX_clients)
)
enable_testing()
add_subdirectory(test)
endif()
10 changes: 10 additions & 0 deletions bindings/fortran/cmake/toolchains/amdflang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# AMD ROCm toolchain (amdflang), the recommended default.
# Usage, from bindings/fortran:
# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/amdflang.cmake

set(CMAKE_Fortran_COMPILER amdflang CACHE FILEPATH "Fortran compiler")
set(CMAKE_C_COMPILER amdclang CACHE FILEPATH "C compiler")
10 changes: 10 additions & 0 deletions bindings/fortran/cmake/toolchains/cray.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# Cray toolchain: the ftn and cc wrappers follow the loaded PrgEnv module.
# Usage, from bindings/fortran:
# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/cray.cmake

set(CMAKE_Fortran_COMPILER ftn CACHE FILEPATH "Fortran compiler")
set(CMAKE_C_COMPILER cc CACHE FILEPATH "C compiler")
10 changes: 10 additions & 0 deletions bindings/fortran/cmake/toolchains/gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# GNU toolchain (gfortran).
# Usage, from bindings/fortran:
# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/gnu.cmake

set(CMAKE_Fortran_COMPILER gfortran CACHE FILEPATH "Fortran compiler")
set(CMAKE_C_COMPILER gcc CACHE FILEPATH "C compiler")
10 changes: 10 additions & 0 deletions bindings/fortran/cmake/toolchains/intel-classic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# Classic Intel toolchain (ifort), deprecated by Intel in favour of ifx.
# Usage, from bindings/fortran:
# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/intel-classic.cmake

set(CMAKE_Fortran_COMPILER ifort CACHE FILEPATH "Fortran compiler")
set(CMAKE_C_COMPILER icx CACHE FILEPATH "C compiler")
10 changes: 10 additions & 0 deletions bindings/fortran/cmake/toolchains/intel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# Intel oneAPI toolchain (ifx).
# Usage, from bindings/fortran:
# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/intel.cmake

set(CMAKE_Fortran_COMPILER ifx CACHE FILEPATH "Fortran compiler")
set(CMAKE_C_COMPILER icx CACHE FILEPATH "C compiler")
10 changes: 10 additions & 0 deletions bindings/fortran/cmake/toolchains/nvhpc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT

# NVIDIA HPC SDK toolchain (nvfortran).
# Usage, from bindings/fortran:
# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/nvhpc.cmake

set(CMAKE_Fortran_COMPILER nvfortran CACHE FILEPATH "Fortran compiler")
set(CMAKE_C_COMPILER nvc CACHE FILEPATH "C compiler")
Loading
Loading