diff --git a/offline_compiler/offline_compiler.cpp b/offline_compiler/offline_compiler.cpp index fd97812883..fbe795f589 100644 --- a/offline_compiler/offline_compiler.cpp +++ b/offline_compiler/offline_compiler.cpp @@ -360,7 +360,7 @@ int OfflineCompiler::initialize(uint32_t numArgs, const char **argv) { } fclDeviceCtx->SetOclApiVersion(hwInfo->capabilityTable.clVersionSupport * 10); - preferredIntermediateRepresentation = IGC::CodeType::llvmBc; + preferredIntermediateRepresentation = fclDeviceCtx->GetPreferredIntermediateRepresentation(); this->igcLib.reset(OsLibrary::load(Os::igcDllName)); if (this->igcLib == nullptr) { diff --git a/runtime/compiler_interface/compiler_interface.cpp b/runtime/compiler_interface/compiler_interface.cpp index 56cfc3fd21..d4a7dd6c1d 100644 --- a/runtime/compiler_interface/compiler_interface.cpp +++ b/runtime/compiler_interface/compiler_interface.cpp @@ -395,7 +395,7 @@ IGC::FclOclDeviceCtxTagOCL *CompilerInterface::getFclDeviceCtx(const Device &dev } IGC::CodeType::CodeType_t CompilerInterface::getPreferredIntermediateRepresentation(const Device &device) { - return IGC::CodeType::llvmBc; + return getFclDeviceCtx(device)->GetPreferredIntermediateRepresentation(); } CIF::RAII::UPtr_t CompilerInterface::createFclTranslationCtx(const Device &device, IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType) { diff --git a/unit_tests/api/cl_build_program_tests.cpp b/unit_tests/api/cl_build_program_tests.cpp index e73cfe9d3e..ce64db9462 100644 --- a/unit_tests/api/cl_build_program_tests.cpp +++ b/unit_tests/api/cl_build_program_tests.cpp @@ -27,6 +27,7 @@ #include "runtime/program/program.h" #include "unit_tests/helpers/kernel_binary_helper.h" #include "unit_tests/helpers/test_files.h" +#include "unit_tests/mocks/mock_compilers.h" using namespace OCLRT; @@ -185,37 +186,34 @@ TEST_F(clBuildProgramTests, GivenProgramCreatedFromBinaryWhenBuildProgramWithOpt CompilerInterface::shutdown(); } -TEST_F(clBuildProgramTests, FromBinarySpir) { +TEST_F(clBuildProgramTests, GivenSpirAsInputWhenCreatingProgramFromBinaryThenProgramBuildSucceeds) { cl_program pProgram = nullptr; cl_int binaryStatus = CL_SUCCESS; - void *pBinary = nullptr; - size_t binarySize = 0; - - KernelBinaryHelper kbHeler("CopyBuffer_simd8", false); - std::string testFile; - retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd8_", ".bc"); - - binarySize = loadDataFromFile( - testFile.c_str(), - pBinary); - - ASSERT_NE(0u, binarySize); - ASSERT_NE(nullptr, pBinary); + char llvm[16] = "BC\xc0\xde"; + void *binary = llvm; + size_t binarySize = sizeof(llvm); pProgram = clCreateProgramWithBinary( pContext, num_devices, devices, &binarySize, - (const unsigned char **)&pBinary, + (const unsigned char **)&binary, &binaryStatus, &retVal); - deleteDataReadFromFile(pBinary); - EXPECT_NE(nullptr, pProgram); ASSERT_EQ(CL_SUCCESS, retVal); + MockCompilerDebugVars igcDebugVars; + SProgramBinaryHeader progBin = {}; + progBin.Magic = iOpenCL::MAGIC_CL; + progBin.Version = iOpenCL::CURRENT_ICBE_VERSION; + progBin.Device = pContext->getDevice(0)->getHardwareInfo().pPlatform->eRenderCoreFamily; + igcDebugVars.binaryToReturn = &progBin; + igcDebugVars.binaryToReturnSize = sizeof(progBin); + auto prevDebugVars = getIgcDebugVars(); + setIgcDebugVars(igcDebugVars); retVal = clBuildProgram( pProgram, num_devices, @@ -223,8 +221,9 @@ TEST_F(clBuildProgramTests, FromBinarySpir) { "-x spir -spir-std=1.2", nullptr, nullptr); + setIgcDebugVars(prevDebugVars); - ASSERT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(CL_SUCCESS, retVal); retVal = clReleaseProgram(pProgram); EXPECT_EQ(CL_SUCCESS, retVal); diff --git a/unit_tests/helpers/test_files.cpp b/unit_tests/helpers/test_files.cpp index 08e748fd8e..9f6f3f4158 100644 --- a/unit_tests/helpers/test_files.cpp +++ b/unit_tests/helpers/test_files.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/helpers/file_io.h" #include "test_files.h" #include "config.h" @@ -37,4 +38,8 @@ void retrieveBinaryKernelFilename(std::string &outputFilename, const std::string outputFilename.append(binaryNameSuffix); outputFilename.append(extension); outputFilename.append(options); -} \ No newline at end of file + + if (!fileExists(outputFilename) && (extension == ".bc")) { + retrieveBinaryKernelFilename(outputFilename, kernelName, ".spv", options); + } +} diff --git a/unit_tests/mocks/mock_compilers.cpp b/unit_tests/mocks/mock_compilers.cpp index 15c0d2fa37..9e8a14f33f 100644 --- a/unit_tests/mocks/mock_compilers.cpp +++ b/unit_tests/mocks/mock_compilers.cpp @@ -406,12 +406,16 @@ void translate(bool usingIgc, CIF::Builtins::BufferSimple *src, CIF::Builtins::B } } - size_t fileSize = 0; - auto fileData = loadBinaryFile(inputFile, fileSize); + if ((debugVars.binaryToReturn != nullptr) || (debugVars.binaryToReturnSize != 0)) { + out->setOutput(debugVars.binaryToReturn, debugVars.binaryToReturnSize); + } else { + size_t fileSize = 0; + auto fileData = loadBinaryFile(inputFile, fileSize); - out->setOutput(fileData.get(), fileSize); - if (fileSize == 0) { - out->setError("error: Mock compiler could not find cached input file: " + inputFile); + out->setOutput(fileData.get(), fileSize); + if (fileSize == 0) { + out->setError("error: Mock compiler could not find cached input file: " + inputFile); + } } if (debugVars.debugDataToReturn != nullptr) { diff --git a/unit_tests/mocks/mock_compilers.h b/unit_tests/mocks/mock_compilers.h index afb2219718..443eb982f7 100644 --- a/unit_tests/mocks/mock_compilers.h +++ b/unit_tests/mocks/mock_compilers.h @@ -42,6 +42,8 @@ struct MockCompilerDebugVars { bool appendOptionsToFileName = true; void *debugDataToReturn = nullptr; size_t debugDataToReturnSize = 0; + void *binaryToReturn = nullptr; + size_t binaryToReturnSize = 0; bool failCreatePlatformInterface = false; bool failCreateGtSystemInfoInterface = false; bool failCreateIgcFeWaInterface = false;