Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00
..

Fortran API reference

This library provides a pure Fortran interface for the rocRAND API.

This interface is intended to target only Host API functions. It provides a mapping to some of the C Host API functions in rocRAND. For documentation of these functions, see the C Host API functions documentation.

Deprecation notice

This library is currently deprecated in favor of hipfort.

Build and install

The Fortran interface is installed as part of the rocRAND package. Add the build option -DBUILD_FORTRAN_WRAPPER=ON when configuring the project, as shown below:

cmake -DBUILD_FORTRAN_WRAPPER=ON ...

Running unit tests

Configure the project with testing enabled, using the -DBUILD_TEST=ON option, then follow the steps below to build and run the unit tests.

  1. Go to the rocRAND build directory:
cd /path/to/rocRAND/build
  1. Build the unit tests for the Fortran interface:
cmake --build . --target test_rocrand_fortran_wrapper
  1. Run the unit tests:
./test/test_rocrand_fortran_wrapper

Usage

Here is an example of how to write a simple Fortran program that generates a set of uniform values.

integer(kind =8) :: gen
real, target, dimension(128) :: h_x
type(c_ptr) :: d_x
integer(c_int) :: status
integer(c_size_t), parameter :: output_size = 128
status = hipMalloc(d_x, output_size * sizeof(h_x(1)))
status = rocrand_create_generator(gen, ROCRAND_RNG_PSEUDO_DEFAULT)
status = rocrand_generate_uniform(gen, d_x, output_size)
status = hipMemcpy(c_loc(h_x), d_x, output_size * sizeof(h_x(1)), hipMemcpyDeviceToHost)
status = hipFree(d_x)
status = rocrand_destroy_generator(gen)

When compiling the source code with a Fortran compiler, the following items should be linked1 :


# Compile on an AMD platform (link HIP library: ${HIP_ROOT_DIR}/lib).
# Note: ${HIP_ROOT_DIR} points to the directory where HIP was installed.
gfortran <input-file>.f90 hip_m.f90 rocrand_m.f90  -lrocrand_fortran -lrocrand -L${HIP_ROOT_DIR}/lib

  1. gfortran is used in this example, however, other Fortran compilers should work. ↩︎