From d00d627b9df8ff42f3e6fe10aa4f6ce2cf8f18fa Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Sun, 27 Sep 2020 12:57:36 -0400 Subject: [PATCH] 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 . 4.Simplify argument list parsing. 5.Fix hip_pch.o missing issue in samples' build. 6.Fix some original small bugs. Change-Id: I30f5e65367613152ce86b80b13e1c9f2a28da803 --- samples/0_Intro/bit_extract/CMakeLists.txt | 8 ++++++++ samples/0_Intro/bit_extract/bit_extract.cpp | 14 ++++++++++++++ samples/0_Intro/square/CMakeLists.txt | 3 +++ .../12_cmake_hip_add_executable/CMakeLists.txt | 3 +++ .../12_cmake_hip_add_executable/Readme.md | 6 ++++++ samples/README.md | 18 ++++++++++++------ 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/samples/0_Intro/bit_extract/CMakeLists.txt b/samples/0_Intro/bit_extract/CMakeLists.txt index c9b13be812..ec3930f691 100644 --- a/samples/0_Intro/bit_extract/CMakeLists.txt +++ b/samples/0_Intro/bit_extract/CMakeLists.txt @@ -2,6 +2,14 @@ project(bit_extract) cmake_minimum_required(VERSION 3.10) +if(NOT DEFINED __HIP_ENABLE_PCH) + set(__HIP_ENABLE_PCH ON CACHE BOOL "enable/disable pre-compiled hip headers") +endif() + +if(${__HIP_ENABLE_PCH}) + add_definitions(-D__HIP_ENABLE_PCH) +endif() + # Search for rocm in common locations list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm) diff --git a/samples/0_Intro/bit_extract/bit_extract.cpp b/samples/0_Intro/bit_extract/bit_extract.cpp index e87124f47f..1f7770ccb5 100644 --- a/samples/0_Intro/bit_extract/bit_extract.cpp +++ b/samples/0_Intro/bit_extract/bit_extract.cpp @@ -54,6 +54,20 @@ int main(int argc, char* argv[]) { size_t N = 1000000; size_t Nbytes = N * sizeof(uint32_t); +#ifdef __HIP_ENABLE_PCH + // Verify hip_pch.o + const char* pch = nullptr; + unsigned int size = 0; + __hipGetPCH(&pch, &size); + printf("pch size: %u\n", size); + if (size == 0) { + printf("__hipGetPCH failed!\n"); + return -1; + } else { + printf("__hipGetPCH succeeded!\n"); + } +#endif + int deviceId; CHECK(hipGetDevice(&deviceId)); hipDeviceProp_t props; diff --git a/samples/0_Intro/square/CMakeLists.txt b/samples/0_Intro/square/CMakeLists.txt index 845c43fd1f..2e101e1470 100644 --- a/samples/0_Intro/square/CMakeLists.txt +++ b/samples/0_Intro/square/CMakeLists.txt @@ -7,6 +7,9 @@ cmake_minimum_required(VERSION 3.10) # Search for rocm in common locations list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm) +# create square.cpp +execute_process(COMMAND sh -c "/opt/rocm/hip/bin/hipify-perl ../square.cu > ../square.cpp") + # Find hip find_package(hip) diff --git a/samples/2_Cookbook/12_cmake_hip_add_executable/CMakeLists.txt b/samples/2_Cookbook/12_cmake_hip_add_executable/CMakeLists.txt index 0e8020a67a..dbfdf9a908 100644 --- a/samples/2_Cookbook/12_cmake_hip_add_executable/CMakeLists.txt +++ b/samples/2_Cookbook/12_cmake_hip_add_executable/CMakeLists.txt @@ -9,6 +9,9 @@ if(NOT DEFINED HIP_PATH) endif() set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH}) +# Search for rocm in common locations +list(APPEND CMAKE_PREFIX_PATH ${HIP_PATH} /opt/rocm) + project(12_cmake) set(HIP_CLANG_NUM_PARALLEL_JOBS 2) diff --git a/samples/2_Cookbook/12_cmake_hip_add_executable/Readme.md b/samples/2_Cookbook/12_cmake_hip_add_executable/Readme.md index 4e322fd83e..9aa6b96fab 100644 --- a/samples/2_Cookbook/12_cmake_hip_add_executable/Readme.md +++ b/samples/2_Cookbook/12_cmake_hip_add_executable/Readme.md @@ -37,7 +37,13 @@ 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 ``` diff --git a/samples/README.md b/samples/README.md index 739045382e..c54ec20b3a 100644 --- a/samples/README.md +++ b/samples/README.md @@ -12,16 +12,22 @@ make 2.CMakeLists.txt can support shared and static libs of hip-rocclr runtime. -To build a sample, type in sample folder, +To build a sample, run in the sample folder, -mkdir build (if build folder is missing) +mkdir -p build && cd build -cd build +rm -rf * (to clear up) + +a. to build with shared libs, run cmake .. +b. to build with static libs, run + +cmake -DCMAKE_PREFIX_PATH="/opt/rocm/llvm/lib/cmake" .. + +Then run, + make -If you want debug version, follow, - -cmake -DCMAKE_BUILD_TYPE=Debug .. \ No newline at end of file +Note that if you want debug version, add "-DCMAKE_BUILD_TYPE=Debug" in cmake cmd. \ No newline at end of file