mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-28 00:03:14 +08:00
Take spec const value sizes from compiler
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
189aa54bae
commit
da3805880b
@@ -102,11 +102,16 @@ 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<const char>(input, inputSize), specConstInfo);
|
||||
if (retVal != NEO::TranslationOutput::ErrorCode::Success) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < pConstants->numConstants; i++) {
|
||||
uint64_t specConstantValue = 0;
|
||||
memcpy_s(&specConstantValue, sizeof(uint64_t),
|
||||
const_cast<void *>(pConstants->pConstantValues[i]), sizeof(uint64_t));
|
||||
uint32_t specConstantId = pConstants->pConstantIds[i];
|
||||
memcpy_s(&specConstantValue, sizeof(uint64_t),
|
||||
const_cast<void *>(pConstants->pConstantValues[i]), specConstInfo.sizesBuffer->GetMemory<uint32_t>()[specConstantId]);
|
||||
specConstantsValues[specConstantId] = specConstantValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ struct MockCompilerInterface : public NEO::CompilerInterface {
|
||||
return NEO::TranslationOutput::ErrorCode::Success;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
|
||||
MockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : moduleNumSpecConstants(moduleNumSpecConstants) {
|
||||
}
|
||||
@@ -116,14 +116,17 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
|
||||
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
|
||||
ArrayRef<const char> 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<uint32_t> moduleSpecConstantsIds{0, 1, 2, 3};
|
||||
const std::vector<uint64_t> moduleSpecConstantsValues{10, 20, 30, 40};
|
||||
const std::vector<T> moduleSpecConstantsValues{10, 20, 30, 40};
|
||||
const std::vector<uint32_t> moduleSpecConstantsSizes{sizeof(T), sizeof(T), sizeof(T), sizeof(T)};
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
|
||||
@@ -229,13 +229,13 @@ HWTEST_F(ModuleTest, GivenIncorrectNameWhenCreatingKernelThenResultErrorInvalidA
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct ModuleSpecConstantsTests : public DeviceFixture,
|
||||
public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DeviceFixture::SetUp();
|
||||
|
||||
mockCompiler = new MockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants);
|
||||
mockCompiler = new MockCompilerInterfaceWithSpecConstants<T>(moduleNumSpecConstants);
|
||||
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
|
||||
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
|
||||
|
||||
@@ -246,17 +246,72 @@ 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<const uint8_t *>(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<T>(module->translationUnit->specConstantsValues[i]), mockCompiler->moduleSpecConstantsValues[i]);
|
||||
}
|
||||
EXPECT_TRUE(success);
|
||||
module->destroy();
|
||||
}
|
||||
|
||||
const uint32_t moduleNumSpecConstants = 4;
|
||||
ze_module_constants_t specConstants;
|
||||
std::vector<const void *> specConstantsPointerValues;
|
||||
|
||||
const std::string binaryFilename = "test_kernel";
|
||||
const std::string kernelName = "test";
|
||||
MockCompilerInterfaceWithSpecConstants *mockCompiler;
|
||||
MockCompilerInterfaceWithSpecConstants<T> *mockCompiler;
|
||||
MockModuleTranslationUnit *mockTranslationUnit;
|
||||
};
|
||||
|
||||
HWTEST_F(ModuleSpecConstantsTests, givenSpecializationConstantsSetInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) {
|
||||
using ModuleSpecConstantsLongTests = ModuleSpecConstantsTests<uint64_t>;
|
||||
TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWithLongSizeInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) {
|
||||
runTest();
|
||||
}
|
||||
using ModuleSpecConstantsCharTests = ModuleSpecConstantsTests<char>;
|
||||
TEST_F(ModuleSpecConstantsCharTests, givenSpecializationConstantsSetWithCharSizeInDescriptorThenModuleCorrectlyPassesThemToTheCompiler) {
|
||||
runTest();
|
||||
}
|
||||
|
||||
TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenCompilerReturnsErrorThenModuleInitFails) {
|
||||
class FailingMockCompilerInterfaceWithSpecConstants : public MockCompilerInterfaceWithSpecConstants<uint64_t> {
|
||||
public:
|
||||
FailingMockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : MockCompilerInterfaceWithSpecConstants<uint64_t>(moduleNumSpecConstants) {}
|
||||
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
|
||||
ArrayRef<const char> 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);
|
||||
std::string testFile;
|
||||
retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv");
|
||||
|
||||
@@ -284,7 +339,7 @@ HWTEST_F(ModuleSpecConstantsTests, givenSpecializationConstantsSetInDescriptorTh
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&moduleDesc, neoDevice);
|
||||
EXPECT_TRUE(success);
|
||||
EXPECT_FALSE(success);
|
||||
module->destroy();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user