Skip to content

Commit dba5484

Browse files
Zebin: enhance clBuildProgramTests ULTs
- Do not use precompiled binaries in clBuildProgramTests. This change is required in order to enable zebin switch by default. Related-To: NEO-7281 Signed-off-by: Kacper Nowak <[email protected]>
1 parent 33e1b3a commit dba5484

File tree

3 files changed

+126
-43
lines changed

3 files changed

+126
-43
lines changed

opencl/test/unit_test/api/cl_build_program_tests.inl

+32-43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared/test/common/helpers/kernel_binary_helper.h"
1010
#include "shared/test/common/helpers/test_files.h"
1111
#include "shared/test/common/mocks/mock_compilers.h"
12+
#include "shared/test/common/mocks/mock_modules_zebin.h"
1213

1314
#include "opencl/source/context/context.h"
1415
#include "opencl/source/program/program.h"
@@ -75,19 +76,17 @@ TEST_F(clBuildProgramTests, GivenSourceAsInputWhenCreatingProgramWithSourceThenP
7576
TEST_F(clBuildProgramTests, GivenBinaryAsInputWhenCreatingProgramWithSourceThenProgramBuildSucceeds) {
7677
cl_program pProgram = nullptr;
7778
cl_int binaryStatus = CL_SUCCESS;
78-
std::unique_ptr<char[]> pBinary = nullptr;
79-
size_t binarySize = 0;
80-
std::string testFile;
81-
retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".bin");
8279

83-
pBinary = loadDataFromFile(
84-
testFile.c_str(),
85-
binarySize);
80+
constexpr auto numBits = is32bit ? Elf::EI_CLASS_32 : Elf::EI_CLASS_64;
81+
auto zebinData = std::make_unique<ZebinTestData::ZebinCopyBufferSimdModule<numBits>>(pDevice->getHardwareInfo(), 16);
82+
const auto &src = zebinData->storage;
8683

87-
ASSERT_NE(0u, binarySize);
88-
ASSERT_NE(nullptr, pBinary);
84+
ASSERT_NE(nullptr, src.data());
85+
ASSERT_NE(0u, src.size());
86+
87+
const unsigned char *binaries[1] = {reinterpret_cast<const unsigned char *>(src.data())};
88+
const size_t binarySize = src.size();
8989

90-
const unsigned char *binaries[1] = {reinterpret_cast<const unsigned char *>(pBinary.get())};
9190
pProgram = clCreateProgramWithBinary(
9291
pContext,
9392
1,
@@ -97,8 +96,6 @@ TEST_F(clBuildProgramTests, GivenBinaryAsInputWhenCreatingProgramWithSourceThenP
9796
&binaryStatus,
9897
&retVal);
9998

100-
pBinary.reset();
101-
10299
EXPECT_NE(nullptr, pProgram);
103100
ASSERT_EQ(CL_SUCCESS, retVal);
104101

@@ -120,21 +117,18 @@ TEST_F(clBuildProgramTests, GivenBinaryAsInputWhenCreatingProgramWithBinaryForMu
120117
MockUnrestrictiveContextMultiGPU context;
121118
cl_program pProgram = nullptr;
122119
cl_int binaryStatus = CL_SUCCESS;
123-
std::unique_ptr<char[]> pBinary = nullptr;
124-
size_t binarySize = 0;
125-
std::string testFile;
126-
retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".bin");
127120

128-
pBinary = loadDataFromFile(
129-
testFile.c_str(),
130-
binarySize);
121+
constexpr auto numBits = is32bit ? Elf::EI_CLASS_32 : Elf::EI_CLASS_64;
122+
auto zebinData = std::make_unique<ZebinTestData::ZebinCopyBufferSimdModule<numBits>>(pDevice->getHardwareInfo(), 16);
123+
const auto &src = zebinData->storage;
131124

132-
ASSERT_NE(0u, binarySize);
133-
ASSERT_NE(nullptr, pBinary);
125+
ASSERT_NE(nullptr, src.data());
126+
ASSERT_NE(0u, src.size());
127+
const size_t binarySize = src.size();
134128

135129
const size_t numBinaries = 6;
136130
const unsigned char *binaries[numBinaries];
137-
std::fill(binaries, binaries + numBinaries, reinterpret_cast<const unsigned char *>(pBinary.get()));
131+
std::fill(binaries, binaries + numBinaries, reinterpret_cast<const unsigned char *>(src.data()));
138132
cl_device_id devicesForProgram[] = {context.pRootDevice0, context.pSubDevice00, context.pSubDevice01, context.pRootDevice1, context.pSubDevice10, context.pSubDevice11};
139133
size_t sizeBinaries[numBinaries];
140134
std::fill(sizeBinaries, sizeBinaries + numBinaries, binarySize);
@@ -148,8 +142,6 @@ TEST_F(clBuildProgramTests, GivenBinaryAsInputWhenCreatingProgramWithBinaryForMu
148142
&binaryStatus,
149143
&retVal);
150144

151-
pBinary.reset();
152-
153145
EXPECT_NE(nullptr, pProgram);
154146
ASSERT_EQ(CL_SUCCESS, retVal);
155147

@@ -170,17 +162,16 @@ TEST_F(clBuildProgramTests, GivenBinaryAsInputWhenCreatingProgramWithBinaryForMu
170162
TEST_F(clBuildProgramTests, GivenProgramCreatedFromBinaryWhenBuildProgramWithOptionsIsCalledThenStoredOptionsAreUsed) {
171163
cl_program pProgram = nullptr;
172164
cl_int binaryStatus = CL_SUCCESS;
173-
size_t binarySize = 0;
174-
std::string testFile;
175-
retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".bin");
176165

177-
auto pBinary = loadDataFromFile(
178-
testFile.c_str(),
179-
binarySize);
166+
constexpr auto numBits = is32bit ? Elf::EI_CLASS_32 : Elf::EI_CLASS_64;
167+
auto zebinData = std::make_unique<ZebinTestData::ZebinCopyBufferSimdModule<numBits>>(pDevice->getHardwareInfo(), 16);
168+
const auto &src = zebinData->storage;
180169

181-
ASSERT_NE(0u, binarySize);
182-
ASSERT_NE(nullptr, pBinary);
183-
const unsigned char *binaries[1] = {reinterpret_cast<const unsigned char *>(pBinary.get())};
170+
ASSERT_NE(nullptr, src.data());
171+
ASSERT_NE(0u, src.size());
172+
const size_t binarySize = src.size();
173+
174+
const unsigned char *binaries[1] = {reinterpret_cast<const unsigned char *>(src.data())};
184175
pProgram = clCreateProgramWithBinary(
185176
pContext,
186177
1,
@@ -192,7 +183,6 @@ TEST_F(clBuildProgramTests, GivenProgramCreatedFromBinaryWhenBuildProgramWithOpt
192183

193184
auto pInternalProgram = castToObject<Program>(pProgram);
194185

195-
pBinary.reset();
196186
auto storedOptionsSize = pInternalProgram->getOptions().size();
197187

198188
EXPECT_NE(nullptr, pProgram);
@@ -316,17 +306,16 @@ TEST_F(clBuildProgramTests, GivenInvalidCallbackInputWhenBuildProgramThenInvalid
316306
TEST_F(clBuildProgramTests, GivenValidCallbackInputWhenBuildProgramThenCallbackIsInvoked) {
317307
cl_program pProgram = nullptr;
318308
cl_int binaryStatus = CL_SUCCESS;
319-
size_t binarySize = 0;
320-
std::string testFile;
321-
retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".bin");
322309

323-
auto pBinary = loadDataFromFile(
324-
testFile.c_str(),
325-
binarySize);
310+
constexpr auto numBits = is32bit ? Elf::EI_CLASS_32 : Elf::EI_CLASS_64;
311+
auto zebinData = std::make_unique<ZebinTestData::ZebinCopyBufferSimdModule<numBits>>(pDevice->getHardwareInfo(), 16);
312+
const auto &src = zebinData->storage;
326313

327-
ASSERT_NE(0u, binarySize);
328-
ASSERT_NE(nullptr, pBinary);
329-
const unsigned char *binaries[1] = {reinterpret_cast<const unsigned char *>(pBinary.get())};
314+
ASSERT_NE(nullptr, src.data());
315+
ASSERT_NE(0u, src.size());
316+
const size_t binarySize = src.size();
317+
318+
const unsigned char *binaries[1] = {reinterpret_cast<const unsigned char *>(src.data())};
330319
pProgram = clCreateProgramWithBinary(
331320
pContext,
332321
1,

shared/test/common/mocks/mock_modules_zebin.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,27 @@ void ZebinWithL0TestCommonModule::recalcPtr() {
223223
elfHeader = reinterpret_cast<NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> *>(storage.data());
224224
}
225225

226+
template ZebinCopyBufferSimdModule<ELF_IDENTIFIER_CLASS::EI_CLASS_32>::ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
227+
template ZebinCopyBufferSimdModule<ELF_IDENTIFIER_CLASS::EI_CLASS_64>::ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
228+
229+
template <ELF_IDENTIFIER_CLASS numBits>
230+
ZebinCopyBufferSimdModule<numBits>::ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize) {
231+
zeInfoSize = static_cast<size_t>(snprintf(nullptr, 0, zeInfoCopyBufferSimdPlaceholder.c_str(), simdSize, simdSize, getLocalIdSize(hwInfo, simdSize)) + 1);
232+
zeInfoCopyBuffer.resize(zeInfoSize);
233+
snprintf(zeInfoCopyBuffer.data(), zeInfoSize, zeInfoCopyBufferSimdPlaceholder.c_str(), simdSize, simdSize, getLocalIdSize(hwInfo, simdSize));
234+
235+
MockElfEncoder<numBits> elfEncoder;
236+
auto &elfHeader = elfEncoder.getElfFileHeader();
237+
elfHeader.type = NEO::Elf::ET_ZEBIN_EXE;
238+
elfHeader.machine = hwInfo.platform.eProductFamily;
239+
240+
const uint8_t testKernelData[0x2c0] = {0u};
241+
242+
elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::textPrefix.str() + "CopyBuffer", testKernelData);
243+
elfEncoder.appendSection(NEO::Elf::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo, zeInfoCopyBuffer);
244+
245+
storage = elfEncoder.encode();
246+
this->elfHeader = reinterpret_cast<NEO::Elf::ElfFileHeader<numBits> *>(storage.data());
247+
}
248+
226249
}; // namespace ZebinTestData

shared/test/common/mocks/mock_modules_zebin.h

+71
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,75 @@ inline std::vector<uint8_t> createIntelGTNoteSection(PRODUCT_FAMILY productFamil
301301
return intelGTNotesSection;
302302
}
303303

304+
template <NEO::Elf::ELF_IDENTIFIER_CLASS numBits>
305+
struct ZebinCopyBufferSimdModule {
306+
ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
307+
inline size_t getLocalIdSize(const NEO::HardwareInfo &hwInfo, uint8_t simdSize) {
308+
return alignUp(simdSize * sizeof(uint16_t), hwInfo.capabilityTable.grfSize) * 3;
309+
}
310+
NEO::Elf::ElfFileHeader<numBits> *elfHeader;
311+
std::vector<uint8_t> storage;
312+
std::string zeInfoCopyBuffer;
313+
size_t zeInfoSize;
314+
std::string zeInfoCopyBufferSimdPlaceholder = std::string("version :\'") + versionToString(NEO::zeInfoDecoderVersion) + R"===('
315+
kernels:
316+
- name: CopyBuffer
317+
execution_env:
318+
disable_mid_thread_preemption: true
319+
grf_count: 128
320+
has_no_stateless_write: true
321+
inline_data_payload_size: 32
322+
offset_to_skip_per_thread_data_load: 192
323+
required_sub_group_size: %d
324+
simd_size: %d
325+
subgroup_independent_forward_progress: true
326+
payload_arguments:
327+
- arg_type: global_id_offset
328+
offset: 0
329+
size: 12
330+
- arg_type: local_size
331+
offset: 12
332+
size: 12
333+
- arg_type: arg_bypointer
334+
offset: 0
335+
size: 0
336+
arg_index: 0
337+
addrmode: stateful
338+
addrspace: global
339+
access_type: readwrite
340+
- arg_type: buffer_address
341+
offset: 32
342+
size: 8
343+
arg_index: 0
344+
- arg_type: arg_bypointer
345+
offset: 0
346+
size: 0
347+
arg_index: 1
348+
addrmode: stateful
349+
addrspace: global
350+
access_type: readwrite
351+
- arg_type: buffer_address
352+
offset: 40
353+
size: 8
354+
arg_index: 1
355+
- arg_type: buffer_offset
356+
offset: 48
357+
size: 4
358+
arg_index: 0
359+
- arg_type: buffer_offset
360+
offset: 52
361+
size: 4
362+
arg_index: 1
363+
per_thread_payload_arguments:
364+
- arg_type: local_id
365+
offset: 0
366+
size: %d
367+
binding_table_indices:
368+
- bti_value: 0
369+
arg_index: 0
370+
- bti_value: 1
371+
arg_index: 1
372+
)===";
373+
};
374+
304375
} // namespace ZebinTestData

0 commit comments

Comments
 (0)