Repository navigation
Document and test the typed and type(c_ptr) forms of scalar arguments - #583
Merged
Merged
Conversation
#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.
dInfo is an integer(c_int), pointer allocated with hipMalloc, so it lives on the device like the arrays beside it, and the array overloads take it as is. The four tests passed c_loc(dInfo), which resolves to the _devptr twin, under a comment saying "devInfo by reference". They now pass dInfo, which also puts the typed devInfo of the array overloads under CTest; the other f2008 hipSOLVER tests still pass c_loc(dInfo) and cover _devptr. hipsolver_dgetrf.f08 is the program the hipSOLVER tutorial shows.
amontoison
force-pushed
the
typed_forms_docs_tests
branch
from
October 7, 2026 04:23
6365348 to
6d2910b
Compare
amontoison
added a commit
that referenced
this pull request
Oct 7, 2026
Regenerated with rocm-fortran 3b65cdb. Typed forms for scalar pointers that still needed c_loc(): the BLAS dot/nrm2/asum/iamax/iamin results and rotg/rotmg scalars (rocBLAS and hipBLAS) and hipBLAS rot's c/s; the sparse doti/dotci results, nnz counts, pivot positions and csr2ell_width's ell_width; hipBLAS getrs/geqrf/gels info (host); hipChooseDevice. The array overloads take the BLAS results and hipBLAS info typed and gain _rank_N_devptr twins that keep the type(c_ptr), so existing c_loc() calls still compile. Fixes: - rocSOLVER larf/larfg alpha/tau are device scalars and lose their _typed form, which would have handed the kernel a host address; - hipsolverRfBatchZeroPivot position (an array) and rocblas_set_solution_fitness_query fitness (a retained pointer) lose theirs too; - csrcolor's coloring/reordering are arrays again in the array overloads; - rocSPARSE's nullable `error` arguments are optional; - hipMalloc(..., source=) and its siblings report an allocation failure instead of the copy's status; - the compat hipsolver*gels/gesvd_bufferSize are no longer bound to cusolverDn symbols with different arguments under USE_CUDA_NAMES; - hipChooseDevice is a generic over hipChooseDeviceR0600's specifics instead of a second interface on the same binding label. Three tests take a result through the new typed forms: rocBLAS ddot, hipBLAS snrm2 and rocSPARSE ddoti (host pointer mode). Also regenerates the supported-API tables (only the generated diff: the variants column gains typed and devptr), and updates the changelog with the Scalar arguments section and tests of #583, the typed forms above and the fixes.
amontoison
added a commit
that referenced
this pull request
Oct 9, 2026
Regenerated with rocm-fortran 3b65cdb. Typed forms for scalar pointers that still needed c_loc(): the BLAS dot/nrm2/asum/iamax/iamin results and rotg/rotmg scalars (rocBLAS and hipBLAS) and hipBLAS rot's c/s; the sparse doti/dotci results, nnz counts, pivot positions and csr2ell_width's ell_width; hipBLAS getrs/geqrf/gels info (host); hipChooseDevice. The array overloads take the BLAS results and hipBLAS info typed and gain _rank_N_devptr twins that keep the type(c_ptr), so existing c_loc() calls still compile. Fixes: - rocSOLVER larf/larfg alpha/tau are device scalars and lose their _typed form, which would have handed the kernel a host address; - hipsolverRfBatchZeroPivot position (an array) and rocblas_set_solution_fitness_query fitness (a retained pointer) lose theirs too; - csrcolor's coloring/reordering are arrays again in the array overloads; - rocSPARSE's nullable `error` arguments are optional; - hipMalloc(..., source=) and its siblings report an allocation failure instead of the copy's status; - the compat hipsolver*gels/gesvd_bufferSize are no longer bound to cusolverDn symbols with different arguments under USE_CUDA_NAMES; - hipChooseDevice is a generic over hipChooseDeviceR0600's specifics instead of a second interface on the same binding label. Three tests take a result through the new typed forms: rocBLAS ddot, hipBLAS snrm2 and rocSPARSE ddoti (host pointer mode). Also regenerates the supported-API tables (only the generated diff: the variants column gains typed and devptr), and updates the changelog with the Scalar arguments section and tests of #583, the typed forms above and the fixes.
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.
Follow-up to #581: documents and tests the typed and type(c_ptr) forms it introduced.
Docs
docs/how-to/fortran-interfaces.rstgains a section Scalar arguments passed by pointer that explains:_typed) and when to pass its address (type(c_ptr)): device address,c_null_ptrfor an output that can be skipped, or existingc_loccode;X_devptr);alpha/betaare typed, so the variable itself has to live on the device;devInfo:type(c_ptr)withtype(c_ptr)buffers, and aninteger(c_int), pointeror atype(c_ptr)with the array overloads;X_typed/X_devptrnames that appear in the reference relate to the generic.The examples compile against the #581 bindings with gfortran and amdflang. The RST is checked with docutils (beyond the Sphinx
:doc:role).Tests
Until now,
alpha/betaonly went through thec_loc(alpha)form in CTest. Eight tests now take an existing check through the_typedform, withalpha/betapassed as named constants:dgemm_typed,caxpy_typedsgemm_typed,zaxpy_typedrocsparse_dgemvi_typed,rocsparse_dcsrgemm_typed(alpha,betaandbuffer_sizeall typed)hipsparse_dgemvi_typed,hipsparse_zcsrsv2_typed_typedprocedures it targets (checked withnm).alphaof 1 use 2 and (2,1) instead, so a lost or misreadalphafails the check._devptrform is already covered by the*_devptrtests (rocSPARSEdcsrgemm/csrgeam...).hipsolver_?getrftests now passdInfoitself (aninteger(c_int), pointerfromhipMalloc) instead ofc_loc(dInfo), which puts the typeddevInfoof the array overloads under CTest and fixes a comment that said "by reference". The other f2008 hipSOLVER tests keepc_loc(dInfo)and cover_rank_N_devptr.hipsolver_dgetrf.f08is the program the hipSOLVER tutorial shows.Validation
ctest -R '_typed$'gives 8/8.