diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index 81b0c1d414..6c7c1088d7 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -102,16 +102,11 @@ bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize NEO::TranslationInput inputArgs = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin}; if (pConstants) { - NEO::SpecConstantInfo specConstInfo; - auto retVal = compilerInterface->getSpecConstantsInfo(*device->getNEODevice(), ArrayRef(input, inputSize), specConstInfo); - if (retVal != NEO::TranslationOutput::ErrorCode::Success) { - return false; - } for (uint32_t i = 0; i < pConstants->numConstants; i++) { uint64_t specConstantValue = 0; - uint32_t specConstantId = pConstants->pConstantIds[i]; memcpy_s(&specConstantValue, sizeof(uint64_t), - const_cast(pConstants->pConstantValues[i]), specConstInfo.sizesBuffer->GetMemory()[specConstantId]); + const_cast(pConstants->pConstantValues[i]), sizeof(uint64_t)); + uint32_t specConstantId = pConstants->pConstantIds[i]; specConstantsValues[specConstantId] = specConstantValue; } } diff --git a/level_zero/core/test/unit_tests/mocks/mock_module.h b/level_zero/core/test/unit_tests/mocks/mock_module.h index 5f84f553bc..d4d39d285b 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_module.h +++ b/level_zero/core/test/unit_tests/mocks/mock_module.h @@ -91,7 +91,7 @@ struct MockCompilerInterface : public NEO::CompilerInterface { return NEO::TranslationOutput::ErrorCode::Success; } }; -template + struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface { MockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : moduleNumSpecConstants(moduleNumSpecConstants) { } @@ -116,17 +116,14 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface { NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device, ArrayRef srcSpirV, NEO::SpecConstantInfo &output) override { output.idsBuffer.reset(new NEO::MockCIFBuffer()); - output.sizesBuffer.reset(new NEO::MockCIFBuffer()); for (uint32_t i = 0; i < moduleNumSpecConstants; i++) { output.idsBuffer->PushBackRawCopy(moduleSpecConstantsIds[i]); - output.sizesBuffer->PushBackRawCopy(moduleSpecConstantsSizes[i]); } return NEO::TranslationOutput::ErrorCode::Success; } uint32_t moduleNumSpecConstants = 0u; const std::vector moduleSpecConstantsIds{0, 1, 2, 3}; - const std::vector moduleSpecConstantsValues{10, 20, 30, 40}; - const std::vector moduleSpecConstantsSizes{sizeof(T), sizeof(T), sizeof(T), sizeof(T)}; + const std::vector moduleSpecConstantsValues{10, 20, 30, 40}; }; } // namespace ult diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 236a8f52db..75887c15ad 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -229,13 +229,13 @@ HWTEST_F(ModuleTest, GivenIncorrectNameWhenCreatingKernelThenResultErrorInvalidA EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res); } -template + struct ModuleSpecConstantsTests : public DeviceFixture, public ::testing::Test { void SetUp() override { DeviceFixture::SetUp(); - mockCompiler = new MockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants); + mockCompiler = new MockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants); auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get(); rootDeviceEnvironment->compilerInterface.reset(mockCompiler); @@ -246,72 +246,17 @@ struct ModuleSpecConstantsTests : public DeviceFixture, DeviceFixture::TearDown(); } - void runTest() { - std::string testFile; - retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv"); - - size_t size = 0; - auto src = loadDataFromFile(testFile.c_str(), size); - - ASSERT_NE(0u, size); - ASSERT_NE(nullptr, src); - - ze_module_desc_t moduleDesc = {}; - moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV; - moduleDesc.pInputModule = reinterpret_cast(src.get()); - moduleDesc.inputSize = size; - - specConstants.numConstants = mockCompiler->moduleNumSpecConstants; - for (uint32_t i = 0; i < mockCompiler->moduleNumSpecConstants; i++) { - specConstantsPointerValues.push_back(&mockCompiler->moduleSpecConstantsValues[i]); - } - - specConstants.pConstantIds = mockCompiler->moduleSpecConstantsIds.data(); - specConstants.pConstantValues = specConstantsPointerValues.data(); - moduleDesc.pConstants = &specConstants; - - auto module = new Module(device, nullptr, ModuleType::User); - module->translationUnit.reset(mockTranslationUnit); - - bool success = module->initialize(&moduleDesc, neoDevice); - for (uint32_t i = 0; i < mockCompiler->moduleNumSpecConstants; i++) { - EXPECT_EQ(static_cast(module->translationUnit->specConstantsValues[i]), mockCompiler->moduleSpecConstantsValues[i]); - } - EXPECT_TRUE(success); - module->destroy(); - } - const uint32_t moduleNumSpecConstants = 4; ze_module_constants_t specConstants; std::vector specConstantsPointerValues; const std::string binaryFilename = "test_kernel"; const std::string kernelName = "test"; - MockCompilerInterfaceWithSpecConstants *mockCompiler; + MockCompilerInterfaceWithSpecConstants *mockCompiler; MockModuleTranslationUnit *mockTranslationUnit; }; -using ModuleSpecConstantsLongTests = ModuleSpecConstantsTests; -TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWithLongSizeInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) { - runTest(); -} -using ModuleSpecConstantsCharTests = ModuleSpecConstantsTests; -TEST_F(ModuleSpecConstantsCharTests, givenSpecializationConstantsSetWithCharSizeInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) { - runTest(); -} - -TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenCompilerReturnsErrorThenModuleInitFails) { - class FailingMockCompilerInterfaceWithSpecConstants : public MockCompilerInterfaceWithSpecConstants { - public: - FailingMockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : MockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants) {} - NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device, - ArrayRef srcSpirV, NEO::SpecConstantInfo &output) override { - return NEO::TranslationOutput::ErrorCode::CompilerNotAvailable; - } - }; - mockCompiler = new FailingMockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants); - auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get(); - rootDeviceEnvironment->compilerInterface.reset(mockCompiler); +HWTEST_F(ModuleSpecConstantsTests, givenSpecializationConstantsSetInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) { std::string testFile; retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv"); @@ -339,7 +284,7 @@ TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenCompiler module->translationUnit.reset(mockTranslationUnit); bool success = module->initialize(&moduleDesc, neoDevice); - EXPECT_FALSE(success); + EXPECT_TRUE(success); module->destroy(); }