Repository navigation
Bind every scalar pointer as type(c_ptr), add its typed form as _typed - #581
Merged
Merged
Conversation
The bind(C) specific of each routine now spells every scalar pointer the way the C API does, type(c_ptr), value: alpha/beta as before, and the host outputs (getters, buffer sizes, counts) as well, which were typed in the specific itself. Their Fortran type moves to a <routine>_typed module procedure of the same generic, which takes the variable and forwards c_loc of it (c_null_ptr for an absent optional). Both forms resolve, as they differ in the type of those arguments, so a call can pass c_loc(x), a device address or NULL, or the variable itself: rocblas_dgemm(handle, ..., alpha, dA, ...) ! _typed rocblas_dgemm(handle, ..., c_loc(alpha), dA, ...) ! bind(C) Two more forms: - <routine>_devptr, for the 42 sparse routines with both a pointer-mode scalar and a host-only one: in device pointer mode alpha/beta are addresses while buffer_size stays a host variable. - <routine>_rank_N_devptr beside the hipSOLVER array overloads: devInfo is typed in the array overloads, like the device arrays next to it (it was a type(c_ptr) there), and a type(c_ptr) in the _devptr twins. devInfo gets no _typed form on the type(c_ptr) interface: a typed host variable beside type(c_ptr) buffers is a shape the API never accepts. Code written against hipfort 0.9.0 compiles again: 728 of its 807 test programs, against 585 before this change. The 79 that do not are listed in the changelog; none is silent. Regenerated with rocm-fortran 9854af6 (lib/hipfort, the symbol tests and the supported-API tables, the latter patched with the generated diff only). Checked against ROCm 10.1, gfortran and amdflang: - the modules compile with no macro, USE_ASSUMED_SHAPE, USE_ASSUMED_RANK and USE_ASSUMED_SHAPE + USE_CUDA_NAMES; the current tests build 1245/1245; - full ctest with -DHIPFORT_EXTENDED_TESTS=ON: 1255/1258, the three known WSL failures; the shared-link tests resolve every symbol against ROCm 10.1 and, without libcuda, against CUDA 13.3; - on a gfx1101 GPU, no 0.9.0 test program that builds behaves differently against the 0.9.0 library and this one.
develop regenerated the symbol tests (#580) against its own bindings. The ones here are regenerated with the same tool against the bindings of this branch, so they are kept as they are.
This was referenced Oct 6, 2026
amontoison
added a commit
that referenced
this pull request
Oct 7, 2026
#581 gives every scalar pointer argument two forms under one generic: the bind(C) specific takes a type(c_ptr), the _typed module procedure the Fortran variable. Nothing in the user documentation said so, and the test suite only called the type(c_ptr) form for alpha/beta (with c_loc, since #564), so the _typed path was not covered by CTest. docs/how-to/fortran-interfaces.rst gains a section "Scalar arguments passed by pointer": when to pass the variable and when its address, the device pointer mode (including the routines that mix a pointer-mode scalar with a host output, and the array overloads, whose alpha/beta are typed), and hipSOLVER's device-only devInfo. Its examples compile against these bindings with gfortran and amdflang. Eight tests take an existing check through the _typed form, with alpha and beta passed as named constants instead of c_loc(): rocBLAS dgemm and caxpy, hipBLAS sgemm and zaxpy, rocSPARSE dgemvi and dcsrgemm (alpha, beta and buffer_size all typed), hipSPARSE dgemvi and zcsrsv2. Each object file references the _typed procedures it is meant to (checked with nm), and the two copies whose alpha was 1 use 2 and (2,1) instead, so a lost or misread alpha fails the check.
This was referenced Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every scalar pointer argument now comes in two forms under the same generic:
bind(C)specific takes it astype(c_ptr), value, the C API's own spelling;<routine>_typedmodule procedure takes the Fortran variable (integer,real,complexor the enum kind) and passes its address.Both forms resolve, so either of these calls works:
This covers two kinds of scalar:
alpha,beta,nnzTotalDevHostPtr, ...). Thetype(c_ptr)form is what makes the device pointer mode usable from Fortran.bind(C)specific itself (Update the classification of the arguments, and cover the query routines #571, Update hip, hipBLAS and rocBLAS bindings #572, 5de6093). They are back totype(c_ptr)there, as in hipfort 0.9.0, and keep their typed form in_typed.Two more forms cover the calls neither of those can spell:
<routine>_devptr, for the 42 rocSPARSE/hipSPARSE routines with both a pointer-mode scalar and a host output (alphanext tobuffer_size). This is the device-pointer-mode call: the pointer-mode scalars astype(c_ptr), the host outputs typed.<routine>_rank_N_devptr, next to the hipSOLVER array overloads. In those overloadsdevInfois now aninteger, like the device arrays next to it, as in 0.9.0. The_devptrtwins take it as atype(c_ptr).devInfogets no typed form on thetype(c_ptr)interface, because a host integer next totype(c_ptr)buffers would be written by the GPU.Compatibility with 0.9.0
728 of the 807 test programs of hipfort 0.9.0 now compile against these modules, up from 585 against
develop. The 79 that still fail break at compile time, for six reasons; the CHANGELOG update will list them:integerdevInfopassed withtype(c_ptr)buffers. Excluded on purpose.taupassed asdTau(1).*syevdx/*heevdx, 4 programs:nevpassed as ac_ptrwhilelworkis typed.rocsolver_{c,z}hegvdx, 4 programs:nevis now a device pointer (fb8f244).dimspassed as a scalar.One change still compiles but behaves differently:
hipsolverRfBatch*now takes its array of host pointers by value.Contents
lib/hipfort, regenerated with rocm-fortran 9854af6.typed/devptr.Validation
Against ROCm 10.1, with gfortran and amdflang:
USE_ASSUMED_SHAPE, withUSE_ASSUMED_RANK, and withUSE_ASSUMED_SHAPE+USE_CUDA_NAMES. The current tests build 1245/1245.-DHIPFORT_EXTENDED_TESTS=ON: 1255/1258. The 3 failures are the known WSL ones (hip_mem_advisef2003/f2008,hip_module_kernel).libcuda: the_typedforms of the 6 HIP routines mapped to the CUDA driver API exist on ROCm only.Generator fixes found along the way
character(c_char)is forwarded to abind(C)valuedummy.hipsolverSgesvd_bufferSizethen returnedINVALID_VALUE. The wrappers now take a Ccharby value._typedform calls the CUDA driver API, so hipfort still needs only the CUDA runtime libraries.