Return 0 when Read-Write images are not supported

clGetDeviceInfo and clGetSupportedImageFormats return 0 when Read-Write
images are not supported

Related-To: NEO-4368

Change-Id: Iabeb3ca35fbdd1ab6eb8497dbcc94bb6876d8f42
Signed-off-by: Andrzej Swierczynski <andrzej.swierczynski@intel.com>
This commit is contained in:
Andrzej Swierczynski
2020-04-20 12:22:53 +02:00
committed by sys_ocldev
parent 290445f922
commit 4c616f8bef
5 changed files with 49 additions and 2 deletions

View File

@@ -230,7 +230,7 @@ void ClDevice::initializeCaps() {
deviceInfo.nativeVectorWidthFloat = 1;
deviceInfo.nativeVectorWidthDouble = 1;
deviceInfo.nativeVectorWidthHalf = 8;
deviceInfo.maxReadWriteImageArgs = 128;
deviceInfo.maxReadWriteImageArgs = enabledClVersion >= 20 ? 128 : 0;
deviceInfo.executionCapabilities = CL_EXEC_KERNEL;
//copy system info to prevent misaligned reads

View File

@@ -289,6 +289,14 @@ cl_int Context::getSupportedImageFormats(
cl_image_format *imageFormats,
cl_uint *numImageFormatsReturned) {
size_t numImageFormats = 0;
if (flags & CL_MEM_KERNEL_READ_AND_WRITE && device->getSpecializedDevice<ClDevice>()->getEnabledClVersion() < 20) {
if (numImageFormatsReturned) {
*numImageFormatsReturned = static_cast<cl_uint>(numImageFormats);
}
return CL_SUCCESS;
}
const bool nv12ExtensionEnabled = device->getSpecializedDevice<ClDevice>()->getDeviceInfo().nv12Extension;
const bool packedYuvExtensionEnabled = device->getSpecializedDevice<ClDevice>()->getDeviceInfo().packedYuvExtension;

View File

@@ -74,6 +74,32 @@ TEST(clGetSupportedImageFormatsTest, givenPlatforNotSupportingImageWhenGettingSu
EXPECT_EQ(0u, numImageFormats);
}
TEST(clGetSupportedImageFormatsTest, givenPlatformNotSupportingReadWriteImagesWhenGettingSupportedImageFormatsThenCLSuccessIsReturned) {
HardwareInfo hwInfo = *defaultHwInfo;
hwInfo.capabilityTable.supportsImages = true;
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
cl_device_id clDevice = device.get();
cl_int retVal;
auto context = ReleaseableObjectPtr<Context>(Context::create<Context>(nullptr, ClDeviceVector(&clDevice, 1), nullptr, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
cl_uint numImageFormats = 0;
retVal = clGetSupportedImageFormats(
context.get(),
CL_MEM_KERNEL_READ_AND_WRITE,
CL_MEM_OBJECT_IMAGE2D,
0,
nullptr,
&numImageFormats);
EXPECT_EQ(CL_SUCCESS, retVal);
if (context->getDevice(0)->getEnabledClVersion() >= 20) {
EXPECT_GT(numImageFormats, 0u);
} else {
EXPECT_EQ(0u, numImageFormats);
}
}
TEST(clGetSupportedImageFormatsTest, givenPlatforNotSupportingImageAndNullPointerToNumFormatsWhenGettingSupportImageFormatsThenCLSuccessReturned) {
HardwareInfo hwInfo = *defaultHwInfo;
hwInfo.capabilityTable.supportsImages = false;

View File

@@ -91,6 +91,15 @@ TEST_P(GetSupportedImageFormatsTest, retrieveImageFormats) {
EXPECT_NE(0u, imageFormatList[entry].image_channel_data_type);
}
retVal = pContext->getSupportedImageFormats(
&castToObject<ClDevice>(devices[0])->getDevice(),
CL_MEM_KERNEL_READ_AND_WRITE,
imageFormats,
numImageFormats,
imageFormatList,
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
delete[] imageFormatList;
}

View File

@@ -97,7 +97,11 @@ TEST_F(DeviceGetCapsTest, WhenCreatingDeviceThenCapsArePopulatedCorrectly) {
EXPECT_LE(128u, sharedCaps.maxReadImageArgs);
EXPECT_LE(128u, sharedCaps.maxWriteImageArgs);
EXPECT_EQ(128u, caps.maxReadWriteImageArgs);
if (device->getEnabledClVersion() >= 20) {
EXPECT_EQ(128u, caps.maxReadWriteImageArgs);
} else {
EXPECT_EQ(0u, caps.maxReadWriteImageArgs);
}
EXPECT_LE(sharedCaps.maxReadImageArgs * sizeof(cl_mem), sharedCaps.maxParameterSize);
EXPECT_LE(sharedCaps.maxWriteImageArgs * sizeof(cl_mem), sharedCaps.maxParameterSize);