Skip to content

Commit

Permalink
Merge pull request #2091 from martygrant/martin/adapter-cts-spec-gap
Browse files Browse the repository at this point in the history
Improvements to align CTS and Spec for Adapter
  • Loading branch information
aarongreig authored Sep 27, 2024
2 parents a21a230 + de59929 commit e824ddc
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ urLoaderTearDown(
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phAdapters != NULL`
UR_APIEXPORT ur_result_t UR_APICALL
urAdapterGet(
uint32_t NumEntries, ///< [in] the number of adapters to be added to phAdapters.
Expand All @@ -857,7 +858,7 @@ urAdapterGet(
///< will be returned.
ur_adapter_handle_t *phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *pNumAdapters ///< [out][optional] returns the total number of adapters available.
);

Expand Down
5 changes: 3 additions & 2 deletions scripts/core/adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ params:
name: phAdapters
desc: |
[out][optional][range(0, NumEntries)] array of handle of adapters.
If NumEntries is less than the number of adapters available, then $xAdapterGet shall only retrieve that number of platforms.
If NumEntries is less than the number of adapters available, then $xAdapterGet shall only retrieve that number of adapters.
- type: "uint32_t*"
name: "pNumAdapters"
desc: |
[out][optional] returns the total number of adapters available.
returns:
- $X_RESULT_ERROR_INVALID_SIZE
- $X_RESULT_ERROR_INVALID_SIZE:
- "`NumEntries == 0 && phAdapters != NULL`"
--- #--------------------------------------------------------------------------
type: function
desc: "Releases the adapter handle reference indicating end of its usage"
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/mock/ur_mockddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGet(
ur_adapter_handle_t *
phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *
pNumAdapters ///< [out][optional] returns the total number of adapters available.
) try {
Expand Down
2 changes: 1 addition & 1 deletion source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGet(
ur_adapter_handle_t *
phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *
pNumAdapters ///< [out][optional] returns the total number of adapters available.
) {
Expand Down
5 changes: 4 additions & 1 deletion source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGet(
ur_adapter_handle_t *
phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *
pNumAdapters ///< [out][optional] returns the total number of adapters available.
) {
Expand All @@ -36,6 +36,9 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGet(
}

if (getContext()->enableParameterValidation) {
if (NumEntries == 0 && phAdapters != NULL) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
}

ur_result_t result = pfnAdapterGet(NumEntries, phAdapters, pNumAdapters);
Expand Down
2 changes: 1 addition & 1 deletion source/loader/ur_ldrddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGet(
ur_adapter_handle_t *
phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *
pNumAdapters ///< [out][optional] returns the total number of adapters available.
) {
Expand Down
3 changes: 2 additions & 1 deletion source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ ur_result_t UR_APICALL urLoaderTearDown(void) try {
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phAdapters != NULL`
ur_result_t UR_APICALL urAdapterGet(
uint32_t
NumEntries, ///< [in] the number of adapters to be added to phAdapters.
Expand All @@ -301,7 +302,7 @@ ur_result_t UR_APICALL urAdapterGet(
ur_adapter_handle_t *
phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *
pNumAdapters ///< [out][optional] returns the total number of adapters available.
) try {
Expand Down
3 changes: 2 additions & 1 deletion source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ ur_result_t UR_APICALL urLoaderTearDown(void) {
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phAdapters != NULL`
ur_result_t UR_APICALL urAdapterGet(
uint32_t
NumEntries, ///< [in] the number of adapters to be added to phAdapters.
Expand All @@ -287,7 +288,7 @@ ur_result_t UR_APICALL urAdapterGet(
ur_adapter_handle_t *
phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters.
///< If NumEntries is less than the number of adapters available, then
///< ::urAdapterGet shall only retrieve that number of platforms.
///< ::urAdapterGet shall only retrieve that number of adapters.
uint32_t *
pNumAdapters ///< [out][optional] returns the total number of adapters available.
) {
Expand Down
3 changes: 2 additions & 1 deletion test/conformance/adapter/urAdapterGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ TEST_F(urAdapterGetTest, InvalidNumEntries) {
uint32_t adapter_count;
ASSERT_SUCCESS(urAdapterGet(0, nullptr, &adapter_count));
std::vector<ur_adapter_handle_t> adapters(adapter_count);
ASSERT_SUCCESS(urAdapterGet(0, adapters.data(), nullptr));
ASSERT_EQ(urAdapterGet(0, adapters.data(), nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}
18 changes: 18 additions & 0 deletions test/conformance/adapter/urAdapterGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,21 @@ TEST_F(urAdapterGetInfoTest, InvalidNullPointerPropSizeRet) {
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_F(urAdapterGetInfoTest, ReferenceCountNotZero) {
uint32_t referenceCount = 0;

ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
sizeof(referenceCount), &referenceCount,
nullptr));
ASSERT_GT(referenceCount, 0);
}

TEST_F(urAdapterGetInfoTest, ValidAdapterBackend) {
ur_adapter_backend_t backend;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend), &backend, nullptr));

ASSERT_TRUE(backend >= UR_ADAPTER_BACKEND_LEVEL_ZERO &&
backend <= UR_ADAPTER_BACKEND_NATIVE_CPU);
}
13 changes: 12 additions & 1 deletion test/conformance/adapter/urAdapterRelease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ struct urAdapterReleaseTest : uur::runtime::urAdapterTest {
};

TEST_F(urAdapterReleaseTest, Success) {
ASSERT_SUCCESS(urAdapterRetain(adapter));
uint32_t referenceCountBefore = 0;

ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
sizeof(referenceCountBefore),
&referenceCountBefore, nullptr));

uint32_t referenceCountAfter = 0;
EXPECT_SUCCESS(urAdapterRelease(adapter));
ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
sizeof(referenceCountAfter),
&referenceCountAfter, nullptr));

ASSERT_LE(referenceCountAfter, referenceCountBefore);
}

TEST_F(urAdapterReleaseTest, InvalidNullHandleAdapter) {
Expand Down
15 changes: 13 additions & 2 deletions test/conformance/adapter/urAdapterRetain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ struct urAdapterRetainTest : uur::runtime::urAdapterTest {
};

TEST_F(urAdapterRetainTest, Success) {
ASSERT_SUCCESS(urAdapterRetain(adapter));
EXPECT_SUCCESS(urAdapterRelease(adapter));
uint32_t referenceCountBefore = 0;

ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
sizeof(referenceCountBefore),
&referenceCountBefore, nullptr));

uint32_t referenceCountAfter = 0;
EXPECT_SUCCESS(urAdapterRetain(adapter));
ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
sizeof(referenceCountAfter),
&referenceCountAfter, nullptr));

ASSERT_GT(referenceCountAfter, referenceCountBefore);
}

TEST_F(urAdapterRetainTest, InvalidNullHandleAdapter) {
Expand Down

0 comments on commit e824ddc

Please sign in to comment.