From 80a7bdf66b0b7b4a160c2d69f67511043a80d347 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Fri, 8 Sep 2017 12:57:23 -0500 Subject: [PATCH] Modified to build within Jenkins Change-Id: I70c9c6b690f198c41641432478343d3714e26ab0 --- rocrtst/samples/CMakeLists.txt | 187 ++++++++++++++++++++------------- 1 file changed, 112 insertions(+), 75 deletions(-) diff --git a/rocrtst/samples/CMakeLists.txt b/rocrtst/samples/CMakeLists.txt index bd47600822..128376a456 100755 --- a/rocrtst/samples/CMakeLists.txt +++ b/rocrtst/samples/CMakeLists.txt @@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 2.8.0) # # 1) Set env. variable specifying the location of ROCR header files # -# export ROCR_DIR="Root for RocR install" +# export ROCM_DIR="Root for RocM install" # # 2) Set env. variable ROCRTST_BLD_TYPE to either "Debug" or "Release". # If not set, the default value is "Debug" is bound. @@ -24,11 +24,8 @@ cmake_minimum_required(VERSION 2.8.0) # # export ROCRTST_BLD_BITS=32 or ROCRTST_BLD_BITS=64 # -# 4) Set env. variable TARGET_DEVICE to indicate gpu type (e.g., gfx803, -# gfx900, ...) -# -# 5) Set env. variables OPENC_DIR and and OPENC_VER to the OpenCL install -# root and OpenCL version, respectively. +# 4) Set env. variable TARGET_DEVICES to indicate gpu types for kernel +# builds (e.g., "gfx803;gfx900; ...") # # Building rocrtst Suite # @@ -38,6 +35,8 @@ cmake_minimum_required(VERSION 2.8.0) # 4) Run "make" # +set(DEFAULT_TARGET "gfx803") + ############################# # COMMON AREA ############################# @@ -50,17 +49,23 @@ if(WIN32) endif() # -# Process environment variables relating to Build type, size and RT version +# Process environment variables # -string(TOLOWER "$ENV{ROCRTST_BLD_TYPE}" tmp) -if("${tmp}" STREQUAL release) - set(BUILD_TYPE "Release") - set(ISDEBUG 0) -else() - set(BUILD_TYPE "Debug") - set(ISDEBUG 1) + +# Required Env. Variables first: + +set(ROCR_INC_DIR $ENV{ROCM_DIR}/include) +set(ROCR_LIB_DIR $ENV{ROCM_DIR}/lib) +# +# Determine ROCR Header files are present +# +if(NOT EXISTS ${ROCR_INC_DIR}/hsa/hsa.h) + message("ERROR: ${ROCR_INC_DIR}/hsa/hsa.h does not exist. Check value of env. var. ROCM_DIR") + return() endif() +# Determine ROCR Library files are present +# if("$ENV{ROCRTST_BLD_BITS}" STREQUAL 32) set (ONLY64STR "") set (IS64BIT 0) @@ -68,23 +73,10 @@ else() set (ONLY64STR "64") set (IS64BIT 1) endif() - -set(ROCR_INC_DIR $ENV{ROCR_DIR}/hsa/include) -set(ROCR_LIB_DIR $ENV{ROCR_DIR}/lib) - -# -# Determine ROCR Header files are present -# -if(NOT EXISTS ${ROCR_INC_DIR}/hsa/hsa.h) - message("ERROR: Environment variable ROCR_INC_DIR pointing to ROCR headers is not set") - return() -endif() - -# Determine ROCR Library files are present # if (${IS64BIT} EQUAL 0) if(NOT EXISTS ${ROCR_LIB_DIR}/libhsa-runtime.so) - message("ERROR: Environment variable ROCR_LIB_DIR pointing to ROCR libraries is not set") + message("ERROR: ${ROCR_LIB_DIR}/libhsa-runtime.so doesn't exist. Check value of env. var. ROCM_DIR") return() endif() else() @@ -94,33 +86,46 @@ else() endif() endif() -if (DEFINED ENV{OPENCL_DIR}) - set(CLANG $ENV{OPENCL_DIR}/bin/x86_64/clang) - set(OPENCL_DIR $ENV{OPENCL_DIR}) +if (DEFINED ENV{LLVM_DIR}) + set(CLANG $ENV{LLVM_DIR}/clang) if (NOT EXISTS ${CLANG}) - message("ERROR: path to clang (${CLANG}) is not valid. Is env. variable OPENCL_DIR correct?") + message("ERROR: path to clang (${CLANG}) is not valid. Is env. variable LLVM_DIR correct?") return() endif() +else() + message("WARNING: LLVM_DIR env. variable is not set. Kernels will not be built.") +endif() - if (DEFINED ENV{OPENCL_VER}) - set(OPENCL_VER $ENV{OPENCL_VER}) - else() - message("OPENCL_VER environment variable is not set. Using default") - set(OPENCL_VER "2.0") - endif() +if (DEFINED ENV{OPENCL_DIR}) + set(OPENCL_INC_DIR $ENV{OPENCL_DIR}/include) + set(OPENCL_LIB_DIR $ENV{OPENCL_DIR}/lib) else() message("WARNING: OPENCL_DIR environment variable is not set. Kernels will not be built.") endif() -if (DEFINED ENV{TARGET_DEVICE}) - set(TARGET_DEVICE $ENV{TARGET_DEVICE}) +if (DEFINED ENV{OPENCL_VER}) + set(OPENCL_VER $ENV{OPENCL_VER}) else() - message("ERROR: TARGET_DEVICE environment variable is not defined.") - message("Please define a valid clang target (e.g., gfx803, gfx900,...).") - return() + message("OPENCL_VER environment variable is not set. Using default") + set(OPENCL_VER "2.0") +endif() + +if (NOT DEFINED TARGET_DEVICES) + message("WARNING: No targets devices provided on command line") + message(" e.g., cmake -DTARGET_DEVICES=\"gfx803;gfx900;gfx...\" ..") + message(" Using default target of $DEFAULT_TARGET") + list(APPEND TARGET_DEVICES "gfx803") endif() -# +string(TOLOWER "$ENV{ROCRTST_BLD_TYPE}" tmp) +if("${tmp}" STREQUAL release) + set(BUILD_TYPE "Release") + set(ISDEBUG 0) +else() + set(BUILD_TYPE "Debug") + set(ISDEBUG 1) +endif() + # Set Name for Samples Project # @@ -145,7 +150,7 @@ message("--------Proj Src Dir: " ${PROJECT_SOURCE_DIR}) message("--------Proj Bld Dir: " ${PROJECT_BINARY_DIR}) message("--------Proj Lib Dir: " ${PROJECT_BINARY_DIR}/lib) message("--------Proj Exe Dir: " ${PROJECT_BINARY_DIR}/bin) -message("-------Target Device: " ${TARGET_DEVICE}) +message("------Target Devices: ${TARGET_DEVICES}") message("----------Clang path: " ${CLANG}) message("-------OpenCL version " ${OPENCL_VER}) message("") @@ -202,11 +207,7 @@ message("ISDEBUG STEP:Done") # # Linux Linker options -# -#set(CMAKE_EXE_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl ") -#set(CMAKE_EXE_LINKER_FLAGS "-Wl,-soname=$(CORE_RUNTIME_NAME).so.1 ") - -# +## # Specify the directory containing various libraries of ROCR # to be linked against for building ROC Perf applications # @@ -217,57 +218,93 @@ link_directories(${ROCR_LIB_DIR}) # set(ROCR_LIBS ${ROCR_LIBS} hsa-runtime${ONLY64STR}) set(ROCR_LIBS ${ROCR_LIBS} hsa-runtime-tools${ONLY64STR}) -message(${ROCR_LIBS}) -include_directories(${ROCR_INC_DIR}) -include_directories($ENV{OPENCL_DIR}/include/opencl$ENV{OPENCL_VER}) +include_directories(${ROCR_INC_DIR} ${OPENCL_INC_DIR}) # Use this function to build any samples that have kernels to be built -function(process_sample S_NAME) - set(SNAME_EXE "${S_NAME}_${PROJECT_NAME}") +function(process_sample S_NAME TARG_DEV HAS_KERNEL) + + set(KERNEL_DIR ${PROJECT_BINARY_DIR}/${TARG_DEV}) set(SNAME_KERNEL "${S_NAME}_kernels.hsaco") - set(TARG_NAME "${S_NAME}_hsaco") - set(HSACO_TARG_LIST ${HSACO_TARG_LIST} ${TARG_NAME} PARENT_SCOPE) - separate_arguments(CLANG_ARG_LIST UNIX_COMMAND "-target amdgcn-amdh-amdhsa -mcpu=${TARGET_DEVICE} -include ${OPENCL_DIR}/include/opencl-c.h ${BITCODE_LIBS} -cl-std=CL${OPENCL_VER} ${CL_FILE_LIST} -o ${PROJECT_BINARY_DIR}/${SNAME_KERNEL}") - add_custom_target(${TARG_NAME} ${CLANG} ${CLANG_ARG_LIST} - COMMENT "BUILDING KERNEL..." - VERBATIM) + + set(TARG_NAME "${S_NAME}_hsaco.${TARG_DEV}") + set (HSACO_TARG_LIST ${HSACO_TARG_LIST} ${TARG_NAME} + CACHE INTERNAL HSACO_TARG_LIST) + + if (${HAS_KERNEL}) + # Build the kernel + separate_arguments(CLANG_ARG_LIST UNIX_COMMAND + "-x cl -Xclang -finclude-default-header -target amdgcn-amdh-amdhsa -mcpu=${TARG_DEV} ${BITCODE_LIBS} -cl-std=CL${OPENCL_VER} ${CL_FILE_LIST} -o ${KERNEL_DIR}/${SNAME_KERNEL}") + add_custom_target("${TARG_NAME}" ${CLANG} ${CLANG_ARG_LIST} COMMAND + ${CMAKE_COMMAND} -E create_symlink + "${PROJECT_BINARY_DIR}/${SNAME_EXE}" "${KERNEL_DIR}/${SNAME_EXE}" + COMMENT "BUILDING KERNEL..." + VERBATIM) + else() + # No kernel to build, but we need to set up symlinks; we'll use the hsaco + # targ name, even though we aren't building an hsaco + add_custom_target("${TARG_NAME}" + ${CMAKE_COMMAND} -E create_symlink + "${PROJECT_BINARY_DIR}/${SNAME_EXE}" "${KERNEL_DIR}/${SNAME_EXE}" + COMMENT "NO KERNEL TO BUILD; SYMLINK ONLY..." + VERBATIM) + endif() +endfunction(process_sample) + +function(build_sample_for_devices S_NAME HAS_KERNEL) + set(SNAME_EXE "${S_NAME}") + aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/${S_NAME} S_NAME_SOURCES) add_executable(${SNAME_EXE} ${S_NAME_SOURCES}) target_link_libraries(${SNAME_EXE} ${ROCR_LIBS} c stdc++ dl pthread rt) -endfunction(process_sample) + set(HSACO_TARG_LIST PARENT_SCOPE) + + foreach(t ${TARGET_DEVICES}) + process_sample(${S_NAME} ${t} ${HAS_KERNEL}) + endforeach(t) +endfunction(build_sample_for_devices) + +function(add_symlink_to_exe DST) + foreach(td ${TARGET_DEVICES}) + endforeach(td) +endfunction(add_symlink_to_exe) + + +# Make directories for each possible target device +foreach(td ${TARGET_DEVICES}) + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/${td}) +endforeach(td) ########################### # SAMPLE SPECIFIC SECTION ########################### + +set (HSACO_TARG_LIST "" CACHE INTERNAL HSACO_TARG_LIST) + set(KERN_SUFFIX "kernels.hsaco") set(BITCODE_PREF "-Xclang -mlink-bitcode-file -Xclang") -set(BITCODE_PREF "${BITCODE_PREF} ${OPENCL_DIR}/lib/x86_64/bitcode") +set(BITCODE_PREF "${BITCODE_PREF} ${OPENCL_LIB_DIR}") set(COMMON_BITCODE_LIBS "${BITCODE_PREF}/opencl.amdgcn.bc") -set(COMMON_BITCODE_LIBS "${COMMON_BITCODE_LIBS} ${BITCODE_PREF}/ockl.amdgcn.bc") +set(COMMON_BITCODE_LIBS + "${COMMON_BITCODE_LIBS} ${BITCODE_PREF}/ockl.amdgcn.bc") # Binary Search set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}") set(BITCODE_LIBS "${BITCODE_LIBS} ${BITCODE_PREF}/ocml.amdgcn.bc") -set(CL_FILE_LIST "${PROJECT_SOURCE_DIR}/binary_search/binary_search_kernels.cl") -process_sample("binary_search") +set(CL_FILE_LIST + "${PROJECT_SOURCE_DIR}/binary_search/binary_search_kernels.cl") +build_sample_for_devices("binary_search" TRUE) # RocR Info -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/rocrinfo ROCR_INFO_SOURCES) -add_executable(rocrinfo ${ROCR_INFO_SOURCES}) -target_link_libraries(rocrinfo ${ROCR_LIBS} c stdc++ dl pthread rt) +build_sample_for_devices("rocrinfo" FALSE) # IPC -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/ipc IPC_SOURCES) -add_executable(ipc ${IPC_SOURCES}) -target_link_libraries(ipc ${ROCR_LIBS} c stdc++ dl pthread rt) +build_sample_for_devices("ipc" FALSE) # Async Mem. Copy -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/async_mem_copy AMC_SOURCES) -add_executable(async_mem_copy ${AMC_SOURCES}) -target_link_libraries(async_mem_copy ${ROCR_LIBS} c stdc++ dl pthread rt) +build_sample_for_devices("async_mem_copy" FALSE) add_custom_target(sample_kernels DEPENDS ${HSACO_TARG_LIST}) install(TARGETS ${SAMPLE_EXE}