Skip to content

Commit f388814

Browse files
committed
Start to implement C bindings for CUDASTF (this will later be used in conjunction with cython to generate python support)
1 parent 9832776 commit f388814

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

c/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory(parallel)
2+
add_subdirectory(experimental/stf/)

c/experimental/stf/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
3+
project(CCCL_C_EXPERIMENTAL_STF LANGUAGES CUDA CXX C)
4+
5+
option(CCCL_C_EXPERIMENTAL_STF_ENABLE_TESTING "Build cccl.experimental.c.stf tests." OFF)
6+
7+
# FIXME Ideally this would be handled by presets and install rules, but for now
8+
# consumers may override this to control the target location of cccl.c.experimental.stf.
9+
set(CCCL_C_EXPERIMENTAL_STF_LIBRARY_OUTPUT_DIRECTORY "" CACHE PATH "Override output directory for the cccl.c.experimental.stf library")
10+
mark_as_advanced(CCCL_C_PARALLEL_LIBRARY_OUTPUT_DIRECTORY)
11+
12+
file(GLOB_RECURSE srcs
13+
RELATIVE "${CMAKE_CURRENT_LIST_DIR}"
14+
CONFIGURE_DEPENDS
15+
"src/*.cu" "src/*.cuh"
16+
)
17+
18+
add_library(cccl.c.experimental.stf SHARED ${srcs})
19+
set_property(TARGET cccl.c.experimental.stf PROPERTY POSITION_INDEPENDENT_CODE ON)
20+
cccl_configure_target(cccl.c.experimental.stf DIALECT 17)
21+
22+
# Override the properties set by cccl_configure_target:
23+
if (CCCL_C_EXPERIMENTAL_STF_LIBRARY_OUTPUT_DIRECTORY)
24+
set_target_properties(cccl.c.parallel PROPERTIES
25+
LIBRARY_OUTPUT_DIRECTORY "${CCCL_C_EXPERIMENTAL_STF_LIBRARY_OUTPUT_DIRECTORY}"
26+
ARCHIVE_OUTPUT_DIRECTORY "${CCCL_C_EXPERIMENTAL_STF_LIBRARY_OUTPUT_DIRECTORY}"
27+
)
28+
endif()
29+
30+
find_package(CUDAToolkit REQUIRED)
31+
set_target_properties(cccl.c.experimental.stf PROPERTIES CUDA_RUNTIME_LIBRARY STATIC)
32+
target_link_libraries(cccl.c.experimental.stf PRIVATE
33+
CUDA::cudart_static
34+
CUDA::nvrtc
35+
CUDA::nvJitLink
36+
CUDA::cuda_driver
37+
cccl.compiler_interface_cpp20
38+
cccl.c.parallel.jit_template
39+
CUB::CUB
40+
Thrust::Thrust
41+
nlohmann_json::nlohmann_json
42+
)
43+
# target_compile_definitions(cccl.c.experimental.stf PUBLIC CCCL_C_EXPERIMENTAL=1)
44+
# target_compile_definitions(cccl.c.experimental.stf PRIVATE
45+
# NVRTC_GET_TYPE_NAME=1
46+
# CUB_DISABLE_CDP=1
47+
# CUB_DEFINE_RUNTIME_POLICIES
48+
# )
49+
target_compile_options(cccl.c.experimental.stf PRIVATE $<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:--extended-lambda>)
50+
51+
target_include_directories(cccl.c.experimental.stf PUBLIC "include")
52+
target_include_directories(cccl.c.experimental.stf PRIVATE "src")
53+
54+
if (CCCL_C_Parallel_ENABLE_TESTING)
55+
add_subdirectory(test)
56+
endif()
57+
58+
if (CCCL_C_Parallel_ENABLE_HEADER_TESTING)
59+
include(cmake/CParallelHeaderTesting.cmake)
60+
endif()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// TODO use CCCL_C_EXTERN_C_BEGIN/CCCL_C_EXTERN_C_END
2+
#ifdef __cplusplus
3+
extern "C"
4+
{
5+
#endif
6+
7+
typedef struct stf_ctx_handle stf_ctx_handle;
8+
9+
void stf_ctx_create(stf_ctx_handle *handle);
10+
void stf_ctx_finalize(stf_ctx_handle *handle);
11+
12+
struct stf_task_handle {
13+
void *handle;
14+
};
15+
16+
struct stf_logical_data_handle {
17+
void *handle;
18+
};
19+
20+
#ifdef __cplusplus
21+
}
22+
#endif

c/experimental/stf/src/stf.cu

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <cccl/c/experimental/stf/stf.h>
2+
//#include <cccl/c/parallel/include/cccl/c/extern_c.h>
3+
#include <cuda/experimental/stf.cuh>
4+
5+
using namespace cuda::experimental::stf;
6+
7+
extern "C"
8+
{
9+
10+
struct stf_ctx_handle {
11+
context *ctx;
12+
};
13+
14+
void stf_ctx_create(stf_ctx_handle *handle)
15+
{
16+
return new context{};
17+
}
18+
19+
void stf_ctx_finalize(stf_ctx_handle *handle)
20+
{
21+
if (handle) {
22+
handle->finalize();
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)