Skip to content

Commit ef65aff

Browse files
committed
Refactor Level Zero and CUDA tests
1 parent 4ccf369 commit ef65aff

12 files changed

+148
-164
lines changed

src/utils/utils_level_zero.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,6 @@ int utils_ze_get_drivers(uint32_t *drivers_num_,
344344
ze_driver_handle_t *drivers = NULL;
345345
uint32_t drivers_num = 0;
346346

347-
ret = utils_ze_init_level_zero();
348-
if (ret != 0) {
349-
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
350-
goto init_fail;
351-
}
352-
353347
ze_result = libze_ops.zeDriverGet(&drivers_num, NULL);
354348
if (ze_result != ZE_RESULT_SUCCESS) {
355349
fprintf(stderr, "zeDriverGet() failed!\n");
@@ -386,7 +380,6 @@ int utils_ze_get_drivers(uint32_t *drivers_num_,
386380
*drivers_ = NULL;
387381
}
388382

389-
init_fail:
390383
return ret;
391384
}
392385

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

400-
ret = utils_ze_init_level_zero();
401-
if (ret != 0) {
402-
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
403-
goto init_fail;
404-
}
405-
406393
ze_result = libze_ops.zeDeviceGet(driver, &devices_num, NULL);
407394
if (ze_result != ZE_RESULT_SUCCESS) {
408395
fprintf(stderr, "zeDeviceGet() failed!\n");
@@ -438,7 +425,7 @@ int utils_ze_get_devices(ze_driver_handle_t driver, uint32_t *devices_num_,
438425
free(devices);
439426
devices = NULL;
440427
}
441-
init_fail:
428+
442429
return ret;
443430
}
444431

src/utils/utils_level_zero.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
extern "C" {
1717
#endif
1818

19-
int utils_ze_init_level_zero(void);
2019
int utils_ze_init_level_zero(void);
2120

2221
int utils_ze_get_drivers(uint32_t *drivers_num_, ze_driver_handle_t **drivers_);

test/common/ipc_common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ int run_consumer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
127127
umf_result =
128128
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
129129
if (umf_result != UMF_RESULT_SUCCESS) {
130-
fprintf(stderr,
131-
"[consumer] ERROR: creating OS memory provider failed\n");
130+
fprintf(stderr, "[consumer] ERROR: creating memory provider failed\n");
132131
return -1;
133132
}
134133

@@ -347,8 +346,7 @@ int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
347346
umf_result =
348347
umfMemoryProviderCreate(provider_ops, provider_params, &provider);
349348
if (umf_result != UMF_RESULT_SUCCESS) {
350-
fprintf(stderr,
351-
"[producer] ERROR: creating OS memory provider failed\n");
349+
fprintf(stderr, "[producer] ERROR: creating memory provider failed\n");
352350
return -1;
353351
}
354352

test/ipcFixtures.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
class MemoryAccessor {
2323
public:
24+
virtual ~MemoryAccessor() = default;
2425
virtual void fill(void *ptr, size_t size, const void *pattern,
2526
size_t pattern_size) = 0;
2627
virtual void copy(void *dst_ptr, void *src_ptr, size_t size) = 0;
@@ -162,6 +163,7 @@ struct umfIpcTest : umf_test::test,
162163
TEST_P(umfIpcTest, GetIPCHandleSize) {
163164
size_t size = 0;
164165
umf::pool_unique_handle_t pool = makePool();
166+
ASSERT_NE(pool.get(), nullptr);
165167

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

176178
umf::pool_unique_handle_t pool = makePool();
179+
ASSERT_NE(pool.get(), nullptr);
180+
177181
ret = umfPoolGetIPCHandleSize(pool.get(), nullptr);
178182
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
179183
}
@@ -190,6 +194,8 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
190194
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
191195

192196
umf::pool_unique_handle_t pool = makePool();
197+
ASSERT_NE(pool.get(), nullptr);
198+
193199
ptr = umfPoolMalloc(pool.get(), SIZE);
194200
EXPECT_NE(ptr, nullptr);
195201

@@ -213,6 +219,8 @@ TEST_P(umfIpcTest, BasicFlow) {
213219
constexpr size_t SIZE = 100;
214220
std::vector<int> expected_data(SIZE);
215221
umf::pool_unique_handle_t pool = makePool();
222+
ASSERT_NE(pool.get(), nullptr);
223+
216224
int *ptr = (int *)umfPoolMalloc(pool.get(), SIZE * sizeof(int));
217225
EXPECT_NE(ptr, nullptr);
218226

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

287296
for (size_t i = 0; i < NUM_POOLS; ++i) {
288297
pools_to_open.push_back(makePool());
@@ -341,6 +350,8 @@ TEST_P(umfIpcTest, GetPoolByOpenedHandle) {
341350
TEST_P(umfIpcTest, AllocFreeAllocTest) {
342351
constexpr size_t SIZE = 64 * 1024;
343352
umf::pool_unique_handle_t pool = makePool();
353+
ASSERT_NE(pool.get(), nullptr);
354+
344355
umf_ipc_handler_handle_t ipcHandler = nullptr;
345356

346357
umf_result_t ret = umfPoolGetIPCHandler(pool.get(), &ipcHandler);
@@ -400,7 +411,9 @@ TEST_P(umfIpcTest, openInTwoIpcHandlers) {
400411
constexpr size_t SIZE = 100;
401412
std::vector<int> expected_data(SIZE);
402413
umf::pool_unique_handle_t pool1 = makePool();
414+
ASSERT_NE(pool1.get(), nullptr);
403415
umf::pool_unique_handle_t pool2 = makePool();
416+
ASSERT_NE(pool2.get(), nullptr);
404417
umf_ipc_handler_handle_t ipcHandler1 = nullptr;
405418
umf_ipc_handler_handle_t ipcHandler2 = nullptr;
406419

@@ -465,6 +478,7 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
465478
constexpr size_t ALLOC_SIZE = 100;
466479
constexpr size_t NUM_POINTERS = 100;
467480
umf::pool_unique_handle_t pool = makePool();
481+
ASSERT_NE(pool.get(), nullptr);
468482

469483
for (size_t i = 0; i < NUM_POINTERS; ++i) {
470484
void *ptr = umfPoolMalloc(pool.get(), ALLOC_SIZE);
@@ -514,6 +528,7 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
514528
constexpr size_t ALLOC_SIZE = 100;
515529
constexpr size_t NUM_POINTERS = 100;
516530
umf::pool_unique_handle_t pool = makePool();
531+
ASSERT_NE(pool.get(), nullptr);
517532

518533
for (size_t i = 0; i < NUM_POINTERS; ++i) {
519534
void *ptr = umfPoolMalloc(pool.get(), ALLOC_SIZE);

test/providers/cuda_helpers.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void init_cuda_once() {
406406
InitResult = init_cuda_lib();
407407
}
408408

409-
int init_cuda() {
409+
int init_cuda(void) {
410410
utils_init_once(&cuda_init_flag, init_cuda_once);
411411

412412
return InitResult;
@@ -415,12 +415,6 @@ int init_cuda() {
415415
int get_cuda_device(CUdevice *device) {
416416
CUdevice cuDevice = -1;
417417

418-
int ret = init_cuda();
419-
if (ret != 0) {
420-
fprintf(stderr, "init_cuda() failed!\n");
421-
return ret;
422-
}
423-
424418
CUresult res = libcu_ops.cuDeviceGet(&cuDevice, 0);
425419
if (res != CUDA_SUCCESS || cuDevice < 0) {
426420
return -1;
@@ -433,12 +427,6 @@ int get_cuda_device(CUdevice *device) {
433427
int create_context(CUdevice device, CUcontext *context) {
434428
CUcontext cuContext = nullptr;
435429

436-
int ret = init_cuda();
437-
if (ret != 0) {
438-
fprintf(stderr, "init_cuda() failed!\n");
439-
return ret;
440-
}
441-
442430
CUresult res = libcu_ops.cuCtxCreate(&cuContext, 0, device);
443431
if (res != CUDA_SUCCESS || cuContext == nullptr) {
444432
return -1;

test/providers/cuda_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
extern "C" {
2727
#endif
2828

29+
int init_cuda(void);
30+
2931
int get_cuda_device(CUdevice *device);
3032

3133
int create_context(CUdevice device, CUcontext *context);

test/providers/ipc_cuda_prov_consumer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -25,7 +25,13 @@ int main(int argc, char *argv[]) {
2525
CUdevice hDevice = -1;
2626
CUcontext hContext = NULL;
2727

28-
int ret = get_cuda_device(&hDevice);
28+
int ret = init_cuda();
29+
if (ret != 0) {
30+
fprintf(stderr, "init_cuda() failed!\n");
31+
return -1;
32+
}
33+
34+
ret = get_cuda_device(&hDevice);
2935
if (ret != 0) {
3036
fprintf(stderr, "get_cuda_device() failed!\n");
3137
return -1;

test/providers/ipc_cuda_prov_producer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -25,7 +25,13 @@ int main(int argc, char *argv[]) {
2525
CUdevice hDevice = -1;
2626
CUcontext hContext = NULL;
2727

28-
int ret = get_cuda_device(&hDevice);
28+
int ret = init_cuda();
29+
if (ret != 0) {
30+
fprintf(stderr, "init_cuda() failed!\n");
31+
return -1;
32+
}
33+
34+
ret = get_cuda_device(&hDevice);
2935
if (ret != 0) {
3036
fprintf(stderr, "get_cuda_device() failed!\n");
3137
return -1;

test/providers/ipc_level_zero_prov_consumer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -27,7 +27,13 @@ int main(int argc, char *argv[]) {
2727
ze_device_handle_t hDevice = NULL;
2828
ze_context_handle_t hContext = NULL;
2929

30-
int ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
30+
int ret = utils_ze_init_level_zero();
31+
if (ret != 0) {
32+
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
33+
return -1;
34+
}
35+
36+
ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
3137
if (ret != 0 || hDriver == NULL) {
3238
fprintf(stderr, "utils_ze_find_driver_with_gpu() failed!\n");
3339
return -1;

test/providers/ipc_level_zero_prov_producer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -27,7 +27,13 @@ int main(int argc, char *argv[]) {
2727
ze_device_handle_t hDevice = NULL;
2828
ze_context_handle_t hContext = NULL;
2929

30-
int ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
30+
int ret = utils_ze_init_level_zero();
31+
if (ret != 0) {
32+
fprintf(stderr, "utils_ze_init_level_zero() failed!\n");
33+
return -1;
34+
}
35+
36+
ret = utils_ze_find_driver_with_gpu(&driver_idx, &hDriver);
3137
if (ret != 0 || hDriver == NULL) {
3238
fprintf(stderr, "utils_ze_find_driver_with_gpu() failed!\n");
3339
return -1;

0 commit comments

Comments
 (0)