Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to align CTS and Spec for USM #2642

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 63 additions & 14 deletions test/conformance/usm/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,82 @@

namespace uur {

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

struct urUSMAllocTest : uur::urQueueTestWithParam<uur::USMAllocTestParams> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::USMAllocTestParams>::SetUp());
if (usePool) {
ur_bool_t poolSupport = false;
ASSERT_SUCCESS(uur::GetDeviceUSMPoolSupport(device, poolSupport));
if (!poolSupport) {
GTEST_SKIP() << "USM pools are not supported.";
}
ur_usm_pool_desc_t pool_desc = {};
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
}
}

void TearDown() override {
if (pool) {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<uur::USMAllocTestParams>::TearDown());
}

ur_usm_pool_handle_t pool = nullptr;
const bool usePool = std::get<0>(getParam()).value;
ur_device_usm_access_capability_flags_t USMSupport = 0;
const uint32_t alignment = std::get<1>(getParam());
size_t allocation_size = std::get<2>(getParam());
const ur_usm_advice_flags_t advice_flags = std::get<3>(getParam());
void *ptr = nullptr;
};

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

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);
}
ss << BoolParam.name << (BoolParam.value ? "Enabled" : "Disabled"); // UsePool
ss << "_";
ss << std::get<1>(USMAllocTestParams); // alignment
ss << "_";
ss << std::get<2>(USMAllocTestParams); // size
ss << "_";
ss << std::get<3>(USMAllocTestParams); // ur_usm_advice_flags_t

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

static std::vector<ur_usm_advice_flags_t> usm_alloc_test_parameters{
UR_USM_ADVICE_FLAG_DEFAULT,
UR_USM_ADVICE_FLAG_SET_READ_MOSTLY,
UR_USM_ADVICE_FLAG_CLEAR_READ_MOSTLY,
UR_USM_ADVICE_FLAG_SET_PREFERRED_LOCATION,
UR_USM_ADVICE_FLAG_CLEAR_PREFERRED_LOCATION,
UR_USM_ADVICE_FLAG_SET_NON_ATOMIC_MOSTLY,
UR_USM_ADVICE_FLAG_CLEAR_NON_ATOMIC_MOSTLY,
UR_USM_ADVICE_FLAG_BIAS_CACHED,
UR_USM_ADVICE_FLAG_BIAS_UNCACHED,
UR_USM_ADVICE_FLAG_SET_ACCESSED_BY_DEVICE,
UR_USM_ADVICE_FLAG_CLEAR_ACCESSED_BY_DEVICE,
UR_USM_ADVICE_FLAG_SET_ACCESSED_BY_HOST,
UR_USM_ADVICE_FLAG_CLEAR_ACCESSED_BY_HOST,
UR_USM_ADVICE_FLAG_SET_PREFERRED_LOCATION_HOST,
UR_USM_ADVICE_FLAG_CLEAR_PREFERRED_LOCATION_HOST,
UR_USM_ADVICE_FLAG_SET_NON_COHERENT_MEMORY,
UR_USM_ADVICE_FLAG_CLEAR_NON_COHERENT_MEMORY};

} // namespace uur

#endif // UUR_ENQUEUE_RECT_HELPERS_H_INCLUDED
103 changes: 47 additions & 56 deletions test/conformance/usm/urUSMDeviceAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,18 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "helpers.h"
#include "uur/utils.h"
#include <limits>
#include <uur/fixtures.h>
#include <uur/known_failure.h>

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

if (usePool) {
ur_bool_t poolSupport = false;
ASSERT_SUCCESS(uur::GetDeviceUSMPoolSupport(device, poolSupport));
if (!poolSupport) {
GTEST_SKIP() << "USM pools are not supported.";
}
ur_usm_pool_desc_t pool_desc = {};
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
}
}

void TearDown() override {
if (pool) {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
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
Expand All @@ -49,14 +26,14 @@ UUR_DEVICE_TEST_SUITE_WITH_PARAM(
urUSMDeviceAllocTest,
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(0), testing::Values(0)),
testing::Values(0), testing::Values(0),
::testing::ValuesIn(uur::usm_alloc_test_parameters)),
uur::printUSMAllocTestString<urUSMDeviceAllocTest>);

TEST_P(urUSMDeviceAllocTest, Success) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

void *ptr = nullptr;
size_t allocation_size = sizeof(int);
allocation_size = sizeof(int);
ASSERT_SUCCESS(
urUSMDeviceAlloc(context, device, nullptr, pool, allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);
Expand All @@ -73,16 +50,15 @@ TEST_P(urUSMDeviceAllocTest, Success) {
}

TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
const ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
nullptr,
/* device flags */ 0};

const ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
advice_flags, alignment};

ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
nullptr,
/* device flags */ 0};
allocation_size = sizeof(int);

ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
/* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
/* alignment */ 0};
void *ptr = nullptr;
size_t allocation_size = sizeof(int);
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);
Expand All @@ -98,14 +74,12 @@ TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
}

TEST_P(urUSMDeviceAllocTest, InvalidNullHandleContext) {
void *ptr = nullptr;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urUSMDeviceAlloc(nullptr, device, nullptr, pool, sizeof(int), &ptr));
}

TEST_P(urUSMDeviceAllocTest, InvalidNullHandleDevice) {
void *ptr = nullptr;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urUSMDeviceAlloc(context, nullptr, nullptr, pool, sizeof(int), &ptr));
Expand All @@ -121,43 +95,60 @@ TEST_P(urUSMDeviceAllocTest, InvalidUSMSize) {
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
uur::NativeCPU{});

void *ptr = nullptr;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_USM_SIZE,
urUSMDeviceAlloc(context, device, nullptr, pool, -1, &ptr));
urUSMDeviceAlloc(context, device, nullptr, pool, 0, &ptr));

// TODO: Producing error X from case "size is greater than
// UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE" is currently unreliable due to
// implementation issues for UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE
// https://github.com/oneapi-src/unified-runtime/issues/2665
}

TEST_P(urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
void *ptr = nullptr;
TEST_P(urUSMDeviceAllocTest, InvalidValue) {
ur_usm_desc_t desc = {};
desc.stype = UR_STRUCTURE_TYPE_USM_DESC;
desc.align = 5;
desc.pNext = nullptr;
desc.hints = UR_USM_ADVICE_FLAG_DEFAULT;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_VALUE,
urUSMDeviceAlloc(context, device, &desc, pool, sizeof(int), &ptr));

desc.align = std::numeric_limits<uint32_t>::max();
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_VALUE,
urUSMDeviceAlloc(context, device, &desc, pool, sizeof(int), &ptr));
}

TEST_P(urUSMDeviceAllocTest, InvalidEnumeration) {
ur_usm_desc_t desc = {};
desc.stype = UR_STRUCTURE_TYPE_USM_DESC;
desc.align = 5;
desc.pNext = nullptr;
desc.hints = UR_USM_ADVICE_FLAG_FORCE_UINT32;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_ENUMERATION,
urUSMDeviceAlloc(context, device, &desc, pool, sizeof(int), &ptr));
}

using urUSMDeviceAllocAlignmentTest = urUSMDeviceAllocTest;

UUR_DEVICE_TEST_SUITE_WITH_PARAM(
urUSMDeviceAllocAlignmentTest,
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(4, 8, 16, 32, 64), testing::Values(8, 512, 2048)),
testing::Values(4, 8, 16, 32, 64), testing::Values(8, 512, 2048),
testing::ValuesIn(uur::usm_alloc_test_parameters)),
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};
const 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};
const ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
advice_flags, alignment};

void *ptr = nullptr;
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
allocation_size, &ptr));
ASSERT_NE(ptr, nullptr);
Expand Down
Loading