Skip to content

HIP Support, master branch (2020.08.19.)

As discussed on atlas-sw-accelerators, I managed to write some code that allows us to build HIP source files very similar to how we build CUDA source files. The syntax does need to be just a little different, since to achieve the exact same syntax, this code would need to be pushed into the CMake source code itself.

While the syntax for enabling CUDA in the build, if it's available is the following:

include( CheckLanguage )
check_language( CUDA )
if( CMAKE_CUDA_COMPILER )
   enable_language( CUDA )
endif()

, the syntax with the new AtlasHIP package is the following:

find_package( AtlasHIP QUIET )
if( AtlasHIP_FOUND )
   include( AtlasCheckLanguage )
   atlas_check_language( HIP )
   if( CMAKE_HIP_COMPILER )
      enable_language( HIP )
   endif()
endif()

In the end "user code" can in both cases rely on the CMAKE_CUDA_COMPILER / CMAKE_HIP_COMPILER variables to decide if they're going to be able to build CUDA/HIP sources.

In order to control the behaviour of the HIP build, one can use the following cache variables:

  • CMAKE_HIP_PLATFORM: Same as the HIP_PLATFORM environment variable used by hipcc, it can be set to 2 different values;
    • "hcc": The build will use the "AMD backend";
    • "nvcc": The build will use the "NVidia/CUDA backend";
  • CMAKE_HIP_STANDARD: The same as CMAKE_CXX_STANDARD and CMAKE_CUDA_STANDARD, it can be used to set the C++ standard used to build the HIP source files;
    • Note that while the "AMD backend" allows the usage of C++17, the "NVidia backend" only goes up to C++14. At least with CUDA <11.

Similar to CUDA, to make CMake recognise a source file as a "HIP source file", it just needs to have the extension .hip. With that all standard AtlasCMake functions will know how to deal with such files. The only addition is that for now you also need to explicitly mark libraries/executables that receive HIP source files, that they should use the "HIP linker". Like:

set_target_properties( MyTarget PROPERTIES LINKER_LANGUAGE HIP )

It should be possible to automate even this, but I didn't figure out yet how to. (Again, it may be something that would have to be done in the CMake C++ code...)

Pinging @leggett, @fwinkl, @baines.

Merge request reports