|
| 1 | +// Copyright (C) 2024 Intel Corporation |
| 2 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +// See LICENSE.TXT |
| 4 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + |
| 6 | +#include <umf/memory_pool.h> |
| 7 | +#include <umf/memory_provider.h> |
| 8 | +#include <uur/fixtures.h> |
| 9 | + |
| 10 | +#ifndef ASSERT_UMF_SUCCESS |
| 11 | +#define ASSERT_UMF_SUCCESS(ACTUAL) ASSERT_EQ(ACTUAL, UMF_RESULT_SUCCESS) |
| 12 | +#endif |
| 13 | + |
| 14 | +using urL0IpcTest = uur::urContextTest; |
| 15 | +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urL0IpcTest); |
| 16 | + |
| 17 | +TEST_P(urL0IpcTest, SuccessHostL0Ipc) { |
| 18 | + ur_device_usm_access_capability_flags_t hostUSMSupport = 0; |
| 19 | + ASSERT_SUCCESS(uur::GetDeviceUSMHostSupport(device, hostUSMSupport)); |
| 20 | + if (!hostUSMSupport) { |
| 21 | + GTEST_SKIP() << "Host USM is not supported."; |
| 22 | + } |
| 23 | + |
| 24 | + void *ptr = nullptr; |
| 25 | + size_t allocSize = sizeof(int); |
| 26 | + ASSERT_SUCCESS(urUSMHostAlloc(context, nullptr, nullptr, allocSize, &ptr)); |
| 27 | + ASSERT_NE(ptr, nullptr); |
| 28 | + |
| 29 | + umf_memory_pool_handle_t umfPool = umfPoolByPtr(ptr); |
| 30 | + ASSERT_NE(umfPool, nullptr); |
| 31 | + |
| 32 | + umf_memory_provider_handle_t umfProvider = nullptr; |
| 33 | + ASSERT_UMF_SUCCESS(umfPoolGetMemoryProvider(umfPool, &umfProvider)); |
| 34 | + |
| 35 | + size_t ipcHandleSize = 0; |
| 36 | + ASSERT_UMF_SUCCESS( |
| 37 | + umfMemoryProviderGetIPCHandleSize(umfProvider, &ipcHandleSize)); |
| 38 | + |
| 39 | + void *ipcHandle = nullptr; |
| 40 | + ASSERT_UMF_SUCCESS( |
| 41 | + umfMemoryProviderAlloc(umfProvider, ipcHandleSize, 0, &ipcHandle)); |
| 42 | + ASSERT_UMF_SUCCESS( |
| 43 | + umfMemoryProviderGetIPCHandle(umfProvider, ptr, allocSize, ipcHandle)); |
| 44 | + |
| 45 | + ASSERT_UMF_SUCCESS(umfMemoryProviderPutIPCHandle(umfProvider, ipcHandle)); |
| 46 | + |
| 47 | + ASSERT_UMF_SUCCESS( |
| 48 | + umfMemoryProviderFree(umfProvider, ipcHandle, ipcHandleSize)); |
| 49 | + |
| 50 | + ASSERT_SUCCESS(urUSMFree(context, ptr)); |
| 51 | +} |
0 commit comments