Skip to content

Commit ea08f87

Browse files
committed
add CUDA provider
1 parent 70b5d21 commit ea08f87

25 files changed

+755
-9
lines changed

.github/workflows/basic.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ jobs:
122122
- name: Set ptrace value for IPC test
123123
run: sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope"
124124

125+
# TODO cuda
126+
125127
- name: Configure build
126128
run: >
127129
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh &&' || ''}}
@@ -133,6 +135,7 @@ jobs:
133135
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
134136
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
135137
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=${{matrix.level_zero_provider}}
138+
-DUMF_BUILD_CUDA_PROVIDER=ON
136139
-DUMF_FORMAT_CODE_STYLE=OFF
137140
-DUMF_DEVELOPER_MODE=ON
138141
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
@@ -287,6 +290,7 @@ jobs:
287290
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
288291
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
289292
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
293+
-DUMF_BUILD_CUDA_PROVIDER=ON
290294
-DUMF_TESTS_FAIL_ON_SKIP=ON
291295
-DUMF_LINK_HWLOC_STATICALLY=ON
292296
@@ -329,6 +333,7 @@ jobs:
329333
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
330334
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
331335
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
336+
-DUMF_BUILD_CUDA_PROVIDER=ON
332337
-DUMF_TESTS_FAIL_ON_SKIP=ON
333338
-DUMF_LINK_HWLOC_STATICALLY=ON
334339

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
-DUMF_FORMAT_CODE_STYLE=OFF
6464
-DUMF_DEVELOPER_MODE=OFF
6565
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
66+
-DUMF_BUILD_CUDA_PROVIDER=ON
6667
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
6768
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
6869

.github/workflows/codeql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
-DUMF_DEVELOPER_MODE=ON
8585
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
8686
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
87+
-DUMF_BUILD_CUDA_PROVIDER=ON
8788
-DUMF_TESTS_FAIL_ON_SKIP=ON
8889
8990
- name: Build

.github/workflows/fast.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ jobs:
106106
-DUMF_BUILD_TESTS=${{matrix.build_tests}}
107107
-DUMF_BUILD_EXAMPLES=ON
108108
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
109+
-DUMF_BUILD_CUDA_PROVIDER=ON
109110
-DUMF_TESTS_FAIL_ON_SKIP=ON
110111
-DUMF_BUILD_SHARED_LIBRARY=ON
111112
${{matrix.extra_build_options}}

.github/workflows/gpu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
6464
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
6565
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
66+
-DUMF_BUILD_CUDA_PROVIDER=ON
6667
-DUMF_TESTS_FAIL_ON_SKIP=ON
6768
6869
- name: Configure build for Ubuntu
@@ -84,6 +85,7 @@ jobs:
8485
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
8586
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
8687
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
88+
-DUMF_BUILD_CUDA_PROVIDER=ON
8789
-DUMF_TESTS_FAIL_ON_SKIP=ON
8890
8991
- name: Build UMF

.github/workflows/nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
8080
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
8181
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
82+
-DUMF_BUILD_CUDA_PROVIDER=OFF
8283
-DUMF_USE_VALGRIND=1
8384
-DUMF_TESTS_FAIL_ON_SKIP=ON
8485

.github/workflows/pr_push.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
-DUMF_FORMAT_CODE_STYLE=ON
3838
-DUMF_BUILD_TESTS=OFF
3939
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
40+
-DUMF_BUILD_CUDA_PROVIDER=OFF
4041
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
4142
4243
- name: Check C/C++ formatting

.github/workflows/sanitizers.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
5656
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
5757
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
58+
-DUMF_BUILD_CUDA_PROVIDER=ON
5859
-DUMF_FORMAT_CODE_STYLE=OFF
5960
-DUMF_DEVELOPER_MODE=ON
6061
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
@@ -130,6 +131,7 @@ jobs:
130131
-DUMF_USE_ASAN=${{matrix.sanitizers.asan}}
131132
-DUMF_BUILD_EXAMPLES=ON
132133
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
134+
-DUMF_BUILD_CUDA_PROVIDER=OFF
133135
-DUMF_TESTS_FAIL_ON_SKIP=ON
134136
135137
- name: Build UMF

.github/workflows/valgrind.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
3636
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
3737
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
38+
-DUMF_BUILD_CUDA_PROVIDER=OFF
3839
-DUMF_USE_VALGRIND=1
3940
-DUMF_TESTS_FAIL_ON_SKIP=ON
4041

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ find_package(PkgConfig)
3636
# Build Options
3737
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
3838
option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)
39+
option(UMF_BUILD_CUDA_PROVIDER "Build CUDA memory provider" ON)
3940
option(UMF_BUILD_LIBUMF_POOL_DISJOINT
4041
"Build the libumf_pool_disjoint static library" OFF)
4142
option(UMF_BUILD_LIBUMF_POOL_JEMALLOC
@@ -399,6 +400,11 @@ if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
399400
add_optional_symbol(umfLevelZeroMemoryProviderOps)
400401
endif()
401402

403+
# Conditional configuration for CUDA provider
404+
if(UMF_BUILD_CUDA_PROVIDER)
405+
add_optional_symbol(umfCUDAMemoryProviderOps)
406+
endif()
407+
402408
if(NOT UMF_DISABLE_HWLOC)
403409
add_optional_symbol(umfOsMemoryProviderOps)
404410
endif()

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ List of options provided by CMake:
101101
| - | - | - | - |
102102
| UMF_BUILD_SHARED_LIBRARY | Build UMF as shared library | ON/OFF | OFF |
103103
| UMF_BUILD_LEVEL_ZERO_PROVIDER | Build Level Zero memory provider | ON/OFF | ON |
104+
| UMF_BUILD_CUDA_PROVIDER | Build CUDA memory provider | ON/OFF | ON |
104105
| UMF_BUILD_LIBUMF_POOL_DISJOINT | Build the libumf_pool_disjoint static library | ON/OFF | OFF |
105106
| UMF_BUILD_LIBUMF_POOL_JEMALLOC | Build the libumf_pool_jemalloc static library | ON/OFF | OFF |
106107
| UMF_BUILD_TESTS | Build UMF tests | ON/OFF | ON |
@@ -172,6 +173,10 @@ Additionally, required for tests:
172173
5) Required packages:
173174
- liblevel-zero-dev (Linux) or level-zero-sdk (Windows)
174175

176+
#### CUDA memory provider
177+
178+
TODO
179+
175180
### Memory pool managers
176181

177182
#### Proxy pool (part of libumf)

benchmark/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ function(add_umf_benchmark)
8585
target_compile_definitions(${BENCH_NAME}
8686
PRIVATE UMF_BUILD_LEVEL_ZERO_PROVIDER=1)
8787
endif()
88+
if(UMF_BUILD_CUDA_PROVIDER)
89+
target_compile_definitions(${BENCH_NAME}
90+
PRIVATE UMF_BUILD_CUDA_PROVIDER=1)
91+
endif()
8892
if(UMF_BUILD_GPU_TESTS)
8993
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_GPU_TESTS=1)
9094
endif()

benchmark/ubench.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ UBENCH_EX(ipc, disjoint_pool_with_level_zero_provider) {
505505
}
506506
#endif /* (defined UMF_BUILD_LIBUMF_POOL_DISJOINT && defined UMF_BUILD_LEVEL_ZERO_PROVIDER && defined UMF_BUILD_GPU_TESTS) */
507507

508+
// TODO cuda
509+
508510
UBENCH_MAIN()
509511

510512
#if defined(_MSC_VER)

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if(UMF_POOL_SCALABLE_ENABLED)
4040
"${DLL_PATH_LIST}")
4141
endif()
4242
endif()
43-
43+
# TODO cuda
4444
if(UMF_BUILD_GPU_EXAMPLES
4545
AND UMF_BUILD_LIBUMF_POOL_DISJOINT
4646
AND UMF_BUILD_LEVEL_ZERO_PROVIDER)

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ are used for this purpose.
1212
### Requirements
1313
* libtbb-dev (libtbbmalloc.so.2) on Linux or tbb (tbbmalloc.dll) on Windows
1414

15+
TODO CUDA
16+
1517
## GPU shared memory
1618

1719
This example demonstrates the usage of Intel's Level Zero API for accessing GPU

include/umf/memory_provider.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
extern "C" {
1818
#endif
1919

20+
typedef enum umf_usm_memory_type_t {
21+
UMF_MEMORY_TYPE_UNKNOWN = 0, ///< The memory pointed to is of unknown type
22+
UMF_MEMORY_TYPE_HOST, ///< The memory pointed to is a host allocation
23+
UMF_MEMORY_TYPE_DEVICE, ///< The memory pointed to is a device allocation
24+
UMF_MEMORY_TYPE_SHARED, ///< The memory pointed to is a shared ownership allocation
25+
} umf_usm_memory_type_t;
26+
2027
/// @brief A struct containing memory provider specific set of functions
2128
typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
2229

include/umf/providers/provider_cuda.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#ifndef UMF_PROVIDER_CUDA_H
9+
#define UMF_PROVIDER_CUDA_H
10+
11+
#include "umf/memory_provider.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/// @brief CUDA Memory Provider settings struct
18+
typedef struct cuda_memory_provider_params_t {
19+
void *cuda_context_handle; ///< Handle to the CUDA context
20+
void *cuda_device_handle; ///< Handle to the CUDA device
21+
umf_usm_memory_type_t memory_type; ///< Allocation memory type
22+
} cuda_memory_provider_params_t;
23+
24+
umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void);
25+
26+
#ifdef __cplusplus
27+
}
28+
#endif
29+
30+
#endif /* UMF_PROVIDER_CUDA_H */

include/umf/providers/provider_level_zero.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
extern "C" {
1515
#endif
1616

17-
/// @brief USM memory allocation type
18-
typedef enum umf_usm_memory_type_t {
19-
UMF_MEMORY_TYPE_UNKNOWN = 0, ///< The memory pointed to is of unknown type
20-
UMF_MEMORY_TYPE_HOST, ///< The memory pointed to is a host allocation
21-
UMF_MEMORY_TYPE_DEVICE, ///< The memory pointed to is a device allocation
22-
UMF_MEMORY_TYPE_SHARED, ///< The memory pointed to is a shared ownership allocation
23-
} umf_usm_memory_type_t;
24-
2517
/// @brief Level Zero Memory Provider settings struct
2618
typedef struct level_zero_memory_provider_params_t {
2719
void *level_zero_context_handle; ///< Handle to the Level Zero context

scripts/qemu/run-build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cd build
2121
cmake .. \
2222
-DCMAKE_BUILD_TYPE=Debug \
2323
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON \
24+
-DUMF_BUILD_CUDA_PROVIDER=ON \
2425
-DUMF_FORMAT_CODE_STYLE=OFF \
2526
-DUMF_DEVELOPER_MODE=ON \
2627
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON \

src/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
3737
message(STATUS "Level Zero include directory: ${LEVEL_ZERO_INCLUDE_DIRS}")
3838
endif()
3939

40+
if(UMF_BUILD_CUDA_PROVIDER)
41+
include(FetchContent)
42+
43+
set(CUDA_REPO
44+
"https://gitlab.com/nvidia/headers/cuda-individual/cudart.git")
45+
set(CUDA_TAG cuda-12.5.1)
46+
47+
message(STATUS "Installing CUDA ${CUDA_TAG} from ${CUDA_REPO} ...")
48+
49+
FetchContent_Declare(
50+
cuda-headers
51+
GIT_REPOSITORY ${CUDA_REPO}
52+
GIT_TAG ${CUDA_TAG}
53+
EXCLUDE_FROM_ALL)
54+
55+
FetchContent_GetProperties(cuda-headers)
56+
if(NOT cuda-headers_POPULATED)
57+
FetchContent_Populate(cuda-headers)
58+
endif()
59+
60+
set(CUDA_INCLUDE_DIRS
61+
${cuda-headers_SOURCE_DIR}
62+
CACHE PATH "Path to CUDA headers")
63+
message(STATUS "CUDA include directory: ${CUDA_INCLUDE_DIRS}")
64+
endif()
65+
4066
add_subdirectory(utils)
4167

4268
set(UMF_LIBS $<BUILD_INTERFACE:umf_utils>)
@@ -191,6 +217,7 @@ target_link_directories(umf PRIVATE ${UMF_PRIVATE_LIBRARY_DIRS})
191217

192218
target_compile_definitions(umf PRIVATE ${UMF_COMMON_COMPILE_DEFINITIONS})
193219

220+
# TODO
194221
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
195222
target_sources(umf PRIVATE provider/provider_level_zero.c)
196223

@@ -206,6 +233,12 @@ if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
206233
"UMF_BUILD_LEVEL_ZERO_PROVIDER=1")
207234
endif()
208235

236+
if(UMF_BUILD_CUDA_PROVIDER)
237+
target_sources(umf PRIVATE provider/provider_cuda.c)
238+
set(UMF_COMPILE_DEFINITIONS ${UMF_COMPILE_DEFINITIONS}
239+
"UMF_BUILD_CUDA_PROVIDER=1")
240+
endif()
241+
209242
add_library(${PROJECT_NAME}::umf ALIAS umf)
210243

211244
if(LIBHWLOC_INCLUDE_DIRS)
@@ -216,6 +249,10 @@ if(LEVEL_ZERO_INCLUDE_DIRS)
216249
target_include_directories(umf PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})
217250
endif()
218251

252+
if(CUDA_INCLUDE_DIRS)
253+
target_include_directories(umf PRIVATE ${CUDA_INCLUDE_DIRS})
254+
endif()
255+
219256
target_include_directories(
220257
umf
221258
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>

0 commit comments

Comments
 (0)