Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

337 lines
10 KiB
CMake
Raw Permalink Normal View History

2017-05-05 23:50:42 -05:00
#
# Minimum version of cmake required
#
cmake_minimum_required(VERSION 2.8.0)
#
# GCC 4.8 or higher compiler required.
#
#
# Required Defines on cmake command line
#
# 1) Set location of ROCR header files
2017-05-05 23:50:42 -05:00
#
# ROCM_DIR="Root for RocM install"
2017-05-05 23:50:42 -05:00
#
# 2) Set ROCRTST_BLD_TYPE to either "Debug" or "Release".
2017-05-05 23:50:42 -05:00
# If not set, the default value is "Debug" is bound.
#
# ROCRTST_BLD_TYPE=Debug or ROCRTST_BLD_TYPE=Release
2017-05-05 23:50:42 -05:00
#
# 3) Set ROCRTST_BLD_BITS to either "32" or "64"
2017-05-05 23:50:42 -05:00
# If not set, the default value of "64" is bound.
#
# ROCRTST_BLD_BITS=32 or ROCRTST_BLD_BITS=64
2017-05-05 23:50:42 -05:00
#
# 4) Set TARGET_DEVICES to indicate gpu types for kernel
2017-09-08 12:57:23 -05:00
# builds (e.g., "gfx803;gfx900; ...")
2017-05-05 23:50:42 -05:00
#
# Building rocrtst Suite
#
2017-05-05 23:50:42 -05:00
# 1) Create build folder e.g. "rocrtst/build" - any name will do
# 2) Cd into build folder
# 3) Run "cmake .."
# 4) Run "make"
#
2020-07-17 20:52:50 +05:30
cmake_minimum_required(VERSION 3.5.0)
# Set Name for Samples Project
#
set(PROJECT_NAME "sample64")
project (${PROJECT_NAME})
2017-09-08 12:57:23 -05:00
set(DEFAULT_TARGET "gfx803")
2017-05-05 23:50:42 -05:00
#############################
# COMMON AREA
#############################
#
# Currently support for Windows platform is not present
#
if(WIN32)
message("This sample is not supported on Windows platform")
return()
endif()
#
# Process input variables
2017-05-05 23:50:42 -05:00
#
# Required Defines first:
2020-07-17 20:52:50 +05:30
find_package(hsa-runtime64 REQUIRED )
message(STATUS "HSA Runtime found at ${hsa-runtime64_DIR} ")
2017-05-05 23:50:42 -05:00
if (DEFINED LLVM_DIR)
set(CLANG ${LLVM_DIR}/clang)
2017-05-05 23:50:42 -05:00
if (NOT EXISTS ${CLANG})
2019-11-16 00:18:52 -06:00
# SPK temp until Jenkins script input is corrected.
set (CLANG ${OPENCL_DIR}/bin/clang)
if (NOT EXISTS ${CLANG})
message("ERROR: path to clang (${CLANG}) is not valid. Is define LLVM_DIR correct?")
2017-05-05 23:50:42 -05:00
return()
2019-11-16 00:18:52 -06:00
endif()
2017-05-05 23:50:42 -05:00
endif()
2017-09-08 12:57:23 -05:00
else()
message("WARNING: LLVM_DIR define is not set. Kernels will not be built.")
2017-09-08 12:57:23 -05:00
endif()
2017-05-05 23:50:42 -05:00
if (DEFINED OPENCL_DIR)
set(OPENCL_INC_DIR ${OPENCL_DIR}/include)
set(OPENCL_LIB_DIR ${OPENCL_DIR}/lib)
2017-05-05 23:50:42 -05:00
else()
message("WARNING: OPENCL_DIR define is not set. Kernels will not be built.")
2017-05-05 23:50:42 -05:00
endif()
if (DEFINED OPENCL_VER)
set(OPENCL_VER ${OPENCL_VER})
2017-05-05 23:50:42 -05:00
else()
message("OPENCL_VER define is not set. Using default")
2017-09-08 12:57:23 -05:00
set(OPENCL_VER "2.0")
endif()
2019-11-16 00:18:52 -06:00
if(NOT EXISTS "${OPENCL_INC_DIR}/opencl-c.h")
2019-12-06 14:58:49 -05:00
set(OPENCL_INC_DIR "${OPENCL_DIR}/../../../external/llvm-project/clang/lib/Headers/")
2019-11-16 00:18:52 -06:00
if(NOT EXISTS "${OPENCL_INC_DIR}/opencl-c.h")
message(WARNING "opencl-c.h not found.")
endif()
endif()
2017-09-08 12:57:23 -05:00
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")
2020-07-13 13:56:25 -04:00
endif()
2017-05-05 23:50:42 -05:00
string(TOLOWER "${ROCRTST_BLD_TYPE}" tmp)
2017-09-08 12:57:23 -05:00
if("${tmp}" STREQUAL release)
set(BUILD_TYPE "Release")
set(ISDEBUG 0)
else()
set(BUILD_TYPE "Debug")
set(ISDEBUG 1)
endif()
# Find AMD Device Libraries (bitcode files) using find_package or manual search
find_package(AMDDeviceLibs QUIET CONFIG)
if(AMDDeviceLibs_FOUND)
# Use the package-provided location
message(STATUS "Found AMDDeviceLibs via CONFIG")
# Try to get the bitcode directory from any target
if(TARGET AMDDeviceLibs::oclc_isa_version_803)
get_target_property(DEVICE_LIBS_LOCATION AMDDeviceLibs::oclc_isa_version_803 IMPORTED_LOCATION)
get_filename_component(BITCODE_DIR "${DEVICE_LIBS_LOCATION}" DIRECTORY)
elseif(TARGET AMDDeviceLibs::oclc_isa_version_900)
get_target_property(DEVICE_LIBS_LOCATION AMDDeviceLibs::oclc_isa_version_900 IMPORTED_LOCATION)
get_filename_component(BITCODE_DIR "${DEVICE_LIBS_LOCATION}" DIRECTORY)
else()
# Fallback to manual search even if package was found
set(AMDDeviceLibs_FOUND FALSE)
endif()
endif()
2020-07-13 13:56:25 -04:00
if(NOT AMDDeviceLibs_FOUND)
# Fallback: search relative to LLVM installation
message(STATUS "Searching for AMD Device Libraries manually...")
# First try to find LLVM if not already found
if(NOT DEFINED LLVM_LIBRARY_DIR)
find_package(LLVM QUIET CONFIG)
if(LLVM_FOUND)
message(STATUS "Found LLVM: ${LLVM_PACKAGE_VERSION}")
endif()
endif()
find_path(BITCODE_DIR
NAMES "opencl.bc" "opencl.amdgcn.bc" "oclc_isa_version_803.bc"
HINTS
"${LLVM_LIBRARY_DIR}/amdgcn/bitcode"
"${LLVM_LIBRARY_DIR}/../amdgcn/bitcode"
"${CMAKE_INSTALL_PREFIX}/amdgcn/bitcode"
"${CMAKE_INSTALL_PREFIX}/lib/amdgcn/bitcode"
"${CMAKE_PREFIX_PATH}/amdgcn/bitcode"
"${CMAKE_PREFIX_PATH}/lib/amdgcn/bitcode"
NO_DEFAULT_PATH
)
if(NOT BITCODE_DIR)
message(FATAL_ERROR
"AMD Device Libraries (bitcode) not found!\n"
"Searched locations:\n"
" ${LLVM_LIBRARY_DIR}/amdgcn/bitcode\n"
" ${LLVM_LIBRARY_DIR}/../amdgcn/bitcode\n"
" ${CMAKE_INSTALL_PREFIX}/amdgcn/bitcode\n"
" ${CMAKE_INSTALL_PREFIX}/lib/amdgcn/bitcode\n"
"Please ensure device-libs are built and installed.")
endif()
endif()
message(STATUS "Samples - Found Device Libraries: ${BITCODE_DIR}")
# Validate bitcode files exist
if(NOT EXISTS "${BITCODE_DIR}")
message(FATAL_ERROR "BITCODE_DIR does not exist: ${BITCODE_DIR}")
endif()
2017-05-05 23:50:42 -05:00
#
# Print out the build configuration being used:
#
# Build Src directory
# Build Binary directory
# Build Type: Debug Vs Release, 32 Vs 64
# Compiler Version, etc
#
message("")
message("Build Configuration:")
message("-------------IS64BIT: " ${IS64BIT})
message("-----------BuildType: " ${BUILD_TYPE})
message("------------Compiler: " ${CMAKE_CXX_COMPILER})
message("-------------Version: " ${CMAKE_CXX_COMPILER_VERSION})
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)
2017-09-08 12:57:23 -05:00
message("------Target Devices: ${TARGET_DEVICES}")
2017-05-05 23:50:42 -05:00
message("----------Clang path: " ${CLANG})
message("----------OpenCL Dir: " ${OPENCL_DIR})
2017-05-05 23:50:42 -05:00
message("-------OpenCL version " ${OPENCL_VER})
message("")
#
# Set the build type based on user input
#
set(CMAKE_BUILD_TYPE ${BUILD_TYPE})
#
# Flag to enable / disable verbose output.
#
SET( CMAKE_VERBOSE_MAKEFILE on )
#
# Compiler pre-processor definitions.
#
# Define MACRO "DEBUG" if build type is "Debug"
if(${BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG)
endif()
2023-05-31 15:00:56 +00:00
#add_definitions(-D__linux__)
2017-05-05 23:50:42 -05:00
add_definitions(-DLITTLEENDIAN_CPU=1)
#
# Linux Compiler options
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2017-05-05 23:50:42 -05:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmerge-all-constants")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fms-extensions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
2020-12-04 22:18:14 -06:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
2020-07-17 20:52:50 +05:30
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
2017-05-05 23:50:42 -05:00
#
# Add compiler flags to include symbol information for debug builds
#
if(ISDEBUG)
2017-05-23 09:37:58 -05:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -O0")
2017-05-05 23:50:42 -05:00
endif()
message("ISDEBUG STEP:Done")
2020-07-17 20:52:50 +05:30
include_directories("${OPENCL_DIR}/include")
2017-05-05 23:50:42 -05:00
2017-06-01 10:15:22 -05:00
# Use this function to build any samples that have kernels to be built
2017-09-08 12:57:23 -05:00
function(process_sample S_NAME TARG_DEV HAS_KERNEL)
set(KERNEL_DIR ${PROJECT_BINARY_DIR}/${TARG_DEV})
2017-05-05 23:50:42 -05:00
set(SNAME_KERNEL "${S_NAME}_kernels.hsaco")
2020-07-13 13:56:25 -04:00
2017-09-08 12:57:23 -05:00
set(TARG_NAME "${S_NAME}_hsaco.${TARG_DEV}")
set (HSACO_TARG_LIST ${HSACO_TARG_LIST} ${TARG_NAME}
CACHE INTERNAL HSACO_TARG_LIST)
2020-07-13 13:56:25 -04:00
2017-09-08 12:57:23 -05:00
if (${HAS_KERNEL})
# Build the kernel
separate_arguments(CLANG_ARG_LIST UNIX_COMMAND
2020-11-10 13:41:20 -05:00
"-x cl -target amdgcn-amd-amdhsa -Xclang -finclude-default-header -mcpu=${TARG_DEV} ${BITCODE_ARGS} -cl-std=CL${OPENCL_VER} ${CL_FILE_LIST} -o ${KERNEL_DIR}/${SNAME_KERNEL}")
2017-09-08 12:57:23 -05:00
add_custom_target("${TARG_NAME}" ${CLANG} ${CLANG_ARG_LIST} COMMAND
${CMAKE_COMMAND} -E create_symlink
"../${SNAME_EXE}" "${KERNEL_DIR}/${SNAME_EXE}"
2017-09-08 12:57:23 -05:00
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
"../${SNAME_EXE}" "${KERNEL_DIR}/${SNAME_EXE}"
2017-09-08 12:57:23 -05:00
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}")
2017-05-05 23:50:42 -05:00
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/${S_NAME} S_NAME_SOURCES)
add_executable(${SNAME_EXE} ${S_NAME_SOURCES})
2020-07-17 20:52:50 +05:30
target_link_libraries(${SNAME_EXE} hsa-runtime64::hsa-runtime64 c stdc++ dl pthread rt)
2017-09-08 12:57:23 -05:00
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)
2017-06-01 10:15:22 -05:00
2017-09-08 12:57:23 -05:00
# Make directories for each possible target device
foreach(td ${TARGET_DEVICES})
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/${td})
endforeach(td)
2017-05-05 23:50:42 -05:00
###########################
2020-07-13 13:56:25 -04:00
# SAMPLE SPECIFIC SECTION
2017-05-05 23:50:42 -05:00
###########################
2017-09-08 12:57:23 -05:00
set (HSACO_TARG_LIST "" CACHE INTERNAL HSACO_TARG_LIST)
2017-05-05 23:50:42 -05:00
set(KERN_SUFFIX "kernels.hsaco")
2020-07-13 13:56:25 -04:00
# Check if device-libs bitcode is following old or new layout
if(EXISTS "${BITCODE_DIR}/opencl.amdgcn.bc")
set(BITCODE_ARGS "-nogpulib
-Xclang -mlink-bitcode-file -Xclang ${BITCODE_DIR}/opencl.amdgcn.bc
-Xclang -mlink-bitcode-file -Xclang ${BITCODE_DIR}/ockl.amdgcn.bc
-Xclang -mlink-bitcode-file -Xclang ${BITCODE_DIR}/ocml.amdgcn.bc")
else()
set(BITCODE_ARGS "--hip-device-lib-path=${BITCODE_DIR}")
endif()
2017-06-01 10:15:22 -05:00
2017-09-08 12:57:23 -05:00
set(CL_FILE_LIST
"${PROJECT_SOURCE_DIR}/binary_search/binary_search_kernels.cl")
build_sample_for_devices("binary_search" TRUE)
2017-05-05 23:50:42 -05:00
2017-05-11 09:53:10 -05:00
# RocR Info
2017-09-08 12:57:23 -05:00
build_sample_for_devices("rocrinfo" FALSE)
2017-05-11 09:53:10 -05:00
2017-05-23 09:37:58 -05:00
# IPC
2017-09-08 12:57:23 -05:00
build_sample_for_devices("ipc" FALSE)
2017-05-23 09:37:58 -05:00
2017-06-01 10:15:22 -05:00
# Async Mem. Copy
2017-09-08 12:57:23 -05:00
build_sample_for_devices("async_mem_copy" FALSE)
2017-06-01 10:15:22 -05:00
add_custom_target(sample_kernels DEPENDS ${HSACO_TARG_LIST})
2017-05-05 23:50:42 -05:00
install(TARGETS ${SAMPLE_EXE}
ARCHIVE DESTINATION ${PROJECT_BINARY_DIR}/lib
LIBRARY DESTINATION ${PROJECT_BINARY_DIR}/lib
RUNTIME DESTINATION ${PROJECT_BINARY_DIR}/bin)