Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building hipfort applications with CMake #133

Open
fluidnumerics-joe opened this issue Dec 18, 2023 · 12 comments
Open

Building hipfort applications with CMake #133

fluidnumerics-joe opened this issue Dec 18, 2023 · 12 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@fluidnumerics-joe
Copy link
Contributor

Hey all,
A google search on this topic turns up this page with a nice outline, but no content : https://rocm.docs.amd.com/projects/hipfort/en/latest/how_to_guides/getting_started.html

Is there any documentation available on building fortran applications that depend on hipfort with CMake ?

@cgmb
Copy link
Collaborator

cgmb commented Jan 9, 2024

Thanks for bringing that to my attention, Joe. Sorry for the slow response, my GitHub notification settings got a bit scrambled in the transition to the ROCm organization.

I think I promised to fill that out and completely forgot about it. That's embarrassing. I'll get that filled in as soon as possible.

@fluidnumerics-joe
Copy link
Contributor Author

Hey @cgmb - any updates here ?
image

Currently guessing-and-checking on using hipfort with a CMake build system. It would be great if

find_package(hipfort REQUIRED)

or something to that effect would be possible..

@cgmb
Copy link
Collaborator

cgmb commented Feb 4, 2024

The short version is that if you've installed ROCm 6.0.2, then you can use a search like find_package(hipfort REQUIRED COMPONENTS hip rocblas rocsparse) and then link with target_link_libraries(yourlib PRIVATE hipfort::rocblas hipfort::rocsparse hipfort::hip).

@fluidnumerics-joe
Copy link
Contributor Author

I can upgrade to ROCm 6.0.2 . However, I use other builds of hipfort from source. Since I don't always just use the system compiler for Fortran and Fortran compilers notoriously don't generate .mod files that are compatible with other compilers, do any of the branches of hipfort on this repo come with/create the hipfort-config.cmake on installation?

@fluidnumerics-joe
Copy link
Contributor Author

The short version is that if you've installed ROCm 6.0.2, then you can use a search like find_package(hipfort REQUIRED COMPONENTS hip rocblas rocsparse) and then link with target_link_libraries(yourlib PRIVATE hipfort::rocblas hipfort::rocsparse hipfort::hip).

This throws errors since we need the correct includes directories for the .mod files when building Fortran code ...

@fluidnumerics-joe
Copy link
Contributor Author

Also, this error is what I was referring to when building with another compiler other than the system compiler

      |       1
Fatal Error: File '/opt/rocm/include/hipfort/amdgcn/hipfort.mod' opened at (1) is not a GNU Fortran module file

@cgmb
Copy link
Collaborator

cgmb commented Feb 5, 2024

do any of the branches of hipfort on this repo come with/create the hipfort-config.cmake on installation?

Anything from ROCm 6.0.0 or later. The CMake files just weren't getting packaged in official releases until 6.0.2. However, hipfort only generates the CMake files if the underlying math libraries are available at build time, so you'll need to have *-dev packages installed for the math libraries (and possibly set -DCMAKE_PREFIX_PATH to find them).

Also, this error is what I was referring to when building with another compiler other than the system compiler

Hmmm... I only was testing with a single compiler. Thanks for reporting this issue.

@fluidnumerics-joe
Copy link
Contributor Author

To summarize, many sites, including ours, want to offer multiple Fortran compilers which would then necessitate multiple installs of hipfort. Right now, this requires installing ROCm from the package manager and manually removing hipfort. From here, hipfort is installed for each compiler and module files are provided to load hipfort.

Unfortunately , the hipconfig.cmake files think that it should be searching in a parent directory for hip, hipBLAS, etc. CMake package config files which fails a CMake build. For now, I'm using find_libraries with a hint to look in HIPFORT_ROOT, an environment variable set by our module files.

Alternatively, we could build HIP from source, and all of the accelerated libraries just to accommodate the way the CMake config is written, but building all of the accelerated libraries from source is not documented.

@fluidnumerics-joe
Copy link
Contributor Author

@cgmb - I'm curious to know how stable it is to build HIP, HIPFort, and the accelerated libraries (ROCblas, etc.) with Spack.

@cgmb
Copy link
Collaborator

cgmb commented Feb 8, 2024

I quite like Spack. They lag a bit behind the official releases, but it's a great package manager and it has official support from AMD. It's particularly good if you want to reduce the size of your binaries by building everything for a single GPU architecture.

With that said, I've never actually used it for hipfort. I was just using it for the math libraries themselves.

@fluidnumerics-joe
Copy link
Contributor Author

Works great for hipfort.
I usually will run a spack checksum [email protected] to add the latest hipfort version to the package in spack. This way we can build multiple instances of hipfort with various compilers. Right now, our CMake solution looks something like

find_package(hip REQUIRED)
find_package(hipblas REQUIRED)
find_library(HIPFORT_LIBRARIES NAMES libhipfort-amdgcn.a HINTS ENV HIPFORT_ROOT REQUIRED)
find_path(HIPFORT_INCLUDE_DIRS hipfort.mod HINTS ENV HIPFORT_ROOT PATH_SUFFIXES include/hipfort/amdgcn/ REQUIRED)

when building for AMD GPUs.
We also have to remove the hipfort provided by the system package manager so that's not accidentally found.

@ppanchad-amd ppanchad-amd added the documentation Improvements or additions to documentation label Jul 30, 2024
@ppanchad-amd
Copy link

@fluidnumerics-joe @cgmb Internal ticket has been created to fix documentation. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants