Split GivenImageArrayThenExpectationsMet test

Related-To: NEO-5797

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2021-07-27 18:36:38 +00:00
committed by Compute-Runtime-Automation
parent 4b723db2ca
commit 960d468107

View File

@ -80,93 +80,158 @@ struct AUBCreateImageArray : public AUBCreateImage,
}
};
HWTEST_F(AUBCreateImageArray, GivenImageArrayThenExpectationsMet) {
cl_mem_object_type ImgArrayTypes[] = {
CL_MEM_OBJECT_IMAGE1D_ARRAY,
CL_MEM_OBJECT_IMAGE2D_ARRAY};
HWTEST_F(AUBCreateImageArray, Given1DImageArrayThenExpectationsMet) {
auto &hwHelper = HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
imageDesc.image_height = 1;
cl_mem_flags flags = CL_MEM_COPY_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
auto imgInfo = MockGmm::initImgInfo(imageDesc, 0, surfaceFormat);
imgInfo.linearStorage = !hwHelper.tilingAllowed(false, Image::isImage1d(imageDesc), false);
auto queryGmm = MockGmm::queryImgParams(pDevice->getGmmClientContext(), imgInfo);
for (auto imageArrayType : ImgArrayTypes) {
auto &hwHelper = HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
imageDesc.image_type = imageArrayType;
if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
imageDesc.image_height = 1;
}
cl_mem_flags flags = CL_MEM_COPY_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
auto imgInfo = MockGmm::initImgInfo(imageDesc, 0, surfaceFormat);
imgInfo.linearStorage = !hwHelper.tilingAllowed(false, Image::isImage1d(imageDesc), false);
auto queryGmm = MockGmm::queryImgParams(pDevice->getGmmClientContext(), imgInfo);
//allocate host_ptr
auto pixelSize = 4;
auto storageSize = imageDesc.image_array_size * pixelSize * imageDesc.image_width * imageDesc.image_height;
//allocate host_ptr
auto pixelSize = 4;
auto storageSize = imageDesc.image_array_size * pixelSize * imageDesc.image_width * imageDesc.image_height;
std::unique_ptr<int[]> hostPtr(new int[storageSize]);
std::unique_ptr<int[]> hostPtr(new int[storageSize]);
for (auto i = 0u; i < storageSize; i++) {
hostPtr[i] = i;
}
for (auto i = 0u; i < storageSize; i++) {
hostPtr[i] = i;
}
image.reset(Image::create(
context,
MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
flags,
0,
surfaceFormat,
&imageDesc,
hostPtr.get(),
retVal));
image.reset(Image::create(
context,
MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
flags,
0,
surfaceFormat,
&imageDesc,
hostPtr.get(),
retVal));
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, image);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, image);
EXPECT_EQ(image->getSize(), imgInfo.size);
EXPECT_EQ(image->getImageDesc().image_slice_pitch, imgInfo.slicePitch);
EXPECT_EQ(image->getImageDesc().image_row_pitch, imgInfo.rowPitch);
EXPECT_GE(image->getImageDesc().image_slice_pitch, image->getImageDesc().image_row_pitch);
EXPECT_EQ(image->getQPitch(), imgInfo.qPitch);
EXPECT_EQ(image->getCubeFaceIndex(), static_cast<uint32_t>(__GMM_NO_CUBE_MAP));
EXPECT_EQ(image->getSize(), imgInfo.size);
EXPECT_EQ(image->getImageDesc().image_slice_pitch, imgInfo.slicePitch);
EXPECT_EQ(image->getImageDesc().image_row_pitch, imgInfo.rowPitch);
EXPECT_GE(image->getImageDesc().image_slice_pitch, image->getImageDesc().image_row_pitch);
EXPECT_EQ(image->getQPitch(), imgInfo.qPitch);
EXPECT_EQ(image->getCubeFaceIndex(), static_cast<uint32_t>(__GMM_NO_CUBE_MAP));
auto imageHeight = imageDesc.image_height;
std::unique_ptr<uint32_t[]> readMemory(new uint32_t[image->getSize() / sizeof(uint32_t)]);
auto allocation = createResidentAllocationAndStoreItInCsr(readMemory.get(), image->getSize());
auto imageHeight = imageDesc.image_height;
std::unique_ptr<uint32_t[]> readMemory(new uint32_t[image->getSize() / sizeof(uint32_t)]);
auto allocation = createResidentAllocationAndStoreItInCsr(readMemory.get(), image->getSize());
size_t imgOrigin[] = {0, 0, 0};
size_t imgRegion[] = {imageDesc.image_width, 1, 1};
size_t imgOrigin[] = {0, 0, 0};
size_t imgRegion[] = {imageDesc.image_width, 1, 1};
imgRegion[1] = imageDesc.image_array_size;
if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
imgRegion[1] = imageDesc.image_array_size;
} else if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY) {
imgRegion[1] = imageDesc.image_height;
imgRegion[2] = imageDesc.image_array_size;
} else {
ASSERT_TRUE(false);
}
retVal = pCmdQ->enqueueReadImage(image.get(), CL_FALSE, imgOrigin, imgRegion, imgInfo.rowPitch, imgInfo.slicePitch,
readMemory.get(), nullptr, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = pCmdQ->enqueueReadImage(image.get(), CL_FALSE, imgOrigin, imgRegion, imgInfo.rowPitch, imgInfo.slicePitch,
readMemory.get(), nullptr, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
allocation = pCommandStreamReceiver->getTemporaryAllocations().peekHead();
while (allocation && allocation->getUnderlyingBuffer() != readMemory.get()) {
allocation = allocation->next;
}
allocation = pCommandStreamReceiver->getTemporaryAllocations().peekHead();
while (allocation && allocation->getUnderlyingBuffer() != readMemory.get()) {
allocation = allocation->next;
}
auto destGpuAddress = reinterpret_cast<uint32_t *>(allocation->getGpuAddress());
pCmdQ->flush();
auto destGpuAddress = reinterpret_cast<uint32_t *>(allocation->getGpuAddress());
pCmdQ->flush();
auto address = (int *)image->getCpuAddress();
auto currentCounter = 0;
for (auto array = 0u; array < imageDesc.image_array_size; array++) {
for (auto height = 0u; height < imageHeight; height++) {
for (auto element = 0u; element < imageDesc.image_width; element++) {
auto offset = (array * imgInfo.slicePitch + element * pixelSize + height * imgInfo.rowPitch) / 4;
if (MemoryPool::isSystemMemoryPool(image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex())->getMemoryPool()) == false) {
AUBCommandStreamFixture::expectMemory<FamilyType>(&destGpuAddress[offset], &currentCounter, pixelSize);
} else {
EXPECT_EQ(currentCounter, address[offset]);
}
currentCounter++;
auto address = (int *)image->getCpuAddress();
auto currentCounter = 0;
for (auto array = 0u; array < imageDesc.image_array_size; array++) {
for (auto height = 0u; height < imageHeight; height++) {
for (auto element = 0u; element < imageDesc.image_width; element++) {
auto offset = (array * imgInfo.slicePitch + element * pixelSize + height * imgInfo.rowPitch) / 4;
if (MemoryPool::isSystemMemoryPool(image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex())->getMemoryPool()) == false) {
AUBCommandStreamFixture::expectMemory<FamilyType>(&destGpuAddress[offset], &currentCounter, pixelSize);
} else {
EXPECT_EQ(currentCounter, address[offset]);
}
currentCounter++;
}
}
}
}
HWTEST_F(AUBCreateImageArray, Given2DImageArrayThenExpectationsMet) {
auto &hwHelper = HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
cl_mem_flags flags = CL_MEM_COPY_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
auto imgInfo = MockGmm::initImgInfo(imageDesc, 0, surfaceFormat);
imgInfo.linearStorage = !hwHelper.tilingAllowed(false, Image::isImage1d(imageDesc), false);
auto queryGmm = MockGmm::queryImgParams(pDevice->getGmmClientContext(), imgInfo);
//allocate host_ptr
auto pixelSize = 4;
auto storageSize = imageDesc.image_array_size * pixelSize * imageDesc.image_width * imageDesc.image_height;
std::unique_ptr<int[]> hostPtr(new int[storageSize]);
for (auto i = 0u; i < storageSize; i++) {
hostPtr[i] = i;
}
image.reset(Image::create(
context,
MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
flags,
0,
surfaceFormat,
&imageDesc,
hostPtr.get(),
retVal));
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, image);
EXPECT_EQ(image->getSize(), imgInfo.size);
EXPECT_EQ(image->getImageDesc().image_slice_pitch, imgInfo.slicePitch);
EXPECT_EQ(image->getImageDesc().image_row_pitch, imgInfo.rowPitch);
EXPECT_GE(image->getImageDesc().image_slice_pitch, image->getImageDesc().image_row_pitch);
EXPECT_EQ(image->getQPitch(), imgInfo.qPitch);
EXPECT_EQ(image->getCubeFaceIndex(), static_cast<uint32_t>(__GMM_NO_CUBE_MAP));
auto imageHeight = imageDesc.image_height;
std::unique_ptr<uint32_t[]> readMemory(new uint32_t[image->getSize() / sizeof(uint32_t)]);
auto allocation = createResidentAllocationAndStoreItInCsr(readMemory.get(), image->getSize());
size_t imgOrigin[] = {0, 0, 0};
size_t imgRegion[] = {imageDesc.image_width, 1, 1};
imgRegion[1] = imageDesc.image_height;
imgRegion[2] = imageDesc.image_array_size;
retVal = pCmdQ->enqueueReadImage(image.get(), CL_FALSE, imgOrigin, imgRegion, imgInfo.rowPitch, imgInfo.slicePitch,
readMemory.get(), nullptr, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
allocation = pCommandStreamReceiver->getTemporaryAllocations().peekHead();
while (allocation && allocation->getUnderlyingBuffer() != readMemory.get()) {
allocation = allocation->next;
}
auto destGpuAddress = reinterpret_cast<uint32_t *>(allocation->getGpuAddress());
pCmdQ->flush();
auto address = (int *)image->getCpuAddress();
auto currentCounter = 0;
for (auto array = 0u; array < imageDesc.image_array_size; array++) {
for (auto height = 0u; height < imageHeight; height++) {
for (auto element = 0u; element < imageDesc.image_width; element++) {
auto offset = (array * imgInfo.slicePitch + element * pixelSize + height * imgInfo.rowPitch) / 4;
if (MemoryPool::isSystemMemoryPool(image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex())->getMemoryPool()) == false) {
AUBCommandStreamFixture::expectMemory<FamilyType>(&destGpuAddress[offset], &currentCounter, pixelSize);
} else {
EXPECT_EQ(currentCounter, address[offset]);
}
currentCounter++;
}
}
}