Skip to content

Commit

Permalink
Merge pull request #658 from veselypeta/petr/590/urPhysicalMemCreate
Browse files Browse the repository at this point in the history
[UR][CTS] Test urPhysicalMem entry-points
  • Loading branch information
veselypeta authored Jun 30, 2023
2 parents 855504b + 71c3fc5 commit 96c17d3
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 24 deletions.
6 changes: 4 additions & 2 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,7 @@ UR_APIEXPORT ur_result_t UR_APICALL
urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void *pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t flags ///< [in] access flags to set for the mapped virtual memory range.
);

Expand Down Expand Up @@ -3291,11 +3291,13 @@ typedef struct ur_physical_mem_properties_t {
/// + `NULL == hDevice`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phPhysicalMem`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + If size is not a multiple of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
UR_APIEXPORT ur_result_t UR_APICALL
urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size_t size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *pProperties, ///< [in][optional] pointer to physical memory creation properties.
ur_physical_mem_handle_t *phPhysicalMem ///< [out] pointer to handle of physical memory object created.
Expand Down
8 changes: 5 additions & 3 deletions scripts/core/virtual_memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ params:
desc: "[in] pointer to the start of the virtual memory range."
- type: size_t
name: size
desc: "[in] size in bytes of the virutal memory range."
desc: "[in] size in bytes of the virtual memory range."
- type: $x_virtual_mem_access_flags_t
name: flags
desc: "[in] access flags to set for the mapped virtual memory range."
Expand Down Expand Up @@ -273,15 +273,17 @@ params:
- type: size_t
name: size
desc: >
[in] size in bytes of phyisical memory to allocate, must be a
[in] size in bytes of physical memory to allocate, must be a
multiple of $X_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
- type: const $x_physical_mem_properties_t*
name: pProperties
desc: "[in][optional] pointer to physical memory creation properties."
- type: $x_physical_mem_handle_t*
name: phPhysicalMem
desc: "[out] pointer to handle of physical memory object created."

returns:
- $X_RESULT_ERROR_INVALID_SIZE:
- "If size is not a multiple of $X_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM."
--- #--------------------------------------------------------------------------
type: function
desc: "Retain a physical memory handle, increment its reference count."
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/null/ur_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ __urdlllocal ur_result_t UR_APICALL urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void
*pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t
flags ///< [in] access flags to set for the mapped virtual memory range.
) try {
Expand Down Expand Up @@ -1531,7 +1531,7 @@ __urdlllocal ur_result_t UR_APICALL urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t
size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *
pProperties, ///< [in][optional] pointer to physical memory creation properties.
Expand Down
4 changes: 2 additions & 2 deletions source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ __urdlllocal ur_result_t UR_APICALL urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void
*pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t
flags ///< [in] access flags to set for the mapped virtual memory range.
) {
Expand Down Expand Up @@ -1740,7 +1740,7 @@ __urdlllocal ur_result_t UR_APICALL urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t
size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *
pProperties, ///< [in][optional] pointer to physical memory creation properties.
Expand Down
4 changes: 2 additions & 2 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,7 @@ __urdlllocal ur_result_t UR_APICALL urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void
*pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t
flags ///< [in] access flags to set for the mapped virtual memory range.
) {
Expand Down Expand Up @@ -2135,7 +2135,7 @@ __urdlllocal ur_result_t UR_APICALL urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t
size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *
pProperties, ///< [in][optional] pointer to physical memory creation properties.
Expand Down
4 changes: 2 additions & 2 deletions source/loader/ur_ldrddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ __urdlllocal ur_result_t UR_APICALL urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void
*pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t
flags ///< [in] access flags to set for the mapped virtual memory range.
) {
Expand Down Expand Up @@ -2004,7 +2004,7 @@ __urdlllocal ur_result_t UR_APICALL urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t
size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *
pProperties, ///< [in][optional] pointer to physical memory creation properties.
Expand Down
6 changes: 4 additions & 2 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@ ur_result_t UR_APICALL urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void
*pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t
flags ///< [in] access flags to set for the mapped virtual memory range.
) try {
Expand Down Expand Up @@ -2403,11 +2403,13 @@ ur_result_t UR_APICALL urVirtualMemGetInfo(
/// + `NULL == hDevice`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phPhysicalMem`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + If size is not a multiple of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
ur_result_t UR_APICALL urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t
size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *
pProperties, ///< [in][optional] pointer to physical memory creation properties.
Expand Down
6 changes: 4 additions & 2 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ ur_result_t UR_APICALL urVirtualMemSetAccess(
ur_context_handle_t hContext, ///< [in] handle to the context object.
const void
*pStart, ///< [in] pointer to the start of the virtual memory range.
size_t size, ///< [in] size in bytes of the virutal memory range.
size_t size, ///< [in] size in bytes of the virtual memory range.
ur_virtual_mem_access_flags_t
flags ///< [in] access flags to set for the mapped virtual memory range.
) {
Expand Down Expand Up @@ -2020,11 +2020,13 @@ ur_result_t UR_APICALL urVirtualMemGetInfo(
/// + `NULL == hDevice`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phPhysicalMem`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + If size is not a multiple of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
ur_result_t UR_APICALL urPhysicalMemCreate(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t hDevice, ///< [in] handle of the device object.
size_t
size, ///< [in] size in bytes of phyisical memory to allocate, must be a multiple
size, ///< [in] size in bytes of physical memory to allocate, must be a multiple
///< of ::UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM.
const ur_physical_mem_properties_t *
pProperties, ///< [in][optional] pointer to physical memory creation properties.
Expand Down
36 changes: 29 additions & 7 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ inline bool hasDevicePartitionSupport(ur_device_handle_t device,
}

struct urAllDevicesTest : urPlatformTest {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urPlatformTest::SetUp());
auto devicesPair = GetDevices(platform);
Expand All @@ -76,7 +75,6 @@ struct urAllDevicesTest : urPlatformTest {

struct urDeviceTest : urPlatformTest,
::testing::WithParamInterface<ur_device_handle_t> {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urPlatformTest::SetUp());
device = GetParam();
Expand Down Expand Up @@ -138,7 +136,6 @@ struct urContextTest : urDeviceTest {
};

struct urSamplerTest : urContextTest {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp());
sampler_desc = {
Expand All @@ -161,7 +158,6 @@ struct urSamplerTest : urContextTest {
};

struct urMemBufferTest : urContextTest {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp());
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, 4096,
Expand Down Expand Up @@ -205,7 +201,6 @@ template <class T> struct urContextTestWithParam : urDeviceTestWithParam<T> {
};

template <class T> struct urSamplerTestWithParam : urContextTestWithParam<T> {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
sampler_desc = {
Expand Down Expand Up @@ -335,7 +330,6 @@ struct urHostPipeTest : urQueueTest {
};

template <class T> struct urQueueTestWithParam : urContextTestWithParam<T> {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
ASSERT_SUCCESS(urQueueCreate(this->context, this->device, 0, &queue));
Expand Down Expand Up @@ -624,7 +618,6 @@ struct urUSMPoolTest : urContextTest {
};

template <class T> struct urUSMPoolTestWithParam : urContextTestWithParam<T> {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
ur_usm_pool_desc_t pool_desc{UR_STRUCTURE_TYPE_USM_POOL_DESC, nullptr,
Expand All @@ -643,6 +636,35 @@ template <class T> struct urUSMPoolTestWithParam : urContextTestWithParam<T> {
ur_usm_pool_handle_t pool;
};

struct urPhysicalMemTest : urContextTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp());
ASSERT_SUCCESS(urVirtualMemGranularityGetInfo(
context, device, UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
sizeof(granularity), &granularity, nullptr));
size = granularity * 256;
ur_physical_mem_properties_t props{
UR_STRUCTURE_TYPE_PHYSICAL_MEM_PROPERTIES,
nullptr,
0 /*flags*/,
};
ASSERT_SUCCESS(
urPhysicalMemCreate(context, device, size, &props, &physical_mem));
ASSERT_NE(physical_mem, nullptr);
}

void TearDown() override {
if (physical_mem) {
EXPECT_SUCCESS(urPhysicalMemRelease(physical_mem));
}
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::TearDown());
}

size_t granularity = 0;
size_t size = 0;
ur_physical_mem_handle_t physical_mem = nullptr;
};

template <class T>
struct urUSMDeviceAllocTestWithParam : urQueueTestWithParam<T> {

Expand Down
64 changes: 64 additions & 0 deletions test/conformance/virtual_memory/urPhysicalMemCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,67 @@
// 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>

using urPhysicalMemCreateTestParams = size_t;
struct urPhysicalMemCreateTest
: uur::urContextTestWithParam<urPhysicalMemCreateTestParams> {

void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(uur::urContextTestWithParam<
urPhysicalMemCreateTestParams>::SetUp());
ASSERT_SUCCESS(urVirtualMemGranularityGetInfo(
context, device, UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
sizeof(granularity), &granularity, nullptr));
ASSERT_NE(granularity, 0);
size = getParam() * granularity;
}

size_t granularity;
size_t size;
};

UUR_TEST_SUITE_P(
urPhysicalMemCreateTest,
::testing::Values(1, 2, 3, 7, 12, 44, 1024, 4000, 12345),
uur::deviceTestWithParamPrinter<urPhysicalMemCreateTestParams>);

TEST_P(urPhysicalMemCreateTest, Success) {
ur_physical_mem_handle_t physical_mem = nullptr;
ASSERT_SUCCESS(
urPhysicalMemCreate(context, device, size, nullptr, &physical_mem));
ASSERT_NE(physical_mem, nullptr);
EXPECT_SUCCESS(urPhysicalMemRelease(physical_mem));
}

TEST_P(urPhysicalMemCreateTest, InvalidNullHandleContext) {
ur_physical_mem_handle_t physical_mem = nullptr;
ASSERT_EQ_RESULT(
urPhysicalMemCreate(nullptr, device, size, nullptr, &physical_mem),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urPhysicalMemCreateTest, InvalidNullHandleDevice) {
ur_physical_mem_handle_t physical_mem = nullptr;
ASSERT_EQ_RESULT(
urPhysicalMemCreate(context, nullptr, size, nullptr, &physical_mem),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urPhysicalMemCreateTest, InvalidNullPointerPhysicalMem) {
ASSERT_EQ_RESULT(
urPhysicalMemCreate(context, device, size, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urPhysicalMemCreateTest, InvalidSize) {
if (granularity == 1) {
GTEST_SKIP()
<< "A granularity of 1 means that any size will be accepted.";
}
ur_physical_mem_handle_t physical_mem = nullptr;
size_t invalid_size = size - 1;
ASSERT_EQ_RESULT(urPhysicalMemCreate(context, device, invalid_size, nullptr,
&physical_mem),
UR_RESULT_ERROR_INVALID_SIZE);
}
14 changes: 14 additions & 0 deletions test/conformance/virtual_memory/urPhysicalMemRelease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@
// 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>

using urPhysicalMemReleaseTest = uur::urPhysicalMemTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urPhysicalMemReleaseTest);

TEST_P(urPhysicalMemReleaseTest, Success) {
ASSERT_SUCCESS(urPhysicalMemRetain(physical_mem));
ASSERT_SUCCESS(urPhysicalMemRelease(physical_mem));
}

TEST_P(urPhysicalMemReleaseTest, InvalidNullHandlePhysicalMem) {
ASSERT_EQ_RESULT(urPhysicalMemRelease(nullptr),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}
14 changes: 14 additions & 0 deletions test/conformance/virtual_memory/urPhysicalMemRetain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@
// 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>

using urPhysicalMemRetainTest = uur::urPhysicalMemTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urPhysicalMemRetainTest);

TEST_P(urPhysicalMemRetainTest, Success) {
ASSERT_SUCCESS(urPhysicalMemRetain(physical_mem));
ASSERT_SUCCESS(urPhysicalMemRelease(physical_mem));
}

TEST_P(urPhysicalMemRetainTest, InvalidNullHandlePhysicalMem) {
ASSERT_EQ_RESULT(urPhysicalMemRetain(nullptr),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

0 comments on commit 96c17d3

Please sign in to comment.