Skip to content

Commit 0eb10d7

Browse files
Switch to new compiler interface to get system routine
Related-To: NEO-4773
1 parent 3ca77a6 commit 0eb10d7

File tree

12 files changed

+111
-237
lines changed

12 files changed

+111
-237
lines changed

opencl/test/unit_test/built_ins/built_in_tests.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -34,6 +34,7 @@
3434
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
3535
#include "opencl/test/unit_test/mocks/mock_compilers.h"
3636
#include "opencl/test/unit_test/mocks/mock_kernel.h"
37+
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
3738
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
3839
#include "test.h"
3940

@@ -2009,24 +2010,12 @@ TEST_F(BuiltInTests, WhenGettingSipKernelThenReturnProgramCreatedFromIsaAcquired
20092010
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->builtins.reset(builtins);
20102011
mockCompilerInterface->sipKernelBinaryOverride = mockCompilerInterface->getDummyGenBinary();
20112012

2012-
cl_int errCode = CL_BUILD_PROGRAM_FAILURE;
2013-
auto p = Program::createBuiltInFromGenBinary(pContext, pContext->getDevices(), mockCompilerInterface->sipKernelBinaryOverride.data(), mockCompilerInterface->sipKernelBinaryOverride.size(), &errCode);
2014-
ASSERT_EQ(CL_SUCCESS, errCode);
2015-
errCode = p->processGenBinary(*pClDevice);
2016-
ASSERT_EQ(CL_SUCCESS, errCode);
2017-
2018-
const auto &sipKernelInfo = p->getKernelInfo(static_cast<size_t>(0), rootDeviceIndex);
2019-
2020-
auto compbinedKernelHeapSize = sipKernelInfo->heapInfo.KernelHeapSize;
2021-
auto sipOffset = sipKernelInfo->systemKernelOffset;
2022-
ASSERT_GT(compbinedKernelHeapSize, sipOffset);
2023-
20242013
const SipKernel &sipKernel = builtins->getSipKernel(SipKernelType::Csr, *pDevice);
20252014

2026-
auto expectedMem = reinterpret_cast<const char *>(sipKernelInfo->heapInfo.pKernelHeap) + sipOffset;
2027-
EXPECT_EQ(0, memcmp(expectedMem, sipKernel.getSipAllocation()->getUnderlyingBuffer(), compbinedKernelHeapSize - sipOffset));
2015+
auto expectedMem = mockCompilerInterface->sipKernelBinaryOverride.data();
2016+
EXPECT_EQ(0, memcmp(expectedMem, sipKernel.getSipAllocation()->getUnderlyingBuffer(), mockCompilerInterface->sipKernelBinaryOverride.size()));
20282017
EXPECT_EQ(SipKernelType::Csr, mockCompilerInterface->requestedSipKernel);
2029-
p->release();
2018+
20302019
mockCompilerInterface->releaseDummyGenBinary();
20312020
}
20322021

@@ -2036,6 +2025,22 @@ TEST_F(BuiltInTests, givenSipKernelWhenItIsCreatedThenItHasGraphicsAllocationFor
20362025
EXPECT_NE(nullptr, sipAllocation);
20372026
}
20382027

2028+
TEST_F(BuiltInTests, givenSipKernelWhenAllocationFailsThenItHasNullptrGraphicsAllocation) {
2029+
auto executionEnvironment = new MockExecutionEnvironment;
2030+
executionEnvironment->prepareRootDeviceEnvironments(1);
2031+
auto memoryManager = new MockMemoryManager(*executionEnvironment);
2032+
executionEnvironment->memoryManager.reset(memoryManager);
2033+
auto device = std::unique_ptr<RootDevice>(Device::create<RootDevice>(executionEnvironment, 0u));
2034+
EXPECT_NE(nullptr, device);
2035+
2036+
memoryManager->failAllocate32Bit = true;
2037+
2038+
auto builtins = std::make_unique<BuiltIns>();
2039+
const SipKernel &sipKern = builtins->getSipKernel(SipKernelType::Csr, *device);
2040+
auto sipAllocation = sipKern.getSipAllocation();
2041+
EXPECT_EQ(nullptr, sipAllocation);
2042+
}
2043+
20392044
TEST_F(BuiltInTests, givenSameDeviceIsUsedWhenUsingStaticGetterThenExpectRetrieveSameAllocation) {
20402045
const SipKernel &sipKern = pDevice->getBuiltIns()->getSipKernel(SipKernelType::Csr, pContext->getDevice(0)->getDevice());
20412046
auto sipAllocation = sipKern.getSipAllocation();

opencl/test/unit_test/built_ins/sip_tests.cpp

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -19,67 +19,6 @@
1919
using namespace NEO;
2020

2121
namespace SipKernelTests {
22-
std::string getDebugSipKernelNameWithBitnessAndProductSuffix(std::string &base, const char *product) {
23-
std::string fullName = base + std::string("_");
24-
25-
if (sizeof(uintptr_t) == 8) {
26-
fullName.append("64_");
27-
} else {
28-
fullName.append("32_");
29-
}
30-
31-
fullName.append(product);
32-
return fullName;
33-
}
34-
35-
TEST(Sip, WhenSipKernelIsInvalidThenEmptyCompilerInternalOptionsAreReturned) {
36-
const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::COUNT);
37-
ASSERT_NE(nullptr, opt);
38-
EXPECT_EQ(0U, strlen(opt));
39-
}
40-
41-
TEST(Sip, WhenRequestingCsrSipKernelThenProperCompilerInternalOptionsAreReturned) {
42-
const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::Csr);
43-
ASSERT_NE(nullptr, opt);
44-
EXPECT_STREQ("-cl-include-sip-csr", opt);
45-
}
46-
47-
TEST(Sip, When32BitAddressesAreNotBeingForcedThenSipLlHasSameBitnessAsHostApplication) {
48-
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
49-
EXPECT_NE(nullptr, mockDevice);
50-
mockDevice->deviceInfo.force32BitAddressess = false;
51-
const char *src = getSipLlSrc(*mockDevice);
52-
ASSERT_NE(nullptr, src);
53-
if (sizeof(void *) == 8) {
54-
EXPECT_NE(nullptr, strstr(src, "target datalayout = \"e-p:64:64:64\""));
55-
EXPECT_NE(nullptr, strstr(src, "target triple = \"spir64\""));
56-
} else {
57-
EXPECT_NE(nullptr, strstr(src, "target datalayout = \"e-p:32:32:32\""));
58-
EXPECT_NE(nullptr, strstr(src, "target triple = \"spir\""));
59-
EXPECT_EQ(nullptr, strstr(src, "target triple = \"spir64\""));
60-
}
61-
}
62-
63-
TEST(Sip, When32BitAddressesAreBeingForcedThenSipLlHas32BitAddresses) {
64-
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
65-
EXPECT_NE(nullptr, mockDevice);
66-
mockDevice->deviceInfo.force32BitAddressess = true;
67-
const char *src = getSipLlSrc(*mockDevice);
68-
ASSERT_NE(nullptr, src);
69-
EXPECT_NE(nullptr, strstr(src, "target datalayout = \"e-p:32:32:32\""));
70-
EXPECT_NE(nullptr, strstr(src, "target triple = \"spir\""));
71-
EXPECT_EQ(nullptr, strstr(src, "target triple = \"spir64\""));
72-
}
73-
74-
TEST(Sip, GivenSipLlWhenGettingMetadataThenMetadataRequiredByCompilerIsReturned) {
75-
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
76-
EXPECT_NE(nullptr, mockDevice);
77-
const char *src = getSipLlSrc(*mockDevice);
78-
ASSERT_NE(nullptr, src);
79-
80-
EXPECT_NE(nullptr, strstr(src, "!opencl.compiler.options"));
81-
EXPECT_NE(nullptr, strstr(src, "!opencl.kernels"));
82-
}
8322

8423
TEST(Sip, WhenGettingTypeThenCorrectTypeIsReturned) {
8524
SipKernel csr{SipKernelType::Csr, nullptr};
@@ -109,18 +48,6 @@ TEST(DebugSip, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrSipTypeIsReturn
10948
EXPECT_LE(SipKernelType::DbgCsr, sipType);
11049
}
11150

112-
TEST(DebugSip, WhenRequestingDbgCsrSipKernelThenProperCompilerInternalOptionsAreReturned) {
113-
const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::DbgCsr);
114-
ASSERT_NE(nullptr, opt);
115-
EXPECT_STREQ("-cl-include-sip-kernel-debug -cl-include-sip-csr -cl-set-bti:0", opt);
116-
}
117-
118-
TEST(DebugSip, WhenRequestingDbgCsrWithLocalMemorySipKernelThenProperCompilerInternalOptionsAreReturned) {
119-
const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::DbgCsrLocal);
120-
ASSERT_NE(nullptr, opt);
121-
EXPECT_STREQ("-cl-include-sip-kernel-local-debug -cl-include-sip-csr -cl-set-bti:0", opt);
122-
}
123-
12451
TEST(DebugSip, givenBuiltInsWhenDbgCsrSipIsRequestedThanCorrectSipKernelIsReturned) {
12552
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
12653
EXPECT_NE(nullptr, mockDevice);

opencl/test/unit_test/gen9/sip_tests_gen9.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -18,8 +18,6 @@
1818
using namespace NEO;
1919

2020
namespace SipKernelTests {
21-
extern std::string getDebugSipKernelNameWithBitnessAndProductSuffix(std::string &base, const char *product);
22-
2321
typedef ::testing::Test gen9SipTests;
2422

2523
GEN9TEST_F(gen9SipTests, givenDebugCsrSipKernelWithLocalMemoryWhenAskedForDebugSurfaceBtiAndSizeThenBtiIsZeroAndSizeGreaterThanZero) {

opencl/test/unit_test/mocks/mock_compilers.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -490,6 +490,15 @@ bool MockIgcOclDeviceCtx::GetSystemRoutine(IGC::SystemRoutineType::SystemRoutine
490490
bool bindless,
491491
CIF::Builtins::BufferSimple *outSystemRoutineBuffer,
492492
CIF::Builtins::BufferSimple *stateSaveAreaHeaderInit) {
493+
MockCompilerDebugVars &debugVars = *NEO::igcDebugVars;
494+
debugVars.typeOfSystemRoutine = typeOfSystemRoutine;
495+
const char mockData[64] = {'C', 'T', 'N', 'I'};
496+
497+
if (debugVars.forceBuildFailure || typeOfSystemRoutine == IGC::SystemRoutineType::undefined) {
498+
return false;
499+
}
500+
501+
outSystemRoutineBuffer->PushBackRawBytes(mockData, 64);
493502
return true;
494503
}
495504

@@ -636,7 +645,6 @@ std::vector<char> MockCompilerInterface::getDummyGenBinary() {
636645
return MockSipKernel::getDummyGenBinary();
637646
}
638647
void MockCompilerInterface::releaseDummyGenBinary() {
639-
MockSipKernel::shutDown();
640648
}
641649

642650
} // namespace NEO

opencl/test/unit_test/mocks/mock_sip.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -26,7 +26,7 @@ namespace NEO {
2626
MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : SipKernel(type, sipAlloc) {
2727
this->mockSipMemoryAllocation =
2828
std::make_unique<MemoryAllocation>(0u,
29-
GraphicsAllocation::AllocationType::KERNEL_ISA,
29+
GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL,
3030
nullptr,
3131
MemoryConstants::pageSize * 10u,
3232
0u,
@@ -37,7 +37,7 @@ MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) :
3737
MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) {
3838
this->mockSipMemoryAllocation =
3939
std::make_unique<MemoryAllocation>(0u,
40-
GraphicsAllocation::AllocationType::KERNEL_ISA,
40+
GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL,
4141
nullptr,
4242
MemoryConstants::pageSize * 10u,
4343
0u,
@@ -47,31 +47,10 @@ MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) {
4747

4848
MockSipKernel::~MockSipKernel() = default;
4949

50-
std::vector<char> MockSipKernel::dummyBinaryForSip;
51-
std::vector<char> MockSipKernel::getDummyGenBinary() {
52-
if (dummyBinaryForSip.empty()) {
53-
dummyBinaryForSip = getBinary();
54-
}
55-
return dummyBinaryForSip;
56-
}
57-
std::vector<char> MockSipKernel::getBinary() {
58-
std::string testFile;
59-
retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".gen");
60-
61-
size_t binarySize = 0;
62-
auto binary = loadDataFromFile(testFile.c_str(), binarySize);
63-
UNRECOVERABLE_IF(binary == nullptr);
64-
65-
std::vector<char> ret{binary.get(), binary.get() + binarySize};
50+
const char *MockSipKernel::dummyBinaryForSip = "12345678";
6651

67-
return ret;
68-
}
69-
void MockSipKernel::initDummyBinary() {
70-
dummyBinaryForSip = getBinary();
71-
}
72-
void MockSipKernel::shutDown() {
73-
MockSipKernel::dummyBinaryForSip.clear();
74-
std::vector<char>().swap(MockSipKernel::dummyBinaryForSip);
52+
std::vector<char> MockSipKernel::getDummyGenBinary() {
53+
return std::vector<char>(dummyBinaryForSip, dummyBinaryForSip + sizeof(MockSipKernel::dummyBinaryForSip));
7554
}
7655

7756
GraphicsAllocation *MockSipKernel::getSipAllocation() const {

opencl/test/unit_test/mocks/mock_sip.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -25,11 +25,8 @@ class MockSipKernel : public SipKernel {
2525
MockSipKernel();
2626
~MockSipKernel() override;
2727

28-
static std::vector<char> dummyBinaryForSip;
28+
static const char *dummyBinaryForSip;
2929
static std::vector<char> getDummyGenBinary();
30-
static std::vector<char> getBinary();
31-
static void initDummyBinary();
32-
static void shutDown();
3330

3431
GraphicsAllocation *getSipAllocation() const override;
3532

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -13,18 +13,8 @@ static std::vector<char> dummyBinaryForSip;
1313

1414
using namespace NEO;
1515

16-
std::vector<char> MockSipKernel::dummyBinaryForSip;
16+
const char *MockSipKernel::dummyBinaryForSip = "12345678";
1717

1818
std::vector<char> MockSipKernel::getDummyGenBinary() {
19-
return MockSipKernel::dummyBinaryForSip;
20-
}
21-
22-
std::vector<char> MockSipKernel::getBinary() {
23-
return MockSipKernel::dummyBinaryForSip;
24-
}
25-
26-
void MockSipKernel::initDummyBinary() {
27-
}
28-
29-
void MockSipKernel::shutDown() {
19+
return std::vector<char>(dummyBinaryForSip, dummyBinaryForSip + sizeof(MockSipKernel::dummyBinaryForSip));
3020
}

shared/source/built_ins/built_ins.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -46,23 +46,22 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) {
4646
UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success);
4747
UNRECOVERABLE_IF(sipBinary.size() == 0);
4848

49-
ProgramInfo programInfo;
50-
auto blob = ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(sipBinary.data()), sipBinary.size());
51-
SingleDeviceBinary deviceBinary = {};
52-
deviceBinary.deviceBinary = blob;
53-
std::string decodeErrors;
54-
std::string decodeWarnings;
49+
const auto allocType = GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL;
5550

56-
DecodeError decodeError;
57-
DeviceBinaryFormat singleDeviceBinaryFormat;
58-
std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, deviceBinary, decodeErrors, decodeWarnings);
59-
UNRECOVERABLE_IF(DecodeError::Success != decodeError);
51+
AllocationProperties properties = {device.getRootDeviceIndex(), sipBinary.size(), allocType, device.getDeviceBitfield()};
52+
properties.flags.use32BitFrontWindow = false;
6053

61-
auto success = programInfo.kernelInfos[0]->createKernelAllocation(device, true);
62-
UNRECOVERABLE_IF(!success);
54+
auto sipAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
6355

64-
sipBuiltIn.first.reset(new SipKernel(type, programInfo.kernelInfos[0]->kernelAllocation));
65-
programInfo.kernelInfos[0]->kernelAllocation = nullptr;
56+
auto &hwInfo = device.getHardwareInfo();
57+
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
58+
59+
if (sipAllocation) {
60+
MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *sipAllocation),
61+
device, sipAllocation, 0, sipBinary.data(),
62+
sipBinary.size());
63+
}
64+
sipBuiltIn.first.reset(new SipKernel(type, sipAllocation));
6665
};
6766
std::call_once(sipBuiltIn.second, initializer);
6867
UNRECOVERABLE_IF(sipBuiltIn.first == nullptr);

0 commit comments

Comments
 (0)