From 21cd2d2ba3d3180d98903fec9a3ba810c051bf14 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Tue, 3 Nov 2026 15:33:26 -0600 Subject: [PATCH] feat: write and read the bindings in bindings/fortran The Fortran bindings move out of the library projects into a top-level bindings/fortran tree in both monorepos: bindings/fortran/ in rocm-systems (HIP, ROCTx) and bindings/fortran// in rocm-libraries. --overwrite now copies each module there, and a checkout's metadata/ is read from there. The headers are still read from projects/. --- README.md | 28 ++++++++++++++-------------- gen.sh | 8 ++++---- src/common/header_sources.jl | 10 +++++----- src/generate_all.jl | 12 ++++++------ src/test/gen_sh.sh | 7 ++++--- src/test/runtests.jl | 22 +++++++++++----------- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 1399a19..5964ff4 100644 --- a/README.md +++ b/README.md @@ -111,19 +111,19 @@ Run from this repository: | Library | Command | Writes | |---|---|---| -| HIP | `ROCM_SYSTEMS= ./gen.sh --overwrite hip` | `projects/fortran/hip.F90` | -| ROCTx | `ROCM_SYSTEMS= ./gen.sh --overwrite roctx` | `projects/fortran/roctx.F90` | -| rocBLAS | `ROCM_LIBRARIES= ./gen.sh --overwrite rocblas` | `projects/rocblas/fortran/rocblas.F90` | -| hipBLAS | `ROCM_LIBRARIES= ./gen.sh --overwrite hipblas` | `projects/hipblas/fortran/hipblas.F90` | -| rocSOLVER | `ROCM_LIBRARIES= ./gen.sh --overwrite rocsolver` | `projects/rocsolver/fortran/rocsolver.F90` | -| hipSOLVER | `ROCM_LIBRARIES= ./gen.sh --overwrite hipsolver` | `projects/hipsolver/fortran/hipsolver.F90` | -| rocSPARSE | `ROCM_LIBRARIES= ./gen.sh --overwrite rocsparse` | `projects/rocsparse/fortran/rocsparse.F90` | -| hipSPARSE | `ROCM_LIBRARIES= ./gen.sh --overwrite hipsparse` | `projects/hipsparse/fortran/hipsparse.F90` | -| rocFFT | `ROCM_LIBRARIES= ./gen.sh --overwrite rocfft` | `projects/rocfft/fortran/rocfft.F90` | -| hipFFT | `ROCM_LIBRARIES= ./gen.sh --overwrite hipfft` | `projects/hipfft/fortran/hipfft.F90` | -| hipFFTW | `ROCM_LIBRARIES= ./gen.sh --overwrite hipfftw` | `projects/hipfft/fortran/hipfftw.F90` | -| rocRAND | `ROCM_LIBRARIES= ./gen.sh --overwrite rocrand` | `projects/rocrand/fortran/rocrand.F90` | -| hipRAND | `ROCM_LIBRARIES= ./gen.sh --overwrite hiprand` | `projects/hiprand/fortran/hiprand.F90` | +| HIP | `ROCM_SYSTEMS= ./gen.sh --overwrite hip` | `bindings/fortran/hip.F90` | +| ROCTx | `ROCM_SYSTEMS= ./gen.sh --overwrite roctx` | `bindings/fortran/roctx.F90` | +| rocBLAS | `ROCM_LIBRARIES= ./gen.sh --overwrite rocblas` | `bindings/fortran/rocblas/rocblas.F90` | +| hipBLAS | `ROCM_LIBRARIES= ./gen.sh --overwrite hipblas` | `bindings/fortran/hipblas/hipblas.F90` | +| rocSOLVER | `ROCM_LIBRARIES= ./gen.sh --overwrite rocsolver` | `bindings/fortran/rocsolver/rocsolver.F90` | +| hipSOLVER | `ROCM_LIBRARIES= ./gen.sh --overwrite hipsolver` | `bindings/fortran/hipsolver/hipsolver.F90` | +| rocSPARSE | `ROCM_LIBRARIES= ./gen.sh --overwrite rocsparse` | `bindings/fortran/rocsparse/rocsparse.F90` | +| hipSPARSE | `ROCM_LIBRARIES= ./gen.sh --overwrite hipsparse` | `bindings/fortran/hipsparse/hipsparse.F90` | +| rocFFT | `ROCM_LIBRARIES= ./gen.sh --overwrite rocfft` | `bindings/fortran/rocfft/rocfft.F90` | +| hipFFT | `ROCM_LIBRARIES= ./gen.sh --overwrite hipfft` | `bindings/fortran/hipfft/hipfft.F90` | +| hipFFTW | `ROCM_LIBRARIES= ./gen.sh --overwrite hipfftw` | `bindings/fortran/hipfft/hipfftw.F90` | +| rocRAND | `ROCM_LIBRARIES= ./gen.sh --overwrite rocrand` | `bindings/fortran/rocrand/rocrand.F90` | +| hipRAND | `ROCM_LIBRARIES= ./gen.sh --overwrite hiprand` | `bindings/fortran/hiprand/hiprand.F90` | `` and `` are the paths of your checkouts, and the last column is relative to them. Several libraries can be named in one run @@ -312,7 +312,7 @@ Without it, `alpha` and `beta` would be buffers: arrays of one element. | | | |---|---| -| **where** | `src//metadata/.toml` in the generator; when a run reads a checkout, the checkout's own `metadata/` next to the module replaces it (`projects/fortran/metadata/` in rocm-systems, `projects//fortran/metadata/` in rocm-libraries) | +| **where** | `src//metadata/.toml` in the generator; when a run reads a checkout, the checkout's own `metadata/` next to the module replaces it (`bindings/fortran/metadata/` in rocm-systems, `bindings/fortran//metadata/` in rocm-libraries) | | **none** | a missing or empty file means no metadata: the C declarations alone | | **`format = 1`** | required as soon as there is an entry; the version of this schema, not of the generator | | **tables** | one per C function, keyed by its arguments' names as the C header spells them | diff --git a/gen.sh b/gen.sh index 9edb672..29c93aa 100755 --- a/gen.sh +++ b/gen.sh @@ -54,13 +54,13 @@ note: Both: all libraries, from the two checkouts only (no ROCm installation). note: Libraries named on the command line (hip, roctx, rocblas, hipfft, ...) are the note: only ones generated; each must come from a header source the run reads. note: --overwrite also copies each generated module into its checkout: -note: /projects//fortran/.F90, or -note: /projects/fortran/.F90. It needs a checkout, the fortran/ +note: /bindings/fortran//.F90, or +note: /bindings/fortran/.F90. It needs a checkout, the binding's note: directory must already exist there, and a library that fails is not copied. note: A run rewrites only the modules it generates: fortran/rocm-systems/fortran/ note: (HIP, ROCTx) and fortran/rocm-libraries// (the math libraries). -note: A checkout's fortran/metadata/.toml (rocm-systems: projects/fortran/metadata/; -note: rocm-libraries: projects//fortran/metadata/), when present, replaces the +note: A checkout's metadata/.toml (rocm-systems: bindings/fortran/metadata/; +note: rocm-libraries: bindings/fortran//metadata/), when present, replaces the note: generator's src//metadata/ for that library. note: The Julia dependencies are installed on the first run (Pkg.instantiate). note: fortran/ is gitignored: the bindings are committed upstream, next to the diff --git a/src/common/header_sources.jl b/src/common/header_sources.jl index 667923a..2ad7048 100644 --- a/src/common/header_sources.jl +++ b/src/common/header_sources.jl @@ -125,10 +125,10 @@ function lib_include(s::HeaderSources, lib) end # The directory of a library's Fortran module in its checkout: one shared -# projects/fortran/ in rocm-systems, projects//fortran/ in rocm-libraries. +# bindings/fortran/ in rocm-systems, bindings/fortran// in rocm-libraries. fortran_dir(s::HeaderSources, lib) = - repo_of(lib) == "rocm-systems" ? joinpath(s.systems, "projects", "fortran") : - joinpath(s.libraries, "projects", proj_of(lib), "fortran") + repo_of(lib) == "rocm-systems" ? joinpath(s.systems, "bindings", "fortran") : + joinpath(s.libraries, "bindings", "fortran", proj_of(lib)) # The path --overwrite writes a library's module to, in its checkout. overwrite_target(s::HeaderSources, lib) = joinpath(fortran_dir(s, lib), "$(lib).F90") @@ -181,7 +181,7 @@ end check_overwrite(s, libs) Throws an `ArgumentError` unless --overwrite can write every module of `libs`: the -run reads a checkout, and each library's fortran/ directory already exists in it. +run reads a checkout, and each library's binding directory already exists in it. Called before generating anything, so a run that cannot finish writes nothing. """ function check_overwrite(s::HeaderSources, libs) @@ -197,7 +197,7 @@ end # A library's metadata file (metadata/.toml): the checkout's # /metadata/ when it exists, else the generator's own # src//metadata/. The file names carry the library name, so the modules sharing -# a fortran/ directory (hip and roctx, hipfft and hipfftw) share one metadata/. +# a binding directory (hip and roctx, hipfft and hipfftw) share one metadata/. function lib_metadata(s::HeaderSources, lib) if from_checkouts(s) d = joinpath(fortran_dir(s, lib), "metadata") diff --git a/src/generate_all.jl b/src/generate_all.jl index b7abaa7..a71a03f 100644 --- a/src/generate_all.jl +++ b/src/generate_all.jl @@ -41,11 +41,11 @@ # Options, before the positional arguments: # --libs=[,...] generate only these libraries (each must be one the run selects) # --overwrite also copy each generated module into its checkout, as -# /projects//fortran/.F90 or -# /projects/fortran/.F90; needs a checkout, -# and that fortran/ directory must already exist +# /bindings/fortran//.F90 or +# /bindings/fortran/.F90; needs a checkout, +# and that directory must already exist # -# Each library's metadata files come from its checkout's projects//fortran/metadata/ +# Each library's metadata files come from its checkout's bindings/fortran//metadata/ # when the run reads that checkout and the directory exists, else from src//metadata/. if any(in(("-h", "--help")), ARGS) @@ -81,7 +81,7 @@ end const OUTPUT_ROOT = abspath(isempty(REST) ? joinpath(@__DIR__, "..", "fortran") : REST[1]) const HIP_VERSION = hip_version(SOURCES) -# rocm-systems keeps its modules in one projects/fortran/ directory. +# rocm-systems keeps its modules in one bindings/fortran/ directory. outdir_of(lib) = repo_of(lib) == "rocm-systems" ? joinpath(OUTPUT_ROOT, "rocm-systems", "fortran") : joinpath(OUTPUT_ROOT, "rocm-libraries", lib) @@ -156,7 +156,7 @@ write(joinpath(OUTPUT_ROOT, ".provenance"), """ hip: $(HIP_VERSION) metadata: $(let ck = filter(l -> !startswith(lib_metadata(SOURCES, l), normpath(@__DIR__)), generated) isempty(ck) ? "generator (src//metadata/)" : - "checkout fortran/metadata/ for $(join(ck, " ")), generator for the others" + "checkout metadata/ for $(join(ck, " ")), generator for the others" end) arrays: $(get(ENV, "ROCM_FORTRAN_ARRAY_INTERFACES", "all")) generator: $(GENERATOR_VERSION) ($(commit)) diff --git a/src/test/gen_sh.sh b/src/test/gen_sh.sh index b725f62..78450b1 100755 --- a/src/test/gen_sh.sh +++ b/src/test/gen_sh.sh @@ -65,7 +65,7 @@ expect 1 "it comes from rocm-systems, so set ROCM_SYSTEMS" \ env ROCM_INCLUDE="$INST" ROCM_LIBRARIES="$LIBS" ./gen.sh hip expect 1 "--overwrite needs ROCM_LIBRARIES or ROCM_SYSTEMS" \ env ROCM_INCLUDE="$INST" ./gen.sh --overwrite rocblas -expect 1 "projects/rocblas/fortran does not exist" \ +expect 1 "bindings/fortran/rocblas does not exist" \ env ROCM_INCLUDE="$INST" ROCM_LIBRARIES="$LIBS" ./gen.sh --overwrite rocblas expect 0 "C signature: headers not read; no HIP headers" \ env ROCM_INCLUDE="$TMP/empty" ./gen.sh --explain rocblas_srot_64 @@ -76,9 +76,10 @@ expect 1 "FAILED to generate" env ROCM_INCLUDE="$INST" ./gen.sh # an empty hip # --explain, from a rocm-libraries checkout holding the fixture rocblas.h and its # metadata: one parse, whatever the number of functions named. CK="$TMP/ck/projects/rocblas" -mkdir -p "$CK/library/include" "$CK/fortran/metadata" +META="$TMP/ck/bindings/fortran/rocblas/metadata" +mkdir -p "$CK/library/include" "$META" cp src/test/fixtures/explain/rocblas.h "$CK/library/include/" -cp src/test/fixtures/explain/rocblas.toml "$CK/fortran/metadata/" +cp src/test/fixtures/explain/rocblas.toml "$META/" out="$(env ROCM_INCLUDE="$INST" ROCM_LIBRARIES="$TMP/ck" \ ./gen.sh --explain rocblas_daxpy rocblas_dfoo_buffer_size rocblas_dbar rocblas_dnope 2>&1)" for text in \ diff --git a/src/test/runtests.jl b/src/test/runtests.jl index 3fdd13c..119fd1c 100644 --- a/src/test/runtests.jl +++ b/src/test/runtests.jl @@ -1234,14 +1234,14 @@ overlong_fortran_lines(s::AbstractString) = @test lib_include(s, "rocblas") == joinpath(libs, "projects", "rocblas", "library", "include") @test hip_installed_include(s) == "" && hip_version(s) == "7.17.3" - # Metadata: a checkout's projects//fortran/metadata/ replaces src//metadata/. + # Metadata: a checkout's bindings/fortran//metadata/ replaces src//metadata/. gen_meta(lib) = joinpath(GEN_ROOT, lib, "metadata") - mkpath(joinpath(libs, "projects", "hipfft", "fortran", "metadata")) - mkpath(joinpath(sys, "projects", "fortran", "metadata")) - @test lib_metadata(s, "hipfft") == joinpath(libs, "projects", "hipfft", "fortran", "metadata") - @test lib_metadata(s, "hipfftw") == joinpath(libs, "projects", "hipfft", "fortran", "metadata") - @test lib_metadata(s, "roctx") == joinpath(sys, "projects", "fortran", "metadata") - @test lib_metadata(s, "hip") == joinpath(sys, "projects", "fortran", "metadata") + mkpath(joinpath(libs, "bindings", "fortran", "hipfft", "metadata")) + mkpath(joinpath(sys, "bindings", "fortran", "metadata")) + @test lib_metadata(s, "hipfft") == joinpath(libs, "bindings", "fortran", "hipfft", "metadata") + @test lib_metadata(s, "hipfftw") == joinpath(libs, "bindings", "fortran", "hipfft", "metadata") + @test lib_metadata(s, "roctx") == joinpath(sys, "bindings", "fortran", "metadata") + @test lib_metadata(s, "hip") == joinpath(sys, "bindings", "fortran", "metadata") @test lib_metadata(s, "rocblas") == gen_meta("rocblas") # no metadata in the checkout let (si, _) = header_sources(Dict{String,String}(), [inst, out]) @test lib_metadata(si, "hipfft") == gen_meta("hipfft") # installed: never a checkout @@ -1260,12 +1260,12 @@ overlong_fortran_lines(s::AbstractString) = @test_throws ArgumentError run_libs(sl, ["rocblass"]) # not a library @test_throws ArgumentError run_libs(sl, ["hip"]) # rocm-systems is not read @test overwrite_target(sl, "hipfftw") == - joinpath(libs, "projects", "hipfft", "fortran", "hipfftw.F90") - @test_throws ArgumentError check_overwrite(sl, ["rocblas"]) # no rocblas/fortran/ yet - mkpath(joinpath(libs, "projects", "rocblas", "fortran")) + joinpath(libs, "bindings", "fortran", "hipfft", "hipfftw.F90") + @test_throws ArgumentError check_overwrite(sl, ["rocblas"]) # no bindings/fortran/rocblas/ yet + mkpath(joinpath(libs, "bindings", "fortran", "rocblas")) @test check_overwrite(sl, ["rocblas", "hipfftw"]) === nothing end - @test overwrite_target(s, "roctx") == joinpath(sys, "projects", "fortran", "roctx.F90") + @test overwrite_target(s, "roctx") == joinpath(sys, "bindings", "fortran", "roctx.F90") let (si, _) = header_sources(Dict{String,String}(), [inst, out]) @test_throws ArgumentError check_overwrite(si, ["rocblas"]) # installed: no checkout end