From 4c616f8befd40510e95f95f0e0f7730905f72879 Mon Sep 17 00:00:00 2001 From: Andrzej Swierczynski Date: Mon, 20 Apr 2020 12:22:53 +0200 Subject: [PATCH] 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 --- opencl/source/cl_device/cl_device_caps.cpp | 2 +- opencl/source/context/context.cpp | 8 ++++++ .../cl_get_supported_image_formats_tests.inl | 26 +++++++++++++++++++ .../get_supported_image_formats_tests.cpp | 9 +++++++ .../unit_test/device/device_caps_tests.cpp | 6 ++++- 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/opencl/source/cl_device/cl_device_caps.cpp b/opencl/source/cl_device/cl_device_caps.cpp index 79ce47005b..6ee7381a72 100644 --- a/opencl/source/cl_device/cl_device_caps.cpp +++ b/opencl/source/cl_device/cl_device_caps.cpp @@ -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 diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index 5e026df832..92c959c122 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -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()->getEnabledClVersion() < 20) { + if (numImageFormatsReturned) { + *numImageFormatsReturned = static_cast(numImageFormats); + } + return CL_SUCCESS; + } + const bool nv12ExtensionEnabled = device->getSpecializedDevice()->getDeviceInfo().nv12Extension; const bool packedYuvExtensionEnabled = device->getSpecializedDevice()->getDeviceInfo().packedYuvExtension; diff --git a/opencl/test/unit_test/api/cl_get_supported_image_formats_tests.inl b/opencl/test/unit_test/api/cl_get_supported_image_formats_tests.inl index 199a3c32a4..9fbd2c25c9 100644 --- a/opencl/test/unit_test/api/cl_get_supported_image_formats_tests.inl +++ b/opencl/test/unit_test/api/cl_get_supported_image_formats_tests.inl @@ -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(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + cl_device_id clDevice = device.get(); + cl_int retVal; + auto context = ReleaseableObjectPtr(Context::create(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; diff --git a/opencl/test/unit_test/context/get_supported_image_formats_tests.cpp b/opencl/test/unit_test/context/get_supported_image_formats_tests.cpp index a6bae5f27e..c8e435acae 100644 --- a/opencl/test/unit_test/context/get_supported_image_formats_tests.cpp +++ b/opencl/test/unit_test/context/get_supported_image_formats_tests.cpp @@ -91,6 +91,15 @@ TEST_P(GetSupportedImageFormatsTest, retrieveImageFormats) { EXPECT_NE(0u, imageFormatList[entry].image_channel_data_type); } + retVal = pContext->getSupportedImageFormats( + &castToObject(devices[0])->getDevice(), + CL_MEM_KERNEL_READ_AND_WRITE, + imageFormats, + numImageFormats, + imageFormatList, + nullptr); + EXPECT_EQ(CL_SUCCESS, retVal); + delete[] imageFormatList; } diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index 112e494a99..2a9a54ede7 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -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);