Skip to content

Commit d239bf1

Browse files
committed
next release - update all code
1 parent 5ffcea6 commit d239bf1

27 files changed

+1428
-363
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ dist/
1212
hiprt/hiprt.h
1313
hiprt/hiprtew.h
1414
hiprt/cache/Kernels.h
15-
hiprt/cache/KernelArgs.h
15+
hiprt/cache/KernelArgs.h
16+
PUBLIC_OUT/

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "contrib/Orochi"]
22
path = contrib/Orochi
3-
url = https://github.com/amdadvtech/Orochi
3+
url = https://github.com/GPUOpen-LibrariesAndSDKs/Orochi
44
[submodule "contrib/easy-encryption"]
55
path = contrib/easy-encryption
66
url = https://github.com/amdadvtech/easy-encryption

CMakeLists.txt

Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(hiprt)
3+
4+
# Options
5+
option(BAKE_KERNEL "Encrypt and bake kernels" OFF)
6+
option(BITCODE "Enable bitcode linking" OFF)
7+
option(PRECOMPILE "Precompile kernels" OFF)
8+
option(HIPRTEW "Use hiprtew" OFF)
9+
10+
# Set C++ Standard
11+
set(CMAKE_CXX_STANDARD 17)
12+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
13+
14+
# Define GTEST_HAS_TR1_TUPLE=0 globally
15+
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
16+
17+
18+
19+
# Functions
20+
function(copy_dir src_dir dst_dir pattern)
21+
file(GLOB_RECURSE files "${src_dir}/${pattern}")
22+
foreach(file ${files})
23+
file(RELATIVE_PATH rel_file ${src_dir} ${file})
24+
set(target "${dst_dir}/${rel_file}")
25+
get_filename_component(target_dir ${target} DIRECTORY)
26+
file(MAKE_DIRECTORY ${target_dir})
27+
file(COPY ${file} DESTINATION ${target_dir})
28+
endforeach()
29+
endfunction()
30+
31+
32+
33+
function(file_exists file)
34+
if(EXISTS ${file})
35+
return(0)
36+
else()
37+
return(1)
38+
endif()
39+
endfunction()
40+
41+
function(read_file file)
42+
file(READ ${file} content)
43+
return(${content})
44+
endfunction()
45+
46+
47+
48+
function(get_version file)
49+
file(STRINGS ${file} lines)
50+
list(GET lines 0 major)
51+
list(GET lines 1 minor)
52+
list(GET lines 2 patch)
53+
set(patch_hex "0x${patch}")
54+
set(major ${major} PARENT_SCOPE)
55+
set(minor ${minor} PARENT_SCOPE)
56+
set(patch ${patch_hex} PARENT_SCOPE)
57+
endfunction()
58+
59+
60+
function(get_hip_sdk_version result)
61+
if(WIN32)
62+
set(root ".\\")
63+
endif()
64+
65+
set(exec_perl "")
66+
set(hipCommand "hipcc")
67+
set(HIP_PATH $ENV{HIP_PATH})
68+
set(PATH $ENV{PATH})
69+
set(hipInPath OFF)
70+
71+
# Check if HIP is in the PATH environment variable
72+
string(REPLACE ";" "\n" PATH_LIST ${PATH})
73+
foreach(token ${PATH_LIST})
74+
if("${token}" MATCHES "hip")
75+
if(EXISTS "${token}/hipcc")
76+
set(hipInPath ON)
77+
endif()
78+
endif()
79+
endforeach()
80+
81+
if(WIN32)
82+
set(exec_perl "perl")
83+
if(hipInPath)
84+
set(hipCommand "hipcc")
85+
elseif(NOT HIP_PATH)
86+
set(hipCommand "hipSdk\\bin\\hipcc")
87+
else()
88+
string(SUBSTRING ${HIP_PATH} -1 1 HIP_PATH_LAST_CHAR)
89+
if(HIP_PATH_LAST_CHAR STREQUAL "\\" OR HIP_PATH_LAST_CHAR STREQUAL "/")
90+
string(SUBSTRING ${HIP_PATH} 0 -1 HIP_PATH)
91+
endif()
92+
# HIP_PATH is expected to look like: C:\Program Files\AMD\ROCm\5.7
93+
set(hipCommand "\"${HIP_PATH}\\bin\\${hipCommand}\"")
94+
endif()
95+
endif()
96+
97+
file(WRITE ${CMAKE_BINARY_DIR}/hip_version_tmp.txt "")
98+
99+
# message(STATUS "hipCommand : ${hipCommand}")
100+
# message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
101+
102+
execute_process(
103+
COMMAND ${exec_perl} "${hipCommand}" --version
104+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/hip_version_tmp.txt
105+
# ERROR_QUIET
106+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
107+
)
108+
109+
file(READ ${CMAKE_BINARY_DIR}/hip_version_tmp.txt version_output)
110+
string(REGEX MATCH "[0-9]+\\.[0-9]+" version "${version_output}")
111+
112+
file(REMOVE ${CMAKE_BINARY_DIR}/hip_version_tmp.txt)
113+
114+
if(NOT version)
115+
set(version "HIP_SDK_NOT_FOUND")
116+
endif()
117+
118+
set(${result} ${version} PARENT_SCOPE)
119+
endfunction()
120+
121+
122+
123+
function(write_version_info in_file header_file version_file version_str_out)
124+
125+
if(NOT EXISTS ${version_file})
126+
message(FATAL_ERROR "Version.txt file missing!")
127+
endif()
128+
if(NOT EXISTS ${in_file})
129+
message(FATAL_ERROR "${in_file} file is missing!")
130+
endif()
131+
132+
# Read version file and extract version information
133+
get_version(${version_file})
134+
135+
# set(version "${major}${minor}")
136+
# set(version_str "${version}_${patch}")
137+
138+
# Read the content of the header template file
139+
file(READ ${in_file} header_content)
140+
141+
# Calculate HIPRT_API_VERSION
142+
math(EXPR HIPRT_VERSION "${major} * 1000 + ${minor}")
143+
144+
145+
# Format version_str as a zero-padded 5-digit string
146+
string(LENGTH "${HIPRT_VERSION}" HIPRT_VERSION_LEN)
147+
if(${HIPRT_VERSION_LEN} LESS 5)
148+
math(EXPR HIPRT_VERSION_PAD "5 - ${HIPRT_VERSION_LEN}")
149+
string(REPEAT "0" ${HIPRT_VERSION_PAD} HIPRT_VERSION_PADDED)
150+
set(version_str "${HIPRT_VERSION_PADDED}${HIPRT_VERSION}" )
151+
else()
152+
set(version_str "${HIPRT_VERSION}" )
153+
endif()
154+
155+
# message(STATUS "HIPRT_API_VERSION: ${version_str}_${patch}")
156+
157+
set(HIPRT_API_VERSION ${HIPRT_VERSION})
158+
159+
# Replace placeholders with actual version values
160+
string(REPLACE "@HIPRT_MAJOR_VERSION@" "${major}" header_content "${header_content}")
161+
string(REPLACE "@HIPRT_MINOR_VERSION@" "${minor}" header_content "${header_content}")
162+
string(REPLACE "@HIPRT_PATCH_VERSION@" "${patch}" header_content "${header_content}")
163+
string(REPLACE "@HIPRT_VERSION_STR@" "\"${version_str}\"" header_content "${header_content}")
164+
string(REPLACE "@HIPRT_API_VERSION@" "${HIPRT_API_VERSION}" header_content "${header_content}")
165+
166+
# Get HIP SDK version and replace placeholder
167+
get_hip_sdk_version(HIP_VERSION_STR)
168+
string(REPLACE "@HIP_VERSION_STR@" "\"${HIP_VERSION_STR}\"" header_content "${header_content}")
169+
170+
# Write the modified content to the header file
171+
file(WRITE ${header_file} "${header_content}")
172+
173+
set(${version_str_out} ${version_str} PARENT_SCOPE)
174+
endfunction()
175+
176+
177+
# Set up configurations
178+
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;DebugGpu" CACHE STRING "Configs" FORCE)
179+
180+
# Define platform-specific flags and settings
181+
if(WIN32)
182+
add_definitions(-D__WINDOWS__)
183+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4305 /wd4018 /wd4996 /Zc:__cplusplus")
184+
elseif(UNIX)
185+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
186+
endif()
187+
188+
add_definitions(-D__USE_HIP__)
189+
190+
191+
# Enable CUDA if possible
192+
include(${CMAKE_SOURCE_DIR}/contrib/Orochi/Orochi/enable_cuew.cmake)
193+
194+
195+
196+
# Base output directory
197+
set(BASE_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dist/bin)
198+
199+
# Set output directories for each build configuration
200+
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} Debug Release RelWithDebInfo MinSizeRel)
201+
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
202+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${BASE_OUTPUT_DIR}/${OUTPUTCONFIG})
203+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${BASE_OUTPUT_DIR}/${OUTPUTCONFIG})
204+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${BASE_OUTPUT_DIR}/${OUTPUTCONFIG})
205+
endforeach()
206+
207+
# Set output directories for single-configuration generators
208+
if(NOT CMAKE_CONFIGURATION_TYPES)
209+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE})
210+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE})
211+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE})
212+
endif()
213+
214+
215+
216+
217+
# Write version info
218+
set(version_str_ "UNDEF")
219+
write_version_info("${CMAKE_SOURCE_DIR}/hiprt/hiprt.h.in" "${CMAKE_SOURCE_DIR}/hiprt/hiprt.h" "${CMAKE_SOURCE_DIR}/version.txt" version_str_)
220+
write_version_info("${CMAKE_SOURCE_DIR}/hiprt/hiprtew.h.in" "${CMAKE_SOURCE_DIR}/hiprt/hiprtew.h" "${CMAKE_SOURCE_DIR}/version.txt" version_str_)
221+
222+
223+
set(HIPRT_NAME "hiprt${version_str_}")
224+
225+
# Project: HIPRT
226+
add_library(${HIPRT_NAME} SHARED)
227+
228+
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_EXPORTS)
229+
230+
231+
if( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" )
232+
set_target_properties(${HIPRT_NAME} PROPERTIES OUTPUT_NAME "${HIPRT_NAME}64D")
233+
else()
234+
set_target_properties(${HIPRT_NAME} PROPERTIES OUTPUT_NAME "${HIPRT_NAME}64")
235+
endif()
236+
237+
238+
if(BITCODE)
239+
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_BITCODE_LINKING ORO_PRECOMPILED)
240+
endif()
241+
242+
if(PRECOMPILE)
243+
execute_process(COMMAND python ${CMAKE_SOURCE_DIR}/scripts/bitcodes/compile.py)
244+
endif()
245+
246+
if(BAKE_KERNEL OR BITCODE)
247+
message(">> BakeKernel Executed")
248+
if(WIN32)
249+
execute_process(COMMAND mkdir hiprt/cache)
250+
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/tools/bakeKernel.bat)
251+
else()
252+
execute_process(COMMAND mkdir hiprt/cache)
253+
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/tools/bakeKernel.sh)
254+
endif()
255+
256+
if(BAKE_KERNEL)
257+
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_LOAD_FROM_STRING ORO_PP_LOAD_FROM_STRING)
258+
endif()
259+
endif()
260+
261+
if(WIN32)
262+
target_link_libraries(${HIPRT_NAME} version)
263+
endif()
264+
265+
266+
target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_SOURCE_DIR})
267+
target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/contrib/Orochi)
268+
269+
file(GLOB_RECURSE hiprt_sources "${CMAKE_SOURCE_DIR}/hiprt/*.h" "${CMAKE_SOURCE_DIR}/hiprt/*.cpp" "${CMAKE_SOURCE_DIR}/hiprt/*.inl")
270+
list(FILTER hiprt_sources EXCLUDE REGEX "hiprt/bitcodes/.*")
271+
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")
272+
target_sources(${HIPRT_NAME} PRIVATE ${hiprt_sources} ${orochi_sources})
273+
274+
# Project: Unit Test
275+
add_executable(unittest)
276+
277+
if(BITCODE)
278+
target_compile_definitions(unittest PRIVATE HIPRT_BITCODE_LINKING)
279+
endif()
280+
if(WIN32)
281+
target_compile_options(unittest PRIVATE /wd4244)
282+
target_link_libraries(unittest PRIVATE version)
283+
endif()
284+
285+
if( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" )
286+
set_target_properties(unittest PROPERTIES OUTPUT_NAME "unittest64D")
287+
else()
288+
set_target_properties(unittest PROPERTIES OUTPUT_NAME "unittest64")
289+
endif()
290+
291+
292+
target_include_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/contrib/Orochi)
293+
target_link_libraries(unittest PRIVATE ${HIPRT_NAME})
294+
295+
if(UNIX)
296+
target_link_libraries(unittest PRIVATE pthread dl)
297+
endif()
298+
299+
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")
300+
301+
302+
target_sources(unittest PRIVATE ${unittest_sources} ${orochi_sources})
303+
304+
target_include_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/gtest-1.6.0 ${CMAKE_SOURCE_DIR}/contrib/embree/include)
305+
306+
307+
308+
309+
310+
if(WIN32)
311+
312+
# Use target_link_directories to specify additional library directories
313+
target_link_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/embree/win)
314+
target_link_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/bin/win64)
315+
316+
copy_dir(${CMAKE_SOURCE_DIR}/contrib/embree/win ${CMAKE_SOURCE_DIR}/dist/bin/Release "*.dll")
317+
copy_dir(${CMAKE_SOURCE_DIR}/contrib/embree/win ${CMAKE_SOURCE_DIR}/dist/bin/Debug "*.dll")
318+
copy_dir(${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/bin/win64 ${CMAKE_SOURCE_DIR}/dist/bin/Release "*.dll")
319+
copy_dir(${CMAKE_SOURCE_DIR}/contrib/Orochi/contrib/bin/win64 ${CMAKE_SOURCE_DIR}/dist/bin/Debug "*.dll")
320+
321+
# Explicitly link libraries from contrib/embree/win and contrib/bin/win64
322+
target_link_libraries(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/embree/win/embree4.lib)
323+
324+
endif()
325+
326+
327+
if(UNIX)
328+
target_link_directories(unittest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/embree/linux)
329+
endif()
330+
331+
332+
333+
334+
target_link_libraries(unittest PRIVATE embree4 tbb)
335+
336+
# Project: HIPRTEW Test
337+
if(HIPRTEW)
338+
add_executable(hiprtewtest)
339+
340+
target_compile_definitions(hiprtewtest PRIVATE HIPRT_EXPORTS USE_HIPRTEW)
341+
if(WIN32)
342+
target_compile_options(hiprtewtest PRIVATE /wd4244)
343+
target_link_libraries(hiprtewtest PRIVATE version)
344+
endif()
345+
346+
target_include_directories(hiprtewtest PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/contrib/Orochi)
347+
if(UNIX)
348+
target_link_libraries(hiprtewtest PRIVATE pthread dl)
349+
endif()
350+
351+
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")
352+
target_sources(hiprtewtest PRIVATE ${hiprtewtest_sources} ${orochi_sources})
353+
354+
target_include_directories(hiprtewtest PRIVATE ${CMAKE_SOURCE_DIR}/contrib/gtest-1.6.0)
355+
356+
target_compile_definitions(hiprtewtest PRIVATE GTEST_HAS_TR1_TUPLE=0)
357+
endif()

0 commit comments

Comments
 (0)