Giter VIP home page Giter VIP logo

hipfort's Introduction

hipfort: Fortran Interface For GPU Kernel Libraries

This repository contains the source and testing for hipfort.
This is a FORTRAN interface library for accessing GPU Kernels.

Known issues

  • hipSOLVER interfaces will only work for AMD GPUs.
  • We recommend gfortran version 7.5.0 or newer as we have observed problems with older versions.

Build and test hipfort from source

Install gfortran, git, cmake, and HIP, if not yet installed. Then build, install, and test hipfort from source with the commands below:

git clone https://github.com/ROCmSoftwarePlatform/hipfort
mkdir build ; cd build
cmake -DHIPFORT_INSTALL_DIR=/tmp/hipfort ..
make install
export PATH=/tmp/hipfort/bin:$PATH
cd ../test/f2003/vecadd
hipfc -v hip_implementation.cpp main.f03
./a.out

The above steps demonstrate the use of the hipfc utility. hipfc calls hipcc for non-Fortran files and then compiles the Fortran files and links to the object file created by hipcc.

Fortran interfaces

hipfort provides interfaces to the following HIP and ROCm libraries:

  • HIP: HIP runtime, hipBLAS, hipSPARSE, hipFFT, hipRAND, hipSOLVER
  • ROCm: rocBLAS, rocSPARSE, rocFFT, rocRAND, rocSOLVER

While the HIP interfaces and libraries allow to write portable code for both AMD and CUDA devices, the ROCm ones can only be used with AMD devices.

The available interfaces depend on the Fortran compiler that is used to compile the hipfort modules and libraries. As the interfaces make use of the iso_c_binding module, the minimum requirement is a Fortran compiler that supports the Fortran 2003 standard (f2003). These interfaces typically require to pass type(c_ptr) variables and the number of bytes to memory management (e.g. hipMalloc) and math library routines (e.g. hipblasDGEMM).

If your compiler understands the Fortran 2008 (f2008) code constructs that occur in hipfort's source and test files, additional interfaces are compiled into the hipfort modules and libraries. These directly take Fortran (array) variables and the number of elements instead of type(c_ptr) variables and the number of bytes, respectively. Therefore, they reduce the chance to introduce compile-time and runtime errors into your code and makes it easier to read too.

NOTE: If you plan to use the f2008 interfaces, we recommend gfortran version 7.5.0 or newer as we have observed problems with older versions.

Example

While you could write the following using the f2003 interfaces:

use iso_c_binding
use hipfort
integer     :: ierr        ! error code
real        :: a_h(5,6)    ! host array
type(c_ptr) :: a_d         ! device array pointer
!
ierr = hipMalloc(a_d,size(a_h)*4_c_size_t) ! real has 4 bytes
                                           ! append suffix '_c_size_t' to write '4' 
                                           ! as 'integer(c_size_t)'
ierr = hipMemcpy(a_d,c_loc(a_h),size(a_h)*4_c_size_t,hipMemcpyHostToDevice)

you could express the same with the f2008 interfaces as follows:

use hipfort
integer     :: ierr        ! error code
real        :: a_h(5,6)    ! host array
real,pointer :: a_d(:,:)   ! device array pointer
!
ierr = 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)
ierr = hipMemcpy(a_d,a_h,size(a_h),hipMemcpyHostToDevice)

The f2008 interfaces also overload hipMalloc similar to the Fortran 2008 ALLOCATE intrinsic. So you could write the whole code as shown below:

integer     :: ierr        ! error code
real        :: a_h(5,6)    ! host array
real,pointer :: a_d(:,:)   ! device array pointer
!
ierr = hipMalloc(a_d,source=a_h)       ! take shape (incl. bounds) of a_h and perform a blocking copy to device

In addition to source, there is also dsource in case the source is a device array.

Supported HIP and ROCm API

The current batch of HIPFORT interfaces is derived from ROCm 4.5.0. The following tables list the supported API:

You may further find it convenient to directly use the search function on HIPFORT's documentation page to get information on the arguments of an interface

hipfc wrapper compiler and Makefile.hipfort

Aside from Fortran interfaces to the HIP and ROCm libraries, hipfort ships the hipfc wrapper compiler and a Makefile.hipfort that can be included into a project's build system. hipfc located in the bin/ subdirectory and Makefile.hipfort in share/hipfort of the repository. While both can be configured via a number of environment variables, hipfc also understands a greater number of command line options that you can print to screen via hipfc -h.

Among the environment variables, the most important are:

Variable Description Default
HIP_PLATFORM The platform to compile for (either 'amd' or 'nvidia') amd
ROCM_PATH Path to ROCm installation /opt/rocm
CUDA_PATH Path to CUDA installation /usr/local/cuda
HIPFORT_COMPILER Fortran compiler to be used gfortran

Examples and tests

The examples, which simultaneously serve as tests, are located in the f2003 and f2008 subdirectories of the repo's test/ folder. Both test collections implement the same tests but require that the used Fortran compiler supports at least the respective Fortran standard. There are further subcategories per hip* or roc* library that is tested.

Building a single test

NOTE: Only the hip* tests can be compiled for CUDA devices. The roc* tests cannot. NOTE: The make targets append the linker flags for AMD devices to the CFLAGS variable per default.

To compile for AMD devices you can simply call make in the test directories.

If you want to compile for CUDA devices, you need to build as follows:

make CFLAGS="--offload-arch=sm_70 <libs>"

where you must substitute <libs> by -lcublas, -lcusparse, ... as needed. Compilation typically boils down to calling hipfc as follows:

hipfc <CFLAGS> <test_name>.f03 -o <test_name>

The vecadd test is the exception as the additional HIP C++ source must be supplied too:

hipfc <CFLAGS> hip_implementation.cpp main.f03 -o main

Building and running all tests

You can build and run the whole test collection from the build/ folder (see Build and test hipfort from source) or from the test/ folder. The instructions are given below.

AMD devices

NOTE: Running all tests as below requires that all ROCm math libraries can be found at /opt/rocm. Specify a different ROCm location via the ROCM_PATH environment variable. NOTE: When using older ROCm versions, you might need to manually set the environment variable HIP_PLATFORM to hcc before running the tests.

cd build/
make all-tests-run

Alternatively:

cd test/
make run_all

CUDA devices

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 or supply it to the CFLAGS variable by appending -cuda-path <path_to_cuda>. NOTE: Choose offload architecture value according to used device.

cd build/
make all-tests-run CFLAGS="--offload-arch=sm_70 -lcublas -lcusolver -lcufft"

Alternatively:

cd test/
make run_all CFLAGS="--offload-arch=sm_70 -lcublas -lcusolver -lcufft"

Copyright, License, and Disclaimer

Copyright (c) 2020-2022 Advanced Micro Devices, Inc. All rights reserved. [MITx11 License]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

hipfort's People

Contributors

amd-jmacaran avatar arvindcheru avatar cgmb avatar daineamd avatar dependabot[bot] avatar doctorcolinsmith avatar domcharrier avatar fluidnumerics-joe avatar gowthamcr-amd avatar gregrodgers avatar lawruble13 avatar lmoriche avatar maetveis avatar malcolmroberts avatar ntrost57 avatar peterjunpark avatar pourroyjean avatar pramenku avatar randyh62 avatar raramakr avatar rkothako avatar rmalavally avatar saldivarcher avatar samjwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hipfort's Issues

CMake configuration error

Hi,

I'm trying to install hipfort on an AMD platform.

I get following error during CMake configuration step :

-- HIPFORT -------------  cmake START -------------------
-- HIPFORT_COMPILER:       /usr/bin/gfortran
-- HIPFORT_AR:             /usr/bin/gcc-ar
-- HIPFORT_RANLIB:         /usr/bin/gcc-ranlib
-- HIPFORT_COMPILER_FLAGS: -ffree-form -cpp -ffree-line-length-none -fmax-errors=5
-- HIPFORT_BUILD_TYPE:     RELEASE
-- HIPFORT_INSTALL_DIR:    /home/rdiarra/hipfft_sample/hipfort/install
-- HIPFORT_VERSION:        0.4-0
-- HIPFORT ----------------------------------------------
-- The Fortran compiler identification is Cray 13.0
-- The C compiler identification is Clang 13.0.1
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /opt/cray/pe/craype/2.7.13/bin/ftn - skipped
-- Checking whether /opt/cray/pe/craype/2.7.13/bin/ftn supports Fortran 90
-- Checking whether /opt/cray/pe/craype/2.7.13/bin/ftn supports Fortran 90 - yes
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/cray/pe/craype/2.7.13/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_INSTALL_PREFIX:/home/rdiarra/hipfft_sample/hipfort/install
-- Detecting Fortran/C Interface
-- Detecting Fortran/C Interface - Found GLOBAL but not MODULE mangling
-- Verifying Fortran/C Compiler Compatibility
-- Verifying Fortran/C Compiler Compatibility - Success
-- Checking whether /opt/cray/pe/craype/2.7.13/bin/ftn supports Fortran 08
-- Checking whether /opt/cray/pe/craype/2.7.13/bin/ftn supports Fortran 08 - yes
CMake Error at cmake/Modules/SetCompileFlag.cmake:109 (MESSAGE):
  No compile flags were found
Call Stack (most recent call first):
  cmake/Modules/SetFortranFlags.cmake:83 (SET_COMPILE_FLAG)
  CMakeLists.txt:114 (INCLUDE)


-- Configuring incomplete, errors occurred!

Loaded modules in my environment are :

Currently Loaded Modules:
  1) perftools-base/21.12.0   3) craype/2.7.13       5) craype-network-ofi   7) craype-x86-rome      9) cray-libsci/21.08.1.2  11) craype-accel-amd-gfx908
  2) cce/13.0.1               4) PrgEnv-cray/8.1.0   6) cray-mpich/8.1.13    8) cray-fftw/3.3.8.12  10) libfabric/1.13.1       12) rocm/4.5.0

How can I resolve this problem ? Thank

Monthly HUG meeting proposal, 3rd Tuesday at 2PM EST.

I would like to start a hipfort user group to manage the use, development, and release processes of hipfort. How does the third Tuesday of the month at 2PM EST / 1PM CST / 11AM Pacific sound? I would serve as chairman for the first call. However, I am looking for another leader to chair this group so that I can participate in other ways.

I will hold an organizational meeting Tuesday August 18 2PM-3PM EST to discuss. The meeting will be on Microsoft Teams. Send me email if you want an invitation. Include any suggestions for HUG or hipfort.

Greg Rodgers

vecadd does not compile on Nvidia hardware

System Info
Operating System : Ubuntu 20.04
GPU : Nvidia GTX 1070
CUDA Toolkit 11.0 installed
HIP Installed from ROCm 3.7.0

Error message
To recreate the error, update test/vecadd/Makefile so that HIPFORT_HOME points to hipfort installation path. Error only occurs on Nvidia hardware. After running make, the following output ensues :

/usr/bin/gfortran -cpp -I/opt/hipfort/include/nvptx "-DHIPFORT_ARCH=\"nvptx\""  -c main.f03 -o /home/joe/apps/hipfort/test/vecadd/main.o
HIP_PLATFORM=nvcc /opt/rocm/bin/hipcc "--gpu-architecture=sm_61" -c hip_implementation.cpp -o /home/joe/apps/hipfort/test/vecadd/hip_implementation.o
hip_implementation.cpp: In function ‘void vector_add(double*, double*, double*, int)’:
hip_implementation.cpp:6:18: error: ‘blockIdx’ was not declared in this scope
    6 |   size_t index = blockIdx.x * blockDim.x + threadIdx.x;
      |                  ^~~~~~~~
hip_implementation.cpp:6:31: error: ‘blockDim’ was not declared in this scope
    6 |   size_t index = blockIdx.x * blockDim.x + threadIdx.x;
      |                               ^~~~~~~~
hip_implementation.cpp:6:44: error: ‘threadIdx’ was not declared in this scope
    6 |   size_t index = blockIdx.x * blockDim.x + threadIdx.x;
      |                                            ^~~~~~~~~
hip_implementation.cpp:7:32: error: ‘gridDim’ was not declared in this scope
    7 |   size_t stride = blockDim.x * gridDim.x;
      |                                ^~~~~~~
In file included from /opt/rocm-3.7.0/hip/include/hip/hip_runtime.h:58,
                 from hip_implementation.cpp:1:
hip_implementation.cpp: In function ‘void launch(double**, double**, double**, int)’:
hip_implementation.cpp:19:5: error: expected primary-expression before ‘<’ token
   19 |     hipLaunchKernelGGL((vector_add), dim3(320), dim3(256), 0, 0, *dout, *da, *db, N);
      |     ^~~~~~~~~~~~~~~~~~
hip_implementation.cpp:19:5: error: expected primary-expression before ‘>’ token
   19 |     hipLaunchKernelGGL((vector_add), dim3(320), dim3(256), 0, 0, *dout, *da, *db, N);
      |     ^~~~~~~~~~~~~~~~~~
make: *** [Makefile:19: /home/joe/apps/hipfort/test/vecadd/hip_implementation.o] Error 1

Outside of the undefined grid/thread/block errors, hipcc seems to now have compilation issues

hip_implementation.cpp:19:5: error: expected primary-expression before ‘<’ token

CI Testing Infrastructure

To help us handle PR review, I'd like to start a discussion on CI infrastructure and testing requirements to help us merge in contributions. To kick this off, here's a few suggestions on what we need to be checking for and how we might do it.

Code Formatting
To maintain consistent formatting, tools like fprettify can help. From the developers side, we can provide specific flags to use that will apply the formatting standards we choose to enforce. From the testing side, such a tool can be used to help verify whether or not format standards are met.

Functionality & Portability
Generally, we need to be able to demonstrate positive answers to the following questions

  • Does it build ?
  • Does it run ?
  • Does it get the right result ?
    on a range of hardware. Following the ROCm and HIP motifs of portability, we likely want to be running these tests on AMD and Nvidia GPUs. This being said, whatever CI platform we use needs to be able to accommodate both AMD and Nvidia GPUs to make sure that hipfort is portable.

It looks like the hipfort repository is set up with tests handled under Cmake and it seems that running tests is straightforward.

CI Infrastructure Strategy
Ultimately, CI infrastructure needs to be heterogeneous. One strategy is to leverage Google Cloud Build with additional steps to perform tests on GCE instances. This could provide access to Nvidia hardware. To expose AMD hardware we could federate a Slurm cluster on GCP to another cloud provider or on-premise system.

I'm interested to know what other maintainers on this repository have thought about with regards to CI for hipfort and if we can come to a consensus on how to do this.

@gregrodgers @pbauman @txomin13

Source of github pages documentation

Hi,

I'm working on #99 as part of the ROCm documentation team / effort.

I have stumbled upon the github pages based documentation for hipfort at https://rocmsoftwareplatform.github.io/hipfort/ . As far as I can see the source of this build (i.e. the Doxyfile) is not published.

Is this available somewhere or would you be able to share it? I would like to consult it as I'm missing the documentation of some of the modules compared to it in #99 (e.g. compare https://rocmsoftwareplatform.github.io/hipfort/namespaces.html with https://advanced-micro-devices-demo--99.com.readthedocs.build/projects/hipfort/en/99/doxygen/html/namespaces.html e.g. hipfort is missing).

Please create rocm-4.3.1 tag

Please create rocm-4.3.1 tag for ROCm-4.3.1 releasing.

Now there is a repo sync error.

work@00923371e74e:~/ROCm$ ./repo sync
Fetching: 40% (20/49) rocprofiler
fatal: couldn't find remote ref refs/tags/rocm-4.3.1

hipfort:
fatal: couldn't find remote ref refs/tags/rocm-4.3.1
hipfort: sleeping 4.0 seconds before retrying
fatal: couldn't find remote ref refs/tags/rocm-4.3.1

hipfort:
fatal: couldn't find remote ref refs/tags/rocm-4.3.1
error: Cannot fetch hipfort from https://hub.fastgit.org/ROCmSoftwarePlatform/hipfort
Fetching: 100% (49/49), done in 14.636s
Garbage collecting: 100% (49/49), done in 0.141s

fatal: couldn't find remote ref refs/tags/rocm-4.3.1

hipfort:
fatal: couldn't find remote ref refs/tags/rocm-4.3.1
hipfort: sleeping 4.0 seconds before retrying
fatal: couldn't find remote ref refs/tags/rocm-4.3.1

hipfort:
fatal: couldn't find remote ref refs/tags/rocm-4.3.1
error: Cannot fetch hipfort from https://hub.fastgit.org/ROCmSoftwarePlatform/hipfort
Fetching: 100% (1/1), done in 5.739s
Garbage collecting: 100% (1/1), done in 0.006s
Updating files: 100% (1522/1522), done.
Updating files: 100% (1716/1716), done.ting files:  27% (480/1716)
Updating files: 100% (2581/2581), done.
Updating files: 100% (1875/1875), done.
Updating files: 100% (71791/71791), done.
Updating files: 100% (35649/35649), done.
error: Cannot checkout hipfort: ManifestInvalidRevisionError: revision refs/tags/rocm-4.3.1 in hipfort not found
Checking out:  34% (17/49), done in 49.009s
error: in `sync`: revision refs/tags/rocm-4.3.1 in hipfort not found

[Feature]: Accept standard CMake input conventions

Suggestion Description

The current use of HIPFORT_ prefixed setting variables is a very non-standard way to effect a number of build options. Overwriting various CMAKE_ prefixed settings prevents users from using the commonly accepted ways of specifying, compiler, flags, and install directory. This will be confusing for users that are well versed in CMake. The hard-coded default compiler path is also problematic as this does not respect environment variables like FC, which is a commonly accepted way to specify a Fortran compiler for most build systems.

Suggested changes:

  • Drop all HIPFORT_ prefixed variables as inputs and use them as internal variables only or
    • HIPFORT_COMPILER should default to being initialized from CMAKE_Fortran_COMPILER_INIT
    • HIPFORT_COMPILER_FLAGS should default to being initialized from CMAKE_Fortran_FLAGS_INIT
    • HIPFORT_BUILD_TYPE should default to being initialized from CMAKE_BUILD_TYPE (it could be made to pick release if empty)
  • Use set(CMAKE_Fortran_FORMAT FREE) to set source to freeform without relying on users to provide a correct compiler flag
  • Use CMAKE_Fortran_PREPROCESS to turn on preprocessing in all source files (available in CMake 3.18)
  • Use VERSION in the project function to specify version (note that having HIPFORT_VERSION as input does not make much sense as the user does not name the versions of the libray, the version should be built into the project by developers)
  • Please use check_fortran_compiler_flag (since CMake 3.3) for any flags you intend to hardcode. I don't know how ubiquitous the -std flag is, but the current build system only works with compilers that support specifically -std=f2008 or Cray (which means no LLVMFlang)

I am willing to provide patches for some of these changes.

Operating System

No response

GPU

No response

ROCm Component

No response

Rank-specialized interfaces for batched HIP/ROCm functions likely won't work

  • Rank-specialized interfaces for batched HIP/ROCm functions are not usable in the current state as
    the backend expects a pointer to pointer as argument, which cannot be mapped to a multidimensional Fortran array.

  • However, the direct bindings might work by passing the first element of a contiguous array of type(c_ptr) type to the backend, i.e. something like this:

type(c_ptr),dimension(5) :: mybatch

! allocate the batch items
...
!
! Call the HIP/ROCm binding or interface and pass the first element:
ierr = myhipfunction_batched(... mybatch(1))

Further testing is necessary to confirm that this works.

HIPRAND routines with Fortran OpenACC Cray compiler on LUMI

Hi all,

I am trying to compile an MPI+OpenACC Fortran90 code using the Cray compiler in LUMI.
I wrote a simple fortran program (main.txt) that mimics the issue that we are experiencing in our code when we try to generate random numbers using HIPRAND interface.
I compiled using the following modules (load_modules.txt) with:

ftn -g -O3 -hfp3 -hacc -h acc_model=auto_async_kernel:fast_addr:deep_copy -eZ -m1 -L/users/$USER/EasyBuild/SW/LUMI-23.09/G/hipfort/0.4-0-cpeCray-23.09-rocm5.2/lib -lhipfort-amdgcn main.f90 -J /users/$USER/EasyBuild/SW/LUMI-23.09/G/hipfort/0.4-0-cpeCray-23.09-rocm5.2/include/hipfort/amdgcn -o main.exe

the error I get is:

/opt/cray/pe/cce/16.0.1/binutils/x86_64/x86_64-pc-linux-gnu/bin/ld: /tmp/pe_104960/main_1.o: in function `main': The Cpu Module:(.text+0x1b): undefined reference to `hiprandCreateGenerator'

ROCm releases vs hipfort interfaces

ROCm 3.7 was just released.
We should generate a new batch of interface modules.

Any suggestions how we contribute them to the repository?

  • Do we just overwrite the existing ones (and tag a commit
    that we regard as stable)?

  • Do we keep subfolders per ROCm release?

  • ...

Cuda Fortran kernels support

Will this tool only support hipify of host fortran calls or it will be able to compile Cuda Fortran kernels?
For example:

  attributes(global) subroutine saxpy(x, y, a)
    implicit none
    real :: x(:), y(:)
    real, value :: a
    integer :: i, n
    n = size(x)
    i = blockDim%x * (blockIdx%x - 1) + threadIdx%x
    if (i <= n) y(i) = y(i) + a*x(i)
  end subroutine saxpy

[discussion] Backend-specific interfaces

Background

HIP and CUDA Fortran interfaces need to be bound to different symbols (cuda/cu... for CUDA
and roc/hip... for HIP) (see hipMalloc example in 1.1).

Some datatypes differ for the backends, e.g. CUDA has integer-type stream handles
while a stream is a datastructure in HIP, which we model as type(c_ptr) in the Fortran interface.

Discussion

We can tackle this with two different approaches; see below.
The hip.f module in the repository currently follows approach 1.
I would prefer approach 2 because it directly
mirrors the structure of the header files in the /opt/rocm/include/hip folder,
where we have hcc_detail and nvcc_detail headers.
Moreover, it is easier to account for differences in the function argument
types.

(As we will automatically generate all interfaces, we do not expect that
one approach requires more time to realize than the other.)

1. Single module with ifdefs per function signature:

module hip

#ifdef USE_CUDA_NAMES
     function hipMalloc(ptr,sizeBytes) bind(c, name="cudaMalloc")
#else
     function hipMalloc(ptr,sizeBytes) bind(c, name="hipMalloc")
#endif
       use iso_c_binding
       use hip_enums
       implicit none
       integer(kind(hipSuccess)) :: hipMalloc
       type(c_ptr) :: ptr
       integer(c_size_t), value :: sizeBytes
     end function hipMalloc

     ! ...
     ! ...
     ! ...
end module hip

2. Backend-specific modules (hcc_detail vs nvcc_detail) as in the HIP headers:

module hip
#ifdef USE_CUDA_NAMES
     use hip_nvcc
#else
     use hip_hcc
#endif
end module hip
module hip_nvcc
     function hipMalloc(ptr,sizeBytes) bind(c, name="cudaMalloc")
     ! ...
     ! ...
     ! ... 
end module hip_nvcc

Please vote for one approach in the comment section.

MPI+ with HIPFort

Hey all, I wanted to reach out to discuss ideas on how to handle MPI+HIPFort .
Ideally, I'd like to be able to pass GPU data (c_ptr) over MPI so that GPU direct communications can be used.

However, it's looking like I'd have to duplicate the MPI code I have written in Fortran in C++ and provide another ISO_C_BINDING wrapper to call it from Fortran. While I've gotten to be ok with mixed language programming for writing GPU kernels, I'd prefer not to have to duplicate code to be able to use GPU direct communications.

Alternatively, I can go for a method of copying device pointers back to the host, handle MPI exchanges on the host, and copy back to GPU; for performance/scalability, this is less than ideal.

I'm interested in discussing with you all any alternative options, or if this kind of wrapper for MPI would be a good candidate for HIPFort.

vecadd example does not compile : Ubuntu 18.04, GCC 7.4.0

I've installed rocm-dev and hipfort on an Ubuntu 18.04 system with gcc (and gfortran) 7.4.0. After a successful install, I navigate to the test/vecadd demo and run

hipfc -v hip_implementation.cpp main.f03

and the following error message is thrown

export HIP_PLATFORM=hcc DEVICE_LIB_PATH=/opt/rocm/lib HIP_CLANG_PATH=/opt/rocm/llvm/bin

/opt/rocm/bin/hipcc -fno-gpu-rdc -fPIC --offload-arch=gfx900 -c  hip_implementation.cpp  -o /tmp/hipfc-tmp-20135/hipcc.o
clang-10: error: unsupported option '--offload-arch=gfx900'
ERROR:  The following command failed with return code 1.
        /opt/rocm/bin/hipcc -fno-gpu-rdc -fPIC --offload-arch=gfx900 -c  hip_implementation.cpp  -o /tmp/hipfc-tmp-20135/hipcc.o

hipfc does override HIP_CLANG_PATH and DEVICE_LIB_PATH if they are already set in the environment

Hi all,
I am using a spack ROCm / hipfort installation with customized installation paths.
hipcc is working fine but when using hipfc I found that the HIP_CLANG_PATH and DEVICE_LIB_PATH set in my environment are overwritten.
I fixed that by modifying the hipfc script as follows:

294,296c294
<     if [ -z ${DEVICE_LIB_PATH+x} ]; then
<        DEVICE_LIB_PATH=$ROCM_PATH/lib
<     fi
---
>     DEVICE_LIB_PATH=$ROCM_PATH/lib
324,330c322
< 
<    if [ -z ${HIP_CLANG_PATH+x} ]; then
<      HIP_CLANG_PATH=$ROCM_PATH/llvm/bin
<    fi
<    
<    HIPCC_ENV="HIP_PLATFORM=$HIP_PLATFORM DEVICE_LIB_PATH=$DEVICE_LIB_PATH HIP_CLANG_PATH=$HIP_CLANG_PATH"
<        
---
>    HIPCC_ENV="HIP_PLATFORM=$HIP_PLATFORM DEVICE_LIB_PATH=$DEVICE_LIB_PATH HIP_CLANG_PATH=$ROCM_PATH/llvm/bin"

Is that really necessary or have I overlooked some option by which I can pass in the two environment variables?

thanks & best Ralf

Configuration fails when trying to compile HIPFORT with a CUDA backend

Problem Description

I need to ensure that Hipfort works with an nvidia backend. However when I try to install hipfort-6.0.2 the CMAKE configuration fails when I set HIP_PLATFORM="nvidia".

I have an RTX 3060 and CUDA 12.4 installed via package manager and everything seems ok with the NVIDIA software stack.

Operating System

Ubuntu 22.04.4 LTS (Jammy Jellyfish)

CPU

AMD Ryzen 7 6800H

GPU

RTX 3060

ROCm Version

ROCm 6.0.2

ROCm Component

hipfort

Steps to Reproduce

  1. Install NVIDIA driver (Driver 550 installed)
  2. Install rocm 6.0.2 using amdgpu-install
  3. Install the hip-runtime-nvidia package (CUDA 12.4 installed, and I have an RTX 3060 with working drivers)
  4. Uninstall hipfort-dev using the package manager
  5. Download and unpack hipfort-rocm-6.0.2
  6. Change directory to unpacked sources
  7. Make a build directory

Run the following script from the build directory

FLAGS="-O2 -g -free -cpp -fPIC -fmax-errors=5 -fno-underscoring"

export HIP_PLATFORM="nvidia"

CFLAGS="--offload-arch=sm_86 -lcublas -lcusolver -lcufft"

cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DHIPFORT_COMPILER=$(which gfortran) -DCMAKE_Fortran_FLAGS="${FLAGS}" -DCMAKE_C_COMPILER=$(which gcc) -DCMAKE_CXX_COMPILER=$(which g++) -DCMAKE_Fortran_COMPILER=$(which gfortran)  .. 

I then get numerous configuration errors to say that another target already exists.

CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:126 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:126 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:126 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipblas/hipblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:133 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipblas/hipblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:133 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipblas/hipblas-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:133 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocfft/rocfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:140 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocfft/rocfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:140 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocfft/rocfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:140 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:147 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:147 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:147 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocrand/rocrand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:154 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocrand/rocrand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:154 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocrand/rocrand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:154 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hiprand/hiprand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:161 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hiprand/hiprand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:161 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hiprand/hiprand-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:161 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:92 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:92 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocblas/rocblas-config.cmake:90 (find_dependency)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsolver/rocsolver-config.cmake:92 (find_dependency)
  lib/CMakeLists.txt:168 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsolver/hipsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:175 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsolver/hipsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:175 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsolver/hipsolver-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:175 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsparse/rocsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:182 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsparse/rocsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:182 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/rocsparse/rocsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:182 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:21 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsparse/hipsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:189 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:22 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsparse/hipsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:189 (find_package)


CMake Error at /opt/rocm-6.0.2/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/rocm-6.0.2/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/rocm-6.0.2/lib/cmake/hipsparse/hipsparse-config.cmake:90 (find_dependency)
  lib/CMakeLists.txt:189 (find_package)

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

Environment variables

HIP_PLATFORM="nvidia"

Extending hipHostMalloc Interface

This is attempting to think ahead a bit and solicit thoughts on what the right thing to do will be. I anticipate this will be one of the first questions from customers. Capturing the thought for now.

If was a Fortran user, and I needed to hipHostMalloc my array, I would like the interface to look Fortran-esque. Something akin to

integer, pointer, dimension(:,:,:)  :: foo
hipCheck(hipHostMalloc3d(foo, [nx,ny,nz]))

Since the memory is being malloc'ed on the C-side, the usual thing to do is something like

double precision, pointer, dimension(:,:,:) :: x
type(c_ptr) :: buffer = c_null_ptr
...
call hipCheck(hipHostMalloc(buffer,n_bytes,0))
call c_f_pointer(buffer,x,[N,N,N])
...
call hipCheck(hipHostFree(buffer))

So what's the right way to handle the buffer? It would be nice if we could make that invisible to the Fortran users and provide them a clean interface for hipHostMalloc.

Or maybe there is better ideas for the interface than I have.

should we add -fopenmp to default behavior for hipfc ?

I expect that OpenMP will be used on the CPU to manage multiple tasks to coordinate asynchronous HIP data transfers and kernel launching, especially for multiple devices. Should we default hipfc behavior with -fopenmp?

[Feature]: inputs to hipMemcyp2D with rank greater than two

Suggestion Description

cudaMemcpy2D accepts fortran pointers to arrays with ranks greater than 2., while hip equivalent does not.
Is this a conscious choice? I have code which uses memcpy2d on 3- and 4-d arrays. I can obviously rewrite, but was hoping to keep changes with respect to cuda version minimal.

Operating System

No response

GPU

No response

ROCm Component

No response

libamdhip64 not found

Operating system : Ubuntu 18.04
Compiler : GCC, GFortran (7.4.0)
GPU : MI25 Radeon

I've created a simple Fortran application to reproduce an issue with compiling Fortran files with hipfc. The program is shown below

PROGRAM Test
USE hip
USE iso_c_binding

IMPLICIT NONE
  INTEGER(c_size_t), PARAMETER :: N=100
  TYPE(c_ptr) :: a_dev
      CALL hipCheck(hipMalloc(a_dev, 4*N))
      CALL hipCheck(hipFree(a_dev))
END PROGRAM Test

I compile with hipfc, which shows the following error

hipfc -v test.f90 

/usr/bin/gfortran -cpp -I/opt/rocm/hipfort/include/amdgcn   test.f90 -L/opt/rocm/lib -lamdhip64 -Wl,-rpath=/opt/rocm/lib  -lstdc++ -L/opt/rocm/hipfort/lib -lhipfort-amdgcn -o /home/joe/self-fluids/src/self/minimal/a.out
/usr/bin/ld: cannot find -lamdhip64
collect2: error: ld returned 1 exit status
ERROR:  The following command failed with return code 1.
        /usr/bin/gfortran -cpp -I/opt/rocm/hipfort/include/amdgcn   test.f90 -L/opt/rocm/lib -lamdhip64 -Wl,-rpath=/opt/rocm/lib  -lstdc++ -L/opt/rocm/hipfort/lib -lhipfort-amdgcn -o /home/joe/self-fluids/src/self/minimal/a.out

I've confirmed that there are no libraries installed that correspond to libamdhip64.so under /opt/rocm/lib.
If this library is a dependency, we need to build out documentation that lists this as a dependency. Removing this flag in hipfc directly resolves the issue.

Please enable two factor authentication in your github account

@fluidnumerics-joe

We are going to enforce two factor authentication in (https://github.com/ROCmSoftwarePlatform/) organization on 29th April, 2022 .
Since we identified you as outside collaborator for ROCmSoftwarePlatform organization, you need to enable two factor authentication in your github account else you shall be removed from the organization after the enforcement.
Please skip if already done.

To set up two factor authentication, please go through the steps in below link:

https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/configuring-two-factor-authentication

Please email "[email protected]" for queries

Compilation errors with Intel compiler

Hi there,

I'm trying to compile hipfort using the Intel compiler on the hipfort develop branch and getting a few issues. One of them I cannot get around.

These lines, starting at CMakeLists.txt:113, breaks the cmake configuration because the added flags -std=f2003 and -std=f2008 are not valid arguments on the Intel Fortran compiler. Therefore testing of command line arguments in a later step fails and cmake configuration halts with an error.

IF(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${HIPFORT_COMPILER_FLAGS} -std=f2008")
ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${HIPFORT_COMPILER_FLAGS} -std=f2003")

If I delete the -std flags in CMakeLists.txt and use the following cmake compile options, then I can get past the cmake configuration step.

# Intel compilation flags
FLAGS="-O2 -g -free -cpp -fPIC -fmax-errors=5 -assume nounderscore"
cmake -DCMAKE_INSTALL_PREFIX=/opt/hipfort_intel/5.7.1 -DHIPFORT_COMPILER=ifort -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER="icx" -DCMAKE_C_FLAGS="-O2 -g" -DCMAKE_CXX_COMPILER="icpx" -DCMAKE_CXX_FLAGS="-O2 -g" -DCMAKE_Fortran_COMPILER="ifort" -DCMAKE_Fortran_FLAGS="${FLAGS}" -DHIPFORT_COMPILER_FLAGS="${FLAGS}" -DCMAKE_BUILD_TYPE=RELEASE ..

running make then fails at this point.

[  6%] Building Fortran object lib/CMakeFiles/hipfort-amdgcn.dir/hipfort/hipfort_hipmalloc.f.o
ifort: command line warning #10006: ignoring unknown option '-fno-underscoring'
ifort: command line remark #10148: option '-vec-report0' not supported
/netsoft/src/hipfort/lib/hipfort/hipfort_hipmalloc.f(1007): error #6911: The syntax of this substring is invalid.   [PTR]
        ptr(LBOUND(dsource,1):,LBOUND(dsource,2):) => tmp
--------^
compilation aborted for /netsoft/src/hipfort/lib/hipfort/hipfort_hipmalloc.f (code 1)
make[2]: *** [lib/CMakeFiles/hipfort-amdgcn.dir/build.make:231: lib/CMakeFiles/hipfort-amdgcn.dir/hipfort/hipfort_hipmalloc.f.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:144: lib/CMakeFiles/hipfort-amdgcn.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Create interoperable derived types for hipDeviceProp_t and hipDeviceArch_t

Predefine the interoperable derived types for the following structs to make it easier
for Fortran users to query device properties.

https://rocm-developer-tools.github.io/HIP/structhipDeviceProp__t.html
https://rocm-developer-tools.github.io/HIP/structhipDeviceArch__t.html

NOTE: Character arrays require special attention as Fortran and C handle
strings differently. While a C string is finalised with a string termination character,
Fortran does not use such a character but stores the length, i.e. the number of characters, at the begin of the string.

https://gcc.gnu.org/onlinedocs/gfortran/Interoperable-Subroutines-and-Functions.html

Preserve ordering of arguments to hipfc

When porting an application over to hipfort (from hip-fortran), I noticed that hipfc will switch the order of the arguments internally by the time the calls are made to $HIPFORT_COMPILER.

This has caused problems for an application build that depends on additional 3rd party libraries. For example, during a linking stage of a program, I call

FFLAGS=-O0 -g -DGPU -ffree-line-length-none -I/usr/local/jsonfortran-gnu-7.1.0/lib
FLIBS=-L/usr/local/jsonfortran-gnu-7.1.0/lib -ljsonfortran
hipfc ${FFLAGS} *.o  ${FLIBS} -o $@

This stage of my builds fail with "undefined reference errors" related to json-fortran (3rd party library). The command issued within hipfc that causes the failure is

ERROR:  The following command failed with return code 1.
        /usr/bin/gfortran  -g -cpp -I/opt/rocm/hipfort/include/nvptx  -L/usr/local/jsonfortran-gnu-7.1.0/lib -ljsonfortran -DGPU -ffree-line-length-none -I/usr/local/jsonfortran-gnu-7.1.0/lib  CommonRoutines.o ConstantsDictionary.o EquationParser_Class.o Lagrange_Class.o Lagrange_Class_Tests.o Lagrange_HIP.o Lagrange_Test.o ModelPrecision.o Quadrature.o -L/usr/local/cuda/targets/x86_64-linux/lib -lcudart -lstdc++ -L/opt/rocm/hipfort/lib -lhipfort-nvptx -o /home/joeschoonover/apps/fluids/self-fluids/src/self/test

Notice that -L/usr/local/jsonfortran-gnu-7.1.0/lib -ljsonfortran is currently placed before the .o files - this causes the undefined reference error (order matters here). Manually copying this command and placing the linker flags for json fortran after the .o results in a successful build.

add test/rocsolver/potrf.f03

use both hipfort_rocblas and hipfort_rocsolver causes
call rocsolverCheck(rocsolver_dpotrf(rocsolver_handle,rocblas_fill_upper, N, B, ldb, c_loc(devInfo_d)))
Error: Name ‘rocblas_fill_upper’ at (1) is an ambiguous reference to ‘rocblas_fill_upper’ from module ‘hipfort_rocblas_enums’

Documentation

Hey all, I've started a branch (https://github.com/ROCmSoftwarePlatform/hipfort/tree/repo-docs) where we can start working together on building this repository's documentation.

It'd be great if we can be transparent in the specifications about the assumptions and expectations we have for end-users of hipfort and provide clear guidelines for revising hipfort specifications with the community.

To lower the barrier for community engagement for contributing to the hipfort repository, we should spend some time thinking about our branching model, versioning model, and process for moving branches from features and bug fixes and into develop and main branches. Documenting this and publishing to this repository will help users and potential contributors more easily see how we get work done on hipfort.

To start, here are some questions to spur discussion around contributing

  • What are our acceptance criteria for getting branches into develop, main, or even into tagged releases ?
  • How can we enable others to test their contributions before opening pull requests ?
  • Do we want to automate testing ?
  • What information is necessary when opening feature requests or bug reports ? Do we want to leverage issue templates ?

Should we start all module names with hipfort?

Currently the hip module requires "use hip" . The other modules have names such as rocfft etc. I propose that we establish a convention where all hipfort modules begin with hipfort for three reasons. 1. The current names may conflict with existing user module names. 2. It will be clear in the source code when an application is using hipfort modules. 3. Builds some brand recognition around hipfort.

use hip --> use hipfort
use rocfft --> use hipfort_rocfft
use hipblas -> use hipfort_hipblas or use hipfort_blas if we can get a single blas interface for nvptx and amdgcn

This is the time to do this before hipfort gets too popular and changing this would be impossible with existing applications.

Recommendations for building applications with CMake and hipfort

I’m looking to understand how we want to support the use of hipfort in the CMake build system. Currently, I’m finding that I have to set FC, CC, and CXX all equal to hipfc in order to build an application that depends on hipfort.

Further, when building distributions for multiple hardware vendors, it’s not clear how to specify the target hardware (—offload-arch does not work to build for nvidia hardware when nvidia hardware is not present).

I’m looking for some guidance on how we should be incorporating hipfc into CMake build systems and how to specify target architectures, even when the target architecture is not present on the build platform.

Test targets are broken

The test cmake target build-test, run-test, run-vecadd, are all broken because of a change we made to bin/CMakeLists.txt.
I will fix this soon.

Move architecture depending CMake variables into toolchain file

The variable 'CMAKE_Fortran_FLAGS' should only be set by the cmake toolchain,

  • either by calling cmake -DCMAKE_Fortran_FLAGS=" -ffree-form -cpp -ffree-line-length-none -fmax-errors=5 -std=f2008 -fno-underscoring or
  • set in a toolchain file and added with 'cmake -DCMAKE_TOOLCHAIN_FILE='.

Should hipfort have versioning independent of ROCm versioning?

The HIPFORT_VERSION cmake option is used to create packages. It currently has a default of 3.8-0 which is the first version of ROCm to include packages (deb and rpm) for hipfort. However, I expect other integrators to use hipfort, especially since the design allows different compilers than gfortran. Also, ROCm allows packages to have a different version number than the ROCm release number. So it is possible

My proposal would be to start with 0.1-0. That is VERSION.RELEASE-MODIFICATION. We could iterate the MODIFICATION with minor updates. While we are on version 0, we can indicate incompatible updates by incrementing the release number. For example, when we change the module names to hipfort* as discussed in another issue, we would call that 0.2-0.

I don't want to get too fancy with github automation features. So as a manual method, we could create a text version file in the root directory. That file would contain the value of the current development version in the first line. All subsequent lines would be ignored. When a new release is desired, the repository is first tagged with the release number from the version file. Then the first line of the version file is updated to the next release number. By just using the first line, the version file could contain release notes of the current and past releases. I would change the main CMakeLists.txt to set HIPFORT_VERSION from the version file if it was not set by the cmake command line.

After we establish an open source governance model for hipfort, we can establish the criteria to make hipfort version 1.0-0.

Error in bin/CMakeLists.txt : String command

I've tried building a fresh install of hipfort with

The first step in the build (running cmake) throws an error in bin/CMakeLists.txt, line 17

$ cmake ../
-- HIPFORT -------------  cmake START -------------------
-- HIPFORT_COMPILER:       /usr/bin/gfortran
-- HIPFORT_AR:             /usr/bin/gcc-ar
-- HIPFORT_RANLIB:         /usr/bin/gcc-ranlib
-- HIPFORT_COMPILER_FLAGS: -std=f2003 -ffree-form -cpp -ffree-line-length-512
-- HIPFORT_BUILD_TYPE:     RELEASE
-- HIPFORT_INSTALL_DIR:    
-- HIPFORT_VERSION:        3.8-0
-- HIPFORT ----------------------------------------------
-- The Fortran compiler identification is GNU 9.2.1
-- The C compiler identification is GNU 9.2.1
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_INSTALL_PREFIX:/usr/local
-- Detecting Fortran/C Interface
-- Detecting Fortran/C Interface - Found GLOBAL and MODULE mangling
-- Verifying Fortran/C Compiler Compatibility
-- Verifying Fortran/C Compiler Compatibility - Success
-- Done seFortranFlags
CMake Error at bin/CMakeLists.txt:17 (string):
  string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
  command.


-- HIPFORT -------------  cmake DONE --------------------
-- Configuring incomplete, errors occurred!

Note, cmake version is 3.13.4

$ cmake --version
cmake version 3.13.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.