Skip to content

Commit

Permalink
[CTS] Add new urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations…
Browse files Browse the repository at this point in the history
… test for checking different combinations of allocation size/alignment.
  • Loading branch information
martygrant committed Mar 29, 2024
1 parent 0c0f48d commit 8c6588b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
4 changes: 2 additions & 2 deletions test/conformance/enqueue/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ print2DTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
const auto platform_device_name =
uur::GetPlatformAndDeviceName(device_handle);
std::stringstream test_name;
auto src_kind = std::get<1>(std::get<1>(info.param));
auto dst_kind = std::get<2>(std::get<1>(info.param));
const auto src_kind = std::get<1>(std::get<1>(info.param));
const auto dst_kind = std::get<2>(std::get<1>(info.param));
test_name << platform_device_name << "__pitch__"
<< std::get<0>(std::get<1>(info.param)).pitch << "__width__"
<< std::get<0>(std::get<1>(info.param)).width << "__height__"
Expand Down
80 changes: 73 additions & 7 deletions test/conformance/usm/urUSMDeviceAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <uur/fixtures.h>

struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
using USMDeviceAllocParams = std::tuple<uur::BoolTestParam, uint32_t, size_t>;

template <typename T>
inline std::string printUSMDeviceAllocTestString(
const testing::TestParamInfo<typename T::ParamType> &info) {
// ParamType will be std::tuple<ur_device_handle_t, USMDeviceAllocParams>
const auto device_handle = std::get<0>(info.param);
const auto platform_device_name =
uur::GetPlatformAndDeviceName(device_handle);
const auto usmDeviceAllocParams = std::get<1>(info.param);
const auto BoolParam = std::get<0>(usmDeviceAllocParams);

std::stringstream ss;
ss << BoolParam.name << (BoolParam.value ? "Enabled" : "Disabled");

const auto alignment = std::get<1>(usmDeviceAllocParams);
const auto size = std::get<2>(usmDeviceAllocParams);
if (alignment && size > 0) {
ss << "_";
ss << std::get<1>(usmDeviceAllocParams);
ss << "_";
ss << std::get<2>(usmDeviceAllocParams);
}

return platform_device_name + "__" + ss.str();
}

struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<USMDeviceAllocParams> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
uur::urQueueTestWithParam<USMDeviceAllocParams>::SetUp());
ur_device_usm_access_capability_flags_t deviceUSMSupport = 0;
ASSERT_SUCCESS(
uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport));
if (!deviceUSMSupport) {
GTEST_SKIP() << "Device USM is not supported.";
}

if (getParam().value) {
if (usePool) {
ur_usm_pool_desc_t pool_desc = {};
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
}
Expand All @@ -27,16 +53,20 @@ struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
uur::urQueueTestWithParam<USMDeviceAllocParams>::TearDown());
}

ur_usm_pool_handle_t pool = nullptr;
bool usePool = std::get<0>(getParam()).value;
};

// The 0 value parameters are not relevant for urUSMDeviceAllocTest tests, they are used below in urUSMDeviceAllocAlignmentTest
UUR_TEST_SUITE_P(
urUSMDeviceAllocTest,
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(0), testing::Values(0)),
printUSMDeviceAllocTestString<urUSMDeviceAllocTest>);

TEST_P(urUSMDeviceAllocTest, Success) {
void *ptr = nullptr;
Expand Down Expand Up @@ -69,6 +99,7 @@ TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
size_t allocation_size = sizeof(int);
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);

ur_event_handle_t event = nullptr;
uint8_t pattern = 0;
Expand Down Expand Up @@ -116,3 +147,38 @@ TEST_P(urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
UR_RESULT_ERROR_INVALID_VALUE,
urUSMDeviceAlloc(context, device, &desc, pool, sizeof(int), &ptr));
}

using urUSMDeviceAllocAlignmentTest = urUSMDeviceAllocTest;

UUR_TEST_SUITE_P(
urUSMDeviceAllocAlignmentTest,
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(4, 8, 16, 32, 64), testing::Values(8, 512, 2048)),
printUSMDeviceAllocTestString<urUSMDeviceAllocAlignmentTest>);

TEST_P(urUSMDeviceAllocAlignmentTest, SuccessAlignedAllocations) {
uint32_t alignment = std::get<1>(getParam());
size_t allocation_size = std::get<2>(getParam());

ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
nullptr,
/* device flags */ 0};

ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
/* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
alignment};
void *ptr = nullptr;
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);

ur_event_handle_t event = nullptr;
uint8_t pattern = 0;
ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern,
allocation_size, 0, nullptr, &event));
ASSERT_SUCCESS(urEventWait(1, &event));

ASSERT_SUCCESS(urUSMFree(context, ptr));
EXPECT_SUCCESS(urEventRelease(event));
}
30 changes: 30 additions & 0 deletions test/conformance/usm/usm_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ urUSMDeviceAllocTest.InvalidUSMSize/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolE
urUSMDeviceAllocTest.InvalidUSMSize/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled
urUSMDeviceAllocTest.InvalidValueAlignPowerOfTwo/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled
urUSMDeviceAllocTest.InvalidValueAlignPowerOfTwo/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_4_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_4_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_4_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_8_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_8_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_8_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_16_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_16_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_16_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_32_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_32_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_32_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_64_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_64_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolEnabled_64_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_4_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_4_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_4_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_8_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_8_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_8_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_16_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_16_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_16_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_32_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_32_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_32_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_64_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_64_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/SYCL_NATIVE_CPU___SYCL_Native_CPU___UsePoolDisabled_64_2048
urUSMFreeTest.SuccessDeviceAlloc/SYCL_NATIVE_CPU___SYCL_Native_CPU_
urUSMFreeTest.SuccessHostAlloc/SYCL_NATIVE_CPU___SYCL_Native_CPU_
urUSMFreeTest.SuccessSharedAlloc/SYCL_NATIVE_CPU___SYCL_Native_CPU_
Expand Down
15 changes: 15 additions & 0 deletions test/conformance/usm/usm_adapter_opencl.match
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ urUSMDeviceAllocTest.InvalidNullHandleDevice/Intel_R__OpenCL___{{.*}}___UsePoolE
urUSMDeviceAllocTest.InvalidNullPtrResult/Intel_R__OpenCL___{{.*}}___UsePoolEnabled
urUSMDeviceAllocTest.InvalidUSMSize/Intel_R__OpenCL___{{.*}}___UsePoolEnabled
urUSMDeviceAllocTest.InvalidValueAlignPowerOfTwo/Intel_R__OpenCL___{{.*}}___UsePoolEnabled
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_4_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_4_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_4_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_8_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_8_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_8_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_16_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_16_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_16_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_32_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_32_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_32_2048
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_64_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_64_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/Intel_R__OpenCL___{{.*}}___UsePoolEnabled_64_2048
urUSMGetMemAllocInfoTest.Success/Intel_R__OpenCL___{{.*}}___UR_USM_ALLOC_INFO_POOL
urUSMHostAllocTest.Success/Intel_R__OpenCL___{{.*}}___UsePoolEnabled
urUSMHostAllocTest.SuccessWithDescriptors/Intel_R__OpenCL___{{.*}}___UsePoolEnabled
Expand Down

0 comments on commit 8c6588b

Please sign in to comment.