Skip to content

Move implementation from examples_level_zero.h to examples_level_zero.c #947

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
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
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if(UMF_BUILD_GPU_EXAMPLES
add_umf_executable(
NAME ${EXAMPLE_NAME}
SRCS level_zero_shared_memory/level_zero_shared_memory.c
common/examples_level_zero_helpers.c
LIBS disjoint_pool ze_loader umf)

target_include_directories(
Expand Down Expand Up @@ -127,6 +128,7 @@ if(UMF_BUILD_GPU_EXAMPLES
add_umf_executable(
NAME ${EXAMPLE_NAME}
SRCS ipc_level_zero/ipc_level_zero.c
common/examples_level_zero_helpers.c
LIBS disjoint_pool ze_loader umf)

target_include_directories(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,12 @@
*
*/

#ifndef UMF_EXAMPLE_UTILS_LEVEL_ZERO_H
#define UMF_EXAMPLE_UTILS_LEVEL_ZERO_H

#include <stdio.h>
#include <stdlib.h>

// To use the Level Zero API, the Level Zero SDK has to be installed
// on the system
#ifdef _WIN32
#include <ze_api.h>
#else
#include <level_zero/ze_api.h>
#endif
#include "examples_level_zero_helpers.h"

static int init_level_zero(void) {
int init_level_zero(void) {
ze_init_flag_t flags = ZE_INIT_FLAG_GPU_ONLY;
ze_result_t result = zeInit(flags);
if (result != ZE_RESULT_SUCCESS) {
Expand Down Expand Up @@ -118,8 +109,7 @@ static inline int get_devices(ze_driver_handle_t driver, uint32_t *devices_num_,
return ret;
}

static inline int find_driver_with_gpu(uint32_t *driver_idx,
ze_driver_handle_t *driver_) {
int find_driver_with_gpu(uint32_t *driver_idx, ze_driver_handle_t *driver_) {
int ret = 0;
ze_result_t ze_result;
uint32_t drivers_num = 0;
Expand Down Expand Up @@ -184,8 +174,7 @@ static inline int find_driver_with_gpu(uint32_t *driver_idx,
return ret;
}

static inline int find_gpu_device(ze_driver_handle_t driver,
ze_device_handle_t *device_) {
int find_gpu_device(ze_driver_handle_t driver, ze_device_handle_t *device_) {
int ret = -1;
uint32_t devices_num = 0;
ze_device_handle_t *devices = NULL;
Expand Down Expand Up @@ -415,5 +404,3 @@ int destroy_context(ze_context_handle_t context) {

return 0;
}

#endif // UMF_EXAMPLE_UTILS_LEVEL_ZERO_H
38 changes: 38 additions & 0 deletions examples/common/examples_level_zero_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/

#ifndef UMF_EXAMPLES_LEVEL_ZERO_H
#define UMF_EXAMPLES_LEVEL_ZERO_H

// To use the Level Zero API, the Level Zero SDK has to be installed
// on the system
#ifdef _WIN32
#include <ze_api.h>
#else
#include <level_zero/ze_api.h>
#endif

int init_level_zero(void);

int create_context(ze_driver_handle_t driver, ze_context_handle_t *context);

int destroy_context(ze_context_handle_t context);

int find_driver_with_gpu(uint32_t *driver_idx, ze_driver_handle_t *driver_);

int find_gpu_device(ze_driver_handle_t driver, ze_device_handle_t *device_);

int level_zero_fill(ze_context_handle_t context, ze_device_handle_t device,
void *ptr, size_t size, const void *pattern,
size_t pattern_size);

int level_zero_copy(ze_context_handle_t context, ze_device_handle_t device,
void *dst_ptr, void *src_ptr, size_t size);

#endif /* UMF_EXAMPLES_LEVEL_ZERO_H */
4 changes: 3 additions & 1 deletion examples/ipc_level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ message(STATUS "Level Zero include directory: ${LEVEL_ZERO_INCLUDE_DIRS}")

# build the example
set(EXAMPLE_NAME umf_example_ipc_level_zero)
add_executable(${EXAMPLE_NAME} ipc_level_zero.c)
add_executable(
${EXAMPLE_NAME} ipc_level_zero.c
${UMF_EXAMPLE_DIR}/common/examples_level_zero_helpers.c)
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS}
${UMF_EXAMPLE_DIR}/common)
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARY_DIRS}
Expand Down
3 changes: 2 additions & 1 deletion examples/ipc_level_zero/ipc_level_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
*/

#include <stdio.h>
#include <stdlib.h>

#include "umf/ipc.h"
#include "umf/memory_pool.h"
#include "umf/pools/pool_disjoint.h"
#include "umf/providers/provider_level_zero.h"

#include "examples_level_zero.h"
#include "examples_level_zero_helpers.h"

int create_level_zero_pool(ze_context_handle_t context,
ze_device_handle_t device,
Expand Down
4 changes: 3 additions & 1 deletion examples/level_zero_shared_memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ message(STATUS "Level Zero include directory: ${LEVEL_ZERO_INCLUDE_DIRS}")

# build the example
set(EXAMPLE_NAME umf_example_level_zero_shared_memory)
add_executable(${EXAMPLE_NAME} level_zero_shared_memory.c)
add_executable(
${EXAMPLE_NAME} level_zero_shared_memory.c
${UMF_EXAMPLE_DIR}/common/examples_level_zero_helpers.c)
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS}
${UMF_EXAMPLE_DIR}/common)
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARY_DIRS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*
*/

#include <stdio.h>

#include <umf/memory_pool.h>
#include <umf/pools/pool_disjoint.h>
#include <umf/providers/provider_level_zero.h>

#include "examples_level_zero.h"
#include "examples_level_zero_helpers.h"

int main(void) {
// A result object for storing UMF API result status
Expand Down
Loading