Skip to content

Commit

Permalink
Merge pull request #649 from callumfare/callum/cts-memImageGetInfo
Browse files Browse the repository at this point in the history
[UR][CTS] Add urMemImageGetInfo tests and missing spec return values
  • Loading branch information
callumfare authored Jun 26, 2023
2 parents 52c98d0 + 3328f87 commit 39b3546
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,17 @@ urMemGetInfo(
/// + `NULL == hMemory`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urMemImageGetInfo(
ur_mem_handle_t hMemory, ///< [in] handle to the image object being queried.
Expand Down
12 changes: 12 additions & 0 deletions scripts/core/memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,15 @@ params:
name: pPropSizeRet
desc: |
[out][optional] pointer to the actual size in bytes of the queried propName.
returns:
- $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
- "If `propName` is not supported by the adapter."
- $X_RESULT_ERROR_INVALID_SIZE:
- "`propSize == 0 && pPropValue != NULL`"
- "If `propSize` is less than the real number of bytes needed to return the info."
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
- "`propSize != 0 && pPropValue == NULL`"
- "`pPropValue == NULL && pPropSizeRet == NULL`"
- $X_RESULT_ERROR_INVALID_MEM_OBJECT
- $X_RESULT_ERROR_OUT_OF_RESOURCES
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
12 changes: 12 additions & 0 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,21 @@ __urdlllocal ur_result_t UR_APICALL urMemImageGetInfo(
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
}

if (propSize != 0 && pPropValue == NULL) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (pPropValue == NULL && pPropSizeRet == NULL) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (UR_IMAGE_INFO_DEPTH < propName) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}

if (propSize == 0 && pPropValue != NULL) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
}

ur_result_t result =
Expand Down
11 changes: 11 additions & 0 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,17 @@ ur_result_t UR_APICALL urMemGetInfo(
/// + `NULL == hMemory`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
ur_result_t UR_APICALL urMemImageGetInfo(
ur_mem_handle_t hMemory, ///< [in] handle to the image object being queried.
ur_image_info_t propName, ///< [in] type of image info to retrieve.
Expand Down
11 changes: 11 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,17 @@ ur_result_t UR_APICALL urMemGetInfo(
/// + `NULL == hMemory`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_IMAGE_INFO_DEPTH < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
ur_result_t UR_APICALL urMemImageGetInfo(
ur_mem_handle_t hMemory, ///< [in] handle to the image object being queried.
ur_image_info_t propName, ///< [in] type of image info to retrieve.
Expand Down
82 changes: 82 additions & 0 deletions test/conformance/memory/urMemImageGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,85 @@
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <uur/fixtures.h>

using urMemImageGetInfoTest = uur::urMemImageTestWithParam<ur_image_info_t>;

static std::unordered_map<ur_image_info_t, size_t> image_info_size_map = {
{UR_IMAGE_INFO_FORMAT, sizeof(ur_image_format_t)},
{UR_IMAGE_INFO_ELEMENT_SIZE, sizeof(size_t)},
{UR_IMAGE_INFO_ROW_PITCH, sizeof(size_t)},
{UR_IMAGE_INFO_SLICE_PITCH, sizeof(size_t)},
{UR_IMAGE_INFO_WIDTH, sizeof(size_t)},
{UR_IMAGE_INFO_HEIGHT, sizeof(size_t)},
{UR_IMAGE_INFO_DEPTH, sizeof(size_t)},
};

UUR_TEST_SUITE_P(urMemImageGetInfoTest,
::testing::Values(UR_IMAGE_INFO_FORMAT,
UR_IMAGE_INFO_ELEMENT_SIZE,
UR_IMAGE_INFO_ROW_PITCH,
UR_IMAGE_INFO_SLICE_PITCH,
UR_IMAGE_INFO_WIDTH, UR_IMAGE_INFO_HEIGHT,
UR_IMAGE_INFO_DEPTH),
uur::deviceTestWithParamPrinter<ur_image_info_t>);

TEST_P(urMemImageGetInfoTest, Success) {
ur_image_info_t info = getParam();
size_t size;
ASSERT_SUCCESS(urMemImageGetInfo(image, info, 0, nullptr, &size));
ASSERT_NE(size, 0);

if (const auto expected_size = image_info_size_map.find(info);
expected_size != image_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
} else {
FAIL() << "Missing info value in image info size map";
}

std::vector<uint8_t> info_data(size);
ASSERT_SUCCESS(
urMemImageGetInfo(image, info, size, info_data.data(), nullptr));
}

TEST_P(urMemImageGetInfoTest, InvalidNullHandleImage) {
size_t info_size = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urMemImageGetInfo(nullptr, UR_IMAGE_INFO_FORMAT,
sizeof(size_t), &info_size, nullptr));
}

TEST_P(urMemImageGetInfoTest, InvalidEnumerationImageInfoType) {
size_t info_size = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
urMemImageGetInfo(image, UR_IMAGE_INFO_FORCE_UINT32,
sizeof(size_t), &info_size, nullptr));
}

TEST_P(urMemImageGetInfoTest, InvalidSizeZero) {
size_t info_size = 0;
ASSERT_EQ_RESULT(
urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT, 0, &info_size, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urMemImageGetInfoTest, InvalidSizeSmall) {
int info_size = 0;
ASSERT_EQ_RESULT(urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT,
sizeof(info_size) - 1, &info_size,
nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urMemImageGetInfoTest, InvalidNullPointerParamValue) {
size_t info_size = 0;
ASSERT_EQ_RESULT(urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT,
sizeof(info_size), nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urMemImageGetInfoTest, InvalidNullPointerPropSizeRet) {
ASSERT_EQ_RESULT(
urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT, 0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}
30 changes: 30 additions & 0 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,36 @@ template <class T> struct urMemBufferTestWithParam : urContextTestWithParam<T> {
ur_mem_handle_t buffer = nullptr;
};

template <class T> struct urMemImageTestWithParam : urContextTestWithParam<T> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
ASSERT_SUCCESS(urMemImageCreate(this->context, UR_MEM_FLAG_READ_WRITE,
&format, &desc, nullptr, &image));
ASSERT_NE(nullptr, image);
}

void TearDown() override {
if (image) {
EXPECT_SUCCESS(urMemRelease(image));
}
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::TearDown());
}
ur_mem_handle_t image = nullptr;
ur_image_format_t format = {UR_IMAGE_CHANNEL_ORDER_RGBA,
UR_IMAGE_CHANNEL_TYPE_FLOAT};
ur_image_desc_t desc = {UR_STRUCTURE_TYPE_IMAGE_DESC, // stype
nullptr, // pNext
UR_MEM_TYPE_IMAGE1D, // mem object type
1024, // image width
1, // image height
1, // image depth
1, // array size
0, // row pitch
0, // slice pitch
0, // mip levels
0}; // num samples
};

struct urQueueTest : urContextTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp());
Expand Down

0 comments on commit 39b3546

Please sign in to comment.