Skip to content

Commit

Permalink
update cmake from latest internal repo
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardGe committed Sep 5, 2024
1 parent 4996b97 commit 83e18cc
Showing 1 changed file with 66 additions and 34 deletions.
100 changes: 66 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
project(hiprt)

# Options
option(BAKE_KERNEL "enable the use of encrypted and baked kernels" OFF)
option(BAKE_KERNEL "Enable the use of encrypted and baked kernels" OFF)
option(BITCODE "Enable bitcode linking" OFF)
option(PRECOMPILE "Precompile kernels" OFF)
option(HIPRTEW "Use hiprtew" OFF)
Expand Down Expand Up @@ -31,6 +31,9 @@ add_definitions(-DGTEST_HAS_TR1_TUPLE=0)






# Functions
function(copy_dir src_dir dst_dir pattern)
file(GLOB_RECURSE files "${src_dir}/${pattern}")
Expand Down Expand Up @@ -252,8 +255,13 @@ endif()
add_definitions(-D__USE_HIP__)


# this define is to identify that we are on the public repository of HIPRT.
# it helps AMD to maintain both a public and a private repo for experimentation.
add_definitions(-DHIPRT_PUBLIC_REPO)


# Enable CUDA if possible
include(${CMAKE_SOURCE_DIR}/contrib/Orochi/Orochi/enable_cuew.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/Orochi/enable_cuew.cmake)



Expand Down Expand Up @@ -282,8 +290,8 @@ endif()

# Write version info
set(version_str_ "UNDEF")
write_version_info("${CMAKE_SOURCE_DIR}/hiprt/hiprt.h.in" "${CMAKE_SOURCE_DIR}/hiprt/hiprt.h" "${CMAKE_SOURCE_DIR}/version.txt" version_str_)
write_version_info("${CMAKE_SOURCE_DIR}/hiprt/hiprtew.h.in" "${CMAKE_SOURCE_DIR}/hiprt/hiprtew.h" "${CMAKE_SOURCE_DIR}/version.txt" version_str_)
write_version_info("${CMAKE_CURRENT_SOURCE_DIR}/hiprt/hiprt.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/hiprt.h" "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" version_str_)
write_version_info("${CMAKE_CURRENT_SOURCE_DIR}/hiprt/hiprtew.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/hiprtew.h" "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" version_str_)


set(HIPRT_NAME "hiprt${version_str_}")
Expand Down Expand Up @@ -321,13 +329,13 @@ endif()
if(PRECOMPILE)
execute_process(
COMMAND python compile.py --nvidia --hipSdkPath ${HIP_PATH}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/scripts/bitcodes
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bitcodes
)

if(NOT NO_UNITTEST)
execute_process(
COMMAND python precompile_bitcode.py --nvidia --hipSdkPath ${HIP_PATH}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/scripts/bitcodes
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bitcodes
)
endif()

Expand All @@ -337,32 +345,46 @@ endif()
if(BAKE_KERNEL OR GENERATE_BAKE_KERNEL)
message(">> BakeKernel Executed")
if(WIN32)
execute_process(COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/hiprt/cache)
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/tools/bakeKernel.bat)
execute_process(
COMMAND mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/hiprt/cache
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/bakeKernel.bat
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
else()
execute_process(COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/hiprt/cache)
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/tools/bakeKernel.sh)
execute_process(
COMMAND mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/hiprt/cache
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/bakeKernel.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()

if(BAKE_KERNEL)
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_LOAD_FROM_STRING ORO_PP_LOAD_FROM_STRING)
endif()

target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_BAKE_KERNEL_GENERATED)


endif()

if(BAKE_KERNEL)
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_LOAD_FROM_STRING ORO_PP_LOAD_FROM_STRING)
endif()



if(WIN32)
target_link_libraries(${HIPRT_NAME} version)
endif()


target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_SOURCE_DIR})
target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/contrib/Orochi)
target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi)

file(GLOB_RECURSE hiprt_sources "${CMAKE_SOURCE_DIR}/hiprt/*.h" "${CMAKE_SOURCE_DIR}/hiprt/*.cpp" "${CMAKE_SOURCE_DIR}/hiprt/*.inl")
file(GLOB_RECURSE hiprt_sources "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/*.inl")
list(FILTER hiprt_sources EXCLUDE REGEX "hiprt/bitcodes/.*")
file(GLOB_RECURSE orochi_sources "${CMAKE_SOURCE_DIR}/contrib/Orochi/Orochi/*.h" "${CMAKE_SOURCE_DIR}/contrib/Orochi/Orochi/*.cpp" "${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/cuew/*.h" "${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/cuew/*.cpp" "${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/hipew/*.h" "${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/hipew/*.cpp" "${CMAKE_SOURCE_DIR}/contrib/Orochi/ParallelPrimitives/*.h" "${CMAKE_SOURCE_DIR}/contrib/Orochi/ParallelPrimitives/*.cpp")
file(GLOB_RECURSE orochi_sources "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/Orochi/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/Orochi/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/contrib/cuew/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/contrib/cuew/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/contrib/hipew/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/contrib/hipew/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/ParallelPrimitives/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/ParallelPrimitives/*.cpp")
target_sources(${HIPRT_NAME} PRIVATE ${hiprt_sources} ${orochi_sources})


Expand All @@ -375,10 +397,20 @@ target_sources(${HIPRT_NAME} PRIVATE ${hiprt_sources} ${orochi_sources})
install(TARGETS ${HIPRT_NAME} DESTINATION bin)

# add header files
file(GLOB HIPRT_HEADERS "${CMAKE_SOURCE_DIR}/hiprt/*.h")
file(GLOB HIPRT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/*.h")
install(FILES ${HIPRT_HEADERS}
DESTINATION include/hiprt)

# add header files from implementation folder
file(GLOB HIPRT_IMPL_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/impl/*.h")
install(FILES ${HIPRT_IMPL_HEADERS}
DESTINATION include/hiprt/impl)

# add some header files from Orochi
file(GLOB HIPRT_ORO_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/ParallelPrimitives/*.h")
install(FILES ${HIPRT_ORO_HEADERS}
DESTINATION include/contrib/Orochi/ParallelPrimitives)

# add hipfb files
file(GLOB HIPRT_HIPFB_FILES "${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE}/*.hipfb")
install(FILES ${HIPRT_HIPFB_FILES}
Expand Down Expand Up @@ -407,40 +439,40 @@ if(NOT NO_UNITTEST)
endif()


target_include_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/contrib/Orochi)
target_include_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi)
target_link_libraries(unittest PRIVATE ${HIPRT_NAME})

if(UNIX)
target_link_libraries(unittest PRIVATE pthread dl)
endif()

file(GLOB_RECURSE unittest_sources "${CMAKE_SOURCE_DIR}/test/hiprtT*.h" "${CMAKE_SOURCE_DIR}/test/hiprtT*.cpp" "${CMAKE_SOURCE_DIR}/test/shared.h" "${CMAKE_SOURCE_DIR}/test/main.cpp" "${CMAKE_SOURCE_DIR}/test/CornellBox.h" "${CMAKE_SOURCE_DIR}/test/kernels/*.h" "${CMAKE_SOURCE_DIR}/contrib/gtest-1.6.0/gtest-all.cc")
file(GLOB_RECURSE unittest_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/hiprtT*.h" "${CMAKE_CURRENT_SOURCE_DIR}/test/hiprtT*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test/shared.h" "${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test/CornellBox.h" "${CMAKE_CURRENT_SOURCE_DIR}/test/kernels/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/gtest-1.6.0/gtest-all.cc")


target_sources(unittest PRIVATE ${unittest_sources} ${orochi_sources})

target_include_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/gtest-1.6.0 ${CMAKE_SOURCE_DIR}/contrib/embree/include)
target_include_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/gtest-1.6.0 ${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/include)


if(WIN32)

# Use target_link_directories to specify additional library directories
target_link_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/embree/win)
target_link_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/bin/win64)
target_link_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/win)
target_link_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/bin/win64)

copy_dir(${CMAKE_SOURCE_DIR}/contrib/embree/win ${CMAKE_SOURCE_DIR}/dist/bin/Release "*.dll")
copy_dir(${CMAKE_SOURCE_DIR}/contrib/embree/win ${CMAKE_SOURCE_DIR}/dist/bin/Debug "*.dll")
copy_dir(${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/bin/win64 ${CMAKE_SOURCE_DIR}/dist/bin/Release "*.dll")
copy_dir(${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/bin/win64 ${CMAKE_SOURCE_DIR}/dist/bin/Debug "*.dll")
copy_dir(${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/win ${CMAKE_CURRENT_SOURCE_DIR}/dist/bin/Release "*.dll")
copy_dir(${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/win ${CMAKE_CURRENT_SOURCE_DIR}/dist/bin/Debug "*.dll")
copy_dir(${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/contrib/bin/win64 ${CMAKE_CURRENT_SOURCE_DIR}/dist/bin/Release "*.dll")
copy_dir(${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/contrib/bin/win64 ${CMAKE_CURRENT_SOURCE_DIR}/dist/bin/Debug "*.dll")

# Explicitly link libraries from contrib/embree/win and contrib/bin/win64
target_link_libraries(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/embree/win/embree4.lib)
target_link_libraries(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/win/embree4.lib)

endif()


if(UNIX)
target_link_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/embree/linux)
target_link_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/linux)
endif()

target_link_libraries(unittest PRIVATE embree4 tbb)
Expand All @@ -458,15 +490,15 @@ if(HIPRTEW)
target_link_libraries(hiprtewtest PRIVATE version)
endif()

target_include_directories(hiprtewtest PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/contrib/Orochi)
target_include_directories(hiprtewtest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi)
if(UNIX)
target_link_libraries(hiprtewtest PRIVATE pthread dl)
endif()

file(GLOB_RECURSE hiprtewtest_sources "${CMAKE_SOURCE_DIR}/test/hiprtewTest.h" "${CMAKE_SOURCE_DIR}/test/hiprtewTest.cpp" "${CMAKE_SOURCE_DIR}/contrib/gtest-1.6.0/gtest-all.cc")
file(GLOB_RECURSE hiprtewtest_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/hiprtewTest.h" "${CMAKE_CURRENT_SOURCE_DIR}/test/hiprtewTest.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/gtest-1.6.0/gtest-all.cc")
target_sources(hiprtewtest PRIVATE ${hiprtewtest_sources} ${orochi_sources})

target_include_directories(hiprtewtest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/gtest-1.6.0)
target_include_directories(hiprtewtest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/gtest-1.6.0)

target_compile_definitions(hiprtewtest PRIVATE GTEST_HAS_TR1_TUPLE=0)
endif()

0 comments on commit 83e18cc

Please sign in to comment.