|
| 1 | +// Copyright (C) 2025 Intel Corporation |
| 2 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM |
| 3 | +// Exceptions. See LICENSE.TXT |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +#include "helpers.h" |
| 7 | +#include "uur/utils.h" |
| 8 | +#include <uur/fixtures.h> |
| 9 | +#include <uur/known_failure.h> |
| 10 | + |
| 11 | +#include <umf.h> |
| 12 | +#include <umf/memory_pool.h> |
| 13 | +#include <umf/memory_provider.h> |
| 14 | + |
| 15 | +struct umfDeviceAllocTest : uur::urUSMAllocTest { |
| 16 | + void SetUp() override { |
| 17 | + UUR_RETURN_ON_FATAL_FAILURE(uur::urUSMAllocTest::SetUp()); |
| 18 | + ASSERT_SUCCESS(uur::GetDeviceUSMDeviceSupport(device, USMSupport)); |
| 19 | + if (!USMSupport) { |
| 20 | + GTEST_SKIP() << "Device USM is not supported."; |
| 21 | + } |
| 22 | + } |
| 23 | +}; |
| 24 | + |
| 25 | +// The 0 value parameters are not relevant for umfDeviceAllocTest tests, they |
| 26 | +// are used below in urUSMDeviceAllocAlignmentTest for allocation size and |
| 27 | +// alignment values |
| 28 | +UUR_DEVICE_TEST_SUITE_WITH_PARAM( |
| 29 | + umfDeviceAllocTest, |
| 30 | + testing::Combine( |
| 31 | + testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")), |
| 32 | + testing::Values(0), testing::Values(0), |
| 33 | + testing::Values(UR_USM_ADVICE_FLAG_DEFAULT)), |
| 34 | + uur::printUSMAllocTestString<umfDeviceAllocTest>); |
| 35 | + |
| 36 | +TEST_P(umfDeviceAllocTest, UMFAllocSuccessfull) { |
| 37 | + UUR_KNOWN_FAILURE_ON(uur::NativeCPU{}, uur::CUDA{}, uur::HIP{}, |
| 38 | + uur::OpenCL{}); |
| 39 | + |
| 40 | + void *ptr = nullptr; |
| 41 | + size_t allocation_size = sizeof(int); |
| 42 | + ASSERT_SUCCESS( |
| 43 | + urUSMDeviceAlloc(context, device, nullptr, pool, allocation_size, &ptr)); |
| 44 | + ASSERT_NE(ptr, nullptr); |
| 45 | + |
| 46 | + auto umfPool = umfPoolByPtr(ptr); |
| 47 | + ASSERT_NE(umfPool, nullptr); |
| 48 | + |
| 49 | + umf_memory_provider_handle_t hProvider; |
| 50 | + ASSERT_EQ(umfPoolGetMemoryProvider(umfPool, &hProvider), UMF_RESULT_SUCCESS); |
| 51 | + ASSERT_NE(hProvider, nullptr); |
| 52 | + |
| 53 | + // make sure that pool can be used for allocations |
| 54 | + void *umfPtr = umfPoolMalloc(umfPool, allocation_size); |
| 55 | + ASSERT_NE(umfPtr, nullptr); |
| 56 | + ASSERT_EQ(umfPoolFree(umfPool, umfPtr), UMF_RESULT_SUCCESS); |
| 57 | + |
| 58 | + ASSERT_SUCCESS(urUSMFree(context, ptr)); |
| 59 | +} |
0 commit comments