Skip to content

Commit ed1e3de

Browse files
Revert "Switch to new compiler interface to get system routine"
This reverts commit 09bdd2a. Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent 7c70a14 commit ed1e3de

File tree

12 files changed

+228
-102
lines changed

12 files changed

+228
-102
lines changed

opencl/test/unit_test/built_ins/built_in_tests.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
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"
3837
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
3938
#include "test.h"
4039

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

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+
20132024
const SipKernel &sipKernel = builtins->getSipKernel(SipKernelType::Csr, *pDevice);
20142025

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

@@ -2025,22 +2036,6 @@ TEST_F(BuiltInTests, givenSipKernelWhenItIsCreatedThenItHasGraphicsAllocationFor
20252036
EXPECT_NE(nullptr, sipAllocation);
20262037
}
20272038

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-
20442039
TEST_F(BuiltInTests, givenSameDeviceIsUsedWhenUsingStaticGetterThenExpectRetrieveSameAllocation) {
20452040
const SipKernel &sipKern = pDevice->getBuiltIns()->getSipKernel(SipKernelType::Csr, pContext->getDevice(0)->getDevice());
20462041
auto sipAllocation = sipKern.getSipAllocation();

opencl/test/unit_test/built_ins/sip_tests.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,67 @@
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+
}
2283

2384
TEST(Sip, WhenGettingTypeThenCorrectTypeIsReturned) {
2485
SipKernel csr{SipKernelType::Csr, nullptr};
@@ -48,6 +109,18 @@ TEST(DebugSip, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrSipTypeIsReturn
48109
EXPECT_LE(SipKernelType::DbgCsr, sipType);
49110
}
50111

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+
51124
TEST(DebugSip, givenBuiltInsWhenDbgCsrSipIsRequestedThanCorrectSipKernelIsReturned) {
52125
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
53126
EXPECT_NE(nullptr, mockDevice);

opencl/test/unit_test/gen9/sip_tests_gen9.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using namespace NEO;
1919

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

2325
GEN9TEST_F(gen9SipTests, givenDebugCsrSipKernelWithLocalMemoryWhenAskedForDebugSurfaceBtiAndSizeThenBtiIsZeroAndSizeGreaterThanZero) {

opencl/test/unit_test/mocks/mock_compilers.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,6 @@ 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);
502493
return true;
503494
}
504495

@@ -645,6 +636,7 @@ std::vector<char> MockCompilerInterface::getDummyGenBinary() {
645636
return MockSipKernel::getDummyGenBinary();
646637
}
647638
void MockCompilerInterface::releaseDummyGenBinary() {
639+
MockSipKernel::shutDown();
648640
}
649641

650642
} // namespace NEO

opencl/test/unit_test/mocks/mock_sip.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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_INTERNAL,
29+
GraphicsAllocation::AllocationType::KERNEL_ISA,
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_INTERNAL,
40+
GraphicsAllocation::AllocationType::KERNEL_ISA,
4141
nullptr,
4242
MemoryConstants::pageSize * 10u,
4343
0u,
@@ -47,10 +47,31 @@ MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) {
4747

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

50-
const char *MockSipKernel::dummyBinaryForSip = "12345678";
51-
50+
std::vector<char> MockSipKernel::dummyBinaryForSip;
5251
std::vector<char> MockSipKernel::getDummyGenBinary() {
53-
return std::vector<char>(dummyBinaryForSip, dummyBinaryForSip + sizeof(MockSipKernel::dummyBinaryForSip));
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};
66+
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);
5475
}
5576

5677
GraphicsAllocation *MockSipKernel::getSipAllocation() const {

opencl/test/unit_test/mocks/mock_sip.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ class MockSipKernel : public SipKernel {
2525
MockSipKernel();
2626
~MockSipKernel() override;
2727

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

3134
GraphicsAllocation *getSipAllocation() const override;
3235

opencl/test/unit_test/offline_compiler/mock/mock_sip_ocloc_tests.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ static std::vector<char> dummyBinaryForSip;
1313

1414
using namespace NEO;
1515

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

1818
std::vector<char> MockSipKernel::getDummyGenBinary() {
19-
return std::vector<char>(dummyBinaryForSip, dummyBinaryForSip + sizeof(MockSipKernel::dummyBinaryForSip));
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() {
2030
}

shared/source/built_ins/built_ins.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) {
4646
UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success);
4747
UNRECOVERABLE_IF(sipBinary.size() == 0);
4848

49-
const auto allocType = GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL;
50-
51-
AllocationProperties properties = {device.getRootDeviceIndex(), sipBinary.size(), allocType, device.getDeviceBitfield()};
52-
properties.flags.use32BitFrontWindow = true;
53-
54-
auto sipAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
55-
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));
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;
55+
56+
DecodeError decodeError;
57+
DeviceBinaryFormat singleDeviceBinaryFormat;
58+
std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, deviceBinary, decodeErrors, decodeWarnings);
59+
UNRECOVERABLE_IF(DecodeError::Success != decodeError);
60+
61+
auto success = programInfo.kernelInfos[0]->createKernelAllocation(device, true);
62+
UNRECOVERABLE_IF(!success);
63+
64+
sipBuiltIn.first.reset(new SipKernel(type, programInfo.kernelInfos[0]->kernelAllocation));
65+
programInfo.kernelInfos[0]->kernelAllocation = nullptr;
6566
};
6667
std::call_once(sipBuiltIn.second, initializer);
6768
UNRECOVERABLE_IF(sipBuiltIn.first == nullptr);

shared/source/built_ins/sip.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,51 @@ namespace NEO {
2222

2323
const size_t SipKernel::maxDbgSurfaceSize = 0x1800000; // proper value should be taken from compiler when it's ready
2424

25+
const char *getSipKernelCompilerInternalOptions(SipKernelType kernel) {
26+
switch (kernel) {
27+
default:
28+
DEBUG_BREAK_IF(true);
29+
return "";
30+
case SipKernelType::Csr:
31+
return "-cl-include-sip-csr";
32+
case SipKernelType::DbgCsr:
33+
return "-cl-include-sip-kernel-debug -cl-include-sip-csr -cl-set-bti:0";
34+
case SipKernelType::DbgCsrLocal:
35+
return "-cl-include-sip-kernel-local-debug -cl-include-sip-csr -cl-set-bti:0";
36+
}
37+
}
38+
39+
const char *getSipLlSrc(const Device &device) {
40+
#define M_DUMMY_LL_SRC \
41+
"define void @f() { \n" \
42+
" ret void \n" \
43+
"} \n" \
44+
"!opencl.compiler.options = !{!0} \n" \
45+
"!opencl.kernels = !{!1} \n" \
46+
"!0 = !{} \n" \
47+
"!1 = !{void()* @f, !2, !3, !4, !5, !6, !7} \n" \
48+
"!2 = !{!\"kernel_arg_addr_space\"} \n" \
49+
"!3 = !{!\"kernel_arg_access_qual\"} \n" \
50+
"!4 = !{!\"kernel_arg_type\"} \n" \
51+
"!5 = !{!\"kernel_arg_type_qual\"} \n" \
52+
"!6 = !{!\"kernel_arg_base_type\"} \n" \
53+
"!7 = !{!\"kernel_arg_name\"} \n"
54+
55+
constexpr const char *llDummySrc32 =
56+
"target datalayout = \"e-p:32:32:32\" \n"
57+
"target triple = \"spir\" \n" M_DUMMY_LL_SRC;
58+
59+
constexpr const char *llDummySrc64 =
60+
"target datalayout = \"e-p:64:64:64\" \n"
61+
"target triple = \"spir64\" \n" M_DUMMY_LL_SRC;
62+
63+
#undef M_DUMMY_LL_SRC
64+
65+
const uint32_t ptrSize = device.getDeviceInfo().force32BitAddressess ? 4 : sizeof(void *);
66+
67+
return (ptrSize == 8) ? llDummySrc64 : llDummySrc32;
68+
}
69+
2570
SipKernel::~SipKernel() = default;
2671

2772
SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : type(type), sipAllocation(sipAlloc) {

shared/source/built_ins/sip.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ namespace NEO {
1717
class Device;
1818
class GraphicsAllocation;
1919

20+
const char *getSipKernelCompilerInternalOptions(SipKernelType kernel);
21+
22+
const char *getSipLlSrc(const Device &device);
23+
2024
class SipKernel {
2125
public:
2226
SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc);

0 commit comments

Comments
 (0)