Skip to content

Commit c0268ab

Browse files
Revert "Take spec const value sizes from compiler"
This reverts commit da38058. Signed-off-by: Compute-Runtime-Validation <[email protected]>
1 parent da5f7b9 commit c0268ab

File tree

3 files changed

+9
-72
lines changed

3 files changed

+9
-72
lines changed

level_zero/core/source/module/module_imp.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,11 @@ bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize
102102
NEO::TranslationInput inputArgs = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin};
103103

104104
if (pConstants) {
105-
NEO::SpecConstantInfo specConstInfo;
106-
auto retVal = compilerInterface->getSpecConstantsInfo(*device->getNEODevice(), ArrayRef<const char>(input, inputSize), specConstInfo);
107-
if (retVal != NEO::TranslationOutput::ErrorCode::Success) {
108-
return false;
109-
}
110105
for (uint32_t i = 0; i < pConstants->numConstants; i++) {
111106
uint64_t specConstantValue = 0;
112-
uint32_t specConstantId = pConstants->pConstantIds[i];
113107
memcpy_s(&specConstantValue, sizeof(uint64_t),
114-
const_cast<void *>(pConstants->pConstantValues[i]), specConstInfo.sizesBuffer->GetMemory<uint32_t>()[specConstantId]);
108+
const_cast<void *>(pConstants->pConstantValues[i]), sizeof(uint64_t));
109+
uint32_t specConstantId = pConstants->pConstantIds[i];
115110
specConstantsValues[specConstantId] = specConstantValue;
116111
}
117112
}

level_zero/core/test/unit_tests/mocks/mock_module.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct MockCompilerInterface : public NEO::CompilerInterface {
9191
return NEO::TranslationOutput::ErrorCode::Success;
9292
}
9393
};
94-
template <typename T>
94+
9595
struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
9696
MockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : moduleNumSpecConstants(moduleNumSpecConstants) {
9797
}
@@ -116,17 +116,14 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
116116
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
117117
ArrayRef<const char> srcSpirV, NEO::SpecConstantInfo &output) override {
118118
output.idsBuffer.reset(new NEO::MockCIFBuffer());
119-
output.sizesBuffer.reset(new NEO::MockCIFBuffer());
120119
for (uint32_t i = 0; i < moduleNumSpecConstants; i++) {
121120
output.idsBuffer->PushBackRawCopy(moduleSpecConstantsIds[i]);
122-
output.sizesBuffer->PushBackRawCopy(moduleSpecConstantsSizes[i]);
123121
}
124122
return NEO::TranslationOutput::ErrorCode::Success;
125123
}
126124
uint32_t moduleNumSpecConstants = 0u;
127125
const std::vector<uint32_t> moduleSpecConstantsIds{0, 1, 2, 3};
128-
const std::vector<T> moduleSpecConstantsValues{10, 20, 30, 40};
129-
const std::vector<uint32_t> moduleSpecConstantsSizes{sizeof(T), sizeof(T), sizeof(T), sizeof(T)};
126+
const std::vector<uint64_t> moduleSpecConstantsValues{10, 20, 30, 40};
130127
};
131128

132129
} // namespace ult

level_zero/core/test/unit_tests/sources/module/test_module.cpp

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ HWTEST_F(ModuleTest, GivenIncorrectNameWhenCreatingKernelThenResultErrorInvalidA
229229

230230
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
231231
}
232-
template <typename T>
232+
233233
struct ModuleSpecConstantsTests : public DeviceFixture,
234234
public ::testing::Test {
235235
void SetUp() override {
236236
DeviceFixture::SetUp();
237237

238-
mockCompiler = new MockCompilerInterfaceWithSpecConstants<T>(moduleNumSpecConstants);
238+
mockCompiler = new MockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants);
239239
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
240240
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
241241

@@ -246,72 +246,17 @@ struct ModuleSpecConstantsTests : public DeviceFixture,
246246
DeviceFixture::TearDown();
247247
}
248248

249-
void runTest() {
250-
std::string testFile;
251-
retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv");
252-
253-
size_t size = 0;
254-
auto src = loadDataFromFile(testFile.c_str(), size);
255-
256-
ASSERT_NE(0u, size);
257-
ASSERT_NE(nullptr, src);
258-
259-
ze_module_desc_t moduleDesc = {};
260-
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
261-
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
262-
moduleDesc.inputSize = size;
263-
264-
specConstants.numConstants = mockCompiler->moduleNumSpecConstants;
265-
for (uint32_t i = 0; i < mockCompiler->moduleNumSpecConstants; i++) {
266-
specConstantsPointerValues.push_back(&mockCompiler->moduleSpecConstantsValues[i]);
267-
}
268-
269-
specConstants.pConstantIds = mockCompiler->moduleSpecConstantsIds.data();
270-
specConstants.pConstantValues = specConstantsPointerValues.data();
271-
moduleDesc.pConstants = &specConstants;
272-
273-
auto module = new Module(device, nullptr, ModuleType::User);
274-
module->translationUnit.reset(mockTranslationUnit);
275-
276-
bool success = module->initialize(&moduleDesc, neoDevice);
277-
for (uint32_t i = 0; i < mockCompiler->moduleNumSpecConstants; i++) {
278-
EXPECT_EQ(static_cast<T>(module->translationUnit->specConstantsValues[i]), mockCompiler->moduleSpecConstantsValues[i]);
279-
}
280-
EXPECT_TRUE(success);
281-
module->destroy();
282-
}
283-
284249
const uint32_t moduleNumSpecConstants = 4;
285250
ze_module_constants_t specConstants;
286251
std::vector<const void *> specConstantsPointerValues;
287252

288253
const std::string binaryFilename = "test_kernel";
289254
const std::string kernelName = "test";
290-
MockCompilerInterfaceWithSpecConstants<T> *mockCompiler;
255+
MockCompilerInterfaceWithSpecConstants *mockCompiler;
291256
MockModuleTranslationUnit *mockTranslationUnit;
292257
};
293258

294-
using ModuleSpecConstantsLongTests = ModuleSpecConstantsTests<uint64_t>;
295-
TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWithLongSizeInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) {
296-
runTest();
297-
}
298-
using ModuleSpecConstantsCharTests = ModuleSpecConstantsTests<char>;
299-
TEST_F(ModuleSpecConstantsCharTests, givenSpecializationConstantsSetWithCharSizeInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) {
300-
runTest();
301-
}
302-
303-
TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenCompilerReturnsErrorThenModuleInitFails) {
304-
class FailingMockCompilerInterfaceWithSpecConstants : public MockCompilerInterfaceWithSpecConstants<uint64_t> {
305-
public:
306-
FailingMockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : MockCompilerInterfaceWithSpecConstants<uint64_t>(moduleNumSpecConstants) {}
307-
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
308-
ArrayRef<const char> srcSpirV, NEO::SpecConstantInfo &output) override {
309-
return NEO::TranslationOutput::ErrorCode::CompilerNotAvailable;
310-
}
311-
};
312-
mockCompiler = new FailingMockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants);
313-
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
314-
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
259+
HWTEST_F(ModuleSpecConstantsTests, givenSpecializationConstantsSetInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) {
315260
std::string testFile;
316261
retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv");
317262

@@ -339,7 +284,7 @@ TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenCompiler
339284
module->translationUnit.reset(mockTranslationUnit);
340285

341286
bool success = module->initialize(&moduleDesc, neoDevice);
342-
EXPECT_FALSE(success);
287+
EXPECT_TRUE(success);
343288
module->destroy();
344289
}
345290

0 commit comments

Comments
 (0)