diff --git a/runtime/built_ins/built_ins.cpp b/runtime/built_ins/built_ins.cpp index 52f50f456f..157d74794b 100644 --- a/runtime/built_ins/built_ins.cpp +++ b/runtime/built_ins/built_ins.cpp @@ -86,7 +86,8 @@ SchedulerKernel &BuiltIns::getSchedulerKernel(Context &context) { auto src = getInstance().builtinsLib->getBuiltinCode(EBuiltInOps::Scheduler, BuiltinCode::ECodeType::Any, *context.getDevice(0)); - auto program = Program::createFromGenBinary(&context, + auto program = Program::createFromGenBinary(*context.getDevice(0)->getExecutionEnvironment(), + &context, src.resource.data(), src.resource.size(), true, @@ -131,7 +132,8 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) { UNRECOVERABLE_IF(ret != CL_SUCCESS); UNRECOVERABLE_IF(sipBinary.size() == 0); - auto program = createProgramForSip(nullptr, + auto program = createProgramForSip(*device.getExecutionEnvironment(), + nullptr, sipBinary, sipBinary.size(), &retVal); diff --git a/runtime/built_ins/built_ins_storage.cpp b/runtime/built_ins/built_ins_storage.cpp index 8fc592efae..88580df84a 100644 --- a/runtime/built_ins/built_ins_storage.cpp +++ b/runtime/built_ins/built_ins_storage.cpp @@ -199,7 +199,7 @@ std::unique_ptr BuiltinsLib::createProgramFromCode(const BuiltinCode &b ret.reset(Program::create(data, &context, device, true, &err)); break; case BuiltinCode::ECodeType::Binary: - ret.reset(Program::createFromGenBinary(&context, data, dataLen, true, nullptr)); + ret.reset(Program::createFromGenBinary(*device.getExecutionEnvironment(), &context, data, dataLen, true, nullptr)); break; } return ret; diff --git a/runtime/helpers/built_ins_helper.cpp b/runtime/helpers/built_ins_helper.cpp index beed50ec94..7c2214c219 100644 --- a/runtime/helpers/built_ins_helper.cpp +++ b/runtime/helpers/built_ins_helper.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/built_ins_helper.h" #include "runtime/program/program.h" @@ -27,13 +28,15 @@ namespace OCLRT { const SipKernel &initSipKernel(SipKernelType type, Device &device) { return BuiltIns::getInstance().getSipKernel(type, device); } -Program *createProgramForSip(Context *context, +Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, + Context *context, std::vector &binary, size_t size, cl_int *errcodeRet) { cl_int retVal = 0; - auto program = Program::createFromGenBinary(nullptr, + auto program = Program::createFromGenBinary(executionEnvironment, + nullptr, binary.data(), size, true, diff --git a/runtime/helpers/built_ins_helper.h b/runtime/helpers/built_ins_helper.h index 44bcedae02..b56608d7f0 100644 --- a/runtime/helpers/built_ins_helper.h +++ b/runtime/helpers/built_ins_helper.h @@ -21,12 +21,14 @@ */ #pragma once +#include "runtime/execution_environment/execution_environment.h" #include "runtime/built_ins/built_ins.h" namespace OCLRT { const SipKernel &initSipKernel(SipKernelType type, Device &device); -Program *createProgramForSip(Context *context, +Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, + Context *context, std::vector &binary, size_t size, cl_int *errcodeRet); diff --git a/runtime/program/create.cpp b/runtime/program/create.cpp index d37be960f1..1520f47bb4 100644 --- a/runtime/program/create.cpp +++ b/runtime/program/create.cpp @@ -28,5 +28,5 @@ template Program *Program::create(cl_context, cl_uint, const cl_device_ template Program *Program::create(cl_context, cl_uint, const char **, const size_t *, cl_int &); template Program *Program::create(const char *, Context *, Device &, bool, cl_int *); template Program *Program::createFromIL(Context *, const void *, size_t length, cl_int &); -template Program *Program::createFromGenBinary(Context *context, const void *binary, size_t size, bool isBuiltIn, cl_int *errcodeRet); +template Program *Program::createFromGenBinary(ExecutionEnvironment &executionEnvironment, Context *context, const void *binary, size_t size, bool isBuiltIn, cl_int *errcodeRet); } // namespace OCLRT diff --git a/runtime/program/create.inl b/runtime/program/create.inl index ad4cd32853..91a5bcc628 100644 --- a/runtime/program/create.inl +++ b/runtime/program/create.inl @@ -122,6 +122,7 @@ T *Program::create( template T *Program::createFromGenBinary( + ExecutionEnvironment &executionEnvironment, Context *context, const void *binary, size_t size, diff --git a/runtime/program/program.h b/runtime/program/program.h index 99f5746e27..5d0f45cd6b 100644 --- a/runtime/program/program.h +++ b/runtime/program/program.h @@ -82,6 +82,7 @@ class Program : public BaseObject<_cl_program> { template static T *createFromGenBinary( + ExecutionEnvironment &executionEnvironment, Context *context, const void *binary, size_t size, diff --git a/unit_tests/built_ins/built_in_tests.cpp b/unit_tests/built_ins/built_in_tests.cpp index 9f58333888..0b037485d4 100644 --- a/unit_tests/built_ins/built_in_tests.cpp +++ b/unit_tests/built_ins/built_in_tests.cpp @@ -1719,7 +1719,7 @@ TEST_F(BuiltInTests, getSipKernelReturnsProgramCreatedOutOfIsaAcquiredFromCompil mockCompilerInterface.overrideGlobalCompilerInterface(); mockCompilerInterface.sipKernelBinaryOverride = mockCompilerInterface.getDummyGenBinary(); cl_int errCode = CL_BUILD_PROGRAM_FAILURE; - auto p = Program::createFromGenBinary(pContext, mockCompilerInterface.sipKernelBinaryOverride.data(), mockCompilerInterface.sipKernelBinaryOverride.size(), + auto p = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, mockCompilerInterface.sipKernelBinaryOverride.data(), mockCompilerInterface.sipKernelBinaryOverride.size(), false, &errCode); ASSERT_EQ(CL_SUCCESS, errCode); errCode = p->processGenBinary(); diff --git a/unit_tests/gtpin/gtpin_tests.cpp b/unit_tests/gtpin/gtpin_tests.cpp index 08abb456af..ccc781f27b 100644 --- a/unit_tests/gtpin/gtpin_tests.cpp +++ b/unit_tests/gtpin/gtpin_tests.cpp @@ -844,7 +844,7 @@ TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelWithoutSSHIsUsedThenK // Prepare a kernel without SSH char binary[1024] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t binSize = 10; - Program *pProgram = Program::createFromGenBinary(pContext, &binary[0], binSize, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, &binary[0], binSize, false, &retVal); ASSERT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); @@ -932,7 +932,7 @@ TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelWithExecEnvIsUsedThen // Prepare a kernel with fake Execution Environment char binary[1024] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t binSize = 10; - Program *pProgram = Program::createFromGenBinary(pContext, &binary[0], binSize, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, &binary[0], binSize, false, &retVal); ASSERT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1938,7 +1938,7 @@ TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenLowMemoryConditionOccursThe // Prepare a program with one kernel having Stateless Private Surface char binary[1024] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t binSize = 10; - Program *pProgram = Program::createFromGenBinary(pContext, &binary[0], binSize, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, &binary[0], binSize, false, &retVal); ASSERT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); @@ -2299,7 +2299,7 @@ TEST_F(ProgramTests, givenGenBinaryWithGtpinInfoWhenProcessGenBinaryCalledThenGt char genBin[1024] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t binSize = 10; - std::unique_ptr pProgram(Program::createFromGenBinary(nullptr, &genBin[0], binSize, false, &retVal)); + std::unique_ptr pProgram(Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), nullptr, &genBin[0], binSize, false, &retVal)); EXPECT_NE(nullptr, pProgram.get()); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ((uint32_t)CL_PROGRAM_BINARY_TYPE_EXECUTABLE, (uint32_t)pProgram->getProgramBinaryType()); diff --git a/unit_tests/helpers/built_ins_helper.cpp b/unit_tests/helpers/built_ins_helper.cpp index df5588d806..04f2e6e8a4 100644 --- a/unit_tests/helpers/built_ins_helper.cpp +++ b/unit_tests/helpers/built_ins_helper.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/built_ins_helper.h" #include "unit_tests/mocks/mock_compilers.h" #include "unit_tests/mocks/mock_program.h" @@ -31,7 +32,8 @@ const SipKernel &initSipKernel(SipKernelType type, Device &device) { mockCompilerInterface->sipKernelBinaryOverride = mockCompilerInterface->getDummyGenBinary(); return BuiltIns::getInstance().getSipKernel(type, device); } -Program *createProgramForSip(Context *context, +Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, + Context *context, std::vector &binary, size_t size, cl_int *errcodeRet) { diff --git a/unit_tests/mocks/mock_program.cpp b/unit_tests/mocks/mock_program.cpp index cc4cc8c550..becf11b9a5 100644 --- a/unit_tests/mocks/mock_program.cpp +++ b/unit_tests/mocks/mock_program.cpp @@ -28,6 +28,7 @@ namespace OCLRT { GlobalMockSipProgram *GlobalMockSipProgram::sipProgram; +ExecutionEnvironment GlobalMockSipProgram::executionEnvironment; std::string MockProgram::getCachedFileName() const { auto hwInfo = this->context->getDevice(0)->getHardwareInfo(); auto input = ArrayRef(this->sourceCode.c_str(), this->sourceCode.size()); @@ -52,7 +53,8 @@ void GlobalMockSipProgram::resetAllocationState() { void GlobalMockSipProgram::initSipProgram() { cl_int retVal = 0; std::vector binary = MockCompilerInterface::getDummyGenBinary(); - sipProgram = Program::createFromGenBinary(nullptr, + sipProgram = Program::createFromGenBinary(executionEnvironment, + nullptr, binary.data(), binary.size(), true, @@ -126,7 +128,7 @@ Program *GlobalMockSipProgram::getSipProgramWithCustomBinary() { pKHdr->CheckSum = static_cast(hashValue & 0xFFFFFFFF); auto errCode = CL_SUCCESS; - auto program = Program::createFromGenBinary(nullptr, binary, totalSize, false, &errCode); + auto program = Program::createFromGenBinary(executionEnvironment, nullptr, binary, totalSize, false, &errCode); UNRECOVERABLE_IF(errCode != CL_SUCCESS); errCode = program->processGenBinary(); UNRECOVERABLE_IF(errCode != CL_SUCCESS); diff --git a/unit_tests/mocks/mock_program.h b/unit_tests/mocks/mock_program.h index ea86b147ac..194ebcb24f 100644 --- a/unit_tests/mocks/mock_program.h +++ b/unit_tests/mocks/mock_program.h @@ -161,6 +161,7 @@ class GlobalMockSipProgram : public Program { protected: void *sipAllocationStorage; + static ExecutionEnvironment executionEnvironment; }; } // namespace OCLRT diff --git a/unit_tests/program/evaluate_unhandled_token_tests.cpp b/unit_tests/program/evaluate_unhandled_token_tests.cpp index d033dfe685..6c1e6d3be6 100644 --- a/unit_tests/program/evaluate_unhandled_token_tests.cpp +++ b/unit_tests/program/evaluate_unhandled_token_tests.cpp @@ -21,6 +21,7 @@ */ #include "gtest/gtest.h" +#include "runtime/execution_environment/execution_environment.h" #include "runtime/program/create.inl" #include "runtime/program/program.h" @@ -50,10 +51,12 @@ struct MockProgramRecordUnhandledTokens : OCLRT::Program { inline cl_int GetDecodeErrorCode(const std::vector &binary, bool allowUnhandledTokens, int defaultUnhandledTokenId, int &foundUnhandledTokenId) { + OCLRT::ExecutionEnvironment executionEnvironment; using PT = MockProgramRecordUnhandledTokens; std::unique_ptr prog; cl_int errorCode = CL_INVALID_BINARY; - prog.reset(OCLRT::Program::createFromGenBinary(nullptr, + prog.reset(OCLRT::Program::createFromGenBinary(executionEnvironment, + nullptr, binary.data(), binary.size(), false, &errorCode)); diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index 3fba1418fc..74def4da0e 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -1582,7 +1582,8 @@ TEST(ProgramFromBinaryTests, givenBinaryWithInvalidICBEThenErrorIsReturned) { { // whatever method we choose CL_INVALID_BINARY is always returned - std::unique_ptr pProgram(Program::createFromGenBinary(nullptr, &binHeader, binSize, false, &retVal)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr pProgram(Program::createFromGenBinary(executionEnvironment, nullptr, &binHeader, binSize, false, &retVal)); ASSERT_NE(nullptr, pProgram.get()); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1622,7 +1623,8 @@ TEST(ProgramFromBinaryTests, CreateWithBinary_FailRecompile) { binHeader.PatchListSize = 0; size_t binSize = sizeof(SProgramBinaryHeader); - std::unique_ptr pProgram(FailProgram::createFromGenBinary(nullptr, &binHeader, binSize, false, &retVal)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr pProgram(FailProgram::createFromGenBinary(executionEnvironment, nullptr, &binHeader, binSize, false, &retVal)); ASSERT_NE(nullptr, pProgram.get()); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1657,7 +1659,8 @@ TEST(ProgramFromBinaryTests, givenEmptyProgramThenErrorIsReturned) { binHeader.PatchListSize = 0; size_t binSize = sizeof(SProgramBinaryHeader); - std::unique_ptr pProgram(TestedProgram::createFromGenBinary(nullptr, &binHeader, binSize, false, &retVal)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr pProgram(TestedProgram::createFromGenBinary(executionEnvironment, nullptr, &binHeader, binSize, false, &retVal)); ASSERT_NE(nullptr, pProgram.get()); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1927,7 +1930,7 @@ TEST_F(ProgramTests, ProgramCreateT3Success) { TEST_F(ProgramTests, ProgramFromGenBinaryWithNullBinary) { cl_int retVal = CL_SUCCESS; - Program *pProgram = Program::createFromGenBinary(pContext, nullptr, 0, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, nullptr, 0, false, &retVal); EXPECT_EQ(nullptr, pProgram); EXPECT_NE(CL_SUCCESS, retVal); } @@ -1937,7 +1940,7 @@ TEST_F(ProgramTests, ProgramFromGenBinary) { char binary[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t size = 10; - Program *pProgram = Program::createFromGenBinary(pContext, binary, size, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, binary, size, false, &retVal); EXPECT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1958,7 +1961,7 @@ TEST_F(ProgramTests, ProgramFromGenBinaryWithBuiltInFlagSet) { char binary[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t size = 10; - Program *pProgram = Program::createFromGenBinary(pContext, binary, size, true, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, binary, size, true, &retVal); EXPECT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1971,7 +1974,7 @@ TEST_F(ProgramTests, ProgramFromGenBinaryWithoutRetVal) { char binary[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t size = 10; - Program *pProgram = Program::createFromGenBinary(pContext, binary, size, false, nullptr); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), pContext, binary, size, false, nullptr); EXPECT_NE(nullptr, pProgram); EXPECT_EQ((uint32_t)CL_PROGRAM_BINARY_TYPE_EXECUTABLE, (uint32_t)pProgram->getProgramBinaryType()); @@ -1989,7 +1992,7 @@ TEST_F(ProgramTests, ProgramFromGenBinaryWithNullcontext) { char binary[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t size = 10; - Program *pProgram = Program::createFromGenBinary(nullptr, binary, size, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), nullptr, binary, size, false, &retVal); EXPECT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ((uint32_t)CL_PROGRAM_BINARY_TYPE_EXECUTABLE, (uint32_t)pProgram->getProgramBinaryType()); @@ -2008,7 +2011,7 @@ TEST_F(ProgramTests, ProgramFromGenBinaryWithPATCH_TOKEN_GLOBAL_MEMORY_OBJECT_KE char genBin[1024] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t binSize = 10; - Program *pProgram = Program::createFromGenBinary(nullptr, &genBin[0], binSize, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), nullptr, &genBin[0], binSize, false, &retVal); EXPECT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ((uint32_t)CL_PROGRAM_BINARY_TYPE_EXECUTABLE, (uint32_t)pProgram->getProgramBinaryType()); @@ -2073,7 +2076,7 @@ TEST_F(ProgramTests, ProgramFromGenBinaryWithPATCH_TOKEN_GTPIN_FREE_GRF_INFO) { char genBin[1024] = {1, 2, 3, 4, 5, 6, 7, 8, 9, '\0'}; size_t binSize = 10; - Program *pProgram = Program::createFromGenBinary(nullptr, &genBin[0], binSize, false, &retVal); + Program *pProgram = Program::createFromGenBinary(*pDevice->getExecutionEnvironment(), nullptr, &genBin[0], binSize, false, &retVal); EXPECT_NE(nullptr, pProgram); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ((uint32_t)CL_PROGRAM_BINARY_TYPE_EXECUTABLE, (uint32_t)pProgram->getProgramBinaryType());