{"id":17632774,"url":"https://github.com/rocm/hipfort","last_synced_at":"2025-04-05T04:08:58.397Z","repository":{"id":37316594,"uuid":"263730798","full_name":"ROCm/hipfort","owner":"ROCm","description":"Fortran interfaces for ROCm libraries","archived":false,"fork":false,"pushed_at":"2025-04-03T15:10:51.000Z","size":26736,"stargazers_count":74,"open_issues_count":20,"forks_count":39,"subscribers_count":21,"default_branch":"develop","last_synced_at":"2025-04-05T04:08:22.058Z","etag":null,"topics":["blas","cuda","fft","fortran","gpgpu","gpu","hip","interoperability","random","rocm","solver","sparse"],"latest_commit_sha":null,"homepage":"https://rocm.docs.amd.com/projects/hipfort/en/latest/","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ROCm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-13T20:00:24.000Z","updated_at":"2025-04-03T02:42:41.000Z","dependencies_parsed_at":"2024-01-22T01:09:34.758Z","dependency_job_id":"09ed3880-29b3-4635-9a3f-fb24798dddd1","html_url":"https://github.com/ROCm/hipfort","commit_stats":{"total_commits":264,"total_committers":36,"mean_commits":7.333333333333333,"dds":0.5568181818181819,"last_synced_commit":"007f76cbb71817b7a23fe2c24ddec053a78e4052"},"previous_names":["rocm/hipfort","rocmsoftwareplatform/hipfort"],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROCm%2Fhipfort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROCm%2Fhipfort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROCm%2Fhipfort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROCm%2Fhipfort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ROCm","download_url":"https://codeload.github.com/ROCm/hipfort/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284948,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blas","cuda","fft","fortran","gpgpu","gpu","hip","interoperability","random","rocm","solver","sparse"],"created_at":"2024-10-23T01:45:41.181Z","updated_at":"2025-04-05T04:08:58.372Z","avatar_url":"https://github.com/ROCm.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hipfort: Fortran Interface For GPU Kernel Libraries\n\nThis repository contains the source and testing for hipfort.  \nThis is a FORTRAN interface library for accessing GPU Kernels.\n\n## Documentation\n\n\u003e [!NOTE]\n\u003e The published hipfort documentation is available at [hipfort](https://rocm.docs.amd.com/projects/hipfort/en/latest/index.html) in an organized, easy-to-read format, with search and a table of contents. The documentation source files reside in the hipfort/docs folder of this repository. As with all ROCm projects, the documentation is open source. For more information, see [Contribute to ROCm documentation](https://rocm.docs.amd.com/en/latest/contribute/contributing.html).\n\n## Known issues\n\n* `hipSOLVER` interfaces will only work for AMD GPUs.\n* We recommend `gfortran` version 7.5.0 or newer as we have observed problems with older versions.\n\n## Build and test hipfort from source\n\nInstall `gfortran`, `git`, `cmake`, and HIP, if not yet installed.\nThen build, install, and test hipfort from source with the commands below:\n\n```shell\ngit clone https://github.com/ROCm/hipfort.git\ncd hipfort\ncmake -S. -Bbuild -DHIPFORT_INSTALL_DIR=/tmp/hipfort -DBUILD_TESTING=ON\nmake -C build\nmake -C build check\n```\n\n## Fortran interfaces\n\n`hipfort` provides interfaces to the following HIP and ROCm libraries:\n\n* **HIP:**   HIP runtime, hipBLAS, hipSPARSE, hipFFT, hipRAND, hipSOLVER\n* **ROCm:** rocBLAS, rocSPARSE, rocFFT, rocRAND, rocSOLVER\n\nWhile the HIP interfaces and libraries allow to write portable code for both AMD and CUDA devices, the ROCm ones \ncan only be used with AMD devices.\n\nThe available interfaces depend on the Fortran compiler that is used to compile the `hipfort` modules and libraries.\nAs the interfaces make use of the `iso_c_binding` module, the minimum requirement is a Fortran compiler \nthat supports the Fortran 2003 standard (`f2003`).\nThese interfaces typically require to pass `type(c_ptr)` variables and the number of bytes to memory\nmanagement (e.g. `hipMalloc`) and math library routines (e.g. `hipblasDGEMM`).\n\nIf your compiler understands the Fortran 2008 (`f2008`) code constructs that occur in `hipfort`'s source and test files, \nadditional interfaces are compiled into the `hipfort` modules and libraries. \nThese directly take Fortran (array) variables and the number of\nelements instead of `type(c_ptr)` variables and the number of bytes, respectively. \nTherefore, they reduce the chance to introduce compile-time and runtime errors\ninto your code and makes it easier to read too.\n\n\u003e **NOTE**: If you plan to use the `f2008` interfaces, we recommend `gfortran` version `7.5.0` or newer\nas we have observed problems with older versions.\n\n### Example\n\nWhile you could write the following using the `f2003` interfaces:\n\n```Fortran\nuse iso_c_binding\nuse hipfort\ninteger     :: ierr        ! error code\nreal        :: a_h(5,6)    ! host array\ntype(c_ptr) :: a_d         ! device array pointer\n!\nierr = hipMalloc(a_d,size(a_h)*4_c_size_t) ! real has 4 bytes\n                                           ! append suffix '_c_size_t' to write '4' \n                                           ! as 'integer(c_size_t)'\nierr = hipMemcpy(a_d,c_loc(a_h),size(a_h)*4_c_size_t,hipMemcpyHostToDevice)\n```\n\nyou could express the same with the `f2008` interfaces as follows:\n\n```Fortran\nuse hipfort\ninteger     :: ierr        ! error code\nreal        :: a_h(5,6)    ! host array\nreal,pointer :: a_d(:,:)   ! device array pointer\n!\nierr = hipMalloc(a_d,shape(a_h))      ! or hipMalloc(a_d,[5,6]) or hipMalloc(a_d,5,6) or hipMalloc(a_d,mold=a_h)\nierr = hipMemcpy(a_d,a_h,size(a_h),hipMemcpyHostToDevice)\n```\n\nThe `f2008` interfaces also overload `hipMalloc` similar to the Fortran 2008 `ALLOCATE` intrinsic. \nSo you could write the whole code as shown below:\n\n```Fortran\ninteger     :: ierr        ! error code\nreal        :: a_h(5,6)    ! host array\nreal,pointer :: a_d(:,:)   ! device array pointer\n!\nierr = hipMalloc(a_d,source=a_h)       ! take shape (incl. bounds) of a_h and perform a blocking copy to device\n```\n\nIn addition to `source`, there is also `dsource` in case the source is a device array.\n\n### Supported HIP and ROCm API\n\nThe current batch of HIPFORT interfaces is derived from ROCm 4.5.0.\nThe following tables list the supported API:\n\n* [HIP](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_HIP.md)\n* [hipBLAS](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_HIPBLAS.md)\n* [hipFFT](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_HIPFFT.md)\n* [hipRAND](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_HIPRAND.md)\n* [hipSOLVER](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_HIPSOLVER.md)\n* [hipSPARSE](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_HIPSPARSE.md)\n* [rocBLAS](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_ROCBLAS.md)\n* [rocFFT](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_ROCFFT.md)\n* [rocRAND](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_ROCRAND.md)\n* [rocSOLVER](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_ROCSOLVER.md)\n* [rocSPARSE](https://github.com/ROCmSoftwarePlatform/hipfort/blob/master/lib/hipfort/SUPPORTED_API_ROCSPARSE.md)\n\nYou may further find it convenient to directly use the search function on\n[HIPFORT's documentation page](https://rocm.docs.amd.com/projects/hipfort/en/latest/) to get information on the arguments of an interface\n\n## hipfc wrapper compiler and Makefile.hipfort\n\nThe hipfc wrapper compiler is deprecated and will be removed in a future release. Users are\nencouraged to call their Fortran or HIP compilers directly instead of relying on the hipfc wrapper.\nThe hipfort project provides exported CMake targets that can be used for linking to the appropriate\nROCm libraries.\n\nhipfort currently ships the `hipfc` wrapper compiler and a `Makefile.hipfort` that can be included\nin a project's build system. hipfc is located in the `bin/` subdirectory and Makefile.hipfort in\nshare/hipfort of the repository. While both can be configured via a number of environment variables,\n`hipfc` also understands a greater number of command line options that you can print to the screen via\n`hipfc -h`.\n\nAmong the environment variables, the most important are:\n\n| Variable | Description | Default |\n|---|---|---|\n| `HIP_PLATFORM` | The platform to compile for (either 'amd' or 'nvidia') | `amd` |\n| `ROCM_PATH` | Path to ROCm installation | `/opt/rocm` |\n| `CUDA_PATH` | Path to CUDA installation | `/usr/local/cuda` | \n| `HIPFORT_COMPILER` | Fortran compiler to be used | `gfortran` | \n\n## Examples and tests\n\nThe examples, which simultaneously serve as tests, are located in the \n`f2003` and `f2008` subdirectories of the repo's `test/` folder.\nBoth test collections implement the same tests but require\nthat the used Fortran compiler supports at least the respective Fortran standard.\nThere are further subcategories per `hip*` or `roc*` library that is tested.\n\n### Building a single test\n\n\u003e **NOTE**: Only the `hip*` tests can be compiled for CUDA devices. The `roc*` tests cannot.\n\u003e **NOTE**: The make targets append the linker flags for AMD devices to the `CFLAGS` variable per default.\n\nTo compile for AMD devices you can simply call `make` in the test directories.\n\nIf you want to compile for CUDA devices, you need to build as follows:\n\n```shell\nmake CFLAGS=\"--offload-arch=sm_70 \u003clibs\u003e\"\n```\n\nwhere you must substitute `\u003clibs\u003e` by `-lcublas`, `-lcusparse`, ... as needed.\nCompilation typically boils down to calling `hipfc` as follows:\n\n```shell\nhipfc \u003cCFLAGS\u003e \u003ctest_name\u003e.f03 -o \u003ctest_name\u003e\n```\n\nThe `vecadd` test is the exception as the additional HIP C++ source must be supplied too:\n\n```shell\nhipfc \u003cCFLAGS\u003e hip_implementation.cpp main.f03 -o main\n```\n\n### Building and running all tests\n\nYou can build and run the whole test collection from the `build/` folder (see [Build and test hipfort from source](#build-and-test-hipfort-from-source)) or\nfrom the `test/` folder. The instructions are given below.\n\n#### AMD devices\n\n\u003e **NOTE**: Running all tests as below requires that all ROCm math libraries can be found at `/opt/rocm`.\nSpecify a different ROCm location via the `ROCM_PATH` environment variable.\n\u003e **NOTE**: When using older ROCm versions, you might need to manually set the environment variable `HIP_PLATFORM` to `hcc`\nbefore running the tests.\n\n```shell\ncd build/\nmake all-tests-run\n```\n\nAlternatively:\n\n```shell\ncd test/\nmake run_all\n```\n\n#### CUDA devices\n\n\u003e **NOTE**: Running all tests as below requires that CUDA can be found at `/usr/local/cuda`. Specify a different CUDA location via the `CUDA_PATH` environment variable\n\u003e or supply it to the `CFLAGS` variable by appending `-cuda-path \u003cpath_to_cuda\u003e`.\n\u003e **NOTE**: Choose offload architecture value according to used device.\n\n```shell\ncd build/\nmake all-tests-run CFLAGS=\"--offload-arch=sm_70 -lcublas -lcusolver -lcufft\"\n```\n\nAlternatively:\n\n```shell\ncd test/\nmake run_all CFLAGS=\"--offload-arch=sm_70 -lcublas -lcusolver -lcufft\"\n```\n\n## Copyright, License, and Disclaimer\n\n\u003cA NAME=\"Copyright\"\u003e\n\nCopyright (c) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.\n[MITx11 License]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocm%2Fhipfort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocm%2Fhipfort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocm%2Fhipfort/lists"}