Skip to content

Commit

Permalink
[CTS] Move USMDeviceAllocParams and printUSMAllocTestString into new …
Browse files Browse the repository at this point in the history
…helpers.h header file. Add a SuccessAlignedAllocations test to both urUSMHostAlloc.cpp and urUSMSharedAlloc.cpp
  • Loading branch information
martygrant authored and AllanZyne committed Apr 7, 2024
1 parent 878bfb6 commit 109941a
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 47 deletions.
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
44 changes: 11 additions & 33 deletions test/conformance/usm/urUSMDeviceAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,14 @@
// 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>

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> {
struct urUSMDeviceAllocTest
: uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<USMDeviceAllocParams>::SetUp());
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::SetUp());
ur_device_usm_access_capability_flags_t deviceUSMSupport = 0;
ASSERT_SUCCESS(
uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport));
Expand All @@ -53,20 +28,22 @@ struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<USMDeviceAllocParams> {
ASSERT_SUCCESS(urUSMPoolRelease(pool));
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urQueueTestWithParam<USMDeviceAllocParams>::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
// 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::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(0), testing::Values(0)),
printUSMDeviceAllocTestString<urUSMDeviceAllocTest>);
uur::printUSMAllocTestString<urUSMDeviceAllocTest>);

TEST_P(urUSMDeviceAllocTest, Success) {
void *ptr = nullptr;
Expand Down Expand Up @@ -155,7 +132,7 @@ UUR_TEST_SUITE_P(
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
testing::Values(4, 8, 16, 32, 64), testing::Values(8, 512, 2048)),
printUSMDeviceAllocTestString<urUSMDeviceAllocAlignmentTest>);
uur::printUSMAllocTestString<urUSMDeviceAllocAlignmentTest>);

TEST_P(urUSMDeviceAllocAlignmentTest, SuccessAlignedAllocations) {
uint32_t alignment = std::get<1>(getParam());
Expand All @@ -168,6 +145,7 @@ TEST_P(urUSMDeviceAllocAlignmentTest, SuccessAlignedAllocations) {
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));
Expand Down
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 109941a

Please sign in to comment.