Skip to content

Commit 9d1a9b5

Browse files
authored
Merge pull request #947 from ldorau/Move_implementation_from_examples_level_zero.h_to_examples_level_zero.c
Move implementation from `examples_level_zero.h` to `examples_level_zero.c`
2 parents 4b18f52 + 022ec6b commit 9d1a9b5

File tree

7 files changed

+55
-21
lines changed

7 files changed

+55
-21
lines changed

examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ if(UMF_BUILD_GPU_EXAMPLES
4949
add_umf_executable(
5050
NAME ${EXAMPLE_NAME}
5151
SRCS level_zero_shared_memory/level_zero_shared_memory.c
52+
common/examples_level_zero_helpers.c
5253
LIBS disjoint_pool ze_loader umf)
5354

5455
target_include_directories(
@@ -127,6 +128,7 @@ if(UMF_BUILD_GPU_EXAMPLES
127128
add_umf_executable(
128129
NAME ${EXAMPLE_NAME}
129130
SRCS ipc_level_zero/ipc_level_zero.c
131+
common/examples_level_zero_helpers.c
130132
LIBS disjoint_pool ze_loader umf)
131133

132134
target_include_directories(

examples/common/examples_level_zero.h renamed to examples/common/examples_level_zero_helpers.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@
77
*
88
*/
99

10-
#ifndef UMF_EXAMPLE_UTILS_LEVEL_ZERO_H
11-
#define UMF_EXAMPLE_UTILS_LEVEL_ZERO_H
12-
1310
#include <stdio.h>
1411
#include <stdlib.h>
1512

16-
// To use the Level Zero API, the Level Zero SDK has to be installed
17-
// on the system
18-
#ifdef _WIN32
19-
#include <ze_api.h>
20-
#else
21-
#include <level_zero/ze_api.h>
22-
#endif
13+
#include "examples_level_zero_helpers.h"
2314

24-
static int init_level_zero(void) {
15+
int init_level_zero(void) {
2516
ze_init_flag_t flags = ZE_INIT_FLAG_GPU_ONLY;
2617
ze_result_t result = zeInit(flags);
2718
if (result != ZE_RESULT_SUCCESS) {
@@ -118,8 +109,7 @@ static inline int get_devices(ze_driver_handle_t driver, uint32_t *devices_num_,
118109
return ret;
119110
}
120111

121-
static inline int find_driver_with_gpu(uint32_t *driver_idx,
122-
ze_driver_handle_t *driver_) {
112+
int find_driver_with_gpu(uint32_t *driver_idx, ze_driver_handle_t *driver_) {
123113
int ret = 0;
124114
ze_result_t ze_result;
125115
uint32_t drivers_num = 0;
@@ -184,8 +174,7 @@ static inline int find_driver_with_gpu(uint32_t *driver_idx,
184174
return ret;
185175
}
186176

187-
static inline int find_gpu_device(ze_driver_handle_t driver,
188-
ze_device_handle_t *device_) {
177+
int find_gpu_device(ze_driver_handle_t driver, ze_device_handle_t *device_) {
189178
int ret = -1;
190179
uint32_t devices_num = 0;
191180
ze_device_handle_t *devices = NULL;
@@ -415,5 +404,3 @@ int destroy_context(ze_context_handle_t context) {
415404

416405
return 0;
417406
}
418-
419-
#endif // UMF_EXAMPLE_UTILS_LEVEL_ZERO_H
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (C) 2024 Intel Corporation
4+
*
5+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
*
8+
*/
9+
10+
#ifndef UMF_EXAMPLES_LEVEL_ZERO_H
11+
#define UMF_EXAMPLES_LEVEL_ZERO_H
12+
13+
// To use the Level Zero API, the Level Zero SDK has to be installed
14+
// on the system
15+
#ifdef _WIN32
16+
#include <ze_api.h>
17+
#else
18+
#include <level_zero/ze_api.h>
19+
#endif
20+
21+
int init_level_zero(void);
22+
23+
int create_context(ze_driver_handle_t driver, ze_context_handle_t *context);
24+
25+
int destroy_context(ze_context_handle_t context);
26+
27+
int find_driver_with_gpu(uint32_t *driver_idx, ze_driver_handle_t *driver_);
28+
29+
int find_gpu_device(ze_driver_handle_t driver, ze_device_handle_t *device_);
30+
31+
int level_zero_fill(ze_context_handle_t context, ze_device_handle_t device,
32+
void *ptr, size_t size, const void *pattern,
33+
size_t pattern_size);
34+
35+
int level_zero_copy(ze_context_handle_t context, ze_device_handle_t device,
36+
void *dst_ptr, void *src_ptr, size_t size);
37+
38+
#endif /* UMF_EXAMPLES_LEVEL_ZERO_H */

examples/ipc_level_zero/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ message(STATUS "Level Zero include directory: ${LEVEL_ZERO_INCLUDE_DIRS}")
4545

4646
# build the example
4747
set(EXAMPLE_NAME umf_example_ipc_level_zero)
48-
add_executable(${EXAMPLE_NAME} ipc_level_zero.c)
48+
add_executable(
49+
${EXAMPLE_NAME} ipc_level_zero.c
50+
${UMF_EXAMPLE_DIR}/common/examples_level_zero_helpers.c)
4951
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS}
5052
${UMF_EXAMPLE_DIR}/common)
5153
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARY_DIRS}

examples/ipc_level_zero/ipc_level_zero.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
*/
99

1010
#include <stdio.h>
11+
#include <stdlib.h>
1112

1213
#include "umf/ipc.h"
1314
#include "umf/memory_pool.h"
1415
#include "umf/pools/pool_disjoint.h"
1516
#include "umf/providers/provider_level_zero.h"
1617

17-
#include "examples_level_zero.h"
18+
#include "examples_level_zero_helpers.h"
1819

1920
int create_level_zero_pool(ze_context_handle_t context,
2021
ze_device_handle_t device,

examples/level_zero_shared_memory/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ message(STATUS "Level Zero include directory: ${LEVEL_ZERO_INCLUDE_DIRS}")
4545

4646
# build the example
4747
set(EXAMPLE_NAME umf_example_level_zero_shared_memory)
48-
add_executable(${EXAMPLE_NAME} level_zero_shared_memory.c)
48+
add_executable(
49+
${EXAMPLE_NAME} level_zero_shared_memory.c
50+
${UMF_EXAMPLE_DIR}/common/examples_level_zero_helpers.c)
4951
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS}
5052
${UMF_EXAMPLE_DIR}/common)
5153
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARY_DIRS}

examples/level_zero_shared_memory/level_zero_shared_memory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
*
88
*/
99

10+
#include <stdio.h>
11+
1012
#include <umf/memory_pool.h>
1113
#include <umf/pools/pool_disjoint.h>
1214
#include <umf/providers/provider_level_zero.h>
1315

14-
#include "examples_level_zero.h"
16+
#include "examples_level_zero_helpers.h"
1517

1618
int main(void) {
1719
// A result object for storing UMF API result status

0 commit comments

Comments
 (0)