forked from GPUOpen-LibrariesAndSDKs/HIPRT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
722 lines (520 loc) · 24.2 KB
/
CMakeLists.txt
File metadata and controls
722 lines (520 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
cmake_minimum_required(VERSION 3.19) # at least 3.19 in order to have the compression-level in Zstd
project(hiprt)
#
# Options
#
# Only one of those 3 flags should be ON at a time, or none. Multiple flags ON are untested and may cause issues.
option(BAKE_KERNEL "Enable the use of baked kernels source code" OFF)
option(BAKE_COMPILED_KERNEL "If enabled, the kernels will be compiled and embedded as a buffer inside the binary. if you do that, you should also enable the flag 'PRECOMPILE'" OFF)
option(BITCODE "Enable bitcode linking: when running the program, it's expected to find precompiled kernels as external files." OFF)
option(PRECOMPILE "Precompile kernels" OFF)
option(HIPRTEW "Use hiprtew" OFF)
option(NO_UNITTEST "Don't build unit tests" OFF)
option(COMPILED_COMPRESSION "enable compression of compiled kernels" ON) # this argument is only used if BAKE_COMPILED_KERNEL is enabled -- advised to let it 'ON' as it's the path tested by the HIPRT team.
option(FORCE_DISABLE_CUDA "By default Cuda support is automatically added if a Cuda install is detected. Turn this flag to ON to force Cuda to be disabled." OFF)
find_program(PYTHON_EXECUTABLE
NAMES python
PATHS /usr/bin /usr/local/bin /opt/local/bin
)
message(STATUS "Python path = ${PYTHON_EXECUTABLE}")
# GENERATE_BAKE_KERNEL is enabled by default if we use the flags 'BAKE_KERNEL' or 'BITCODE'.
# It can be forced to OFF, but in this case, some building functions from the HIPRT API, like hiprtBuildTraceKernelsFromBitcode will fail.
if(BAKE_KERNEL OR BITCODE)
set(GENERATE_BAKE_KERNEL___DEFAULT ON)
else()
set(GENERATE_BAKE_KERNEL___DEFAULT OFF)
endif()
option(GENERATE_BAKE_KERNEL "generate the baked kernels" ${GENERATE_BAKE_KERNEL___DEFAULT})
message(STATUS "GENERATE_BAKE_KERNEL= ${GENERATE_BAKE_KERNEL}")
# Set C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Define GTEST_HAS_TR1_TUPLE=0 globally
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
# Functions
function(copy_dir src_dir dst_dir pattern)
file(GLOB_RECURSE files "${src_dir}/${pattern}")
foreach(file ${files})
file(RELATIVE_PATH rel_file ${src_dir} ${file})
set(target "${dst_dir}/${rel_file}")
get_filename_component(target_dir ${target} DIRECTORY)
file(MAKE_DIRECTORY ${target_dir})
file(COPY ${file} DESTINATION ${target_dir})
endforeach()
endfunction()
function(file_exists file)
if(EXISTS ${file})
return(0)
else()
return(1)
endif()
endfunction()
function(read_file file)
file(READ ${file} content)
return(${content})
endfunction()
function(get_version file)
file(STRINGS ${file} lines)
list(GET lines 0 major)
list(GET lines 1 minor)
list(GET lines 2 patch)
list(GET lines 3 hash)
set(patch_hex "0x${hash}")
set(major ${major} PARENT_SCOPE)
set(minor ${minor} PARENT_SCOPE)
set(patch ${patch} PARENT_SCOPE)
set(hash ${patch_hex} PARENT_SCOPE)
endfunction()
# Remove the last character from the string if it's a / or \\
function(remove_trailing_slash strInOut)
string(LENGTH "${${strInOut}}" strLength)
math(EXPR lastIndex "${strLength} - 1")
string(SUBSTRING "${${strInOut}}" ${lastIndex} 1 lastChar)
if("${lastChar}" STREQUAL "\\" OR "${lastChar}" STREQUAL "/")
string(SUBSTRING "${${strInOut}}" 0 ${lastIndex} strInOut_modified)
set(${strInOut} "${strInOut_modified}" PARENT_SCOPE)
endif()
endfunction()
# 'result' is the HIP version as string, for example: 6.2
# 'result_path' is the output of the path to HIP, for example: C:\Program Files\AMD\ROCm\6.2
function(get_hip_sdk_version result result_path)
if(WIN32)
set(root ".\\")
endif()
set(exec_perl "")
set(hipCommand "hipcc")
set(PATH $ENV{PATH})
set(useHipFromPATH OFF)
# Check if HIP_PATH is defined as a CMake parameter
if(DEFINED HIP_PATH)
message(STATUS "HIP_PATH is defined as a CMake parameter: ${HIP_PATH}")
# Check if HIP_PATH is defined as an environment variable
elseif(DEFINED ENV{HIP_PATH})
set(HIP_PATH $ENV{HIP_PATH})
message(STATUS "HIP_PATH is defined as an environment variable: ${HIP_PATH}")
# if HIP_PATH is not in cmake, and not in environment variable
else()
message(WARNING "WARNING: HIP_PATH is not defined as a CMake parameter or an environment variable - NOT RECOMMENDED")
# TODO: improve that, but it's not recommanded to use the cmake script without defining HIP_PATH anyway...
set(${result_path} "UNKONWN_PATH" PARENT_SCOPE)
# Check if HIP is in the PATH environment variable
string(REPLACE ";" "\n" PATH_LIST ${PATH})
foreach(token ${PATH_LIST})
if("${token}" MATCHES "hip")
if(EXISTS "${token}/hipcc")
set(useHipFromPATH ON)
endif()
endif()
endforeach()
endif()
# clean/format HIP_PATH here.
if ( HIP_PATH )
remove_trailing_slash(HIP_PATH)
# message(STATUS "HIP_PATH formatted: ${HIP_PATH}")
set(${result_path} ${HIP_PATH} PARENT_SCOPE)
endif()
# build hip command for Windows
if(WIN32)
set(exec_perl "perl")
if(NOT HIP_PATH)
if(useHipFromPATH)
set(hipCommand "hipcc")
else()
# use special path used by HIPRT developers
if(EXISTS "hipSdk\\bin\\hipcc.exe")
set(exec_perl "")
set(hipCommand "hipSdk\\bin\\hipcc.exe")
else()
set(hipCommand "hipSdk\\bin\\hipcc")
endif()
endif()
else()
# HIP_PATH is expected to look like: C:\Program Files\AMD\ROCm\5.7
if(EXISTS "${HIP_PATH}\\bin\\hipcc.exe")
# in newer version of HIP SDK (>= 6.3), we are using 'hipcc.exe --version' to check the version
# message(STATUS "using hipcc.exe to get the version")
set(exec_perl "")
set(hipCommand "${HIP_PATH}\\bin\\hipcc.exe")
else()
# in older version of HIP SDK, we are using 'perl hipcc --version' to check the version
# message(STATUS "using perl hipcc to get the version")
set(hipCommand "${HIP_PATH}\\bin\\${hipCommand}")
endif()
endif()
# build hip command for Linux
else()
# If not defined we try to take it from the PATH
if(NOT HIP_PATH)
set(hipCommand "hipcc")
# otherwise, build the hipcc command with full path.
else()
set(hipCommand "${HIP_PATH}/bin/${hipCommand}")
endif()
endif()
file(WRITE ${CMAKE_BINARY_DIR}/hip_version_tmp.txt "")
# message(STATUS "hipCommand : ${hipCommand}")
# message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
execute_process(
COMMAND ${exec_perl} "${hipCommand}" --version
OUTPUT_FILE ${CMAKE_BINARY_DIR}/hip_version_tmp.txt
# ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
file(READ ${CMAKE_BINARY_DIR}/hip_version_tmp.txt version_output)
string(REGEX MATCH "[0-9]+\\.[0-9]+" version "${version_output}")
file(REMOVE ${CMAKE_BINARY_DIR}/hip_version_tmp.txt)
if(NOT version)
set(version "HIP_SDK_NOT_FOUND")
endif()
message(STATUS "HIP VERSION from command : ${version}")
set(${result} ${version} PARENT_SCOPE)
endfunction()
# fill the HIP_VERSION_STR variable, it will look like: "6.2"
# also get the path to hip that'll be used along all this cmake.
get_hip_sdk_version(HIP_VERSION_STR HIP_FINAL_PATH)
message(STATUS "HIP_VERSION_STR = ${HIP_VERSION_STR}")
message(STATUS "HIP_FINAL_PATH = ${HIP_FINAL_PATH}")
function(write_version_info in_file header_file version_file version_str_out)
if(NOT EXISTS ${version_file})
message(FATAL_ERROR "Version.txt file missing!")
endif()
if(NOT EXISTS ${in_file})
message(FATAL_ERROR "${in_file} file is missing!")
endif()
# Read version file and extract version information
get_version(${version_file})
# set(version "${major}${minor}")
# set(version_str "${version}_${hash}")
# Read the content of the header template file
file(READ ${in_file} header_content)
# Calculate HIPRT_API_VERSION
math(EXPR HIPRT_VERSION "${major} * 1000 + ${minor}")
# Format version_str as a zero-padded 5-digit string
string(LENGTH "${HIPRT_VERSION}" HIPRT_VERSION_LEN)
if(${HIPRT_VERSION_LEN} LESS 5)
math(EXPR HIPRT_VERSION_PAD "5 - ${HIPRT_VERSION_LEN}")
string(REPEAT "0" ${HIPRT_VERSION_PAD} HIPRT_VERSION_PADDED)
set(version_str "${HIPRT_VERSION_PADDED}${HIPRT_VERSION}" )
else()
set(version_str "${HIPRT_VERSION}" )
endif()
# message(STATUS "HIPRT_API_VERSION: ${version_str}_${hash}")
set(HIPRT_API_VERSION ${HIPRT_VERSION})
# Replace placeholders with actual version values
string(REPLACE "@HIPRT_MAJOR_VERSION@" "${major}" header_content "${header_content}")
string(REPLACE "@HIPRT_MINOR_VERSION@" "${minor}" header_content "${header_content}")
string(REPLACE "@HIPRT_PATCH_VERSION@" "${patch}" header_content "${header_content}")
string(REPLACE "@HIPRT_HASH_VERSION@" "${hash}" header_content "${header_content}")
string(REPLACE "@HIPRT_VERSION_STR@" "\"${version_str}\"" header_content "${header_content}")
string(REPLACE "@HIPRT_API_VERSION@" "${HIPRT_API_VERSION}" header_content "${header_content}")
# Get HIP SDK version and replace placeholder
string(REPLACE "@HIP_VERSION_STR@" "\"${HIP_VERSION_STR}\"" header_content "${header_content}")
# Write the modified content to the header file
file(WRITE ${header_file} "${header_content}")
set(${version_str_out} ${version_str} PARENT_SCOPE)
endfunction()
# Set up configurations
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;DebugGpu" CACHE STRING "Configs" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUGGPU "")
set(CMAKE_EXE_LINKER_FLAGS_DEBUGGPU "")
# Define platform-specific flags and settings
if(WIN32)
add_definitions(-D__WINDOWS__)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4305 /wd4018 /wd4996 /Zc:__cplusplus")
elseif(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
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)
if (NOT FORCE_DISABLE_CUDA)
# Enable CUDA if possible
include(${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/Orochi/enable_cuew.cmake)
else()
message(STATUS "CUDA support is forced to disabled.")
endif()
# Base output directory
set(BASE_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dist/bin)
file(MAKE_DIRECTORY "${BASE_OUTPUT_DIR}/Debug")
file(MAKE_DIRECTORY "${BASE_OUTPUT_DIR}/Release")
# Set output directories for each build configuration
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} Debug Release RelWithDebInfo MinSizeRel)
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${BASE_OUTPUT_DIR}/${OUTPUTCONFIG})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${BASE_OUTPUT_DIR}/${OUTPUTCONFIG})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${BASE_OUTPUT_DIR}/${OUTPUTCONFIG})
endforeach()
# Set output directories for single-configuration generators
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE})
endif()
# Write version info
set(version_str_ "UNDEF")
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_}")
# Project: HIPRT
add_library(${HIPRT_NAME} SHARED)
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_EXPORTS)
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
set_target_properties(${HIPRT_NAME} PROPERTIES OUTPUT_NAME "${HIPRT_NAME}64D")
else()
set_target_properties(${HIPRT_NAME} PROPERTIES OUTPUT_NAME "${HIPRT_NAME}64")
endif()
if(BITCODE)
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_BITCODE_LINKING ORO_PRECOMPILED)
endif()
# files generated by compile.py and precompile_bitcode.py
if(WIN32)
set(KERNEL_OS_POSTFIX "win")
else()
set(KERNEL_OS_POSTFIX "linux")
endif()
set(KERNEL_HIPRT_COMP "${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE}/hiprt${version_str_}_${HIP_VERSION_STR}_amd.hipfb") # example: hiprt02005_6.2_amd.hipfb
set(KERNEL_UNITTEST_COMP "${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE}/hiprt${version_str_}_${HIP_VERSION_STR}_precompiled_bitcode_${KERNEL_OS_POSTFIX}.hipfb") # example: hiprt02005_6.2_precompiled_bitcode_win.hipfb
set(KERNEL_OROCHI_COMP "${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE}/oro_compiled_kernels.hipfb")
# temp files: compiled kernel, compressed.
set(KERNEL_HIPRT_COMP_COMPRESSED "${CMAKE_BINARY_DIR}/hiprt${version_str_}_${HIP_VERSION_STR}_amd.zstd" )
set(KERNEL_OROCHI_COMP_COMPRESSED "${CMAKE_BINARY_DIR}/oro_compiled_kernels.zstd" )
# precompile kernels:
if(PRECOMPILE)
if(FORCE_DISABLE_CUDA)
set(CUDA_OPTION "")
else()
set(CUDA_OPTION "--nvidia")
endif()
set(bvh_source
${CMAKE_SOURCE_DIR}/hiprt/hiprt_vec.h
${CMAKE_SOURCE_DIR}/hiprt/hiprt_math.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Aabb.h
${CMAKE_SOURCE_DIR}/hiprt/impl/AabbList.h
${CMAKE_SOURCE_DIR}/hiprt/impl/BvhCommon.h
${CMAKE_SOURCE_DIR}/hiprt/impl/BvhNode.h
${CMAKE_SOURCE_DIR}/hiprt/impl/QrDecomposition.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Quaternion.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Transform.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Instance.h
${CMAKE_SOURCE_DIR}/hiprt/impl/InstanceList.h
${CMAKE_SOURCE_DIR}/hiprt/impl/MortonCode.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Header.h
${CMAKE_SOURCE_DIR}/hiprt/impl/TriangleMesh.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Triangle.h
${CMAKE_SOURCE_DIR}/hiprt/impl/BvhBuilderUtil.h
${CMAKE_SOURCE_DIR}/hiprt/impl/SbvhCommon.h
${CMAKE_SOURCE_DIR}/hiprt/impl/BvhConfig.h
${CMAKE_SOURCE_DIR}/hiprt/impl/NodeList.h
${CMAKE_SOURCE_DIR}/hiprt/impl/MemoryArena.h
${CMAKE_SOURCE_DIR}/hiprt/impl/Obb.h
${CMAKE_SOURCE_DIR}/hiprt/hiprt_types.h
${CMAKE_SOURCE_DIR}/hiprt/hiprt_common.h
)
message(">> add_custom_command: ${PYTHON_EXECUTABLE} compile.py ${CUDA_OPTION} --hipSdkPath \"${HIP_FINAL_PATH}\"")
add_custom_command(
OUTPUT ${KERNEL_HIPRT_COMP} ${KERNEL_OROCHI_COMP}
COMMAND ${PYTHON_EXECUTABLE} compile.py ${CUDA_OPTION} --hipSdkPath ${HIP_FINAL_PATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bitcodes
COMMENT "Precompiling kernels via compile.py"
VERBATIM
DEPENDS ${bvh_source}
)
# create the 'precompile_kernels' project
add_custom_target(precompile_kernels ALL
DEPENDS ${KERNEL_HIPRT_COMP} ${KERNEL_OROCHI_COMP}
)
if(NOT NO_UNITTEST)
set(unittest_kernel_source
${CMAKE_SOURCE_DIR}/test/bitcodes/custom_func_table.cpp
${CMAKE_SOURCE_DIR}/test/bitcodes/unit_test.cpp
)
message(">> add_custom_command: ${PYTHON_EXECUTABLE} precompile_bitcode.py ${CUDA_OPTION} --hipSdkPath \"${HIP_FINAL_PATH}\"")
add_custom_command(
OUTPUT ${KERNEL_UNITTEST_COMP}
COMMAND ${PYTHON_EXECUTABLE} precompile_bitcode.py ${CUDA_OPTION} --hipSdkPath ${HIP_FINAL_PATH}
DEPENDS ${KERNEL_HIPRT_COMP} # Ensure compile.py has already run.
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bitcodes
COMMENT "Precompiling unit tests kernels via precompile_bitcode.py"
VERBATIM
DEPENDS ${unittest_kernel_source}
)
# create the 'precompile_unittest_kernels' project
add_custom_target(precompile_unittest_kernels ALL
DEPENDS ${KERNEL_UNITTEST_COMP}
)
add_dependencies(${HIPRT_NAME} precompile_unittest_kernels)
endif()
endif()
# convert the binary to a buffer that will be embeded inside the binary
# it's expected the step 'PRECOMPILE' has been executed.
if ( BAKE_COMPILED_KERNEL )
message(">> precompiled will be embedded.")
set(PYTHON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/scripts/convert_binary_to_array.py")
set(ARCHIVE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/scripts/create_archive.cmake")
# HIPRT binary
set(KERNEL_HIPRT_H "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/impl/bvh_build_array.h")
add_custom_command(
OUTPUT ${KERNEL_HIPRT_H}
# 1) Create the Zstd archive
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE=${KERNEL_HIPRT_COMP} -DOUTPUT_FILE=${KERNEL_HIPRT_COMP_COMPRESSED} -DDO_COMPRESS=${COMPILED_COMPRESSION} -P ${ARCHIVE_SCRIPT}
# 2) Run the Python converter on that archive
COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE} ${KERNEL_HIPRT_COMP} ${KERNEL_HIPRT_COMP_COMPRESSED} ${KERNEL_HIPRT_H} ${COMPILED_COMPRESSION}
DEPENDS ${KERNEL_HIPRT_COMP} # Ensure compile.py has already run.
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Converting HIPRT compiled kernel to header"
VERBATIM
)
# Orochi binary
set(KERNEL_OROCHI_H "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi/ParallelPrimitives/cache/oro_compiled_kernels.h")
add_custom_command(
OUTPUT ${KERNEL_OROCHI_H}
# 1) Create the Zstd archive
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE=${KERNEL_OROCHI_COMP} -DOUTPUT_FILE=${KERNEL_OROCHI_COMP_COMPRESSED} -DDO_COMPRESS=${COMPILED_COMPRESSION} -P ${ARCHIVE_SCRIPT}
# 2) Run the Python converter on that archive
COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE} ${KERNEL_OROCHI_COMP} ${KERNEL_OROCHI_COMP_COMPRESSED} ${KERNEL_OROCHI_H} ${COMPILED_COMPRESSION}
DEPENDS ${KERNEL_OROCHI_COMP} # Ensure compile.py has already run.
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Converting Orochi compiled kernel to header"
VERBATIM
)
# Create the 'bake_compiled_kernels' project
add_custom_target(bake_compiled_kernels ALL
DEPENDS ${KERNEL_HIPRT_H} ${KERNEL_OROCHI_H} precompile_kernels
)
add_dependencies(${HIPRT_NAME} precompile_kernels bake_compiled_kernels)
endif()
if(BAKE_KERNEL OR GENERATE_BAKE_KERNEL)
message(">> BakeKernel Executed")
if(WIN32)
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/bakeKernel.bat
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
else()
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/bakeKernel.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_BAKE_KERNEL_GENERATED)
endif()
if ( BAKE_COMPILED_KERNEL )
if ( COMPILED_COMPRESSION )
# Gather minimal Zstd sources
file(GLOB ZSTD_SRCS
contrib/zstd/lib/common/*.c
contrib/zstd/lib/decompress/*.c
)
# Build a static lib zstd_embedded
add_library(zstd_embedded STATIC
${ZSTD_SRCS}
)
# Include Zstd headers
target_include_directories(zstd_embedded
PUBLIC
contrib/zstd/lib
)
set_target_properties(zstd_embedded PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC
target_compile_definitions(zstd_embedded PRIVATE ZSTD_DISABLE_ASM) # disable ASM for easier build
# Link against zstd_embedded
target_link_libraries(${HIPRT_NAME} zstd_embedded )
# the 'ORO_LINK_ZSTD' flag enables use of ZSTD API in the source code.
target_compile_definitions(${HIPRT_NAME} PRIVATE ORO_LINK_ZSTD)
endif()
# enable the 'BAKE_COMPILED_KERNEL' on Orochi: this mode is activated by adding those 2 defines.
target_compile_definitions(${HIPRT_NAME} PRIVATE ORO_PP_LOAD_FROM_STRING HIPRT_BITCODE_LINKING ORO_PRECOMPILED)
#enable the 'BAKE_COMPILED_KERNEL' on HIPRT:
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_BAKE_COMPILED_KERNEL )
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_CURRENT_SOURCE_DIR})
target_include_directories(${HIPRT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/Orochi)
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_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})
#
# install script
#
install(TARGETS ${HIPRT_NAME} DESTINATION bin)
# add header files
file(GLOB HIPRT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/*.h")
install(FILES ${HIPRT_HEADERS}
DESTINATION include/hiprt)
# Add header files from implementation folder.
# Ignore header which is generated by the baking tool and is only needed by the build process.
file(GLOB HIPRT_IMPL_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/impl/*.h")
list(REMOVE_ITEM HIPRT_IMPL_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/hiprt/impl/bvh_build_array.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
if(PRECOMPILE AND NOT BAKE_COMPILED_KERNEL)
install(FILES ${KERNEL_HIPRT_COMP} ${KERNEL_OROCHI_COMP}
DESTINATION bin)
endif()
# Project: Unit Test
if(NOT NO_UNITTEST)
add_executable(unittest)
if(BITCODE OR BAKE_COMPILED_KERNEL)
target_compile_definitions(unittest PRIVATE HIPRT_BITCODE_LINKING)
endif()
if(WIN32)
target_compile_options(unittest PRIVATE /wd4244)
target_link_libraries(unittest PRIVATE version)
endif()
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
set_target_properties(unittest PROPERTIES OUTPUT_NAME "unittest64D")
else()
set_target_properties(unittest PROPERTIES OUTPUT_NAME "unittest64")
endif()
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_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_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_CURRENT_SOURCE_DIR}/contrib/embree/win)
target_link_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/bin/win64)
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_CURRENT_SOURCE_DIR}/contrib/embree/win/embree4.lib)
endif()
if(UNIX)
target_link_directories(unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/embree/linux)
endif()
target_link_libraries(unittest PRIVATE embree4 tbb)
endif()
# Project: HIPRTEW Test
if(HIPRTEW)
add_executable(hiprtewtest)
target_compile_definitions(hiprtewtest PRIVATE HIPRT_EXPORTS USE_HIPRTEW)
if(WIN32)
target_compile_options(hiprtewtest PRIVATE /wd4244)
target_link_libraries(hiprtewtest PRIVATE version)
endif()
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_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_CURRENT_SOURCE_DIR}/contrib/gtest-1.6.0)
target_compile_definitions(hiprtewtest PRIVATE GTEST_HAS_TR1_TUPLE=0)
endif()