Skip to content

Commit

Permalink
Merge pull request #2227 from RossBrunton/ross/platformget
Browse files Browse the repository at this point in the history
Handle INVALID_VALUE in OCL urPlatformGet
  • Loading branch information
aarongreig authored Oct 29, 2024
2 parents f31bec3 + 9989d97 commit 884b646
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@ typedef enum ur_adapter_backend_t {
/// + `NULL == phAdapters`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phPlatforms != NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
/// + `pNumPlatforms == NULL && phPlatforms == NULL`
UR_APIEXPORT ur_result_t UR_APICALL
urPlatformGet(
ur_adapter_handle_t *phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms.
Expand Down
2 changes: 2 additions & 0 deletions scripts/core/platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ params:
returns:
- $X_RESULT_ERROR_INVALID_SIZE:
- "`NumEntries == 0 && phPlatforms != NULL`"
- $X_RESULT_ERROR_INVALID_VALUE:
- "`pNumPlatforms == NULL && phPlatforms == NULL`"
--- #--------------------------------------------------------------------------
type: enum
desc: "Supported platform info"
Expand Down
5 changes: 5 additions & 0 deletions source/adapters/opencl/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries,
}
}

/* INVALID_VALUE is returned when the size is invalid, special case it here */
if (Result == CL_INVALID_VALUE && phPlatforms != nullptr && NumEntries == 0) {
return UR_RESULT_ERROR_INVALID_SIZE;
}

return mapCLErrorToUR(Result);
}

Expand Down
4 changes: 4 additions & 0 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet(
if (NumEntries == 0 && phPlatforms != NULL) {
return UR_RESULT_ERROR_INVALID_SIZE;
}

if (pNumPlatforms == NULL && phPlatforms == NULL) {
return UR_RESULT_ERROR_INVALID_VALUE;
}
}

ur_result_t result =
Expand Down
2 changes: 2 additions & 0 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ ur_result_t UR_APICALL urAdapterGetInfo(
/// + `NULL == phAdapters`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phPlatforms != NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
/// + `pNumPlatforms == NULL && phPlatforms == NULL`
ur_result_t UR_APICALL urPlatformGet(
ur_adapter_handle_t *
phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms.
Expand Down
2 changes: 2 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ ur_result_t UR_APICALL urAdapterGetInfo(
/// + `NULL == phAdapters`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phPlatforms != NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
/// + `pNumPlatforms == NULL && phPlatforms == NULL`
ur_result_t UR_APICALL urPlatformGet(
ur_adapter_handle_t *
phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms.
Expand Down
7 changes: 7 additions & 0 deletions test/conformance/platform/urPlatformGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ TEST_F(urPlatformGetTest, InvalidNullPointer) {
static_cast<uint32_t>(adapters.size()), 0,
nullptr, &count));
}

TEST_F(urPlatformGetTest, NullArgs) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
urPlatformGet(adapters.data(),
static_cast<uint32_t>(adapters.size()), 0,
nullptr, nullptr));
}

0 comments on commit 884b646

Please sign in to comment.