Dosyalar
rocm-systems/samples/2_Cookbook/12_cmake_hip_add_executable
Tao Sang ef2751c120 Make directed_test support static libs
1.Make directed_test apps linked against static libs
    of hip, rocclr, rocr, roct and amd_comgr.
    2.Remove custom_target amdhip64_static_combiner.
    3.Support EXCLUDE_HIP_LIB_TYPE <static|shared>.
    4.Simplify argument list parsing.
    5.Install rocclr when rocm is installed.
    6.Fix some original small bugs.

Revert "Revert "Make directed_test support static libs""
This reverts commit 144a6fb100.

Change-Id: I918eeae94487e5e2ff5bfde083667ac65fb6e702
2020-10-26 12:39:58 -04:00
..

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

set(CMAKE_MODULE_PATH "/opt/rocm/hip/cmake" ${CMAKE_MODULE_PATH})
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. The macro supports specifying HCC-specific, CLANG-specific, NVCC-specific compiler options using the HCC_OPTIONS, CLANG_OPTIONS and NVCC_OPTIONS keywords. Common options targeting both compilers can be specificed after the HIPCC_OPTIONS keyword.

How to build and run:

Use the following commands to build and execute the sample

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" ..

Then,
make
./MatrixTranspose

More Info: