2017-12-05 10:48:29 +05:30
## hip_add_executable ###
This tutorial shows how to use the FindHIP cmake module and create an executable using ```hip_add_executable` `` macro.
## Including FindHIP cmake module in the project
Since FindHIP cmake module is not yet a part of the default cmake distribution, ` ``CMAKE_MODULE_PATH` `` needs to be updated to contain the path to FindHIP.cmake.
The simplest approach is to use
` ``
2023-08-21 11:09:47 +00:00
set(CMAKE_MODULE_PATH "/opt/rocm/lib/cmake/hip/" ${CMAKE_MODULE_PATH})
2017-12-05 10:48:29 +05:30
find_package(HIP)
` ``
A more generic solution that allows for a user specified location for the HIP installation would look something like
` ``
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
endif()
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
find_package(HIP)
` ``
If your project already modifies ` ``CMAKE_MODULE_PATH` ``, you will need to append the path to FindHIP.cmake instead of replacing it.
## Using the hip_add_executable macro
FindHIP provides the ` ``hip_add_executable` `` macro that is similar to the ` ``cuda_add_executable` `` macro that is provided by FindCUDA.
The syntax is also similar. The ` ``hip_add_executable` `` macro uses the hipcc wrapper as the compiler.
2021-01-04 19:58:20 -05:00
The macro supports specifying CLANG-specific, NVCC-specific compiler options using the ` ``CLANG_OPTIONS` `` and ` ``NVCC_OPTIONS` `` keywords.
2020-04-29 05:41:12 -04:00
Common options targeting both compilers can be specificed after the ` ``HIPCC_OPTIONS` `` keyword.
2017-12-05 10:48:29 +05:30
## How to build and run:
2023-12-11 03:43:30 +00:00
- Build sample using cmake
` ``
$ mkdir build; cd build
# For shared lib of hip rt,
$ cmake ..
# Or for static lib of hip rt,
$ cmake -DCMAKE_PREFIX_PATH="/opt/rocm/llvm/lib/cmake" ..
$ make
2017-12-05 10:48:29 +05:30
` ``
2020-10-12 10:27:33 -04:00
2023-12-11 03:43:30 +00:00
- Execute the sample
` ``
$ ./MatrixTranspose
Device name
PASSED!
2017-12-05 10:48:29 +05:30
` ``
## More Info:
2024-04-24 15:21:05 -04:00
- [HIP FAQ ](https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/faq.html )
2024-02-28 14:57:02 -05:00
- [HIP Kernel Language ](https://rocm.docs.amd.com/projects/HIP/en/latest/reference/kernel_language.html )
2024-02-14 15:05:46 -05:00
- [HIP Runtime API (Doxygen) ](https://rocm.docs.amd.com/projects/HIP/en/latest/doxygen/html/index.html )
2024-04-24 15:21:05 -04:00
- [HIP Porting Guide ](https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/hip_porting_guide.html )
2024-02-28 14:57:02 -05:00
- [HIP Terminology ](https://rocm.docs.amd.com/projects/HIP/en/latest/reference/terms.html ) (including comparing syntax for different compute terms across CUDA/HIP/OpenL)
- [HIPIFY ](https://rocm.docs.amd.com/projects/HIPIFY/en/latest/index.html )
2024-04-24 15:21:05 -04:00
- [Developer/CONTRIBUTING Info ](https://github.com/ROCm/HIP/blob/develop/CONTRIBUTING.md )