Skip to content

Commit

Permalink
Improvements to align CTS and Spec for Context:
Browse files Browse the repository at this point in the history
- Add test for urContextCreate returning UR_RESULT_ERROR_INVALID_ENUMERATION
- Added testing in urContextGetInfo for the atomic memory enums, checking against the type mask
or UR_RESULT_ERROR_UNSUPPORTED_ENUM (as some adapters don't support this currently)
	- Updated some adapter code to include these enums and return the correct error code
  • Loading branch information
martygrant committed Sep 20, 2024
1 parent 7384e2d commit b3cf34b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
4 changes: 4 additions & 0 deletions source/adapters/cuda/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetInfo(
UR_MEMORY_SCOPE_CAPABILITY_FLAG_DEVICE;
return ReturnValue(Capabilities);
}
case UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
// 2D USM memcpy is supported.
return ReturnValue(true);
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
// These queries should be dealt with in context_impl.cpp by calling the
// queries of each device separately and building the intersection set.
return UR_RESULT_ERROR_INVALID_ENUMERATION;
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
// 2D USM memcpy is supported.
Expand Down
9 changes: 6 additions & 3 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ ur_result_t urContextGetInfo(
UR_MEMORY_ORDER_CAPABILITY_FLAG_SEQ_CST;
return ReturnValue(Capabilities);
}

case UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
default:
// TODO: implement other parameters
die("urGetContextInfo: unsuppported ParamName.");
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}

return UR_RESULT_SUCCESS;
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 @@ -64,7 +64,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
default:
return UR_RESULT_ERROR_INVALID_ENUMERATION;
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
/* These queries should be dealt with in context_impl.cpp by calling the
* queries of each device separately and building the intersection set. */
return UR_RESULT_ERROR_INVALID_ARGUMENT;
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
case UR_CONTEXT_INFO_NUM_DEVICES:
case UR_CONTEXT_INFO_DEVICES:
Expand Down
11 changes: 11 additions & 0 deletions test/conformance/context/urContextCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ TEST_P(urContextCreateTest, InvalidNullPointerContext) {
urContextCreate(1, &device, nullptr, nullptr));
}

TEST_P(urContextCreateTest, InvalidEnumeration) {
auto device = GetParam();

ur_context_properties_t properties{UR_STRUCTURE_TYPE_CONTEXT_PROPERTIES,
nullptr, 0xFFFFFFFE};
uur::raii::Context context = nullptr;

ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
urContextCreate(1, &device, &properties, context.ptr()));
}

using urContextCreateMultiDeviceTest = uur::urAllDevicesTest;
TEST_F(urContextCreateMultiDeviceTest, Success) {
if (devices.size() < 2) {
Expand Down
53 changes: 46 additions & 7 deletions test/conformance/context/urContextGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ struct urContextGetInfoTestWithInfoParam
{UR_CONTEXT_INFO_REFERENCE_COUNT, sizeof(uint32_t)},
{UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT, sizeof(bool)},
{UR_CONTEXT_INFO_USM_FILL2D_SUPPORT, sizeof(bool)},
{UR_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES,
sizeof(ur_memory_order_capability_flags_t)},
{UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES,
sizeof(ur_memory_order_capability_flags_t)},
{UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES,
sizeof(ur_memory_order_capability_flags_t)},
{UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES,
sizeof(ur_memory_order_capability_flags_t)}};

ctx_info_mem_flags_map = {
{UR_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES,
UR_MEMORY_ORDER_CAPABILITY_FLAGS_MASK},
{UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES,
UR_MEMORY_SCOPE_CAPABILITY_FLAGS_MASK},
{UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES,
UR_MEMORY_ORDER_CAPABILITY_FLAGS_MASK},
{UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES,
UR_MEMORY_SCOPE_CAPABILITY_FLAGS_MASK},
};
}

Expand All @@ -26,24 +44,34 @@ struct urContextGetInfoTestWithInfoParam
}

std::unordered_map<ur_context_info_t, size_t> ctx_info_size_map;
std::unordered_map<ur_context_info_t, ur_memory_order_capability_flags_t>
ctx_info_mem_flags_map;
};

UUR_TEST_SUITE_P(urContextGetInfoTestWithInfoParam,
::testing::Values(

UR_CONTEXT_INFO_NUM_DEVICES, //
UR_CONTEXT_INFO_DEVICES, //
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT, //
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT, //
UR_CONTEXT_INFO_REFERENCE_COUNT //

UR_CONTEXT_INFO_NUM_DEVICES, //
UR_CONTEXT_INFO_DEVICES, //
UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT, //
UR_CONTEXT_INFO_USM_FILL2D_SUPPORT, //
UR_CONTEXT_INFO_REFERENCE_COUNT, //
UR_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES, //
UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES, //
UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES, //
UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES //
),
uur::deviceTestWithParamPrinter<ur_context_info_t>);

TEST_P(urContextGetInfoTestWithInfoParam, Success) {
ur_context_info_t info = getParam();
size_t info_size = 0;
ASSERT_SUCCESS(urContextGetInfo(context, info, 0, nullptr, &info_size));
ur_result_t result =
urContextGetInfo(context, info, 0, nullptr, &info_size);
if (result != UR_RESULT_SUCCESS) {
ASSERT_EQ(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
return; // exit before further checks fail because this type is unsupported
}
ASSERT_NE(info_size, 0);

if (const auto expected_size = ctx_info_size_map.find(info);
Expand Down Expand Up @@ -83,6 +111,17 @@ TEST_P(urContextGetInfoTestWithInfoParam, Success) {
ASSERT_GT(*returned_reference_count, 0U);
break;
}
case UR_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES:
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
if (const auto flags = ctx_info_mem_flags_map.find(info);
flags != ctx_info_mem_flags_map.end()) {
auto value = reinterpret_cast<uint32_t *>(info_data.data());
ASSERT_EQ(*value & flags->second, 0);
}
break;
}
default:
break;
}
Expand Down

0 comments on commit b3cf34b

Please sign in to comment.