mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 23:56:39 +08:00
Copy specialization constant value
Change-Id: I5bee6ef3e5d48d42194df690860fdd6ef6b90246 Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
ed59e46c72
commit
ab3ae5fea7
@@ -130,6 +130,15 @@ Program::~Program() {
|
|||||||
if (context && !isBuiltIn) {
|
if (context && !isBuiltIn) {
|
||||||
context->decRefInternal();
|
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(
|
cl_int Program::createProgramFromBinary(
|
||||||
@@ -227,6 +236,10 @@ cl_int Program::setProgramSpecializationConstant(cl_uint specId, size_t specSize
|
|||||||
return CL_INVALID_VALUE;
|
return CL_INVALID_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->specConstantsIds.reset(specConstInfo.idsBuffer.release());
|
||||||
|
this->specConstantsSizes.reset(specConstInfo.sizesBuffer.release());
|
||||||
|
this->specConstantsValues.reset(specConstInfo.valuesBuffer.release());
|
||||||
|
|
||||||
areSpecializationConstantsInitialized = true;
|
areSpecializationConstantsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,10 +247,15 @@ cl_int Program::setProgramSpecializationConstant(cl_uint specId, size_t specSize
|
|||||||
}
|
}
|
||||||
|
|
||||||
cl_int Program::updateSpecializationConstant(cl_uint specId, size_t specSize, const void *specValue) {
|
cl_int Program::updateSpecializationConstant(cl_uint specId, size_t specSize, const void *specValue) {
|
||||||
for (uint32_t i = 0; i < specConstantsIds->GetSize<cl_uint>(); i++) {
|
for (uint32_t i = 0; i < specConstantsIds->GetSize<uint32_t>(); i++) {
|
||||||
if (specConstantsIds->GetMemory<cl_uint>()[i] == specId) {
|
if (specConstantsIds->GetMemory<uint32_t>()[i] == specId) {
|
||||||
if (specConstantsSizes->GetMemory<size_t>()[i] == specSize) {
|
if (specConstantsSizes->GetMemory<uint32_t>()[i] == static_cast<uint32_t>(specSize)) {
|
||||||
specConstantsValues->GetMemoryWriteable<const void *>()[i] = specValue;
|
auto specConstPtr = specConstantsValues->GetMemoryWriteable<void *>()[i];
|
||||||
|
if (specConstPtr == nullptr) {
|
||||||
|
specConstPtr = new char[specSize];
|
||||||
|
}
|
||||||
|
memcpy_s(specConstPtr, specSize, specValue, specSize);
|
||||||
|
specConstantsValues->GetMemoryWriteable<void *>()[i] = specConstPtr;
|
||||||
return CL_SUCCESS;
|
return CL_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return CL_INVALID_VALUE;
|
return CL_INVALID_VALUE;
|
||||||
|
|||||||
@@ -32,42 +32,59 @@ struct UpdateSpecConstantsTest : public ::testing::Test {
|
|||||||
mockProgram->specConstantsSizes.reset(new MockCIFBuffer());
|
mockProgram->specConstantsSizes.reset(new MockCIFBuffer());
|
||||||
mockProgram->specConstantsValues.reset(new MockCIFBuffer());
|
mockProgram->specConstantsValues.reset(new MockCIFBuffer());
|
||||||
|
|
||||||
mockProgram->specConstantsIds->PushBackRawCopy(1);
|
uint32_t id1 = 1u, id2 = 2u, id3 = 3u;
|
||||||
mockProgram->specConstantsIds->PushBackRawCopy(2);
|
mockProgram->specConstantsIds->PushBackRawCopy(id1);
|
||||||
mockProgram->specConstantsIds->PushBackRawCopy(3);
|
mockProgram->specConstantsIds->PushBackRawCopy(id2);
|
||||||
|
mockProgram->specConstantsIds->PushBackRawCopy(id3);
|
||||||
|
|
||||||
mockProgram->specConstantsSizes->PushBackRawCopy(sizeof(char));
|
uint32_t size1 = sizeof(char), size2 = sizeof(uint16_t), size3 = sizeof(int);
|
||||||
mockProgram->specConstantsSizes->PushBackRawCopy(sizeof(uint16_t));
|
mockProgram->specConstantsSizes->PushBackRawCopy(size1);
|
||||||
mockProgram->specConstantsSizes->PushBackRawCopy(sizeof(int));
|
mockProgram->specConstantsSizes->PushBackRawCopy(size2);
|
||||||
|
mockProgram->specConstantsSizes->PushBackRawCopy(size3);
|
||||||
|
|
||||||
mockProgram->specConstantsValues->PushBackRawCopy(&val1);
|
val1 = new char;
|
||||||
mockProgram->specConstantsValues->PushBackRawCopy(&val2);
|
val2 = new uint16_t;
|
||||||
mockProgram->specConstantsValues->PushBackRawCopy(&val3);
|
|
||||||
|
|
||||||
values = mockProgram->specConstantsValues->GetMemory<const void *>();
|
*val1 = 5;
|
||||||
|
*val2 = 50;
|
||||||
|
|
||||||
EXPECT_EQ(val1, *reinterpret_cast<const char *>(values[0]));
|
mockProgram->specConstantsValues->PushBackRawCopy(val1);
|
||||||
EXPECT_EQ(val2, *reinterpret_cast<const uint16_t *>(values[1]));
|
mockProgram->specConstantsValues->PushBackRawCopy(val2);
|
||||||
EXPECT_EQ(val3, *reinterpret_cast<const int *>(values[2]));
|
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]));
|
||||||
}
|
}
|
||||||
ExecutionEnvironment executionEnvironment;
|
ExecutionEnvironment executionEnvironment;
|
||||||
std::unique_ptr<MockProgram> mockProgram;
|
std::unique_ptr<MockProgram> mockProgram;
|
||||||
|
|
||||||
char val1 = 5;
|
char *val1 = nullptr;
|
||||||
uint16_t val2 = 50;
|
uint16_t *val2 = nullptr;
|
||||||
int val3 = 500;
|
int *val3 = nullptr;
|
||||||
const void *const *values;
|
void **values;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWhenUpdateSpecializationConstantThenProperValueIsUpdated) {
|
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWhenUpdateSpecializationConstantThenProperValueIsCopiedAndUpdated) {
|
||||||
int newSpecConstVal3 = 5000;
|
int newSpecConstVal3 = 5000;
|
||||||
|
|
||||||
auto ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
auto ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
||||||
|
|
||||||
EXPECT_EQ(CL_SUCCESS, ret);
|
EXPECT_EQ(CL_SUCCESS, ret);
|
||||||
EXPECT_EQ(val1, *reinterpret_cast<const char *>(values[0]));
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||||
EXPECT_EQ(val2, *reinterpret_cast<const uint16_t *>(values[1]));
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||||
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<const int *>(values[2]));
|
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
||||||
|
EXPECT_NE(&newSpecConstVal3, values[2]);
|
||||||
|
EXPECT_NE(val3, values[2]);
|
||||||
|
|
||||||
|
newSpecConstVal3 = 50000;
|
||||||
|
EXPECT_NE(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
||||||
|
|
||||||
|
ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
||||||
|
EXPECT_EQ(CL_SUCCESS, ret);
|
||||||
|
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
||||||
@@ -76,9 +93,9 @@ TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperSizeWhenUpdate
|
|||||||
auto ret = mockProgram->updateSpecializationConstant(3, 10 * sizeof(int), &newSpecConstVal3);
|
auto ret = mockProgram->updateSpecializationConstant(3, 10 * sizeof(int), &newSpecConstVal3);
|
||||||
|
|
||||||
EXPECT_EQ(CL_INVALID_VALUE, ret);
|
EXPECT_EQ(CL_INVALID_VALUE, ret);
|
||||||
EXPECT_EQ(val1, *reinterpret_cast<const char *>(values[0]));
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||||
EXPECT_EQ(val2, *reinterpret_cast<const uint16_t *>(values[1]));
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||||
EXPECT_EQ(val3, *reinterpret_cast<const int *>(values[2]));
|
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperIdAndSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperIdAndSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
||||||
@@ -87,7 +104,7 @@ TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperIdAndSizeWhenU
|
|||||||
auto ret = mockProgram->updateSpecializationConstant(4, sizeof(int), &newSpecConstVal3);
|
auto ret = mockProgram->updateSpecializationConstant(4, sizeof(int), &newSpecConstVal3);
|
||||||
|
|
||||||
EXPECT_EQ(CL_INVALID_SPEC_ID, ret);
|
EXPECT_EQ(CL_INVALID_SPEC_ID, ret);
|
||||||
EXPECT_EQ(val1, *reinterpret_cast<const char *>(values[0]));
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
||||||
EXPECT_EQ(val2, *reinterpret_cast<const uint16_t *>(values[1]));
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
||||||
EXPECT_EQ(val3, *reinterpret_cast<const int *>(values[2]));
|
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,6 +258,8 @@ TranslationOutput::ErrorCode CompilerInterface::getSpecConstantsInfo(const NEO::
|
|||||||
return TranslationOutput::ErrorCode::UnknownError;
|
return TranslationOutput::ErrorCode::UnknownError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output.valuesBuffer->Resize(output.idsBuffer->GetSize<uint32_t>() * sizeof(void *));
|
||||||
|
|
||||||
return TranslationOutput::ErrorCode::Success;
|
return TranslationOutput::ErrorCode::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user