Skip to content

Commit 95943de

Browse files
Dont generate gen file by default
Ocloc can dump gen file when we add -gen_file flag to cmd. Otherwise gen is not generated Signed-off-by: Mateusz Borzyszkowski <[email protected]>
1 parent 3f54e9f commit 95943de

File tree

9 files changed

+146
-30
lines changed

9 files changed

+146
-30
lines changed

level_zero/core/test/common/gen_kernel.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2020-2021 Intel Corporation
2+
# Copyright (C) 2020-2022 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -28,7 +28,7 @@ function(level_zero_generate_kernels target_list platform_name suffix options)
2828
add_custom_command(
2929
COMMAND echo generate ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${platform_name} -out_dir ${outputdir} -options "${options}"
3030
OUTPUT ${output_files}
31-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${platform_name} -out_dir ${outputdir} -options "${options}"
31+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath} -device ${platform_name} -out_dir ${outputdir} -options "${options}"
3232
WORKING_DIRECTORY ${workdir}
3333
DEPENDS ${filepath} ocloc
3434
)
@@ -80,7 +80,7 @@ function(level_zero_generate_kernels_with_internal_options target_list platform_
8080
add_custom_command(
8181
COMMAND echo generate ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${platform_name} -out_dir ${outputdir} ${output_name} -options ${options} -internal_options ${internal_options} , workdir is ${workdir}
8282
OUTPUT ${output_files}
83-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${platform_name} -out_dir ${outputdir} ${output_name} -options ${options} -internal_options ${internal_options}
83+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath} -device ${platform_name} -out_dir ${outputdir} ${output_name} -options ${options} -internal_options ${internal_options}
8484
WORKING_DIRECTORY ${workdir}
8585
DEPENDS ${filepath} ocloc
8686
)

opencl/source/built_ins/kernels/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function(compile_builtin core_type platform_type builtin bits builtin_options)
6868

6969
add_custom_command(
7070
OUTPUT ${OUTPUT_FILES}
71-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${DEFAULT_SUPPORTED_${core_type}_${platform_type}_PLATFORM} ${builtin_options} -${bits} -out_dir ${OUTPUTDIR} -options "$<JOIN:${__ocloc__options__}, >"
71+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath} -device ${DEFAULT_SUPPORTED_${core_type}_${platform_type}_PLATFORM} ${builtin_options} -${bits} -out_dir ${OUTPUTDIR} -options "$<JOIN:${__ocloc__options__}, >"
7272
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
7373
DEPENDS ${builtin} ocloc copy_compiler_files
7474
)

opencl/test/unit_test/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function(neo_gen_kernels platform_name_with_type platform_name revision_id suffi
192192

193193
add_custom_command(
194194
OUTPUT ${output_files}
195-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${platform_name} -${NEO_BITS} -revision_id ${revision_id} -out_dir ${outputdir}
195+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath} -device ${platform_name} -${NEO_BITS} -revision_id ${revision_id} -out_dir ${outputdir}
196196
WORKING_DIRECTORY ${workdir}
197197
DEPENDS ${filepath} ocloc
198198
)
@@ -239,7 +239,7 @@ function(neo_gen_kernels_with_options platform_name_with_type platform_name revi
239239

240240
add_custom_command(
241241
OUTPUT ${output_files}
242-
COMMAND ${ocloc_cmd_prefix} -file ${absolute_filepath} -device ${platform_name} -${NEO_BITS} -out_dir ${outputdir} -revision_id ${revision_id} -options ${arg} -options_name
242+
COMMAND ${ocloc_cmd_prefix} -gen_file -file ${absolute_filepath} -device ${platform_name} -${NEO_BITS} -out_dir ${outputdir} -revision_id ${revision_id} -options ${arg} -options_name
243243
WORKING_DIRECTORY ${workdir}
244244
DEPENDS ${filearg} ocloc
245245
)
@@ -292,7 +292,7 @@ function(neo_gen_kernels_with_internal_options platform_name_with_type platform_
292292

293293
add_custom_command(
294294
OUTPUT ${output_files}
295-
COMMAND ${ocloc_cmd_prefix} -file ${absolute_filepath} -device ${platform_name} -revision_id ${revision_id} -${NEO_BITS} -out_dir ${outputdir} ${output_name} -internal_options ${ARGN}
295+
COMMAND ${ocloc_cmd_prefix} -gen_file -file ${absolute_filepath} -device ${platform_name} -revision_id ${revision_id} -${NEO_BITS} -out_dir ${outputdir} ${output_name} -internal_options ${ARGN}
296296
WORKING_DIRECTORY ${workdir}
297297
DEPENDS ${filearg} ocloc
298298
)
@@ -340,7 +340,7 @@ function(neo_gen_kernel_with_kernel_debug_options platform_name_with_type platfo
340340

341341
add_custom_command(
342342
OUTPUT ${output_files}
343-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -device ${platform_name} -revision_id ${revision_id} -${NEO_BITS} -out_dir ${outputdir} -output ${argwospaces} -internal_options ${TEST_KERNEL_kernel_debug_enable} -options "-g"
343+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath} -device ${platform_name} -revision_id ${revision_id} -${NEO_BITS} -out_dir ${outputdir} -output ${argwospaces} -internal_options ${TEST_KERNEL_kernel_debug_enable} -options "-g"
344344
WORKING_DIRECTORY ${workdir}
345345
DEPENDS ${filepath} ocloc
346346
)
@@ -377,7 +377,7 @@ function(neo_gen_kernel_from_ll platform_name_with_type platform_name suffix fil
377377
378378
add_custom_command(
379379
OUTPUT ${output_files}
380-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath} -output ${output_name} -device ${platform_name} -${NEO_BITS} -out_dir ${outputdir} -internal_options ${compile_options} -llvm_input
380+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath} -output ${output_name} -device ${platform_name} -${NEO_BITS} -out_dir ${outputdir} -internal_options ${compile_options} -llvm_input
381381
WORKING_DIRECTORY ${workdir}
382382
DEPENDS ${filepath} ocloc
383383
)

opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -19,6 +19,7 @@ class MockOfflineCompiler : public OfflineCompiler {
1919
using OfflineCompiler::deviceName;
2020
using OfflineCompiler::elfBinary;
2121
using OfflineCompiler::excludeIr;
22+
using OfflineCompiler::familyNameWithType;
2223
using OfflineCompiler::fclDeviceCtx;
2324
using OfflineCompiler::forceStatelessToStatefulOptimization;
2425
using OfflineCompiler::genBinary;

opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp

Lines changed: 123 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "offline_compiler_tests.h"
99

10+
#include "shared/offline_compiler/source/ocloc_api.h"
1011
#include "shared/source/compiler_interface/intermediate_representations.h"
1112
#include "shared/source/compiler_interface/oclc_extensions.h"
1213
#include "shared/source/debug_settings/debug_settings_manager.h"
@@ -121,6 +122,7 @@ TEST_F(MultiCommandTests, GivenOutputFileWhenBuildingMultiCommandThenSuccessIsRe
121122
};
122123

123124
std::vector<std::string> singleArgs = {
125+
"-gen_file",
124126
"-file",
125127
"test_files/copybuffer.cl",
126128
"-device",
@@ -154,6 +156,7 @@ TEST_F(MultiCommandTests, GivenSpecifiedOutputDirWhenBuildingMultiCommandThenSuc
154156
};
155157

156158
std::vector<std::string> singleArgs = {
159+
"-gen_file",
157160
"-file",
158161
"test_files/copybuffer.cl",
159162
"-device",
@@ -197,6 +200,7 @@ TEST_F(MultiCommandTests, GivenSpecifiedOutputDirWithProductConfigValueWhenBuild
197200
};
198201

199202
std::vector<std::string> singleArgs = {
203+
"-gen_file",
200204
"-file",
201205
"test_files/copybuffer.cl",
202206
"-device",
@@ -280,6 +284,7 @@ TEST_F(MultiCommandTests, GivenOutputFileListFlagWhenBuildingMultiCommandThenSuc
280284
};
281285

282286
std::vector<std::string> singleArgs = {
287+
"-gen_file",
283288
"-file",
284289
"test_files/copybuffer.cl",
285290
"-device",
@@ -679,7 +684,8 @@ TEST_F(OfflineCompilerTests, GivenArgsWhenBuildingThenBuildSucceeds) {
679684
"-file",
680685
"test_files/copybuffer.cl",
681686
"-device",
682-
gEnvironment->devicePrefix.c_str()};
687+
gEnvironment->devicePrefix.c_str(),
688+
"-gen_file"};
683689

684690
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
685691

@@ -713,25 +719,30 @@ TEST_F(OfflineCompilerTests, GivenArgsWhenBuildingWithDeviceConfigValueThenBuild
713719
"-file",
714720
"test_files/copybuffer.cl",
715721
"-device",
716-
configString};
722+
configString,
723+
"-gen_file"};
717724

718-
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
725+
MockOfflineCompiler offlineCompiler{};
726+
727+
offlineCompiler.argHelper = oclocArgHelperWithoutInput.get();
728+
retVal = offlineCompiler.initialize(argv.size(), argv);
719729

720-
EXPECT_NE(nullptr, pOfflineCompiler);
721730
EXPECT_EQ(CL_SUCCESS, retVal);
722731

723732
testing::internal::CaptureStdout();
724-
retVal = pOfflineCompiler->build();
733+
retVal = offlineCompiler.build();
725734
std::string output = testing::internal::GetCapturedStdout();
726735
EXPECT_EQ(CL_SUCCESS, retVal);
736+
737+
Environment testedEnv{configString, offlineCompiler.familyNameWithType};
738+
VariableBackup<Environment *> backup(&gEnvironment, &testedEnv);
739+
727740
EXPECT_TRUE(compilerOutputExists("copybuffer", "bc") || compilerOutputExists("copybuffer", "spv"));
728741
EXPECT_TRUE(compilerOutputExists("copybuffer", "gen"));
729742
EXPECT_TRUE(compilerOutputExists("copybuffer", "bin"));
730743

731-
std::string buildLog = pOfflineCompiler->getBuildLog();
744+
std::string buildLog = offlineCompiler.getBuildLog();
732745
EXPECT_STREQ(buildLog.c_str(), "");
733-
734-
delete pOfflineCompiler;
735746
}
736747

737748
TEST_F(OfflineCompilerTests, GivenLlvmTextWhenBuildingThenBuildSucceeds) {
@@ -741,7 +752,8 @@ TEST_F(OfflineCompilerTests, GivenLlvmTextWhenBuildingThenBuildSucceeds) {
741752
"test_files/copybuffer.cl",
742753
"-device",
743754
gEnvironment->devicePrefix.c_str(),
744-
"-llvm_text"};
755+
"-llvm_text",
756+
"-gen_file"};
745757

746758
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
747759

@@ -757,6 +769,97 @@ TEST_F(OfflineCompilerTests, GivenLlvmTextWhenBuildingThenBuildSucceeds) {
757769
delete pOfflineCompiler;
758770
}
759771

772+
TEST_F(OfflineCompilerTests, WhenGenFileFlagIsNotProvidedThenGenFileIsNotCreated) {
773+
uint32_t numOutputs = 0u;
774+
uint64_t *lenOutputs = nullptr;
775+
uint8_t **dataOutputs = nullptr;
776+
char **nameOutputs = nullptr;
777+
778+
bool isSpvFile = false;
779+
bool isGenFile = false;
780+
bool isBinFile = false;
781+
782+
const char *argv[] = {
783+
"ocloc",
784+
"-q",
785+
"-file",
786+
"test_files/copybuffer.cl",
787+
"-device",
788+
gEnvironment->devicePrefix.c_str()};
789+
790+
unsigned int argc = sizeof(argv) / sizeof(const char *);
791+
int retVal = oclocInvoke(argc, argv,
792+
0, nullptr, nullptr, nullptr,
793+
0, nullptr, nullptr, nullptr,
794+
&numOutputs, &dataOutputs, &lenOutputs, &nameOutputs);
795+
796+
EXPECT_EQ(retVal, CL_SUCCESS);
797+
EXPECT_EQ(numOutputs, 3u);
798+
799+
for (unsigned int i = 0; i < numOutputs; i++) {
800+
std::string nameOutput(nameOutputs[i]);
801+
if (nameOutput.find(".spv") != std::string::npos) {
802+
isSpvFile = true;
803+
}
804+
if (nameOutput.find(".gen") != std::string::npos) {
805+
isGenFile = true;
806+
}
807+
if (nameOutput.find(".bin") != std::string::npos) {
808+
isBinFile = true;
809+
}
810+
}
811+
812+
EXPECT_TRUE(isSpvFile);
813+
EXPECT_FALSE(isGenFile);
814+
EXPECT_TRUE(isBinFile);
815+
}
816+
817+
TEST_F(OfflineCompilerTests, WhenGenFileFlagIsProvidedThenGenFileIsCreated) {
818+
uint32_t numOutputs = 0u;
819+
uint64_t *lenOutputs = nullptr;
820+
uint8_t **dataOutputs = nullptr;
821+
char **nameOutputs = nullptr;
822+
823+
bool isSpvFile = false;
824+
bool isGenFile = false;
825+
bool isBinFile = false;
826+
827+
const char *argv[] = {
828+
"ocloc",
829+
"-q",
830+
"-gen_file",
831+
"-file",
832+
"test_files/copybuffer.cl",
833+
"-device",
834+
gEnvironment->devicePrefix.c_str()};
835+
836+
unsigned int argc = sizeof(argv) / sizeof(const char *);
837+
int retVal = oclocInvoke(argc, argv,
838+
0, nullptr, nullptr, nullptr,
839+
0, nullptr, nullptr, nullptr,
840+
&numOutputs, &dataOutputs, &lenOutputs, &nameOutputs);
841+
842+
EXPECT_EQ(retVal, CL_SUCCESS);
843+
EXPECT_EQ(numOutputs, 4u);
844+
845+
for (unsigned int i = 0; i < numOutputs; i++) {
846+
std::string nameOutput(nameOutputs[i]);
847+
if (nameOutput.find(".spv") != std::string::npos) {
848+
isSpvFile = true;
849+
}
850+
if (nameOutput.find(".gen") != std::string::npos) {
851+
isGenFile = true;
852+
}
853+
if (nameOutput.find(".bin") != std::string::npos) {
854+
isBinFile = true;
855+
}
856+
}
857+
858+
EXPECT_TRUE(isSpvFile);
859+
EXPECT_TRUE(isGenFile);
860+
EXPECT_TRUE(isBinFile);
861+
}
862+
760863
TEST_F(OfflineCompilerTests, WhenFclNotNeededThenDontLoadIt) {
761864
std::vector<std::string> argv = {
762865
"ocloc",
@@ -824,7 +927,8 @@ TEST_F(OfflineCompilerTests, GivenCppFileWhenBuildingThenBuildSucceeds) {
824927
"test_files/copybuffer.cl",
825928
"-device",
826929
gEnvironment->devicePrefix.c_str(),
827-
"-cpp_file"};
930+
"-cpp_file",
931+
"-gen_file"};
828932

829933
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
830934

@@ -847,6 +951,7 @@ TEST_F(OfflineCompilerTests, GivenOutputDirWhenBuildingThenBuildSucceeds) {
847951
"test_files/copybuffer.cl",
848952
"-device",
849953
gEnvironment->devicePrefix.c_str(),
954+
"-gen_file",
850955
"-out_dir",
851956
"offline_compiler_test"};
852957

@@ -1189,7 +1294,8 @@ TEST(OfflineCompilerTest, givenSpvOnlyOptionPassedWhenCmdLineParsedThenGenerateO
11891294
"myOutputFileName",
11901295
"-spv_only",
11911296
"-device",
1192-
gEnvironment->devicePrefix.c_str()};
1297+
gEnvironment->devicePrefix.c_str(),
1298+
"-gen_file"};
11931299

11941300
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
11951301
ASSERT_NE(nullptr, mockOfflineCompiler);
@@ -1398,7 +1504,8 @@ TEST(OfflineCompilerTest, givenOutputFileOptionWhenSourceIsCompiledThenOutputFil
13981504
"-output",
13991505
"myOutputFileName",
14001506
"-device",
1401-
gEnvironment->devicePrefix.c_str()};
1507+
gEnvironment->devicePrefix.c_str(),
1508+
"-gen_file"};
14021509

14031510
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
14041511
ASSERT_NE(nullptr, mockOfflineCompiler);
@@ -1431,7 +1538,8 @@ TEST(OfflineCompilerTest, givenDebugDataAvailableWhenSourceIsBuiltThenDebugDataF
14311538
"-output",
14321539
"myOutputFileName",
14331540
"-device",
1434-
gEnvironment->devicePrefix.c_str()};
1541+
gEnvironment->devicePrefix.c_str(),
1542+
"-gen_file"};
14351543

14361544
char debugData[10];
14371545
MockCompilerDebugVars igcDebugVars(gEnvironment->igcDebugVars);
@@ -2032,7 +2140,8 @@ TEST(OclocCompile, givenSpirvInputThenDontGenerateSpirvFile) {
20322140
"offline_compiler_test",
20332141
"-device",
20342142
gEnvironment->devicePrefix.c_str(),
2035-
"-spirv_input"};
2143+
"-spirv_input",
2144+
"-gen_file"};
20362145

20372146
int retVal = ocloc.initialize(argv.size(), argv);
20382147
ASSERT_EQ(0, retVal);

shared/offline_compiler/source/offline_compiler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
684684
inputFileSpirV = true;
685685
} else if ("-cpp_file" == currArg) {
686686
useCppFile = true;
687+
} else if ("-gen_file" == currArg) {
688+
useGenFile = true;
687689
} else if (("-options" == currArg) && hasMoreArgs) {
688690
options = argv[argIndex + 1];
689691
argIndex++;
@@ -1039,6 +1041,8 @@ Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename
10391041
-cpp_file Will generate c++ file with C-array
10401042
containing Intel Compute device binary.
10411043
1044+
-gen_file Will generate gen file.
1045+
10421046
-output_no_suffix Prevents ocloc from adding family name suffix.
10431047
10441048
--help Print this usage message.
@@ -1161,9 +1165,10 @@ void OfflineCompiler::writeOutAllFiles() {
11611165
}
11621166

11631167
if (genBinary) {
1164-
std::string genOutputFile = generateFilePath(outputDirectory, fileBase, ".gen") + generateOptsSuffix();
1165-
1166-
argHelper->saveOutput(genOutputFile, genBinary, genBinarySize);
1168+
if (useGenFile) {
1169+
std::string genOutputFile = generateFilePath(outputDirectory, fileBase, ".gen") + generateOptsSuffix();
1170+
argHelper->saveOutput(genOutputFile, genBinary, genBinarySize);
1171+
}
11671172

11681173
if (useCppFile) {
11691174
std::string cppOutputFile = generateFilePath(outputDirectory, fileBase, ".cpp");

shared/offline_compiler/source/offline_compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class OfflineCompiler {
134134
bool useLlvmText = false;
135135
bool useLlvmBc = false;
136136
bool useCppFile = false;
137+
bool useGenFile = false;
137138
bool useOptionsSuffix = false;
138139
bool quiet = false;
139140
bool onlySpirV = false;

shared/source/built_ins/kernels/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function(compile_builtin core_type platform_type builtin bits builtin_options mo
8888
get_filename_component(absolute_filepath_spv ${OUTPUT_FILE_SPV} ABSOLUTE)
8989
add_custom_command(
9090
OUTPUT ${OUTPUT_FILES_BINARIES}
91-
COMMAND ${ocloc_cmd_prefix} -q -file ${absolute_filepath_spv} -spirv_input -device ${DEFAULT_SUPPORTED_${core_type}_${platform_type}_PLATFORM} ${builtin_options} -${bits} -output ${mode}_${BASENAME}_${REVISION_ID} -out_dir ${OUTPUTDIR} -revision_id ${REVISION_ID} ${INTERNAL_OPTIONS} -options "$<JOIN:${__ocloc__options__}, >"
91+
COMMAND ${ocloc_cmd_prefix} -q -gen_file -file ${absolute_filepath_spv} -spirv_input -device ${DEFAULT_SUPPORTED_${core_type}_${platform_type}_PLATFORM} ${builtin_options} -${bits} -output ${mode}_${BASENAME}_${REVISION_ID} -out_dir ${OUTPUTDIR} -revision_id ${REVISION_ID} ${INTERNAL_OPTIONS} -options "$<JOIN:${__ocloc__options__}, >"
9292
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
9393
DEPENDS ${OUTPUT_FILE_SPV} ocloc copy_compiler_files
9494
)

0 commit comments

Comments
 (0)