Skip to content

Commit

Permalink
Merge pull request #1346 from omarahmed1111/ensure-getinfo-cts-tests-…
Browse files Browse the repository at this point in the history
…report-same-dependency-creation-object

Add output validation checks for getInfo tests and a small USM spec fix
  • Loading branch information
kbenzie authored Apr 29, 2024
2 parents 54829f0 + cbd581f commit a6cdcf4
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 30 deletions.
8 changes: 5 additions & 3 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3448,7 +3448,7 @@ urUSMHostAlloc(
ur_context_handle_t hContext, ///< [in] handle of the context object
const ur_usm_desc_t *pUSMDesc, ///< [in][optional] USM memory allocation descriptor
ur_usm_pool_handle_t pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t size, ///< [in] size in bytes of the USM memory object to be allocated
size_t size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
);

Expand Down Expand Up @@ -3496,7 +3496,7 @@ urUSMDeviceAlloc(
ur_device_handle_t hDevice, ///< [in] handle of the device object
const ur_usm_desc_t *pUSMDesc, ///< [in][optional] USM memory allocation descriptor
ur_usm_pool_handle_t pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t size, ///< [in] size in bytes of the USM memory object to be allocated
size_t size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
);

Expand Down Expand Up @@ -3545,7 +3545,7 @@ urUSMSharedAlloc(
ur_device_handle_t hDevice, ///< [in] handle of the device object
const ur_usm_desc_t *pUSMDesc, ///< [in][optional] Pointer to USM memory allocation descriptor.
ur_usm_pool_handle_t pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t size, ///< [in] size in bytes of the USM memory object to be allocated
size_t size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
);

Expand Down Expand Up @@ -4116,6 +4116,8 @@ urProgramCreateWithIL(
/// - Following a successful call to this entry point, `phProgram` will
/// contain a binary of type ::UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT or
/// ::UR_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`.
/// - The device specified by `hDevice` must be device associated with
/// context.
///
/// @remarks
/// _Analogues_
Expand Down
1 change: 1 addition & 0 deletions scripts/core/program.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ analogue:
details:
- "The application may call this function from simultaneous threads."
- "Following a successful call to this entry point, `phProgram` will contain a binary of type $X_PROGRAM_BINARY_TYPE_COMPILED_OBJECT or $X_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`."
- "The device specified by `hDevice` must be device associated with context."
params:
- type: $x_context_handle_t
name: hContext
Expand Down
6 changes: 3 additions & 3 deletions scripts/core/usm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ params:
desc: "[in][optional] Pointer to a pool created using urUSMPoolCreate"
- type: "size_t"
name: size
desc: "[in] size in bytes of the USM memory object to be allocated"
desc: "[in] minimum size in bytes of the USM memory object to be allocated"
- type: void**
name: ppMem
desc: "[out] pointer to USM host memory object"
Expand Down Expand Up @@ -293,7 +293,7 @@ params:
desc: "[in][optional] Pointer to a pool created using urUSMPoolCreate"
- type: "size_t"
name: size
desc: "[in] size in bytes of the USM memory object to be allocated"
desc: "[in] minimum size in bytes of the USM memory object to be allocated"
- type: void**
name: ppMem
desc: "[out] pointer to USM device memory object"
Expand Down Expand Up @@ -339,7 +339,7 @@ params:
desc: "[in][optional] Pointer to a pool created using urUSMPoolCreate"
- type: "size_t"
name: size
desc: "[in] size in bytes of the USM memory object to be allocated"
desc: "[in] minimum size in bytes of the USM memory object to be allocated"
- type: void**
name: ppMem
desc: "[out] pointer to USM shared memory object"
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName,
case UR_PROGRAM_INFO_NUM_DEVICES:
return ReturnValue(1u);
case UR_PROGRAM_INFO_DEVICES:
return ReturnValue(hProgram->getDevice(), 1);
return ReturnValue(&hProgram->getContext()->getDevices()[0], 1);
case UR_PROGRAM_INFO_SOURCE:
return ReturnValue(hProgram->Binary);
case UR_PROGRAM_INFO_BINARY_SIZES:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/native_cpu/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_DEVICES:
return returnValue(hContext->_device);
case UR_CONTEXT_INFO_REFERENCE_COUNT:
return returnValue(nullptr);
return returnValue(uint32_t{hContext->getReferenceCount()});
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
return returnValue(true);
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/null/ur_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMHostAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
) try {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -1296,7 +1296,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMDeviceAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
) try {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -1324,7 +1324,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMSharedAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
) try {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down
6 changes: 3 additions & 3 deletions source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMHostAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
) {
auto pfnHostAlloc = context.urDdiTable.USM.pfnHostAlloc;
Expand Down Expand Up @@ -1363,7 +1363,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMDeviceAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
) {
auto pfnDeviceAlloc = context.urDdiTable.USM.pfnDeviceAlloc;
Expand Down Expand Up @@ -1396,7 +1396,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMSharedAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
) {
auto pfnSharedAlloc = context.urDdiTable.USM.pfnSharedAlloc;
Expand Down
6 changes: 3 additions & 3 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMHostAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
) {
auto pfnHostAlloc = context.urDdiTable.USM.pfnHostAlloc;
Expand Down Expand Up @@ -1825,7 +1825,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMDeviceAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
) {
auto pfnDeviceAlloc = context.urDdiTable.USM.pfnDeviceAlloc;
Expand Down Expand Up @@ -1892,7 +1892,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMSharedAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
) {
auto pfnSharedAlloc = context.urDdiTable.USM.pfnSharedAlloc;
Expand Down
6 changes: 3 additions & 3 deletions source/loader/ur_ldrddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMHostAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
) {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -1747,7 +1747,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMDeviceAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
) {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -1785,7 +1785,7 @@ __urdlllocal ur_result_t UR_APICALL urUSMSharedAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
) {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down
8 changes: 5 additions & 3 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ ur_result_t UR_APICALL urUSMHostAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
) try {
auto pfnHostAlloc = ur_lib::context->urDdiTable.USM.pfnHostAlloc;
Expand Down Expand Up @@ -2263,7 +2263,7 @@ ur_result_t UR_APICALL urUSMDeviceAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
) try {
auto pfnDeviceAlloc = ur_lib::context->urDdiTable.USM.pfnDeviceAlloc;
Expand Down Expand Up @@ -2323,7 +2323,7 @@ ur_result_t UR_APICALL urUSMSharedAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
) try {
auto pfnSharedAlloc = ur_lib::context->urDdiTable.USM.pfnSharedAlloc;
Expand Down Expand Up @@ -2940,6 +2940,8 @@ ur_result_t UR_APICALL urProgramCreateWithIL(
/// - Following a successful call to this entry point, `phProgram` will
/// contain a binary of type ::UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT or
/// ::UR_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`.
/// - The device specified by `hDevice` must be device associated with
/// context.
///
/// @remarks
/// _Analogues_
Expand Down
8 changes: 5 additions & 3 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ ur_result_t UR_APICALL urUSMHostAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM host memory object
) {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -1945,7 +1945,7 @@ ur_result_t UR_APICALL urUSMDeviceAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM device memory object
) {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -1999,7 +1999,7 @@ ur_result_t UR_APICALL urUSMSharedAlloc(
ur_usm_pool_handle_t
pool, ///< [in][optional] Pointer to a pool created using urUSMPoolCreate
size_t
size, ///< [in] size in bytes of the USM memory object to be allocated
size, ///< [in] minimum size in bytes of the USM memory object to be allocated
void **ppMem ///< [out] pointer to USM shared memory object
) {
ur_result_t result = UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -2503,6 +2503,8 @@ ur_result_t UR_APICALL urProgramCreateWithIL(
/// - Following a successful call to this entry point, `phProgram` will
/// contain a binary of type ::UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT or
/// ::UR_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`.
/// - The device specified by `hDevice` must be device associated with
/// context.
///
/// @remarks
/// _Analogues_
Expand Down
2 changes: 0 additions & 2 deletions test/conformance/context/context_adapter_native_cpu.match
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
urContextReleaseTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_
urContextRetainTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_
urContextSetExtendedDeleterTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_
35 changes: 34 additions & 1 deletion test/conformance/context/urContextGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ UUR_TEST_SUITE_P(urContextGetInfoTestWithInfoParam,
UR_CONTEXT_INFO_NUM_DEVICES, //
UR_CONTEXT_INFO_DEVICES, //
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT, //
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT //
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT, //
UR_CONTEXT_INFO_REFERENCE_COUNT //

),
uur::deviceTestWithParamPrinter<ur_context_info_t>);
Expand All @@ -56,6 +57,38 @@ TEST_P(urContextGetInfoTestWithInfoParam, Success) {
std::vector<uint8_t> info_data(info_size);
ASSERT_SUCCESS(
urContextGetInfo(context, info, info_size, info_data.data(), nullptr));

switch (info) {
case UR_CONTEXT_INFO_NUM_DEVICES: {
auto returned_num_of_devices =
reinterpret_cast<uint32_t *>(info_data.data());
ASSERT_GE(uur::DevicesEnvironment::instance->devices.size(),
*returned_num_of_devices);
break;
}
case UR_CONTEXT_INFO_DEVICES: {
auto returned_devices =
reinterpret_cast<ur_device_handle_t *>(info_data.data());
size_t devices_count = info_size / sizeof(ur_device_handle_t);
ASSERT_GT(devices_count, 0);
for (uint32_t i = 0; i < devices_count; i++) {
auto &devices = uur::DevicesEnvironment::instance->devices;
auto queried_device =
std::find(devices.begin(), devices.end(), returned_devices[i]);
EXPECT_TRUE(queried_device != devices.end())
<< "device associated with the context is not valid";
}
break;
}
case UR_CONTEXT_INFO_REFERENCE_COUNT: {
auto returned_reference_count =
reinterpret_cast<uint32_t *>(info_data.data());
ASSERT_GT(*returned_reference_count, 0U);
break;
}
default:
break;
}
}

using urContextGetInfoTest = uur::urContextTest;
Expand Down
7 changes: 7 additions & 0 deletions test/conformance/device/urDeviceGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ TEST_P(urDeviceGetInfoTest, Success) {
std::vector<char> info_data(size);
ASSERT_SUCCESS(urDeviceGetInfo(device, info_type, size,
info_data.data(), nullptr));

if (info_type == UR_DEVICE_INFO_PLATFORM) {
auto returned_platform =
reinterpret_cast<ur_platform_handle_t *>(info_data.data());
ASSERT_EQ(*returned_platform, platform);
}

} else {
ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
}
Expand Down
22 changes: 22 additions & 0 deletions test/conformance/kernel/urKernelGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ TEST_P(urKernelGetInfoTest, Success) {
property_value.resize(property_size);
ASSERT_SUCCESS(urKernelGetInfo(kernel, property_name, property_size,
property_value.data(), nullptr));
switch (property_name) {
case UR_KERNEL_INFO_CONTEXT: {
auto returned_context =
reinterpret_cast<ur_context_handle_t *>(property_value.data());
ASSERT_EQ(context, *returned_context);
break;
}
case UR_KERNEL_INFO_PROGRAM: {
auto returned_program =
reinterpret_cast<ur_program_handle_t *>(property_value.data());
ASSERT_EQ(program, *returned_program);
break;
}
case UR_KERNEL_INFO_REFERENCE_COUNT: {
auto returned_reference_count =
reinterpret_cast<uint32_t *>(property_value.data());
ASSERT_GT(*returned_reference_count, 0U);
break;
}
default:
break;
}
}

TEST_P(urKernelGetInfoTest, InvalidNullHandleKernel) {
Expand Down
16 changes: 16 additions & 0 deletions test/conformance/memory/urMemGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ TEST_P(urMemGetInfoTest, Success) {

std::vector<uint8_t> info_data(size);
ASSERT_SUCCESS(urMemGetInfo(buffer, info, size, info_data.data(), nullptr));

switch (info) {
case UR_MEM_INFO_CONTEXT: {
auto returned_context =
reinterpret_cast<ur_context_handle_t *>(info_data.data());
ASSERT_EQ(context, *returned_context);
break;
}
case UR_MEM_INFO_SIZE: {
auto returned_size = reinterpret_cast<size_t *>(info_data.data());
ASSERT_GE(*returned_size, allocation_size);
break;
}
default:
break;
}
}

TEST_P(urMemGetInfoTest, InvalidNullHandleMemory) {
Expand Down
Loading

0 comments on commit a6cdcf4

Please sign in to comment.