Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ set ( PACKAGE_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_COMMIT
## Find external dependencies.
find_package(PkgConfig)
find_package(LibElf REQUIRED)
find_package(hsakmt 1.0 REQUIRED HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
pkg_check_modules(drm REQUIRED IMPORTED_TARGET libdrm)

## Find dependencies that may be built with us or from an installed package.
if(TARGET hsakmt::hsakmt)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be checking for if(TARGET) as this would require the superproject to order the add_subdirectory based on the dependency order. This can be quite fragile as we would need to change the order if the dependencies between components change. Instead we should just let cmake order the dependencies.

message(STATUS "Using build dep on hsakmt")
else()
find_package(hsakmt 1.0 REQUIRED HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The find_package should be disabled by the superproject either by using the OVERRIDE_FIND_PACKAGE in FetchContent_Declare or by using the register_source_package function as described here:

function(register_source_package NAME)
  file(WRITE "${CMAKE_BINARY_DIR}/__pkg/${NAME}/${NAME}Config.cmake" "")
  set(${NAME}_DIR ${CMAKE_BINARY_DIR}/__pkg/${NAME} CACHE PATH "")
endfunction()

endif()

## Create the rocr target.
add_library( ${CORE_RUNTIME_TARGET} "" )

Expand Down Expand Up @@ -126,6 +132,19 @@ target_include_directories( ${CORE_RUNTIME_TARGET}
${CMAKE_CURRENT_BINARY_DIR}/core/runtime/trap_handler
${CMAKE_CURRENT_BINARY_DIR}/core/runtime/blit_shaders)

## ------------------------- Device Library Options ----------------------------
set(ROCR_RUNTIME_DEVICE_LIB_PATH "" CACHE PATH "Builds against custom device-lib bitcode files (passed to clang --rocm-device-lib-path=)")
set(ROCR_RUNTIME_DEVICE_LIB_DEPS "" CACHE STRING "Custom deps to depend on to ensure device libs are built")

if (ROCR_RUNTIME_DEVICE_LIB_PATH)
message(STATUS "ROCR Runtime custom device lib path: ${ROCR_RUNTIME_DEVICE_LIB_PATH}")
if(NOT IS_DIRECTORY "${ROCR_RUNTIME_DEVICE_LIB_PATH}")
message(WARNING "Custom ROCR_RUNTIME_DEVICE_LIB_PATH does not exist")
endif()
set(ROCR_RUNTIME_CLANG_DEVICE_LIB_ARGS "--rocm-device-lib-path=${ROCR_RUNTIME_DEVICE_LIB_PATH}")
else()
set(ROCR_RUNTIME_CLANG_DEVICE_LIB_ARGS)
endif()

## ------------------------- Linux Compiler and Linker options -------------------------
set ( HSA_CXX_FLAGS ${HSA_COMMON_CXX_FLAGS} -fexceptions -fno-rtti -fvisibility=hidden -Wno-error=missing-braces -Wno-error=sign-compare -Wno-sign-compare -Wno-write-strings -Wno-conversion-null -fno-math-errno -fno-threadsafe-statics -fmerge-all-constants -fms-extensions -Wno-error=comment -Wno-comment -Wno-error=pointer-arith -Wno-pointer-arith -Wno-error=unused-variable -Wno-error=unused-function )
Expand Down Expand Up @@ -157,6 +176,24 @@ target_compile_options(${CORE_RUNTIME_TARGET} PRIVATE ${HSA_CXX_FLAGS})
set_property(TARGET ${CORE_RUNTIME_TARGET} PROPERTY LINK_FLAGS ${HSA_SHARED_LINK_FLAGS})
## ------------------------- End Compiler and Linker options ----------------------------

## Ensure that 'clang' and 'llvm-objcopy' targets are available
if(NOT TARGET clang OR NOT TARGET llvm-objcopy)
if(TARGET clang OR TARGET llvm-objcopy)
message(FATAL_ERROR "Detected one of 'clang' or 'llvm-objcopy' targets but not both")
endif()
message(STATUS "LLVM deps not found: finding Clang and LLVM packages")
find_package(Clang REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )
find_package(LLVM REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )
endif()

if(${CMAKE_VERBOSE_MAKEFILE})
get_property(clang_path TARGET clang PROPERTY LOCATION)
get_property(objcopy_path TARGET llvm-objcopy PROPERTY LOCATION)
message("Using clang from: ${clang_path}")
message("Using llvm-objcopy from: ${objcopy_path}")
message("Trap handlers assembled for: ${TARGET_DEVS}")
endif()

## Source files.
set ( SRCS core/util/lnx/os_linux.cpp
core/util/small_heap.cpp
Expand Down
13 changes: 0 additions & 13 deletions src/core/runtime/blit_shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,11 @@
# Minimum required version of CMake
cmake_minimum_required ( VERSION 3.7 )

# Find Clang package and LLVM package
find_package(Clang REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )
find_package(LLVM REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )

# Set the target devices
set (TARGET_DEVS "gfx900;gfx940;gfx1010;gfx1030;gfx1100")
# Set the postfix for each target device
set (POSTFIX "9;940;1010;10;11")

# If verbose output is enabled, print paths and target devices
if(${CMAKE_VERBOSE_MAKEFILE})
get_property(clang_path TARGET clang PROPERTY LOCATION)
get_property(objcopy_path TARGET llvm-objcopy PROPERTY LOCATION)
message("Using clang from: ${clang_path}")
message("Using llvm-objcopy from: ${objcopy_path}")
message("Blit Shaders assembled for: ${TARGET_DEVS}")
endif()

# Function to generate kernel bitcode
function(gen_kernel_bc TARGET_ID INPUT_FILE OUTPUT_FILE)
set(CODE_OBJECT "${OUTPUT_FILE}.hsaco")
Expand Down
12 changes: 0 additions & 12 deletions src/core/runtime/trap_handler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,9 @@

cmake_minimum_required ( VERSION 3.7 )

# Import target 'clang' and 'llvm-objcopy'
find_package(Clang REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )
find_package(LLVM REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )

set (TARGET_DEVS "gfx900;gfx940;gfx941;gfx942;gfx1010;gfx1030;gfx1100")
set (POSTFIX "9;940;941;942;1010;10;11")

if(${CMAKE_VERBOSE_MAKEFILE})
get_property(clang_path TARGET clang PROPERTY LOCATION)
get_property(objcopy_path TARGET llvm-objcopy PROPERTY LOCATION)
message("Using clang from: ${clang_path}")
message("Using llvm-objcopy from: ${objcopy_path}")
message("Trap handlers assembled for: ${TARGET_DEVS}")
endif()

##==========================================
## Add custom command to generate a kernel code object file
##==========================================
Expand Down
21 changes: 6 additions & 15 deletions src/image/blit_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,26 @@

cmake_minimum_required ( VERSION 3.7 )

# Import target 'clang'
find_package(Clang REQUIRED HINTS ${CMAKE_PREFIX_PATH}/llvm PATHS /opt/rocm/llvm )

# Determine the target devices if not specified
if (NOT DEFINED TARGET_DEVICES)
set(TARGET_DEVICES "gfx700;gfx701;gfx702;gfx801;gfx802;gfx803;gfx805;gfx810;gfx900;gfx902;gfx904;gfx906;gfx908;gfx909;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx1010;gfx1011;gfx1012;gfx1013;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103")
endif()
set( TARGET_DEVICES ${TARGET_DEVICES} CACHE STRING "Build targets" FORCE )

if(${CMAKE_VERBOSE_MAKEFILE})
get_property(clang_path TARGET clang PROPERTY LOCATION)
message("Using clang from: ${clang_path}")
message("Build Setting:")
message(" Target Devices*: ${TARGET_DEVICES}")
message(" (Specify \";\" separated list of target IDs.)")
message(" Clang path: ${clang_path}")
endif()

##==========================================
## Add custom command to generate a kernel code object file
##==========================================
function(gen_kernel_bc TARGET_ID INPUT_FILE OUTPUT_FILE)

separate_arguments(CLANG_ARG_LIST UNIX_COMMAND
"-O2 -x cl -Xclang -finclude-default-header -cl-denorms-are-zero -cl-std=CL2.0
-target amdgcn-amd-amdhsa -mcpu=${TARGET_ID} -mcode-object-version=4
${ROCR_RUNTIME_CLANG_DEVICE_LIB_ARGS}
-o ${OUTPUT_FILE} ${INPUT_FILE}")

## Add custom command to produce a code object file.
## This depends on the kernel source file & compiler.
add_custom_command(OUTPUT ${OUTPUT_FILE} COMMAND clang ${CLANG_ARG_LIST}
DEPENDS ${INPUT_FILE} clang
DEPENDS ${INPUT_FILE} clang ${ROCR_RUNTIME_DEVICE_LIB_DEPS}
COMMENT "BUILDING bitcode for ${OUTPUT_FILE}..."
VERBATIM)

Expand Down Expand Up @@ -130,7 +118,10 @@ function(generate_blit_file BFILE)
DEPENDS ${HSACO_TARG_LIST} create_hsaco_ascii_file.sh )

## Export a target that builds (and depends on) opencl_blit_objects.cpp
add_custom_target( ${BFILE} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BFILE}.cpp )
add_custom_target(${BFILE}
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${BFILE}.cpp
${ROCR_RUNTIME_DEVICE_LIB_DEPS} )

endfunction(generate_blit_file)

Expand Down