Skip to content

Commit

Permalink
Merge pull request #2112 from martygrant/martin/context-cts-spec-gap
Browse files Browse the repository at this point in the history
Improvements to align CTS and Spec for Context
  • Loading branch information
callumfare authored Nov 11, 2024
2 parents 1ba7f39 + 2a08189 commit 2eae687
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 23 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 @@ -75,7 +75,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,13 +126,16 @@ 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;
}

ur_result_t urContextGetNativeHandle(
Expand Down
8 changes: 7 additions & 1 deletion source/adapters/level_zero/v2/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,14 @@ ur_result_t urContextGetInfo(ur_context_handle_t hContext,
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
// 2D USM fill is not supported.
return ReturnValue(uint8_t{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_UNSUPPORTED_ENUMERATION;
}
default:
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}
}
} // namespace ur::level_zero
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 @@ -89,7 +89,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
2 changes: 1 addition & 1 deletion test/conformance/context/context_adapter_level_zero.match
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{NONDETERMINISTIC}}
urContextSetExtendedDeleterTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urContextSetExtendedDeleterTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
Original file line number Diff line number Diff line change
@@ -1 +1 @@
urContextSetExtendedDeleterTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__
{{OPT}}urContextSetExtendedDeleterTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__
2 changes: 1 addition & 1 deletion test/conformance/context/context_adapter_native_cpu.match
Original file line number Diff line number Diff line change
@@ -1 +1 @@
urContextSetExtendedDeleterTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urContextSetExtendedDeleterTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
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
38 changes: 31 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,30 @@ 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));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urContextGetInfo(context, info, 0, nullptr, &info_size));
ASSERT_NE(info_size, 0);

if (const auto expected_size = ctx_info_size_map.find(info);
Expand Down
3 changes: 2 additions & 1 deletion test/conformance/context/urContextSetExtendedDeleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ TEST_P(urContextSetExtendedDeleterTest, Success) {
*static_cast<bool *>(userdata) = true;
};

ASSERT_SUCCESS(urContextSetExtendedDeleter(context, deleter, &called));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urContextSetExtendedDeleter(context, deleter, &called));
}
ASSERT_TRUE(called);
}
Expand Down
6 changes: 4 additions & 2 deletions test/conformance/enqueue/urEnqueueUSMFill2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ struct urEnqueueUSMFill2DTestWithParam
UUR_RETURN_ON_FATAL_FAILURE(urQueueTestWithParam::SetUp());

bool memfill2d_support = false;
ASSERT_SUCCESS(urContextGetInfo(
[[maybe_unused]] ur_result_t result = urContextGetInfo(
context, UR_CONTEXT_INFO_USM_FILL2D_SUPPORT,
sizeof(memfill2d_support), &memfill2d_support, nullptr));
sizeof(memfill2d_support), &memfill2d_support, nullptr);
ASSERT_TRUE(result == UR_RESULT_SUCCESS ||
result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
if (!memfill2d_support) {
GTEST_SKIP() << "2D USM mem fill is not supported";
}
Expand Down
6 changes: 4 additions & 2 deletions test/conformance/enqueue/urEnqueueUSMMemcpy2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ struct urEnqueueUSMMemcpy2DTestWithParam
}

bool memcpy2d_support = false;
ASSERT_SUCCESS(urContextGetInfo(
[[maybe_unused]] ur_result_t result = urContextGetInfo(
context, UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT,
sizeof(memcpy2d_support), &memcpy2d_support, nullptr));
sizeof(memcpy2d_support), &memcpy2d_support, nullptr);
ASSERT_TRUE(result == UR_RESULT_SUCCESS ||
result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
if (!memcpy2d_support) {
GTEST_SKIP() << "2D USM memcpy is not supported";
}
Expand Down
3 changes: 2 additions & 1 deletion test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

#define UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(ret) \
auto status = ret; \
if (status == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) { \
if (status == UR_RESULT_ERROR_UNSUPPORTED_FEATURE || \
status == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) { \
GTEST_SKIP(); \
} else { \
ASSERT_EQ(status, UR_RESULT_SUCCESS); \
Expand Down

0 comments on commit 2eae687

Please sign in to comment.