Skip to content

Commit

Permalink
Merge pull request #1482 from oneapi-src/martin/alignedUSMAllocationsCTS
Browse files Browse the repository at this point in the history
[CTS] Add new urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations test
  • Loading branch information
martygrant committed Apr 5, 2024
2 parents 065bf2d + db31783 commit befdc7c
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 23 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
42 changes: 42 additions & 0 deletions test/conformance/usm/helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2024 Intel Corporation
// 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

#ifndef UUR_USM_HELPERS_H_INCLUDED
#define UUR_USM_HELPERS_H_INCLUDED

#include <uur/fixtures.h>

namespace uur {

using USMDeviceAllocParams = std::tuple<uur::BoolTestParam, uint32_t, size_t>;

template <typename T>
inline std::string printUSMAllocTestString(
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();
}

} // namespace uur

#endif // UUR_ENQUEUE_RECT_HELPERS_H_INCLUDED
58 changes: 51 additions & 7 deletions test/conformance/usm/urUSMDeviceAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
// 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 "helpers.h"
#include <uur/fixtures.h>

struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
struct urUSMDeviceAllocTest
: uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
uur::urQueueTestWithParam<uur::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 +28,22 @@ struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
uur::urQueueTestWithParam<uur::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 for allocation size and
// alignment values
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)),
uur::printUSMAllocTestString<urUSMDeviceAllocTest>);

TEST_P(urUSMDeviceAllocTest, Success) {
void *ptr = nullptr;
Expand Down Expand Up @@ -69,6 +76,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 +124,39 @@ 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)),
uur::printUSMAllocTestString<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));
}
58 changes: 51 additions & 7 deletions test/conformance/usm/urUSMHostAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "helpers.h"
#include <cstring>
#include <uur/fixtures.h>

struct urUSMHostAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
struct urUSMHostAllocTest
: uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::SetUp());
ur_device_usm_access_capability_flags_t hostUSMSupport = 0;
ASSERT_SUCCESS(uur::GetDeviceUSMHostSupport(device, hostUSMSupport));
if (!hostUSMSupport) {
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 @@ -26,16 +29,22 @@ struct urUSMHostAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::TearDown());
}

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

// The 0 value parameters are not relevant for urUSMHostAllocTest tests, they
// are used below in urUSMHostAllocAlignmentTest for allocation size and
// alignment values
UUR_TEST_SUITE_P(
urUSMHostAllocTest,
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(0), testing::Values(0)),
uur::printUSMAllocTestString<urUSMHostAllocTest>);

TEST_P(urUSMHostAllocTest, Success) {
ur_device_usm_access_capability_flags_t hostUSMSupport = 0;
Expand Down Expand Up @@ -77,7 +86,6 @@ TEST_P(urUSMHostAllocTest, Success) {
}

TEST_P(urUSMHostAllocTest, SuccessWithDescriptors) {

ur_usm_host_desc_t usm_host_desc{UR_STRUCTURE_TYPE_USM_HOST_DESC, nullptr,
/* host flags */ 0};

Expand All @@ -88,6 +96,7 @@ TEST_P(urUSMHostAllocTest, SuccessWithDescriptors) {
size_t allocation_size = sizeof(int);
ASSERT_SUCCESS(
urUSMHostAlloc(context, &usm_desc, pool, allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);

ur_event_handle_t event = nullptr;
uint8_t pattern = 0;
Expand Down Expand Up @@ -125,3 +134,38 @@ TEST_P(urUSMHostAllocTest, InvalidValueAlignPowerOfTwo) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
urUSMHostAlloc(context, &desc, pool, sizeof(int), &ptr));
}

using urUSMHostAllocAlignmentTest = urUSMHostAllocTest;

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

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

ur_usm_host_desc_t usm_host_desc{UR_STRUCTURE_TYPE_USM_HOST_DESC, nullptr,
/* host flags */ 0};

ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_host_desc,
/* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
alignment};

void *ptr = nullptr;
ASSERT_SUCCESS(
urUSMHostAlloc(context, &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));
}
64 changes: 57 additions & 7 deletions test/conformance/usm/urUSMSharedAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "helpers.h"
#include <uur/fixtures.h>

struct urUSMSharedAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
struct urUSMSharedAllocTest
: uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::SetUp());
ur_device_usm_access_capability_flags_t shared_usm_cross = 0;
ur_device_usm_access_capability_flags_t shared_usm_single = 0;

Expand All @@ -21,7 +23,7 @@ struct urUSMSharedAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
GTEST_SKIP() << "Shared USM is not supported by the device.";
}

if (getParam().value) {
if (usePool) {
ur_usm_pool_desc_t pool_desc = {};
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
}
Expand All @@ -32,22 +34,29 @@ struct urUSMSharedAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::TearDown());
}

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

// The 0 value parameters are not relevant for urUSMSharedAllocTest tests, they
// are used below in urUSMSharedAllocAlignmentTest for allocation size and
// alignment values
UUR_TEST_SUITE_P(
urUSMSharedAllocTest,
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(0), testing::Values(0)),
uur::printUSMAllocTestString<urUSMSharedAllocTest>);

TEST_P(urUSMSharedAllocTest, Success) {
void *ptr = nullptr;
size_t allocation_size = sizeof(int);
ASSERT_SUCCESS(urUSMSharedAlloc(context, device, nullptr, pool,
allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);

ur_event_handle_t event = nullptr;
uint8_t pattern = 0;
Expand All @@ -60,7 +69,6 @@ TEST_P(urUSMSharedAllocTest, Success) {
}

TEST_P(urUSMSharedAllocTest, SuccessWithDescriptors) {

ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
nullptr,
/* device flags */ 0};
Expand All @@ -76,6 +84,7 @@ TEST_P(urUSMSharedAllocTest, SuccessWithDescriptors) {
size_t allocation_size = sizeof(int);
ASSERT_SUCCESS(urUSMSharedAlloc(context, device, &usm_desc, pool,
allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);

ur_event_handle_t event = nullptr;
uint8_t pattern = 0;
Expand All @@ -97,6 +106,7 @@ TEST_P(urUSMSharedAllocTest, SuccessWithMultipleAdvices) {
size_t allocation_size = sizeof(int);
ASSERT_SUCCESS(urUSMSharedAlloc(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 @@ -144,3 +154,43 @@ TEST_P(urUSMSharedAllocTest, InvalidValueAlignPowerOfTwo) {
UR_RESULT_ERROR_INVALID_VALUE,
urUSMSharedAlloc(context, device, &desc, pool, sizeof(int), &ptr));
}

using urUSMSharedAllocAlignmentTest = urUSMSharedAllocTest;

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

TEST_P(urUSMSharedAllocAlignmentTest, 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_host_desc_t usm_host_desc{UR_STRUCTURE_TYPE_USM_HOST_DESC,
&usm_device_desc,
/* host flags */ 0};

ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_host_desc,
/* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
alignment};

void *ptr = nullptr;
ASSERT_SUCCESS(urUSMSharedAlloc(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));
}
Loading

0 comments on commit befdc7c

Please sign in to comment.