diff --git a/opencl/test/unit_test/built_ins/built_in_tests.cpp b/opencl/test/unit_test/built_ins/built_in_tests.cpp index 5612e0bbf0..5ebe131584 100644 --- a/opencl/test/unit_test/built_ins/built_in_tests.cpp +++ b/opencl/test/unit_test/built_ins/built_in_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -34,6 +34,7 @@ #include "opencl/test/unit_test/mocks/mock_command_queue.h" #include "opencl/test/unit_test/mocks/mock_compilers.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/test_macros/test_checks_ocl.h" #include "test.h" @@ -2009,24 +2010,12 @@ TEST_F(BuiltInTests, WhenGettingSipKernelThenReturnProgramCreatedFromIsaAcquired pDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->builtins.reset(builtins); mockCompilerInterface->sipKernelBinaryOverride = mockCompilerInterface->getDummyGenBinary(); - cl_int errCode = CL_BUILD_PROGRAM_FAILURE; - auto p = Program::createBuiltInFromGenBinary(pContext, pContext->getDevices(), mockCompilerInterface->sipKernelBinaryOverride.data(), mockCompilerInterface->sipKernelBinaryOverride.size(), &errCode); - ASSERT_EQ(CL_SUCCESS, errCode); - errCode = p->processGenBinary(*pClDevice); - ASSERT_EQ(CL_SUCCESS, errCode); - - const auto &sipKernelInfo = p->getKernelInfo(static_cast(0), rootDeviceIndex); - - auto compbinedKernelHeapSize = sipKernelInfo->heapInfo.KernelHeapSize; - auto sipOffset = sipKernelInfo->systemKernelOffset; - ASSERT_GT(compbinedKernelHeapSize, sipOffset); - const SipKernel &sipKernel = builtins->getSipKernel(SipKernelType::Csr, *pDevice); - auto expectedMem = reinterpret_cast(sipKernelInfo->heapInfo.pKernelHeap) + sipOffset; - EXPECT_EQ(0, memcmp(expectedMem, sipKernel.getSipAllocation()->getUnderlyingBuffer(), compbinedKernelHeapSize - sipOffset)); + auto expectedMem = mockCompilerInterface->sipKernelBinaryOverride.data(); + EXPECT_EQ(0, memcmp(expectedMem, sipKernel.getSipAllocation()->getUnderlyingBuffer(), mockCompilerInterface->sipKernelBinaryOverride.size())); EXPECT_EQ(SipKernelType::Csr, mockCompilerInterface->requestedSipKernel); - p->release(); + mockCompilerInterface->releaseDummyGenBinary(); } @@ -2036,6 +2025,22 @@ TEST_F(BuiltInTests, givenSipKernelWhenItIsCreatedThenItHasGraphicsAllocationFor EXPECT_NE(nullptr, sipAllocation); } +TEST_F(BuiltInTests, givenSipKernelWhenAllocationFailsThenItHasNullptrGraphicsAllocation) { + auto executionEnvironment = new MockExecutionEnvironment; + executionEnvironment->prepareRootDeviceEnvironments(1); + auto memoryManager = new MockMemoryManager(*executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); + auto device = std::unique_ptr(Device::create(executionEnvironment, 0u)); + EXPECT_NE(nullptr, device); + + memoryManager->failAllocate32Bit = true; + + auto builtins = std::make_unique(); + const SipKernel &sipKern = builtins->getSipKernel(SipKernelType::Csr, *device); + auto sipAllocation = sipKern.getSipAllocation(); + EXPECT_EQ(nullptr, sipAllocation); +} + TEST_F(BuiltInTests, givenSameDeviceIsUsedWhenUsingStaticGetterThenExpectRetrieveSameAllocation) { const SipKernel &sipKern = pDevice->getBuiltIns()->getSipKernel(SipKernelType::Csr, pContext->getDevice(0)->getDevice()); auto sipAllocation = sipKern.getSipAllocation(); diff --git a/opencl/test/unit_test/built_ins/sip_tests.cpp b/opencl/test/unit_test/built_ins/sip_tests.cpp index 1686476e4e..34ce042fe5 100644 --- a/opencl/test/unit_test/built_ins/sip_tests.cpp +++ b/opencl/test/unit_test/built_ins/sip_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,67 +19,6 @@ using namespace NEO; namespace SipKernelTests { -std::string getDebugSipKernelNameWithBitnessAndProductSuffix(std::string &base, const char *product) { - std::string fullName = base + std::string("_"); - - if (sizeof(uintptr_t) == 8) { - fullName.append("64_"); - } else { - fullName.append("32_"); - } - - fullName.append(product); - return fullName; -} - -TEST(Sip, WhenSipKernelIsInvalidThenEmptyCompilerInternalOptionsAreReturned) { - const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::COUNT); - ASSERT_NE(nullptr, opt); - EXPECT_EQ(0U, strlen(opt)); -} - -TEST(Sip, WhenRequestingCsrSipKernelThenProperCompilerInternalOptionsAreReturned) { - const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::Csr); - ASSERT_NE(nullptr, opt); - EXPECT_STREQ("-cl-include-sip-csr", opt); -} - -TEST(Sip, When32BitAddressesAreNotBeingForcedThenSipLlHasSameBitnessAsHostApplication) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - EXPECT_NE(nullptr, mockDevice); - mockDevice->deviceInfo.force32BitAddressess = false; - const char *src = getSipLlSrc(*mockDevice); - ASSERT_NE(nullptr, src); - if (sizeof(void *) == 8) { - EXPECT_NE(nullptr, strstr(src, "target datalayout = \"e-p:64:64:64\"")); - EXPECT_NE(nullptr, strstr(src, "target triple = \"spir64\"")); - } else { - EXPECT_NE(nullptr, strstr(src, "target datalayout = \"e-p:32:32:32\"")); - EXPECT_NE(nullptr, strstr(src, "target triple = \"spir\"")); - EXPECT_EQ(nullptr, strstr(src, "target triple = \"spir64\"")); - } -} - -TEST(Sip, When32BitAddressesAreBeingForcedThenSipLlHas32BitAddresses) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - EXPECT_NE(nullptr, mockDevice); - mockDevice->deviceInfo.force32BitAddressess = true; - const char *src = getSipLlSrc(*mockDevice); - ASSERT_NE(nullptr, src); - EXPECT_NE(nullptr, strstr(src, "target datalayout = \"e-p:32:32:32\"")); - EXPECT_NE(nullptr, strstr(src, "target triple = \"spir\"")); - EXPECT_EQ(nullptr, strstr(src, "target triple = \"spir64\"")); -} - -TEST(Sip, GivenSipLlWhenGettingMetadataThenMetadataRequiredByCompilerIsReturned) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - EXPECT_NE(nullptr, mockDevice); - const char *src = getSipLlSrc(*mockDevice); - ASSERT_NE(nullptr, src); - - EXPECT_NE(nullptr, strstr(src, "!opencl.compiler.options")); - EXPECT_NE(nullptr, strstr(src, "!opencl.kernels")); -} TEST(Sip, WhenGettingTypeThenCorrectTypeIsReturned) { SipKernel csr{SipKernelType::Csr, nullptr}; @@ -109,18 +48,6 @@ TEST(DebugSip, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrSipTypeIsReturn EXPECT_LE(SipKernelType::DbgCsr, sipType); } -TEST(DebugSip, WhenRequestingDbgCsrSipKernelThenProperCompilerInternalOptionsAreReturned) { - const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::DbgCsr); - ASSERT_NE(nullptr, opt); - EXPECT_STREQ("-cl-include-sip-kernel-debug -cl-include-sip-csr -cl-set-bti:0", opt); -} - -TEST(DebugSip, WhenRequestingDbgCsrWithLocalMemorySipKernelThenProperCompilerInternalOptionsAreReturned) { - const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::DbgCsrLocal); - ASSERT_NE(nullptr, opt); - EXPECT_STREQ("-cl-include-sip-kernel-local-debug -cl-include-sip-csr -cl-set-bti:0", opt); -} - TEST(DebugSip, givenBuiltInsWhenDbgCsrSipIsRequestedThanCorrectSipKernelIsReturned) { auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); EXPECT_NE(nullptr, mockDevice); diff --git a/opencl/test/unit_test/gen9/sip_tests_gen9.cpp b/opencl/test/unit_test/gen9/sip_tests_gen9.cpp index cabafa5395..001a65f497 100644 --- a/opencl/test/unit_test/gen9/sip_tests_gen9.cpp +++ b/opencl/test/unit_test/gen9/sip_tests_gen9.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,8 +18,6 @@ using namespace NEO; namespace SipKernelTests { -extern std::string getDebugSipKernelNameWithBitnessAndProductSuffix(std::string &base, const char *product); - typedef ::testing::Test gen9SipTests; GEN9TEST_F(gen9SipTests, givenDebugCsrSipKernelWithLocalMemoryWhenAskedForDebugSurfaceBtiAndSizeThenBtiIsZeroAndSizeGreaterThanZero) { diff --git a/opencl/test/unit_test/mocks/mock_compilers.cpp b/opencl/test/unit_test/mocks/mock_compilers.cpp index da257ca658..8651897410 100644 --- a/opencl/test/unit_test/mocks/mock_compilers.cpp +++ b/opencl/test/unit_test/mocks/mock_compilers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -490,6 +490,15 @@ bool MockIgcOclDeviceCtx::GetSystemRoutine(IGC::SystemRoutineType::SystemRoutine bool bindless, CIF::Builtins::BufferSimple *outSystemRoutineBuffer, CIF::Builtins::BufferSimple *stateSaveAreaHeaderInit) { + MockCompilerDebugVars &debugVars = *NEO::igcDebugVars; + debugVars.typeOfSystemRoutine = typeOfSystemRoutine; + const char mockData[64] = {'C', 'T', 'N', 'I'}; + + if (debugVars.forceBuildFailure || typeOfSystemRoutine == IGC::SystemRoutineType::undefined) { + return false; + } + + outSystemRoutineBuffer->PushBackRawBytes(mockData, 64); return true; } @@ -636,7 +645,6 @@ std::vector MockCompilerInterface::getDummyGenBinary() { return MockSipKernel::getDummyGenBinary(); } void MockCompilerInterface::releaseDummyGenBinary() { - MockSipKernel::shutDown(); } } // namespace NEO diff --git a/opencl/test/unit_test/mocks/mock_sip.cpp b/opencl/test/unit_test/mocks/mock_sip.cpp index 0407a15258..e81d73261f 100644 --- a/opencl/test/unit_test/mocks/mock_sip.cpp +++ b/opencl/test/unit_test/mocks/mock_sip.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -26,7 +26,7 @@ namespace NEO { MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : SipKernel(type, sipAlloc) { this->mockSipMemoryAllocation = std::make_unique(0u, - GraphicsAllocation::AllocationType::KERNEL_ISA, + GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, nullptr, MemoryConstants::pageSize * 10u, 0u, @@ -37,7 +37,7 @@ MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) { this->mockSipMemoryAllocation = std::make_unique(0u, - GraphicsAllocation::AllocationType::KERNEL_ISA, + GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, nullptr, MemoryConstants::pageSize * 10u, 0u, @@ -47,31 +47,10 @@ MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) { MockSipKernel::~MockSipKernel() = default; -std::vector MockSipKernel::dummyBinaryForSip; +const char *MockSipKernel::dummyBinaryForSip = "12345678"; + std::vector MockSipKernel::getDummyGenBinary() { - if (dummyBinaryForSip.empty()) { - dummyBinaryForSip = getBinary(); - } - return dummyBinaryForSip; -} -std::vector MockSipKernel::getBinary() { - std::string testFile; - retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".gen"); - - size_t binarySize = 0; - auto binary = loadDataFromFile(testFile.c_str(), binarySize); - UNRECOVERABLE_IF(binary == nullptr); - - std::vector ret{binary.get(), binary.get() + binarySize}; - - return ret; -} -void MockSipKernel::initDummyBinary() { - dummyBinaryForSip = getBinary(); -} -void MockSipKernel::shutDown() { - MockSipKernel::dummyBinaryForSip.clear(); - std::vector().swap(MockSipKernel::dummyBinaryForSip); + return std::vector(dummyBinaryForSip, dummyBinaryForSip + sizeof(MockSipKernel::dummyBinaryForSip)); } GraphicsAllocation *MockSipKernel::getSipAllocation() const { diff --git a/opencl/test/unit_test/mocks/mock_sip.h b/opencl/test/unit_test/mocks/mock_sip.h index 7dbb801cc5..73f4605ccd 100644 --- a/opencl/test/unit_test/mocks/mock_sip.h +++ b/opencl/test/unit_test/mocks/mock_sip.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -25,11 +25,8 @@ class MockSipKernel : public SipKernel { MockSipKernel(); ~MockSipKernel() override; - static std::vector dummyBinaryForSip; + static const char *dummyBinaryForSip; static std::vector getDummyGenBinary(); - static std::vector getBinary(); - static void initDummyBinary(); - static void shutDown(); GraphicsAllocation *getSipAllocation() const override; diff --git a/opencl/test/unit_test/offline_compiler/mock/mock_sip_ocloc_tests.cpp b/opencl/test/unit_test/offline_compiler/mock/mock_sip_ocloc_tests.cpp index 6bc3623130..d21fffcbe3 100644 --- a/opencl/test/unit_test/offline_compiler/mock/mock_sip_ocloc_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/mock/mock_sip_ocloc_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,18 +13,8 @@ static std::vector dummyBinaryForSip; using namespace NEO; -std::vector MockSipKernel::dummyBinaryForSip; +const char *MockSipKernel::dummyBinaryForSip = "12345678"; std::vector MockSipKernel::getDummyGenBinary() { - return MockSipKernel::dummyBinaryForSip; -} - -std::vector MockSipKernel::getBinary() { - return MockSipKernel::dummyBinaryForSip; -} - -void MockSipKernel::initDummyBinary() { -} - -void MockSipKernel::shutDown() { + return std::vector(dummyBinaryForSip, dummyBinaryForSip + sizeof(MockSipKernel::dummyBinaryForSip)); } diff --git a/shared/source/built_ins/built_ins.cpp b/shared/source/built_ins/built_ins.cpp index 943fa0df6d..126bf3af5c 100644 --- a/shared/source/built_ins/built_ins.cpp +++ b/shared/source/built_ins/built_ins.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -46,23 +46,22 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) { UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success); UNRECOVERABLE_IF(sipBinary.size() == 0); - ProgramInfo programInfo; - auto blob = ArrayRef(reinterpret_cast(sipBinary.data()), sipBinary.size()); - SingleDeviceBinary deviceBinary = {}; - deviceBinary.deviceBinary = blob; - std::string decodeErrors; - std::string decodeWarnings; + const auto allocType = GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL; - DecodeError decodeError; - DeviceBinaryFormat singleDeviceBinaryFormat; - std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, deviceBinary, decodeErrors, decodeWarnings); - UNRECOVERABLE_IF(DecodeError::Success != decodeError); + AllocationProperties properties = {device.getRootDeviceIndex(), sipBinary.size(), allocType, device.getDeviceBitfield()}; + properties.flags.use32BitFrontWindow = false; - auto success = programInfo.kernelInfos[0]->createKernelAllocation(device, true); - UNRECOVERABLE_IF(!success); + auto sipAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); - sipBuiltIn.first.reset(new SipKernel(type, programInfo.kernelInfos[0]->kernelAllocation)); - programInfo.kernelInfos[0]->kernelAllocation = nullptr; + auto &hwInfo = device.getHardwareInfo(); + auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + + if (sipAllocation) { + MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *sipAllocation), + device, sipAllocation, 0, sipBinary.data(), + sipBinary.size()); + } + sipBuiltIn.first.reset(new SipKernel(type, sipAllocation)); }; std::call_once(sipBuiltIn.second, initializer); UNRECOVERABLE_IF(sipBuiltIn.first == nullptr); diff --git a/shared/source/built_ins/sip.cpp b/shared/source/built_ins/sip.cpp index fa07ba63fc..dae8ff3477 100644 --- a/shared/source/built_ins/sip.cpp +++ b/shared/source/built_ins/sip.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,51 +22,6 @@ namespace NEO { const size_t SipKernel::maxDbgSurfaceSize = 0x1800000; // proper value should be taken from compiler when it's ready -const char *getSipKernelCompilerInternalOptions(SipKernelType kernel) { - switch (kernel) { - default: - DEBUG_BREAK_IF(true); - return ""; - case SipKernelType::Csr: - return "-cl-include-sip-csr"; - case SipKernelType::DbgCsr: - return "-cl-include-sip-kernel-debug -cl-include-sip-csr -cl-set-bti:0"; - case SipKernelType::DbgCsrLocal: - return "-cl-include-sip-kernel-local-debug -cl-include-sip-csr -cl-set-bti:0"; - } -} - -const char *getSipLlSrc(const Device &device) { -#define M_DUMMY_LL_SRC \ - "define void @f() { \n" \ - " ret void \n" \ - "} \n" \ - "!opencl.compiler.options = !{!0} \n" \ - "!opencl.kernels = !{!1} \n" \ - "!0 = !{} \n" \ - "!1 = !{void()* @f, !2, !3, !4, !5, !6, !7} \n" \ - "!2 = !{!\"kernel_arg_addr_space\"} \n" \ - "!3 = !{!\"kernel_arg_access_qual\"} \n" \ - "!4 = !{!\"kernel_arg_type\"} \n" \ - "!5 = !{!\"kernel_arg_type_qual\"} \n" \ - "!6 = !{!\"kernel_arg_base_type\"} \n" \ - "!7 = !{!\"kernel_arg_name\"} \n" - - constexpr const char *llDummySrc32 = - "target datalayout = \"e-p:32:32:32\" \n" - "target triple = \"spir\" \n" M_DUMMY_LL_SRC; - - constexpr const char *llDummySrc64 = - "target datalayout = \"e-p:64:64:64\" \n" - "target triple = \"spir64\" \n" M_DUMMY_LL_SRC; - -#undef M_DUMMY_LL_SRC - - const uint32_t ptrSize = device.getDeviceInfo().force32BitAddressess ? 4 : sizeof(void *); - - return (ptrSize == 8) ? llDummySrc64 : llDummySrc32; -} - SipKernel::~SipKernel() = default; SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : type(type), sipAllocation(sipAlloc) { diff --git a/shared/source/built_ins/sip.h b/shared/source/built_ins/sip.h index d8566bd15d..fcebc5ffd2 100644 --- a/shared/source/built_ins/sip.h +++ b/shared/source/built_ins/sip.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,10 +17,6 @@ namespace NEO { class Device; class GraphicsAllocation; -const char *getSipKernelCompilerInternalOptions(SipKernelType kernel); - -const char *getSipLlSrc(const Device &device); - class SipKernel { public: SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc); diff --git a/shared/source/compiler_interface/compiler_interface.cpp b/shared/source/compiler_interface/compiler_interface.cpp index 04463b0282..cb74860339 100644 --- a/shared/source/compiler_interface/compiler_interface.cpp +++ b/shared/source/compiler_interface/compiler_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -308,23 +308,37 @@ TranslationOutput::ErrorCode CompilerInterface::getSipKernelBinary(NEO::Device & return TranslationOutput::ErrorCode::CompilerNotAvailable; } - const char *sipSrc = getSipLlSrc(device); - std::string sipInternalOptions = getSipKernelCompilerInternalOptions(type); + IGC::SystemRoutineType::SystemRoutineType_t typeOfSystemRoutine = IGC::SystemRoutineType::undefined; + switch (type) { + case SipKernelType::Csr: + typeOfSystemRoutine = IGC::SystemRoutineType::contextSaveRestore; + break; + case SipKernelType::DbgCsr: + typeOfSystemRoutine = IGC::SystemRoutineType::debug; + break; + case SipKernelType::DbgCsrLocal: + typeOfSystemRoutine = IGC::SystemRoutineType::debugSlm; + break; + default: + break; + } - auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), sipSrc, strlen(sipSrc) + 1); - auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0); - auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), sipInternalOptions.c_str(), sipInternalOptions.size() + 1); + auto deviceCtx = getIgcDeviceCtx(device); + const bool bindlessSip = false; - auto igcTranslationCtx = createIgcTranslationCtx(device, IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin); + auto systemRoutineBuffer = igcMain.get()->CreateBuiltin(); + auto stateSaveAreaBuffer = igcMain.get()->CreateBuiltin(); - auto igcOutput = translate(igcTranslationCtx.get(), igcSrc.get(), - igcOptions.get(), igcInternalOptions.get()); + auto result = deviceCtx->GetSystemRoutine(typeOfSystemRoutine, + bindlessSip, + systemRoutineBuffer.get(), + stateSaveAreaBuffer.get()); - if ((igcOutput == nullptr) || (igcOutput->Successful() == false)) { + if (!result) { return TranslationOutput::ErrorCode::UnknownError; } - retBinary.assign(igcOutput->GetOutput()->GetMemory(), igcOutput->GetOutput()->GetMemory() + igcOutput->GetOutput()->GetSizeRaw()); + retBinary.assign(systemRoutineBuffer->GetMemory(), systemRoutineBuffer->GetMemory() + systemRoutineBuffer->GetSizeRaw()); return TranslationOutput::ErrorCode::Success; } diff --git a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp index a0bf31abba..40a772cec5 100644 --- a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp +++ b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1007,15 +1007,7 @@ TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenGetSipKernelBinaryFa EXPECT_EQ(0U, sipBinary.size()); } -TEST_F(CompilerInterfaceTest, whenIgcTranslatorReturnsNullptrThenGetSipKernelBinaryFailsGracefully) { - pCompilerInterface->failCreateIgcTranslationCtx = true; - std::vector sipBinary; - auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary); - EXPECT_EQ(TranslationOutput::ErrorCode::UnknownError, err); - EXPECT_EQ(0U, sipBinary.size()); -} - -TEST_F(CompilerInterfaceTest, whenIgcTranslatorReturnsBuildErrorThenGetSipKernelBinaryFailsGracefully) { +TEST_F(CompilerInterfaceTest, whenIgcReturnsErrorThenGetSipKernelBinaryFailsGracefully) { MockCompilerDebugVars igcDebugVars; igcDebugVars.forceBuildFailure = true; gEnvironment->igcPushDebugVars(igcDebugVars); @@ -1040,22 +1032,36 @@ TEST_F(CompilerInterfaceTest, whenEverythingIsOkThenGetSipKernelReturnsIgcsOutpu gEnvironment->igcPopDebugVars(); } -TEST_F(CompilerInterfaceTest, whenRequestingSipKernelBinaryThenProperInternalOptionsAndSrcAreUsed) { - std::string receivedInternalOptions; - std::string receivedInput; - +TEST_F(CompilerInterfaceTest, whenRequestingSipKernelBinaryThenProperSystemRoutineIsSelectedFromCompiler) { MockCompilerDebugVars igcDebugVars; - retrieveBinaryKernelFilename(igcDebugVars.fileName, "CopyBuffer_simd16_", ".bc"); - igcDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions; - igcDebugVars.receivedInput = &receivedInput; gEnvironment->igcPushDebugVars(igcDebugVars); std::vector sipBinary; auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary); EXPECT_EQ(TranslationOutput::ErrorCode::Success, err); EXPECT_NE(0U, sipBinary.size()); - EXPECT_EQ(0, strcmp(getSipKernelCompilerInternalOptions(SipKernelType::Csr), receivedInternalOptions.c_str())); - std::string expectedInut = getSipLlSrc(*this->pDevice); - EXPECT_EQ(0, strcmp(expectedInut.c_str(), receivedInput.c_str())); + EXPECT_EQ(IGC::SystemRoutineType::contextSaveRestore, getIgcDebugVars().typeOfSystemRoutine); + + err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsr, sipBinary); + EXPECT_EQ(TranslationOutput::ErrorCode::Success, err); + EXPECT_NE(0U, sipBinary.size()); + EXPECT_EQ(IGC::SystemRoutineType::debug, getIgcDebugVars().typeOfSystemRoutine); + + err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsrLocal, sipBinary); + EXPECT_EQ(TranslationOutput::ErrorCode::Success, err); + EXPECT_NE(0U, sipBinary.size()); + EXPECT_EQ(IGC::SystemRoutineType::debugSlm, getIgcDebugVars().typeOfSystemRoutine); + + gEnvironment->igcPopDebugVars(); +} + +TEST_F(CompilerInterfaceTest, whenRequestingIvalidSipKernelBinaryThenErrorIsReturned) { + MockCompilerDebugVars igcDebugVars; + gEnvironment->igcPushDebugVars(igcDebugVars); + std::vector sipBinary; + auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::COUNT, sipBinary); + EXPECT_EQ(TranslationOutput::ErrorCode::UnknownError, err); + EXPECT_EQ(0U, sipBinary.size()); + EXPECT_EQ(IGC::SystemRoutineType::undefined, getIgcDebugVars().typeOfSystemRoutine); gEnvironment->igcPopDebugVars(); }