Skip to content

Instantly share code, notes, and snippets.

@cgmb
Last active November 21, 2022 15:01
Show Gist options
  • Save cgmb/ff73a25935024c5657744387ba74e0a5 to your computer and use it in GitHub Desktop.
Save cgmb/ff73a25935024c5657744387ba74e0a5 to your computer and use it in GitHub Desktop.
HIP platform selection
  1. In the install script, determine the build platform by querying hipconfig --platform
    • This is necessary, as the install script needs to know the build platform so it can to choose what dependencies to install.
    • hipconfig --platform determines the platform by reading the contents of the .hipInfo file installed as part of the hip runtime.
    • If the platform is autodetected incorrectly, it can be be set explicitly via an environment variable, e.g., export HIP_PLATFORM=amd or export HIP_PLATFORM=nvidia.
  2. In CMake, find_package(hip REQUIRED) will be used for both the AMD and NVIDIA platforms.
    • There will be no need for a different find_package call on each platform; the same call will be used for both platforms.
    • find_package(hip) will set HIP_PLATFORM so the rest of the build rules can branch on if(HIP_PLATFORM STREQUAL amd) or if(HIP_PLATFORM STREQUAL nvidia).
    • find_package(hip) will create the imported interface target hip::host, which will have all necessary defines, dependencies and include paths for using the HIP library with a normal C or C++ compiler. For example, anything linked with hip::host will be passed -D__HIP_PLATFORM_AMD__ when HIP_PLATFORM=amd and -D__HIP_PLATFORM_NVIDIA__ when HIP_PLATFORM=nvidia.
  3. find_package(hip) will be implemented in cmake/Findhip.cmake. This file will be copied into each project that needs to support the NVIDIA platform.
    • Findhip.cmake will use hipconfig --platform to set the HIP_PLATFORM CMake variable. This behaviour will be copied directly from FindHIP.cmake.
    • On the AMD platform, Findhip.cmake will be a thin wrapper around hip-config.cmake
    • On the NVIDIA platform, Findhip.cmake will find the HIP include directories and create the hip::host target.
    • Once hip-config.cmake defines HIP_PLATFORM and adds hip::host to the NVIDIA platform, Findhip.cmake can be deleted. It's just a compatibility shim to add features that have not been implemented in HIP yet. Once they are implemented, the shim can be removed without any further changes required to the libraries.
@SergiyKostrov
Copy link

Currently, valid values are as follows:

 HIP_PLATFORM={ amd, nvidia }
      and
 { __HIP_PLATFORM_AMD__, __HIP_PLATFORM_NVIDIA__ }

Does it make sense to consider an extension:

 HIP_PLATFORM={ amd, xilinx, nvidia }
      and
 { __HIP_PLATFORM_AMD__, __HIP_PLATFORM_XILINX__, __HIP_PLATFORM_NVIDIA__ }

 and of course 'hipconfig' utility should support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment