1- cmake_minimum_required (VERSION 3.10)
1+ cmake_minimum_required (VERSION 3.19) # at least 3.19 in order to have the compression-level in Zstd
22project (hiprt)
33
44#
@@ -15,6 +15,7 @@ option(HIPRTEW "Use hiprtew" OFF)
1515option (NO_ENCRYPT "Don't encrypt kernel source and binaries" OFF )
1616option (NO_UNITTEST "Don't build unit tests" OFF )
1717option (HIPRT_PREFER_HIP_5 "Prefer HIP 5" OFF )
18+ 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.
1819
1920option (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 )
2021
@@ -388,6 +389,10 @@ set(KERNEL_HIPRT_COMP "${BASE_OUTPUT_DIR}/${CMAKE_BUILD_TYPE}/hiprt${version_
388389set (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
389390set (KERNEL_OROCHI_COMP "${BASE_OUTPUT_DIR} /${CMAKE_BUILD_TYPE} /oro_compiled_kernels.hipfb" )
390391
392+ # temp files: compiled kernel, compressed.
393+ set (KERNEL_HIPRT_COMP_COMPRESSED "${CMAKE_BINARY_DIR} /hiprt${version_str_} _${HIP_VERSION_STR} _amd.zstd" )
394+ set (KERNEL_OROCHI_COMP_COMPRESSED "${CMAKE_BINARY_DIR} /oro_compiled_kernels.zstd" )
395+
391396
392397# precompile kernels:
393398if (PRECOMPILE)
@@ -406,19 +411,16 @@ if(PRECOMPILE)
406411 ${CMAKE_SOURCE_DIR} /hiprt/impl/AabbList.h
407412 ${CMAKE_SOURCE_DIR} /hiprt/impl/BvhCommon.h
408413 ${CMAKE_SOURCE_DIR} /hiprt/impl/BvhNode.h
409- ${CMAKE_SOURCE_DIR} /hiprt/impl/Geometry.h
410414 ${CMAKE_SOURCE_DIR} /hiprt/impl/QrDecomposition.h
411415 ${CMAKE_SOURCE_DIR} /hiprt/impl/Quaternion.h
412416 ${CMAKE_SOURCE_DIR} /hiprt/impl/Transform.h
413417 ${CMAKE_SOURCE_DIR} /hiprt/impl/Instance.h
414418 ${CMAKE_SOURCE_DIR} /hiprt/impl/InstanceList.h
415419 ${CMAKE_SOURCE_DIR} /hiprt/impl/MortonCode.h
416- ${CMAKE_SOURCE_DIR} /hiprt/impl/Scene.h
417420 ${CMAKE_SOURCE_DIR} /hiprt/impl/TriangleMesh.h
418421 ${CMAKE_SOURCE_DIR} /hiprt/impl/Triangle.h
419422 ${CMAKE_SOURCE_DIR} /hiprt/impl/BvhBuilderUtil.h
420423 ${CMAKE_SOURCE_DIR} /hiprt/impl/SbvhCommon.h
421- ${CMAKE_SOURCE_DIR} /hiprt/impl/ApiNodeList.h
422424 ${CMAKE_SOURCE_DIR} /hiprt/impl/BvhConfig.h
423425 ${CMAKE_SOURCE_DIR} /hiprt/impl/MemoryArena.h
424426 ${CMAKE_SOURCE_DIR} /hiprt/hiprt_types.h
@@ -479,11 +481,16 @@ if ( BAKE_COMPILED_KERNEL )
479481
480482 set (PYTHON_FILE "${CMAKE_CURRENT_SOURCE_DIR} /contrib/Orochi/scripts/convert_binary_to_array.py" )
481483
484+ set (ARCHIVE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR} /contrib/Orochi/scripts/create_archive.cmake" )
485+
482486 # HIPRT binary
483487 set (KERNEL_HIPRT_H "${CMAKE_CURRENT_SOURCE_DIR} /hiprt/impl/bvh_build_array.h" )
484488 add_custom_command (
485489 OUTPUT ${KERNEL_HIPRT_H}
486- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE} ${KERNEL_HIPRT_COMP} ${KERNEL_HIPRT_H}
490+ # 1) Create the Zstd archive
491+ COMMAND ${CMAKE_COMMAND} -DINPUT_FILE=${KERNEL_HIPRT_COMP} -DOUTPUT_FILE=${KERNEL_HIPRT_COMP_COMPRESSED} -DDO_COMPRESS=${COMPILED_COMPRESSION} -P ${ARCHIVE_SCRIPT}
492+ # 2) Run the Python converter on that archive
493+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE} ${KERNEL_HIPRT_COMP} ${KERNEL_HIPRT_COMP_COMPRESSED} ${KERNEL_HIPRT_H} ${COMPILED_COMPRESSION}
487494 DEPENDS ${KERNEL_HIPRT_COMP} # Ensure compile.py has already run.
488495 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
489496 COMMENT "Converting HIPRT compiled kernel to header"
@@ -494,7 +501,10 @@ if ( BAKE_COMPILED_KERNEL )
494501 set (KERNEL_OROCHI_H "${CMAKE_CURRENT_SOURCE_DIR} /contrib/Orochi/ParallelPrimitives/cache/oro_compiled_kernels.h" )
495502 add_custom_command (
496503 OUTPUT ${KERNEL_OROCHI_H}
497- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE} ${KERNEL_OROCHI_COMP} ${KERNEL_OROCHI_H}
504+ # 1) Create the Zstd archive
505+ COMMAND ${CMAKE_COMMAND} -DINPUT_FILE=${KERNEL_OROCHI_COMP} -DOUTPUT_FILE=${KERNEL_OROCHI_COMP_COMPRESSED} -DDO_COMPRESS=${COMPILED_COMPRESSION} -P ${ARCHIVE_SCRIPT}
506+ # 2) Run the Python converter on that archive
507+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_FILE} ${KERNEL_OROCHI_COMP} ${KERNEL_OROCHI_COMP_COMPRESSED} ${KERNEL_OROCHI_H} ${COMPILED_COMPRESSION}
498508 DEPENDS ${KERNEL_OROCHI_COMP} # Ensure compile.py has already run.
499509 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
500510 COMMENT "Converting Orochi compiled kernel to header"
@@ -533,8 +543,40 @@ endif()
533543
534544
535545if ( BAKE_COMPILED_KERNEL )
546+
547+
548+ if ( COMPILED_COMPRESSION )
549+ # Gather minimal Zstd sources
550+ file (GLOB ZSTD_SRCS
551+ contrib/zstd/lib/common/*.c
552+ contrib/zstd/lib/decompress/*.c
553+ )
554+
555+ # Build a static lib zstd_embedded
556+ add_library (zstd_embedded STATIC
557+ ${ZSTD_SRCS}
558+ )
559+
560+ # Include Zstd headers
561+ target_include_directories (zstd_embedded
562+ PUBLIC
563+ contrib/zstd/lib
564+ )
565+
566+ set_target_properties (zstd_embedded PROPERTIES POSITION_INDEPENDENT_CODE ON ) # -fPIC
567+ target_compile_definitions (zstd_embedded PRIVATE ZSTD_DISABLE_ASM) # disable ASM for easier build
568+
569+ # Link against zstd_embedded
570+ target_link_libraries (${HIPRT_NAME} zstd_embedded )
571+
572+ # the 'ORO_LINK_ZSTD' flag enables use of ZSTD API in the source code.
573+ target_compile_definitions (${HIPRT_NAME} PRIVATE ORO_LINK_ZSTD)
574+ endif ()
575+
576+
577+
536578 # enable the 'BAKE_COMPILED_KERNEL' on Orochi: this mode is activated by adding those 2 defines.
537- target_compile_definitions (${HIPRT_NAME} PRIVATE ORO_PP_LOAD_FROM_STRING ORO_PRECOMPILED)
579+ target_compile_definitions (${HIPRT_NAME} PRIVATE ORO_PP_LOAD_FROM_STRING HIPRT_BITCODE_LINKING ORO_PRECOMPILED)
538580
539581 #enable the 'BAKE_COMPILED_KERNEL' on HIPRT:
540582 target_compile_definitions (${HIPRT_NAME} PRIVATE HIPRT_BAKE_COMPILED_KERNEL )
@@ -592,12 +634,17 @@ if(PRECOMPILE AND NOT BAKE_COMPILED_KERNEL)
592634 DESTINATION bin)
593635endif ()
594636
637+
638+
639+
640+
641+
595642# Project: Unit Test
596643if (NOT NO_UNITTEST)
597644
598645 add_executable (unittest)
599646
600- if (BITCODE)
647+ if (BITCODE OR BAKE_COMPILED_KERNEL )
601648 target_compile_definitions (unittest PRIVATE HIPRT_BITCODE_LINKING)
602649 endif ()
603650 if (WIN32 )
0 commit comments