mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Pass proper spec const values to IGC
Change-Id: Id02f6fca1ce3ab603ac8b539ecb8ae5383276473 Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
5b255433c5
commit
fe0f259eaa
@ -130,15 +130,6 @@ Program::~Program() {
|
||||
if (context && !isBuiltIn) {
|
||||
context->decRefInternal();
|
||||
}
|
||||
|
||||
if (specConstantsValues.get() != nullptr) {
|
||||
for (auto i = 0u; i < specConstantsValues->GetSize<void *>(); i++) {
|
||||
auto specConstPtr = specConstantsValues->GetMemory<void *>()[i];
|
||||
if (specConstPtr != nullptr) {
|
||||
delete[] reinterpret_cast<char *>(specConstPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cl_int Program::createProgramFromBinary(
|
||||
@ -250,12 +241,9 @@ cl_int Program::updateSpecializationConstant(cl_uint specId, size_t specSize, co
|
||||
for (uint32_t i = 0; i < specConstantsIds->GetSize<uint32_t>(); i++) {
|
||||
if (specConstantsIds->GetMemory<uint32_t>()[i] == specId) {
|
||||
if (specConstantsSizes->GetMemory<uint32_t>()[i] == static_cast<uint32_t>(specSize)) {
|
||||
auto specConstPtr = specConstantsValues->GetMemoryWriteable<void *>()[i];
|
||||
if (specConstPtr == nullptr) {
|
||||
specConstPtr = new char[specSize];
|
||||
}
|
||||
memcpy_s(specConstPtr, specSize, specValue, specSize);
|
||||
specConstantsValues->GetMemoryWriteable<void *>()[i] = specConstPtr;
|
||||
uint64_t specConstValue = 0u;
|
||||
memcpy_s(&specConstValue, sizeof(uint64_t), specValue, specSize);
|
||||
specConstantsValues->GetMemoryWriteable<uint64_t>()[i] = specConstValue;
|
||||
return CL_SUCCESS;
|
||||
} else {
|
||||
return CL_INVALID_VALUE;
|
||||
|
@ -42,29 +42,23 @@ struct UpdateSpecConstantsTest : public ::testing::Test {
|
||||
mockProgram->specConstantsSizes->PushBackRawCopy(size2);
|
||||
mockProgram->specConstantsSizes->PushBackRawCopy(size3);
|
||||
|
||||
val1 = new char;
|
||||
val2 = new uint16_t;
|
||||
mockProgram->specConstantsValues->PushBackRawCopy(static_cast<uint64_t>(val1));
|
||||
mockProgram->specConstantsValues->PushBackRawCopy(static_cast<uint64_t>(val2));
|
||||
mockProgram->specConstantsValues->PushBackRawCopy(static_cast<uint64_t>(val3));
|
||||
|
||||
*val1 = 5;
|
||||
*val2 = 50;
|
||||
values = mockProgram->specConstantsValues->GetMemoryWriteable<uint64_t>();
|
||||
|
||||
mockProgram->specConstantsValues->PushBackRawCopy(val1);
|
||||
mockProgram->specConstantsValues->PushBackRawCopy(val2);
|
||||
mockProgram->specConstantsValues->PushBackRawCopy(val3);
|
||||
|
||||
values = mockProgram->specConstantsValues->GetMemoryWriteable<void *>();
|
||||
|
||||
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
||||
EXPECT_EQ(val1, static_cast<char>(values[0]));
|
||||
EXPECT_EQ(val2, static_cast<uint16_t>(values[1]));
|
||||
EXPECT_EQ(val3, static_cast<int>(values[2]));
|
||||
}
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
std::unique_ptr<MockProgram> mockProgram;
|
||||
|
||||
char *val1 = nullptr;
|
||||
uint16_t *val2 = nullptr;
|
||||
int *val3 = nullptr;
|
||||
void **values;
|
||||
char val1 = 5;
|
||||
uint16_t val2 = 50;
|
||||
int val3 = 500;
|
||||
uint64_t *values;
|
||||
};
|
||||
|
||||
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWhenUpdateSpecializationConstantThenProperValueIsCopiedAndUpdated) {
|
||||
@ -73,18 +67,17 @@ TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWhenUpdateSpecializationCo
|
||||
auto ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
||||
EXPECT_NE(&newSpecConstVal3, values[2]);
|
||||
EXPECT_NE(val3, values[2]);
|
||||
EXPECT_EQ(val1, static_cast<char>(values[0]));
|
||||
EXPECT_EQ(val2, static_cast<uint16_t>(values[1]));
|
||||
EXPECT_EQ(newSpecConstVal3, static_cast<int>(values[2]));
|
||||
EXPECT_NE(val3, static_cast<int>(values[2]));
|
||||
|
||||
newSpecConstVal3 = 50000;
|
||||
EXPECT_NE(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
||||
EXPECT_NE(newSpecConstVal3, static_cast<int>(values[2]));
|
||||
|
||||
ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
||||
EXPECT_EQ(newSpecConstVal3, static_cast<int>(values[2]));
|
||||
}
|
||||
|
||||
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
||||
@ -93,9 +86,9 @@ TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperSizeWhenUpdate
|
||||
auto ret = mockProgram->updateSpecializationConstant(3, 10 * sizeof(int), &newSpecConstVal3);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_VALUE, ret);
|
||||
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
||||
EXPECT_EQ(val1, static_cast<char>(values[0]));
|
||||
EXPECT_EQ(val2, static_cast<uint16_t>(values[1]));
|
||||
EXPECT_EQ(val3, static_cast<int>(values[2]));
|
||||
}
|
||||
|
||||
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperIdAndSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
||||
@ -104,7 +97,7 @@ TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperIdAndSizeWhenU
|
||||
auto ret = mockProgram->updateSpecializationConstant(4, sizeof(int), &newSpecConstVal3);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_SPEC_ID, ret);
|
||||
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
||||
EXPECT_EQ(val1, static_cast<char>(values[0]));
|
||||
EXPECT_EQ(val2, static_cast<uint16_t>(values[1]));
|
||||
EXPECT_EQ(val3, static_cast<int>(values[2]));
|
||||
}
|
||||
|
@ -258,9 +258,9 @@ TranslationOutput::ErrorCode CompilerInterface::getSpecConstantsInfo(const NEO::
|
||||
return TranslationOutput::ErrorCode::UnknownError;
|
||||
}
|
||||
|
||||
output.valuesBuffer->Resize(output.idsBuffer->GetSize<uint32_t>() * sizeof(void *));
|
||||
for (uint32_t i = 0; i < output.valuesBuffer->GetSize<void *>(); i++) {
|
||||
output.valuesBuffer->GetMemoryWriteable<void *>()[i] = nullptr;
|
||||
output.valuesBuffer->Resize(output.idsBuffer->GetSizeRaw() * 2);
|
||||
for (uint32_t i = 0; i < output.valuesBuffer->GetSize<uint64_t>(); i++) {
|
||||
output.valuesBuffer->GetMemoryWriteable<void *>()[i] = 0u;
|
||||
}
|
||||
|
||||
return TranslationOutput::ErrorCode::Success;
|
||||
|
Reference in New Issue
Block a user