Set arg immediate for all Kernel devices

convert tests to multi root device scenario

Related-To: NEO-5001
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-12-17 16:26:13 +00:00
committed by Compute-Runtime-Automation
parent e665111013
commit c3083592ad
7 changed files with 270 additions and 201 deletions

View File

@@ -6,7 +6,7 @@
*/
#include "opencl/source/kernel/kernel.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "opencl/test/unit_test/mocks/mock_program.h"
@@ -18,64 +18,68 @@
using namespace NEO;
template <typename T>
class KernelArgImmediateTest : public Test<ClDeviceFixture> {
class KernelArgImmediateTest : public MultiRootDeviceWithSubDevicesFixture {
public:
protected:
void SetUp() override {
ClDeviceFixture::SetUp();
memset(pCrossThreadData, 0xfe, sizeof(pCrossThreadData));
program = std::make_unique<MockProgram>(toClDeviceVector(*pClDevice));
MultiRootDeviceWithSubDevicesFixture::SetUp();
program = std::make_unique<MockProgram>(context.get(), false, context->getDevices());
// define kernel info
pKernelInfo = std::make_unique<KernelInfo>();
pKernelInfo->kernelDescriptor.kernelAttributes.simdSize = 1;
KernelInfoContainer kernelInfos;
kernelInfos.resize(3);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
memset(&pCrossThreadData[rootDeviceIndex], 0xfe, sizeof(pCrossThreadData[rootDeviceIndex]));
// setup kernel arg offsets
KernelArgPatchInfo kernelArgPatchInfo;
// define kernel info
pKernelInfo[rootDeviceIndex] = std::make_unique<KernelInfo>();
pKernelInfo[rootDeviceIndex]->kernelDescriptor.kernelAttributes.simdSize = 1;
pKernelInfo->kernelArgInfo.resize(4);
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
// setup kernel arg offsets
KernelArgPatchInfo kernelArgPatchInfo;
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset = 0x38;
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset = 0x28;
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[0].crossthreadOffset = 0x20;
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].crossthreadOffset = 0x30;
pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector[0].crossthreadOffset = 0x40;
pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = 0x50;
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = sizeof(T);
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(T);
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo[rootDeviceIndex]->kernelArgInfo.resize(4);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[2].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[1].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
program = std::make_unique<MockProgram>(toClDeviceVector(*pClDevice));
pKernel = new MockKernel(program.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, rootDeviceIndex));
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset = 0x38;
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset = 0x28;
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[0].crossthreadOffset = 0x20;
pKernelInfo[rootDeviceIndex]->kernelArgInfo[2].kernelArgPatchInfoVector[0].crossthreadOffset = 0x30;
pKernelInfo[rootDeviceIndex]->kernelArgInfo[1].kernelArgPatchInfoVector[0].crossthreadOffset = 0x40;
pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = 0x50;
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = sizeof(T);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(T);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[2].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[1].kernelArgPatchInfoVector[0].size = sizeof(T);
pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(T);
kernelInfos[rootDeviceIndex] = pKernelInfo[rootDeviceIndex].get();
}
pKernel = new MockKernel(program.get(), kernelInfos);
ASSERT_EQ(CL_SUCCESS, pKernel->initialize());
pKernel->setCrossThreadData(pCrossThreadData, sizeof(pCrossThreadData));
pKernel->setKernelArgHandler(0, &Kernel::setArgImmediate);
pKernel->setKernelArgHandler(1, &Kernel::setArgImmediate);
pKernel->setKernelArgHandler(2, &Kernel::setArgImmediate);
pKernel->setKernelArgHandler(3, &Kernel::setArgImmediate);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
pKernel->setCrossThreadDataForRootDeviceIndex(rootDeviceIndex, &pCrossThreadData[rootDeviceIndex], sizeof(pCrossThreadData[rootDeviceIndex]));
}
}
void TearDown() override {
delete pKernel;
ClDeviceFixture::TearDown();
MultiRootDeviceWithSubDevicesFixture::TearDown();
}
cl_int retVal = CL_SUCCESS;
std::unique_ptr<MockProgram> program;
MockKernel *pKernel = nullptr;
std::unique_ptr<KernelInfo> pKernelInfo;
char pCrossThreadData[0x60];
std::unique_ptr<KernelInfo> pKernelInfo[3];
char pCrossThreadData[3][0x60];
};
typedef ::testing::Types<
@@ -97,10 +101,12 @@ TYPED_TEST(KernelArgImmediateTest, WhenSettingKernelArgThenArgIsSetCorrectly) {
auto pVal = &val;
this->pKernel->setArg(0, sizeof(TypeParam), pVal);
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
EXPECT_EQ(val, *pKernelArg);
}
}
TYPED_TEST(KernelArgImmediateTest, GivenInvalidIndexWhenSettingKernelArgThenInvalidArgIndexErrorIsReturned) {
@@ -114,55 +120,65 @@ TYPED_TEST(KernelArgImmediateTest, GivenInvalidIndexWhenSettingKernelArgThenInva
TYPED_TEST(KernelArgImmediateTest, GivenMultipleArgumentsWhenSettingKernelArgThenEachArgIsSetCorrectly) {
auto val = (TypeParam)0xaaaaaaaaULL;
auto pVal = &val;
this->pKernel->setArg(0, sizeof(TypeParam), pVal);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
}
val = (TypeParam)0xbbbbbbbbULL;
this->pKernel->setArg(1, sizeof(TypeParam), &val);
pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[1].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
}
val = (TypeParam)0xccccccccULL;
this->pKernel->setArg(2, sizeof(TypeParam), &val);
pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].crossthreadOffset);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[2].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
EXPECT_EQ(val, *pKernelArg);
}
}
TYPED_TEST(KernelArgImmediateTest, GivenCrossThreadDataOverwritesWhenSettingKernelArgThenArgsAreSetCorrectly) {
TypeParam val = (TypeParam)0xaaaaaaaaULL;
TypeParam *pVal = &val;
this->pKernel->setArg(0, sizeof(TypeParam), pVal);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
TypeParam *pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
TypeParam *pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
EXPECT_EQ(val, *pKernelArg);
}
val = (TypeParam)0xbbbbbbbbULL;
this->pKernel->setArg(1, sizeof(TypeParam), &val);
pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[1].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
}
val = (TypeParam)0xccccccccULL;
this->pKernel->setArg(0, sizeof(TypeParam), &val);
pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pKernelArg = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(val, *pKernelArg);
EXPECT_EQ(val, *pKernelArg);
}
}
TYPED_TEST(KernelArgImmediateTest, GivenMultipleStructElementsWhenSettingKernelArgThenArgsAreSetCorrectly) {
@@ -178,155 +194,170 @@ TYPED_TEST(KernelArgImmediateTest, GivenMultipleStructElementsWhenSettingKernelA
immediateStruct.unused[1] = 0xfe;
immediateStruct.unused[2] = 0xfe;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[0].sourceOffset = offsetof(struct ImmediateStruct, a);
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = offsetof(struct ImmediateStruct, b);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[0].sourceOffset = offsetof(struct ImmediateStruct, a);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = offsetof(struct ImmediateStruct, b);
}
this->pKernel->setArg(3, sizeof(immediateStruct), &immediateStruct);
auto pCrossthreadA = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(immediateStruct.a, *pCrossthreadA);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
auto pCrossthreadA = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[0].crossthreadOffset);
EXPECT_EQ(immediateStruct.a, *pCrossthreadA);
auto pCrossthreadB = (TypeParam *)(this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset);
EXPECT_EQ(immediateStruct.b, *pCrossthreadB);
auto pCrossthreadB = (TypeParam *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset);
EXPECT_EQ(immediateStruct.b, *pCrossthreadB);
}
}
TYPED_TEST(KernelArgImmediateTest, givenTooLargePatchSizeWhenSettingArgThenDontReadMemoryBeyondLimit) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto destinationMemoryAddress = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
const auto memoryBeyondLimitAddress = destinationMemoryAddress + sizeof(TypeParam);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto memoryBeyondLimitBefore = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
const auto destinationMemoryAddress = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
const auto memoryBeyondLimitAddress = destinationMemoryAddress + sizeof(TypeParam);
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(TypeParam) + 1;
auto retVal = this->pKernel->setArg(0, sizeof(TypeParam), &memory[0]);
const auto memoryBeyondLimitBefore = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
const auto memoryBeyondLimitAfter = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
EXPECT_EQ(memoryBeyondLimitBefore, memoryBeyondLimitAfter);
EXPECT_EQ(memory[0], *reinterpret_cast<TypeParam *>(destinationMemoryAddress));
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(TypeParam) + 1;
auto retVal = this->pKernel->setArg(0, sizeof(TypeParam), &memory[0]);
EXPECT_EQ(CL_SUCCESS, retVal);
const auto memoryBeyondLimitAfter = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
EXPECT_EQ(memoryBeyondLimitBefore, memoryBeyondLimitAfter);
EXPECT_EQ(memory[0], *reinterpret_cast<TypeParam *>(destinationMemoryAddress));
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TYPED_TEST(KernelArgImmediateTest, givenNotTooLargePatchSizeWhenSettingArgThenDontReadMemoryBeyondLimit) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto destinationMemoryAddress = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
const auto memoryBeyondLimitAddress = destinationMemoryAddress + sizeof(TypeParam);
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto memoryBeyondLimitBefore = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
const auto destinationMemoryAddress = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
const auto memoryBeyondLimitAddress = destinationMemoryAddress + sizeof(TypeParam);
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(TypeParam);
auto retVal = this->pKernel->setArg(0, sizeof(TypeParam), &memory[0]);
const auto memoryBeyondLimitBefore = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
const auto memoryBeyondLimitAfter = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
EXPECT_EQ(memoryBeyondLimitBefore, memoryBeyondLimitAfter);
EXPECT_EQ(memory[0], *reinterpret_cast<TypeParam *>(destinationMemoryAddress));
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(TypeParam);
auto retVal = this->pKernel->setArg(0, sizeof(TypeParam), &memory[0]);
EXPECT_EQ(CL_SUCCESS, retVal);
const auto memoryBeyondLimitAfter = *reinterpret_cast<TypeParam *>(memoryBeyondLimitAddress);
EXPECT_EQ(memoryBeyondLimitBefore, memoryBeyondLimitAfter);
EXPECT_EQ(memory[0], *reinterpret_cast<TypeParam *>(destinationMemoryAddress));
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TYPED_TEST(KernelArgImmediateTest, givenMulitplePatchesAndFirstPatchSizeTooLargeWhenSettingArgThenDontReadMemoryBeyondLimit) {
if (sizeof(TypeParam) == 1)
return; // multiple patch chars don't make sense
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto destinationMemoryAddress1 = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset;
const auto destinationMemoryAddress2 = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset;
const auto memoryBeyondLimitAddress1 = destinationMemoryAddress1 + sizeof(TypeParam);
const auto memoryBeyondLimitAddress2 = destinationMemoryAddress2 + sizeof(TypeParam) / 2;
const auto destinationMemoryAddress1 = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset;
const auto destinationMemoryAddress2 = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset;
const auto memoryBeyondLimitAddress1 = destinationMemoryAddress1 + sizeof(TypeParam);
const auto memoryBeyondLimitAddress2 = destinationMemoryAddress2 + sizeof(TypeParam) / 2;
const std::vector<unsigned char> memoryBeyondLimitBefore1(memoryBeyondLimitAddress1, memoryBeyondLimitAddress1 + sizeof(TypeParam));
const std::vector<unsigned char> memoryBeyondLimitBefore2(memoryBeyondLimitAddress2, memoryBeyondLimitAddress2 + sizeof(TypeParam) / 2);
const std::vector<unsigned char> memoryBeyondLimitBefore1(memoryBeyondLimitAddress1, memoryBeyondLimitAddress1 + sizeof(TypeParam));
const std::vector<unsigned char> memoryBeyondLimitBefore2(memoryBeyondLimitAddress2, memoryBeyondLimitAddress2 + sizeof(TypeParam) / 2);
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].sourceOffset = 0;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = sizeof(TypeParam) / 2;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = sizeof(TypeParam);
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(TypeParam) / 2;
auto retVal = this->pKernel->setArg(3, sizeof(TypeParam), &memory[0]);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].sourceOffset = 0;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = sizeof(TypeParam) / 2;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = sizeof(TypeParam);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(TypeParam) / 2;
auto retVal = this->pKernel->setArg(3, sizeof(TypeParam), &memory[0]);
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore1.data(), memoryBeyondLimitAddress1, sizeof(TypeParam)));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore2.data(), memoryBeyondLimitAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore1.data(), memoryBeyondLimitAddress1, sizeof(TypeParam)));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore2.data(), memoryBeyondLimitAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress1, sizeof(TypeParam)));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress1, sizeof(TypeParam)));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TYPED_TEST(KernelArgImmediateTest, givenMulitplePatchesAndSecondPatchSizeTooLargeWhenSettingArgThenDontReadMemoryBeyondLimit) {
if (sizeof(TypeParam) == 1)
return; // multiple patch chars don't make sense
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto destinationMemoryAddress1 = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset;
const auto destinationMemoryAddress2 = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset;
const auto memoryBeyondLimitAddress1 = destinationMemoryAddress1 + sizeof(TypeParam) / 2;
const auto memoryBeyondLimitAddress2 = destinationMemoryAddress2 + sizeof(TypeParam) / 2;
const auto destinationMemoryAddress1 = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset;
const auto destinationMemoryAddress2 = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset;
const auto memoryBeyondLimitAddress1 = destinationMemoryAddress1 + sizeof(TypeParam) / 2;
const auto memoryBeyondLimitAddress2 = destinationMemoryAddress2 + sizeof(TypeParam) / 2;
const std::vector<unsigned char> memoryBeyondLimitBefore1(memoryBeyondLimitAddress1, memoryBeyondLimitAddress1 + sizeof(TypeParam) / 2);
const std::vector<unsigned char> memoryBeyondLimitBefore2(memoryBeyondLimitAddress2, memoryBeyondLimitAddress2 + sizeof(TypeParam) / 2);
const std::vector<unsigned char> memoryBeyondLimitBefore1(memoryBeyondLimitAddress1, memoryBeyondLimitAddress1 + sizeof(TypeParam) / 2);
const std::vector<unsigned char> memoryBeyondLimitBefore2(memoryBeyondLimitAddress2, memoryBeyondLimitAddress2 + sizeof(TypeParam) / 2);
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[0].size = 0;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].sourceOffset = 0;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = sizeof(TypeParam) / 2;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = sizeof(TypeParam) / 2;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(TypeParam);
auto retVal = this->pKernel->setArg(3, sizeof(TypeParam), &memory[0]);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[0].size = 0;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].sourceOffset = 0;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = sizeof(TypeParam) / 2;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = sizeof(TypeParam) / 2;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(TypeParam);
auto retVal = this->pKernel->setArg(3, sizeof(TypeParam), &memory[0]);
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore1.data(), memoryBeyondLimitAddress1, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore2.data(), memoryBeyondLimitAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore1.data(), memoryBeyondLimitAddress1, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore2.data(), memoryBeyondLimitAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress1, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress1, sizeof(TypeParam) / 2));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress2, sizeof(TypeParam) / 2));
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TYPED_TEST(KernelArgImmediateTest, givenMultiplePatchesAndOneSourceOffsetBeyondArgumentWhenSettingArgThenDontCopyThisPatch) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
TypeParam memory[2];
std::memset(&memory[0], 0xaa, sizeof(TypeParam));
std::memset(&memory[1], 0xbb, sizeof(TypeParam));
const auto destinationMemoryAddress1 = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset;
const auto destinationMemoryAddress2 = this->pKernel->getCrossThreadData(this->rootDeviceIndex) +
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset;
const auto memoryBeyondLimitAddress1 = destinationMemoryAddress1 + sizeof(TypeParam);
const auto memoryBeyondLimitAddress2 = destinationMemoryAddress2;
const auto destinationMemoryAddress1 = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].crossthreadOffset;
const auto destinationMemoryAddress2 = this->pKernel->getCrossThreadData(rootDeviceIndex) +
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].crossthreadOffset;
const auto memoryBeyondLimitAddress1 = destinationMemoryAddress1 + sizeof(TypeParam);
const auto memoryBeyondLimitAddress2 = destinationMemoryAddress2;
const std::vector<unsigned char> memoryBeyondLimitBefore1(memoryBeyondLimitAddress1, memoryBeyondLimitAddress1 + sizeof(TypeParam));
const std::vector<unsigned char> memoryBeyondLimitBefore2(memoryBeyondLimitAddress2, memoryBeyondLimitAddress2 + sizeof(TypeParam));
const std::vector<unsigned char> memoryBeyondLimitBefore1(memoryBeyondLimitAddress1, memoryBeyondLimitAddress1 + sizeof(TypeParam));
const std::vector<unsigned char> memoryBeyondLimitBefore2(memoryBeyondLimitAddress2, memoryBeyondLimitAddress2 + sizeof(TypeParam));
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[0].size = 0;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = 0;
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(TypeParam);
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].sourceOffset = sizeof(TypeParam);
this->pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = 1;
auto retVal = this->pKernel->setArg(3, sizeof(TypeParam), &memory[0]);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[0].size = 0;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].sourceOffset = 0;
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[1].size = sizeof(TypeParam);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].sourceOffset = sizeof(TypeParam);
this->pKernelInfo[rootDeviceIndex]->kernelArgInfo[3].kernelArgPatchInfoVector[2].size = 1;
auto retVal = this->pKernel->setArg(3, sizeof(TypeParam), &memory[0]);
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore1.data(), memoryBeyondLimitAddress1, memoryBeyondLimitBefore1.size()));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore2.data(), memoryBeyondLimitAddress2, memoryBeyondLimitBefore2.size()));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore1.data(), memoryBeyondLimitAddress1, memoryBeyondLimitBefore1.size()));
EXPECT_EQ(0, std::memcmp(memoryBeyondLimitBefore2.data(), memoryBeyondLimitAddress2, memoryBeyondLimitBefore2.size()));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress1, sizeof(TypeParam)));
EXPECT_EQ(0, std::memcmp(&memory[0], destinationMemoryAddress1, sizeof(TypeParam)));
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
}
}