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 25, 2024
1 parent 7ecf64d commit ea5afa9
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 38 deletions.
11 changes: 5 additions & 6 deletions source/adapters/cuda/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ 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:
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
// 2D USM memcpy is supported.
return ReturnValue(true);
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
// 2D USM operations currently not supported.
return ReturnValue(false);

case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT: {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
default:
break;
}
Expand Down
13 changes: 4 additions & 9 deletions source/adapters/hip/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,13 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
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: {
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES:
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT: {
// 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.
return ReturnValue(true);
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
// 2D USM operations currently not supported.
return ReturnValue(false);

default:
break;
}
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
7 changes: 2 additions & 5 deletions source/adapters/level_zero/v2/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ ur_result_t urContextGetInfo(ur_context_handle_t hContext,
case UR_CONTEXT_INFO_REFERENCE_COUNT:
return ReturnValue(uint32_t{hContext->RefCount.load()});
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
// TODO: this is currently not implemented
return ReturnValue(uint8_t{false});
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
// 2D USM fill is not supported.
return ReturnValue(uint8_t{false});
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}
}
} // namespace ur::level_zero
5 changes: 1 addition & 4 deletions source/adapters/native_cpu/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
return returnValue(true);
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
// case UR_CONTEXT_INFO_USM_MEMSET2D_SUPPORT:
// 2D USM operations currently not supported.
return returnValue(false);
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: {
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
default:
return UR_RESULT_ERROR_INVALID_ENUMERATION;
Expand Down
6 changes: 2 additions & 4 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
switch (static_cast<uint32_t>(propName)) {
/* 2D USM memops are not supported. */
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT: {
return ReturnValue(false);
}
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
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: {
/* 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, UR_CONTEXT_FLAGS_MASK};
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 ea5afa9

Please sign in to comment.