Skip to content

Commit 4996b97

Browse files
committed
add the HIPRT_BAKE_KERNEL_GENERATED flag
1 parent d14726e commit 4996b97

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CMakeLists.txt

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@ cmake_minimum_required(VERSION 3.10)
22
project(hiprt)
33

44
# Options
5-
option(BAKE_KERNEL "Encrypt and bake kernels" OFF)
5+
option(BAKE_KERNEL "enable the use of encrypted and baked kernels" OFF)
66
option(BITCODE "Enable bitcode linking" OFF)
77
option(PRECOMPILE "Precompile kernels" OFF)
88
option(HIPRTEW "Use hiprtew" OFF)
99
option(NO_ENCRYPT "Don't encrypt kernel source and binaries" OFF)
1010
option(NO_UNITTEST "Don't build unit tests" OFF)
1111
option(HIPRT_PREFER_HIP_5 "Prefer HIP 5" OFF)
1212

13+
14+
# GENERATE_BAKE_KERNEL is enabled by default if we use the flags 'BAKE_KERNEL' or 'BITCODE'.
15+
# It can be forced to OFF, but in this case, some building functions from the HIPRT API, like hiprtBuildTraceKernelsFromBitcode will fail.
16+
if(BAKE_KERNEL OR BITCODE)
17+
set(GENERATE_BAKE_KERNEL___DEFAULT ON)
18+
else()
19+
set(GENERATE_BAKE_KERNEL___DEFAULT OFF)
20+
endif()
21+
option(GENERATE_BAKE_KERNEL "generate the baked kernels" ${GENERATE_BAKE_KERNEL___DEFAULT})
22+
message(STATUS "GENERATE_BAKE_KERNEL= ${GENERATE_BAKE_KERNEL}")
23+
24+
1325
# Set C++ Standard
1426
set(CMAKE_CXX_STANDARD 17)
1527
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -322,7 +334,7 @@ if(PRECOMPILE)
322334
endif()
323335

324336

325-
if(BAKE_KERNEL OR BITCODE)
337+
if(BAKE_KERNEL OR GENERATE_BAKE_KERNEL)
326338
message(">> BakeKernel Executed")
327339
if(WIN32)
328340
execute_process(COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/hiprt/cache)
@@ -335,6 +347,9 @@ if(BAKE_KERNEL OR BITCODE)
335347
if(BAKE_KERNEL)
336348
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_LOAD_FROM_STRING ORO_PP_LOAD_FROM_STRING)
337349
endif()
350+
351+
target_compile_definitions(${HIPRT_NAME} PRIVATE HIPRT_BAKE_KERNEL_GENERATED)
352+
338353
endif()
339354

340355
if(WIN32)

hiprt/hiprt_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
#define HIPRT_HOST_DEVICE __host__ __device__
9494

9595
// TODO: cleanup after baking is removed
96-
#if defined( HIPRT_LOAD_FROM_STRING ) || defined( HIPRT_BITCODE_LINKING )
96+
#if defined( HIPRT_BAKE_KERNEL_GENERATED )
9797
#define GET_ARGS( X ) ( hip::X##Args )
9898
#define GET_INC( X ) ( hip::X##Includes )
9999
#else

hiprt/impl/Compiler.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <contrib/easy-encryption/encrypt.h>
3232
#endif
3333
#include <regex>
34-
#if defined( HIPRT_LOAD_FROM_STRING ) || defined( HIPRT_BITCODE_LINKING )
34+
#if defined( HIPRT_BAKE_KERNEL_GENERATED )
3535
#include <hiprt/cache/Kernels.h>
3636
#include <hiprt/cache/KernelArgs.h>
3737
#endif
@@ -49,6 +49,12 @@ constexpr auto UseBakedCode = true;
4949
#else
5050
constexpr auto UseBakedCode = false;
5151
#endif
52+
53+
#if defined( HIPRT_BAKE_KERNEL_GENERATED )
54+
constexpr auto BakedCodeIsGenerated = true;
55+
#else
56+
constexpr auto BakedCodeIsGenerated = false;
57+
#endif
5258
} // namespace
5359

5460
namespace hiprt
@@ -224,7 +230,7 @@ void Compiler::buildKernels(
224230
std::string extSrc = src;
225231
if ( extended )
226232
{
227-
if constexpr ( UseBakedCode || UseBitcode )
233+
if constexpr ( BakedCodeIsGenerated )
228234
{
229235
extSrc = "#include <hiprt_device_impl.h>\n";
230236
addCustomFuncsSwitchCase( extSrc, funcNameSets, numGeomTypes, numRayTypes );
@@ -776,7 +782,7 @@ oroFunction Compiler::getFunctionFromPrecompiledBinary( const std::string& funcN
776782
std::string Compiler::buildFunctionTableBitcode(
777783
Context& context, uint32_t numGeomTypes, uint32_t numRayTypes, const std::vector<hiprtFuncNameSet>& funcNameSets )
778784
{
779-
if constexpr ( UseBitcode )
785+
if constexpr ( BakedCodeIsGenerated )
780786
{
781787
bool amd = oroGetCurAPI( 0 ) == ORO_API_HIP;
782788

@@ -847,7 +853,7 @@ std::string Compiler::buildFunctionTableBitcode(
847853
}
848854
else
849855
{
850-
throw std::runtime_error( "Not compiled with the bitcode linking support" );
856+
throw std::runtime_error( "Not compiled with the baked kernel code support" );
851857
}
852858
}
853859
} // namespace hiprt

premake5.lua

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ workspace "hiprt"
251251
defines {"HIPRT_LOAD_FROM_STRING"}
252252
defines { "ORO_PP_LOAD_FROM_STRING" }
253253
end
254+
defines {"HIPRT_BAKE_KERNEL_GENERATED"}
254255
end
255256
if os.istarget("windows") then
256257
links{ "version" }

0 commit comments

Comments
 (0)