mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-18 05:52:19 +08:00
Create a library with .spv kernels for L0 use
Change-Id: Ia319c5621e363f750159d58aaedd81e411d3babb Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
@@ -882,6 +882,7 @@ endif()
|
||||
set(BIKSIM_LIB_NAME "biksim")
|
||||
set(BUILTINS_SOURCES_LIB_NAME "builtins_sources")
|
||||
set(BUILTINS_BINARIES_LIB_NAME "builtins_binaries")
|
||||
set(BUILTINS_SPIRV_LIB_NAME "builtins_spirv")
|
||||
set(BUILTINS_VME_LIB_NAME "builtins_vme")
|
||||
set(SCHEDULER_BINARY_LIB_NAME "scheduler_binary")
|
||||
|
||||
@@ -906,6 +907,7 @@ macro(generate_runtime_lib LIB_NAME MOCKABLE GENERATE_EXEC)
|
||||
target_compile_definitions(${BUILTINS_SOURCES_LIB_NAME} PUBLIC MOCKABLE_VIRTUAL=)
|
||||
target_compile_definitions(${BUILTINS_VME_LIB_NAME} PUBLIC MOCKABLE_VIRTUAL=)
|
||||
target_compile_definitions(${BUILTINS_BINARIES_LIB_NAME} PUBLIC MOCKABLE_VIRTUAL=)
|
||||
target_compile_definitions(${BUILTINS_SPIRV_LIB_NAME} PUBLIC MOCKABLE_VIRTUAL=)
|
||||
target_compile_definitions(${SCHEDULER_BINARY_LIB_NAME} PUBLIC MOCKABLE_VIRTUAL=)
|
||||
|
||||
if(${MOCKABLE})
|
||||
|
||||
@@ -249,6 +249,7 @@ if(BUILD_WITH_L0)
|
||||
endif()
|
||||
target_sources(${TARGET_NAME_L0}
|
||||
PRIVATE
|
||||
$<TARGET_OBJECTS:${BUILTINS_SPIRV_LIB_NAME}>
|
||||
$<TARGET_OBJECTS:${BUILTINS_BINARIES_LIB_NAME}>
|
||||
)
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ endif()
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
$<TARGET_OBJECTS:mock_gmm>
|
||||
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
|
||||
$<TARGET_OBJECTS:${BUILTINS_SPIRV_LIB_NAME}>
|
||||
$<TARGET_OBJECTS:${BUILTINS_BINARIES_LIB_NAME}>
|
||||
)
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
constexpr int ARG_COUNT = 9;
|
||||
constexpr int MIN_ARG_COUNT = 7;
|
||||
|
||||
static void show_usage(std::string name) {
|
||||
std::cerr << "Usage " << name << "<option(s)> - ALL MUST BE SPECIFIED\n"
|
||||
std::cerr << "Usage " << name << "<option(s)> - ALL BUT -p, --platform MUST BE SPECIFIED\n"
|
||||
<< "Options :\n"
|
||||
<< "\t -f, --file\t\tA file which content will be parsed into a uint32_t array in a .cpp file\n"
|
||||
<< "\t -o, --out\t\t.Cpp output file name\n"
|
||||
<< "\t -p, --platform\t\tFamily name with type\n"
|
||||
<< "\t -p, --platform\t\tOPTIONAL - Family name with type\n"
|
||||
<< "\t -a, --array\t\tName of an uin32_t type array containing parsed input file" << std::endl;
|
||||
}
|
||||
std::string parseToCharArray(std::unique_ptr<uint8_t[]> binary, size_t size, std::string &builtinName, std::string &platform, bool isSpirV) {
|
||||
@@ -59,8 +59,9 @@ std::string parseToCharArray(std::unique_ptr<uint8_t[]> binary, size_t size, std
|
||||
out << "static RegisterEmbeddedResource register" << builtinName;
|
||||
isSpirV ? out << "Ir(" : out << "Bin(";
|
||||
out << std::endl;
|
||||
out << " \"" << platform << "_0_" << builtinName;
|
||||
isSpirV ? out << ".builtin_kernel.spv\"," : out << ".builtin_kernel.bin\",";
|
||||
out << " \"";
|
||||
platform != "" ? out << platform << "_0_" << builtinName : out << builtinName;
|
||||
isSpirV ? out << ".builtin_kernel.bc\"," : out << ".builtin_kernel.bin\",";
|
||||
out << std::endl;
|
||||
out << " (const char *)" << builtinName << "Binary_" << platform << "," << std::endl;
|
||||
out << " " << builtinName << "BinarySize_" << platform << ");" << std::endl;
|
||||
@@ -70,14 +71,14 @@ std::string parseToCharArray(std::unique_ptr<uint8_t[]> binary, size_t size, std
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != ARG_COUNT) {
|
||||
if (argc < MIN_ARG_COUNT) {
|
||||
show_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
std::string fileName;
|
||||
std::string cppOutputName;
|
||||
std::string arrayName;
|
||||
std::string platform;
|
||||
std::string platform = "";
|
||||
size_t size = 0;
|
||||
std::fstream inputFile;
|
||||
bool isSpirV;
|
||||
@@ -95,6 +96,10 @@ int main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (fileName.empty() || cppOutputName.empty() || arrayName.empty()) {
|
||||
std::cerr << "All three: fileName, cppOutputName and arrayName must be specified!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
inputFile.open(fileName.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
|
||||
|
||||
if (inputFile.is_open()) {
|
||||
|
||||
@@ -90,6 +90,49 @@ function(compile_builtin gen_type platform_type builtin bits builtin_options)
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(generate_cpp_spirv builtin)
|
||||
if(NOT DEFINED cloc_cmd_prefix)
|
||||
if(WIN32)
|
||||
set(cloc_cmd_prefix $<TARGET_FILE:ocloc>)
|
||||
else()
|
||||
if(DEFINED NEO__IGC_LIBRARY_PATH)
|
||||
set(cloc_cmd_prefix LD_LIBRARY_PATH=${NEO__IGC_LIBRARY_PATH}:$<TARGET_FILE_DIR:ocloc_lib> $<TARGET_FILE:ocloc>)
|
||||
else()
|
||||
set(cloc_cmd_prefix LD_LIBRARY_PATH=$<TARGET_FILE_DIR:ocloc_lib> $<TARGET_FILE:ocloc>)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
get_filename_component(BASENAME ${builtin} NAME_WE)
|
||||
get_filename_component(DIR ${builtin} DIRECTORY)
|
||||
|
||||
set(OUTPUTDIR "${BUILTINS_OUTDIR_WITH_ARCH}/spirv/${DIR}")
|
||||
string(REPLACE "//" "/" OUTPUTDIR ${OUTPUTDIR})
|
||||
|
||||
set(INPUT_FILENAME ${builtin}.builtin_kernel)
|
||||
|
||||
set(GENERATED_SPV_INPUT ${OUTPUTDIR}/${BASENAME}.spv)
|
||||
set(OUTPUT_FILE_CPP
|
||||
${OUTPUTDIR}/${BASENAME}.cpp
|
||||
)
|
||||
|
||||
set(OUTPUT_LIST_SPV_FILES ${OUTPUT_LIST_SPV_FILES} ${OUTPUT_FILES_FOR_SPV} PARENT_SCOPE)
|
||||
set(OUTPUT_LIST_CPP_FILES ${OUTPUT_LIST_CPP_FILES} ${OUTPUT_FILE_CPP} PARENT_SCOPE)
|
||||
string(TOLOWER ${DEFAULT_SUPPORTED_PLATFORM} DEF_PLATFORM)
|
||||
add_custom_command(
|
||||
OUTPUT ${GENERATED_SPV_INPUT}
|
||||
COMMAND ${cloc_cmd_prefix} -q -spv_only -file ${INPUT_FILENAME} -device ${DEF_PLATFORM} -out_dir ${OUTPUTDIR} -output_no_suffix -options "-cl-kernel-arg-info"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${INPUT_FILENAME} ocloc copy_compiler_files
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT ${OUTPUT_FILE_CPP}
|
||||
COMMAND $<TARGET_FILE:cpp_generate_tool> --file ${GENERATED_SPV_INPUT} --output ${OUTPUT_FILE_CPP} --array ${BASENAME}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${GENERATED_SPV_INPUT} $<TARGET_FILE:cpp_generate_tool>
|
||||
)
|
||||
endfunction()
|
||||
|
||||
macro(macro_for_each_gen)
|
||||
foreach(PLATFORM_TYPE ${PLATFORM_TYPES})
|
||||
if(${GEN_TYPE}_HAS_${PLATFORM_TYPE})
|
||||
@@ -133,4 +176,21 @@ macro(macro_for_each_gen)
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
file(MAKE_DIRECTORY "${BUILTINS_OUTDIR_WITH_ARCH}/spirv")
|
||||
foreach(builtin ${GENERATED_BUILTINS})
|
||||
generate_cpp_spirv(${builtin})
|
||||
endforeach()
|
||||
foreach(builtin_images ${GENERATED_BUILTINS_IMAGES})
|
||||
generate_cpp_spirv(${builtin_images})
|
||||
endforeach()
|
||||
foreach(builtin_stateless ${GENERATED_BUILTINS_STATELESS})
|
||||
generate_cpp_spirv(${builtin_stateless})
|
||||
endforeach()
|
||||
foreach(builtin_images_stateless ${GENERATED_BUILTINS_IMAGES_STATELESS})
|
||||
generate_cpp_spirv(${builtin_images_stateless})
|
||||
endforeach()
|
||||
add_custom_target(spirv_builtins ALL DEPENDS ${OUTPUT_LIST_SPV_FILES} ${OUTPUT_LIST_CPP_FILES})
|
||||
add_library(${BUILTINS_SPIRV_LIB_NAME} OBJECT ${OUTPUT_LIST_CPP_FILES})
|
||||
set_target_properties(${BUILTINS_SPIRV_LIB_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
apply_macro_for_each_gen("SUPPORTED")
|
||||
|
||||
Reference in New Issue
Block a user