Skip to content

Refactor Level Zero and CUDA tests #1094

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

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
15 changes: 1 addition & 14 deletions src/utils/utils_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,6 @@ int utils_ze_get_drivers(uint32_t *drivers_num_,
ze_driver_handle_t *drivers = NULL;
uint32_t drivers_num = 0;

ret = utils_ze_init_level_zero();
if (ret != 0) {
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
goto init_fail;
}

ze_result = libze_ops.zeDriverGet(&drivers_num, NULL);
if (ze_result != ZE_RESULT_SUCCESS) {
fprintf(stderr, "zeDriverGet() failed!\n");
Expand Down Expand Up @@ -386,7 +380,6 @@ int utils_ze_get_drivers(uint32_t *drivers_num_,
*drivers_ = NULL;
}

init_fail:
return ret;
}

Expand All @@ -397,12 +390,6 @@ int utils_ze_get_devices(ze_driver_handle_t driver, uint32_t *devices_num_,
uint32_t devices_num = 0;
ze_device_handle_t *devices = NULL;

ret = utils_ze_init_level_zero();
if (ret != 0) {
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
goto init_fail;
}

ze_result = libze_ops.zeDeviceGet(driver, &devices_num, NULL);
if (ze_result != ZE_RESULT_SUCCESS) {
fprintf(stderr, "zeDeviceGet() failed!\n");
Expand Down Expand Up @@ -438,7 +425,7 @@ int utils_ze_get_devices(ze_driver_handle_t driver, uint32_t *devices_num_,
free(devices);
devices = NULL;
}
init_fail:

return ret;
}

Expand Down
1 change: 0 additions & 1 deletion src/utils/utils_level_zero.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
extern "C" {
#endif

int utils_ze_init_level_zero(void);
int utils_ze_init_level_zero(void);

int utils_ze_get_drivers(uint32_t *drivers_num_, ze_driver_handle_t **drivers_);
Expand Down
6 changes: 2 additions & 4 deletions test/common/ipc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ int run_consumer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
umf_result =
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"[consumer] ERROR: creating OS memory provider failed\n");
fprintf(stderr, "[consumer] ERROR: creating memory provider failed\n");
return -1;
}

Expand Down Expand Up @@ -347,8 +346,7 @@ int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
umf_result =
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"[producer] ERROR: creating OS memory provider failed\n");
fprintf(stderr, "[producer] ERROR: creating memory provider failed\n");
return -1;
}

Expand Down
15 changes: 15 additions & 0 deletions test/ipcFixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class MemoryAccessor {
public:
virtual ~MemoryAccessor() = default;
virtual void fill(void *ptr, size_t size, const void *pattern,
size_t pattern_size) = 0;
virtual void copy(void *dst_ptr, void *src_ptr, size_t size) = 0;
Expand Down Expand Up @@ -162,6 +163,7 @@ struct umfIpcTest : umf_test::test,
TEST_P(umfIpcTest, GetIPCHandleSize) {
size_t size = 0;
umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

umf_result_t ret = umfPoolGetIPCHandleSize(pool.get(), &size);
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
Expand All @@ -174,6 +176,8 @@ TEST_P(umfIpcTest, GetIPCHandleSizeInvalidArgs) {
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);

umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

ret = umfPoolGetIPCHandleSize(pool.get(), nullptr);
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
}
Expand All @@ -190,6 +194,8 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);

umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

ptr = umfPoolMalloc(pool.get(), SIZE);
EXPECT_NE(ptr, nullptr);

Expand All @@ -213,6 +219,8 @@ TEST_P(umfIpcTest, BasicFlow) {
constexpr size_t SIZE = 100;
std::vector<int> expected_data(SIZE);
umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

int *ptr = (int *)umfPoolMalloc(pool.get(), SIZE * sizeof(int));
EXPECT_NE(ptr, nullptr);

Expand Down Expand Up @@ -283,6 +291,7 @@ TEST_P(umfIpcTest, GetPoolByOpenedHandle) {
void *openedPtrs[NUM_POOLS][NUM_ALLOCS];
std::vector<umf::pool_unique_handle_t> pools_to_open;
umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

for (size_t i = 0; i < NUM_POOLS; ++i) {
pools_to_open.push_back(makePool());
Expand Down Expand Up @@ -341,6 +350,8 @@ TEST_P(umfIpcTest, GetPoolByOpenedHandle) {
TEST_P(umfIpcTest, AllocFreeAllocTest) {
constexpr size_t SIZE = 64 * 1024;
umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

umf_ipc_handler_handle_t ipcHandler = nullptr;

umf_result_t ret = umfPoolGetIPCHandler(pool.get(), &ipcHandler);
Expand Down Expand Up @@ -400,7 +411,9 @@ TEST_P(umfIpcTest, openInTwoIpcHandlers) {
constexpr size_t SIZE = 100;
std::vector<int> expected_data(SIZE);
umf::pool_unique_handle_t pool1 = makePool();
ASSERT_NE(pool1.get(), nullptr);
umf::pool_unique_handle_t pool2 = makePool();
ASSERT_NE(pool2.get(), nullptr);
umf_ipc_handler_handle_t ipcHandler1 = nullptr;
umf_ipc_handler_handle_t ipcHandler2 = nullptr;

Expand Down Expand Up @@ -465,6 +478,7 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
constexpr size_t ALLOC_SIZE = 100;
constexpr size_t NUM_POINTERS = 100;
umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

for (size_t i = 0; i < NUM_POINTERS; ++i) {
void *ptr = umfPoolMalloc(pool.get(), ALLOC_SIZE);
Expand Down Expand Up @@ -514,6 +528,7 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
constexpr size_t ALLOC_SIZE = 100;
constexpr size_t NUM_POINTERS = 100;
umf::pool_unique_handle_t pool = makePool();
ASSERT_NE(pool.get(), nullptr);

for (size_t i = 0; i < NUM_POINTERS; ++i) {
void *ptr = umfPoolMalloc(pool.get(), ALLOC_SIZE);
Expand Down
14 changes: 1 addition & 13 deletions test/providers/cuda_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void init_cuda_once() {
InitResult = init_cuda_lib();
}

int init_cuda() {
int init_cuda(void) {
utils_init_once(&cuda_init_flag, init_cuda_once);

return InitResult;
Expand All @@ -415,12 +415,6 @@ int init_cuda() {
int get_cuda_device(CUdevice *device) {
CUdevice cuDevice = -1;

int ret = init_cuda();
if (ret != 0) {
fprintf(stderr, "init_cuda() failed!\n");
return ret;
}

CUresult res = libcu_ops.cuDeviceGet(&cuDevice, 0);
if (res != CUDA_SUCCESS || cuDevice < 0) {
return -1;
Expand All @@ -433,12 +427,6 @@ int get_cuda_device(CUdevice *device) {
int create_context(CUdevice device, CUcontext *context) {
CUcontext cuContext = nullptr;

int ret = init_cuda();
if (ret != 0) {
fprintf(stderr, "init_cuda() failed!\n");
return ret;
}

CUresult res = libcu_ops.cuCtxCreate(&cuContext, 0, device);
if (res != CUDA_SUCCESS || cuContext == nullptr) {
return -1;
Expand Down
2 changes: 2 additions & 0 deletions test/providers/cuda_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
extern "C" {
#endif

int init_cuda(void);

int get_cuda_device(CUdevice *device);

int create_context(CUdevice device, CUcontext *context);
Expand Down
10 changes: 8 additions & 2 deletions test/providers/ipc_cuda_prov_consumer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand All @@ -25,7 +25,13 @@ int main(int argc, char *argv[]) {
CUdevice hDevice = -1;
CUcontext hContext = NULL;

int ret = get_cuda_device(&hDevice);
int ret = init_cuda();
if (ret != 0) {
fprintf(stderr, "init_cuda() failed!\n");
return -1;
}

ret = get_cuda_device(&hDevice);
if (ret != 0) {
fprintf(stderr, "get_cuda_device() failed!\n");
return -1;
Expand Down
10 changes: 8 additions & 2 deletions test/providers/ipc_cuda_prov_producer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand All @@ -25,7 +25,13 @@ int main(int argc, char *argv[]) {
CUdevice hDevice = -1;
CUcontext hContext = NULL;

int ret = get_cuda_device(&hDevice);
int ret = init_cuda();
if (ret != 0) {
fprintf(stderr, "init_cuda() failed!\n");
return -1;
}

ret = get_cuda_device(&hDevice);
if (ret != 0) {
fprintf(stderr, "get_cuda_device() failed!\n");
return -1;
Expand Down
10 changes: 8 additions & 2 deletions test/providers/ipc_level_zero_prov_consumer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand Down Expand Up @@ -27,7 +27,13 @@ int main(int argc, char *argv[]) {
ze_device_handle_t hDevice = NULL;
ze_context_handle_t hContext = NULL;

int ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
int ret = utils_ze_init_level_zero();
if (ret != 0) {
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
return -1;
}

ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
if (ret != 0 || hDriver == NULL) {
fprintf(stderr, "utils_ze_find_driver_with_gpu() failed!\n");
return -1;
Expand Down
10 changes: 8 additions & 2 deletions test/providers/ipc_level_zero_prov_producer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand Down Expand Up @@ -27,7 +27,13 @@ int main(int argc, char *argv[]) {
ze_device_handle_t hDevice = NULL;
ze_context_handle_t hContext = NULL;

int ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
int ret = utils_ze_init_level_zero();
if (ret != 0) {
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
return -1;
}

ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
if (ret != 0 || hDriver == NULL) {
fprintf(stderr, "utils_ze_find_driver_with_gpu() failed!\n");
return -1;
Expand Down
Loading
Loading