Skip to content

Commit

Permalink
Move urMemImageGetInfo success test from a switch to individual test.
Browse files Browse the repository at this point in the history
Added implementation details to OpenCL adapter for processing image format structs.
Added a couple missing enums to spec for ur_image_info_t and added CTS tests for these.
  • Loading branch information
martygrant committed Jan 15, 2025
1 parent 9e48f54 commit 573b206
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 132 deletions.
21 changes: 12 additions & 9 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2595,13 +2595,16 @@ typedef enum ur_image_channel_type_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Image information types
typedef enum ur_image_info_t {
UR_IMAGE_INFO_FORMAT = 0, ///< [::ur_image_format_t] image format
UR_IMAGE_INFO_ELEMENT_SIZE = 1, ///< [size_t] element size
UR_IMAGE_INFO_ROW_PITCH = 2, ///< [size_t] row pitch
UR_IMAGE_INFO_SLICE_PITCH = 3, ///< [size_t] slice pitch
UR_IMAGE_INFO_WIDTH = 4, ///< [size_t] image width
UR_IMAGE_INFO_HEIGHT = 5, ///< [size_t] image height
UR_IMAGE_INFO_DEPTH = 6, ///< [size_t] image depth
UR_IMAGE_INFO_FORMAT = 0, ///< [::ur_image_format_t] image format
UR_IMAGE_INFO_ELEMENT_SIZE = 1, ///< [size_t] element size
UR_IMAGE_INFO_ROW_PITCH = 2, ///< [size_t] row pitch
UR_IMAGE_INFO_SLICE_PITCH = 3, ///< [size_t] slice pitch
UR_IMAGE_INFO_WIDTH = 4, ///< [size_t] image width
UR_IMAGE_INFO_HEIGHT = 5, ///< [size_t] image height
UR_IMAGE_INFO_DEPTH = 6, ///< [size_t] image depth
UR_IMAGE_INFO_ARRAY_SIZE = 7, ///< [size_t] array size
UR_IMAGE_INFO_NUM_MIP_LEVELS = 8, ///< [size_t] number of MIP levels
UR_IMAGE_INFO_NUM_SAMPLES = 9, ///< [size_t] number of samples
/// @cond
UR_IMAGE_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -3055,7 +3058,7 @@ urMemGetInfo(
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hMemory`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// + `::UR_IMAGE_INFO_NUM_SAMPLES < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
Expand Down Expand Up @@ -7990,7 +7993,7 @@ urBindlessImagesImageCopyExp(
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// + `::UR_IMAGE_INFO_NUM_SAMPLES < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
Expand Down
45 changes: 45 additions & 0 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5954,6 +5954,15 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_image_info_t value) {
case UR_IMAGE_INFO_DEPTH:
os << "UR_IMAGE_INFO_DEPTH";
break;
case UR_IMAGE_INFO_ARRAY_SIZE:
os << "UR_IMAGE_INFO_ARRAY_SIZE";
break;
case UR_IMAGE_INFO_NUM_MIP_LEVELS:
os << "UR_IMAGE_INFO_NUM_MIP_LEVELS";
break;
case UR_IMAGE_INFO_NUM_SAMPLES:
os << "UR_IMAGE_INFO_NUM_SAMPLES";
break;
default:
os << "unknown enumerator";
break;
Expand Down Expand Up @@ -6054,6 +6063,42 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_image_info_

os << ")";
} break;
case UR_IMAGE_INFO_ARRAY_SIZE: {
const size_t *tptr = (const size_t *)ptr;
if (sizeof(size_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";

os << *tptr;

os << ")";
} break;
case UR_IMAGE_INFO_NUM_MIP_LEVELS: {
const size_t *tptr = (const size_t *)ptr;
if (sizeof(size_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";

os << *tptr;

os << ")";
} break;
case UR_IMAGE_INFO_NUM_SAMPLES: {
const size_t *tptr = (const size_t *)ptr;
if (sizeof(size_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";

os << *tptr;

os << ")";
} break;
default:
os << "unknown enumerator";
return UR_RESULT_ERROR_INVALID_ENUMERATION;
Expand Down
6 changes: 6 additions & 0 deletions scripts/core/memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ etors:
desc: "[size_t] image height"
- name: DEPTH
desc: "[size_t] image depth"
- name: ARRAY_SIZE
desc: "[size_t] array size"
- name: NUM_MIP_LEVELS
desc: "[size_t] number of MIP levels"
- name: NUM_SAMPLES
desc: "[size_t] number of samples"
--- #--------------------------------------------------------------------------
type: struct
desc: "Image format including channel layout and data type"
Expand Down
99 changes: 99 additions & 0 deletions source/adapters/opencl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,92 @@

#include "common.hpp"

#include <unordered_map>

const std::unordered_map<ur_image_channel_order_t, cl_channel_order>
ChannelOrderMap = {
{UR_IMAGE_CHANNEL_ORDER_A, CL_A},
{UR_IMAGE_CHANNEL_ORDER_R, CL_R},
{UR_IMAGE_CHANNEL_ORDER_RG, CL_RG},
{UR_IMAGE_CHANNEL_ORDER_RA, CL_RA},
{UR_IMAGE_CHANNEL_ORDER_RGB, CL_RGB},
{UR_IMAGE_CHANNEL_ORDER_RGBA, CL_RGBA},
{UR_IMAGE_CHANNEL_ORDER_BGRA, CL_BGRA},
{UR_IMAGE_CHANNEL_ORDER_ARGB, CL_ARGB},
{UR_IMAGE_CHANNEL_ORDER_ABGR, CL_ABGR},
{UR_IMAGE_CHANNEL_ORDER_INTENSITY, CL_INTENSITY},
{UR_IMAGE_CHANNEL_ORDER_LUMINANCE, CL_LUMINANCE},
{UR_IMAGE_CHANNEL_ORDER_RX, CL_Rx},
{UR_IMAGE_CHANNEL_ORDER_RGX, CL_RGx},
{UR_IMAGE_CHANNEL_ORDER_RGBX, CL_RGBx},
{UR_IMAGE_CHANNEL_ORDER_SRGBA, CL_sRGBA},
};

const std::unordered_map<ur_image_channel_type_t, cl_channel_type>
ChannelTypeMap = {
{UR_IMAGE_CHANNEL_TYPE_SNORM_INT8, CL_SNORM_INT8},
{UR_IMAGE_CHANNEL_TYPE_SNORM_INT16, CL_SNORM_INT16},
{UR_IMAGE_CHANNEL_TYPE_UNORM_INT8, CL_UNORM_INT8},
{UR_IMAGE_CHANNEL_TYPE_UNORM_INT16, CL_UNORM_INT16},
{UR_IMAGE_CHANNEL_TYPE_UNORM_SHORT_565, CL_UNORM_SHORT_565},
{UR_IMAGE_CHANNEL_TYPE_UNORM_SHORT_555, CL_UNORM_SHORT_555},
{UR_IMAGE_CHANNEL_TYPE_INT_101010, CL_UNORM_INT_101010},
{UR_IMAGE_CHANNEL_TYPE_SIGNED_INT8, CL_SIGNED_INT8},
{UR_IMAGE_CHANNEL_TYPE_SIGNED_INT16, CL_SIGNED_INT16},
{UR_IMAGE_CHANNEL_TYPE_SIGNED_INT32, CL_SIGNED_INT32},
{UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8, CL_UNSIGNED_INT8},
{UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16, CL_UNSIGNED_INT16},
{UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32, CL_UNSIGNED_INT32},
{UR_IMAGE_CHANNEL_TYPE_HALF_FLOAT, CL_HALF_FLOAT},
{UR_IMAGE_CHANNEL_TYPE_FLOAT, CL_FLOAT},
};

cl_image_format mapURImageFormatToCL(const ur_image_format_t &PImageFormat) {
cl_image_format CLImageFormat = {UR_IMAGE_CHANNEL_ORDER_FORCE_UINT32,
UR_IMAGE_CHANNEL_TYPE_FORCE_UINT32};

auto channelOrderIt = ChannelOrderMap.find(PImageFormat.channelOrder);
if (channelOrderIt != ChannelOrderMap.end()) {
CLImageFormat.image_channel_order = channelOrderIt->second;
}

auto channelTypeIt = ChannelTypeMap.find(PImageFormat.channelType);
if (channelTypeIt != ChannelTypeMap.end()) {
CLImageFormat.image_channel_data_type = channelTypeIt->second;
}

return CLImageFormat;
}

ur_image_format_t mapCLImageFormatToUR(const cl_image_format *PImageFormat) {
ur_image_format_t URImageFormat = {UR_IMAGE_CHANNEL_ORDER_FORCE_UINT32,
UR_IMAGE_CHANNEL_TYPE_FORCE_UINT32};

auto reverseChannelOrderIt =
std::find_if(ChannelOrderMap.begin(), ChannelOrderMap.end(),
[PImageFormat](const auto &pair) {
return pair.second == PImageFormat->image_channel_order;
});
if (reverseChannelOrderIt != ChannelOrderMap.end()) {
URImageFormat.channelOrder = reverseChannelOrderIt->first;
}

URImageFormat.channelOrder = (reverseChannelOrderIt != ChannelOrderMap.end())
? reverseChannelOrderIt->first
: UR_IMAGE_CHANNEL_ORDER_FORCE_UINT32;

auto reverseChannelTypeIt = std::find_if(
ChannelTypeMap.begin(), ChannelTypeMap.end(),
[PImageFormat](const auto &pair) {
return pair.second == PImageFormat->image_channel_data_type;
});
if (reverseChannelTypeIt != ChannelTypeMap.end()) {
URImageFormat.channelType = reverseChannelTypeIt->first;
}

return URImageFormat;
}

cl_image_format mapURImageFormatToCL(const ur_image_format_t *PImageFormat) {
cl_image_format CLImageFormat;
switch (PImageFormat->channelOrder) {
Expand Down Expand Up @@ -174,6 +260,12 @@ cl_int mapURMemImageInfoToCL(ur_image_info_t URPropName) {
return CL_IMAGE_HEIGHT;
case UR_IMAGE_INFO_DEPTH:
return CL_IMAGE_DEPTH;
case UR_IMAGE_INFO_ARRAY_SIZE:
return CL_IMAGE_DEPTH;
case UR_IMAGE_INFO_NUM_MIP_LEVELS:
return CL_IMAGE_DEPTH;
case UR_IMAGE_INFO_NUM_SAMPLES:
return CL_IMAGE_DEPTH;
default:
return -1;
}
Expand Down Expand Up @@ -397,7 +489,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
CL_RETURN_ON_FAILURE(ClResult);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
} else {
if (propName == UR_IMAGE_INFO_FORMAT) {
ur_image_format_t format = mapCLImageFormatToUR(
reinterpret_cast<const cl_image_format *>(pPropValue));
return ReturnValue(format);
}
}

return UR_RESULT_SUCCESS;
}

Expand Down
4 changes: 2 additions & 2 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ __urdlllocal ur_result_t UR_APICALL urMemImageGetInfo(
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (UR_IMAGE_INFO_DEPTH < propName) {
if (UR_IMAGE_INFO_NUM_SAMPLES < propName) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}

Expand Down Expand Up @@ -7456,7 +7456,7 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesImageGetInfoExp(
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (UR_IMAGE_INFO_DEPTH < propName) {
if (UR_IMAGE_INFO_NUM_SAMPLES < propName) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ ur_result_t UR_APICALL urMemGetInfo(
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hMemory`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// + `::UR_IMAGE_INFO_NUM_SAMPLES < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
Expand Down Expand Up @@ -7007,7 +7007,7 @@ ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// + `::UR_IMAGE_INFO_NUM_SAMPLES < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
Expand Down
4 changes: 2 additions & 2 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ ur_result_t UR_APICALL urMemGetInfo(
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hMemory`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// + `::UR_IMAGE_INFO_NUM_SAMPLES < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
Expand Down Expand Up @@ -5981,7 +5981,7 @@ ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// + `::UR_IMAGE_INFO_NUM_SAMPLES < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
Expand Down
14 changes: 14 additions & 0 deletions test/conformance/memory/memory_adapter_level_zero.match
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{OPT}}urMemBufferMultiQueueMemBufferTest.WriteBack
urMemBufferPartitionWithFlagsTest.Success/*__UR_MEM_FLAG_WRITE_ONLY
urMemBufferPartitionWithFlagsTest.Success/*__UR_MEM_FLAG_READ_ONLY
urMemBufferPartitionTest.InvalidValueCreateType/*
urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/*
{{OPT}}urMemImageCreateWithNativeHandleTest.Success/*
{{OPT}}urMemGetInfoImageTest.SuccessSize/*
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/*__UR_IMAGE_CHANNEL_ORDER_RGBA__*

# These tests fail in the "Multi device testing" job, but pass in the hardware specific test
{{OPT}}urMemImageCreateTest.InvalidImageDescStype/*
{{OPT}}urMemImageCreateTest.InvalidSize/*
{{OPT}}urMemImageCreateWithHostPtrFlagsTest.Success/*
{{OPT}}urMemImageGetInfoTest.InvalidSizeSmall/*
Loading

0 comments on commit 573b206

Please sign in to comment.