From b3cf34b7f151f1f92f21d99a8bce6b37f10c6edc Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Fri, 20 Sep 2024 10:36:46 +0100 Subject: [PATCH] Improvements to align CTS and Spec for Context: - 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 --- source/adapters/cuda/context.cpp | 4 ++ source/adapters/hip/context.cpp | 2 +- source/adapters/level_zero/context.cpp | 9 ++-- source/adapters/native_cpu/context.cpp | 2 +- source/adapters/opencl/context.cpp | 2 +- test/conformance/context/urContextCreate.cpp | 11 ++++ test/conformance/context/urContextGetInfo.cpp | 53 ++++++++++++++++--- 7 files changed, 70 insertions(+), 13 deletions(-) diff --git a/source/adapters/cuda/context.cpp b/source/adapters/cuda/context.cpp index 69796cf79d..ffd991d59f 100644 --- a/source/adapters/cuda/context.cpp +++ b/source/adapters/cuda/context.cpp @@ -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); diff --git a/source/adapters/hip/context.cpp b/source/adapters/hip/context.cpp index b0733a236d..954606bdbc 100644 --- a/source/adapters/hip/context.cpp +++ b/source/adapters/hip/context.cpp @@ -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. diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index a989cea36d..634c6e1e57 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -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; diff --git a/source/adapters/native_cpu/context.cpp b/source/adapters/native_cpu/context.cpp index 8efc61a024..7c178f951a 100644 --- a/source/adapters/native_cpu/context.cpp +++ b/source/adapters/native_cpu/context.cpp @@ -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; diff --git a/source/adapters/opencl/context.cpp b/source/adapters/opencl/context.cpp index 38202bbf58..94e7277330 100644 --- a/source/adapters/opencl/context.cpp +++ b/source/adapters/opencl/context.cpp @@ -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: diff --git a/test/conformance/context/urContextCreate.cpp b/test/conformance/context/urContextCreate.cpp index 0f268a3992..4d98465ece 100644 --- a/test/conformance/context/urContextCreate.cpp +++ b/test/conformance/context/urContextCreate.cpp @@ -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) { diff --git a/test/conformance/context/urContextGetInfo.cpp b/test/conformance/context/urContextGetInfo.cpp index f9f699d511..d44797d650 100644 --- a/test/conformance/context/urContextGetInfo.cpp +++ b/test/conformance/context/urContextGetInfo.cpp @@ -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}, }; } @@ -26,24 +44,34 @@ struct urContextGetInfoTestWithInfoParam } std::unordered_map ctx_info_size_map; + std::unordered_map + 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); 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); @@ -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(info_data.data()); + ASSERT_EQ(*value & flags->second, 0); + } + break; + } default: break; }