-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement C API for device reduction (#2256)
* Implement C device reduce * Format * Fix device-specific module loading * Don't need a context at build step now * Address review feedback
- Loading branch information
1 parent
1e1af8d
commit 5a4881b
Showing
10 changed files
with
1,686 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.30) | ||
|
||
project(cccl.c LANGUAGES CUDA CXX) | ||
|
||
add_library(cccl.c SHARED src/reduce.cu) | ||
set_property(TARGET cccl.c PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
set_property(TARGET cccl.c PROPERTY CXX_STANDARD 20) | ||
set_property(TARGET cccl.c PROPERTY CUDA_STANDARD 20) | ||
|
||
find_package(CUDAToolkit REQUIRED) | ||
|
||
# TODO Use static versions of cudart, nvrtc, and nvJitLink | ||
target_link_libraries(cccl.c PRIVATE CUDA::cudart | ||
CUDA::nvrtc | ||
CUDA::nvJitLink | ||
CUDA::cuda_driver) | ||
target_compile_definitions(cccl.c PRIVATE NVRTC_GET_TYPE_NAME=1 CCCL_C_EXPERIMENTAL=1) | ||
target_include_directories(cccl.c PUBLIC "include") | ||
|
||
add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of CUDA Experimental in CUDA C++ Core Libraries, | ||
// under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#ifndef CCCL_C_EXPERIMENTAL | ||
# warning "C exposure is experimental and subject to change. Define CCCL_C_EXPERIMENTAL to acknowledge this warning." | ||
#else // ^^^ !CCCL_C_EXPERIMENTAL ^^^ / vvv CCCL_C_EXPERIMENTAL vvv | ||
|
||
# include <cuda.h> | ||
|
||
# include <cccl/types.h> | ||
|
||
struct cccl_device_reduce_build_result_t | ||
{ | ||
int cc; | ||
void* cubin; | ||
size_t cubin_size; | ||
CUlibrary library; | ||
CUkernel single_tile_kernel; | ||
CUkernel single_tile_second_kernel; | ||
CUkernel reduction_kernel; | ||
}; | ||
|
||
// TODO return a union of nvtx/cuda/nvrtc errors or a string? | ||
extern "C" CCCL_C_API CUresult cccl_device_reduce_build( | ||
cccl_device_reduce_build_result_t* build, | ||
cccl_iterator_t d_in, | ||
cccl_iterator_t d_out, | ||
cccl_op_t op, | ||
cccl_value_t init, | ||
int cc_major, | ||
int cc_minor, | ||
const char* cub_path, | ||
const char* thrust_path, | ||
const char* libcudacxx_path, | ||
const char* ctk_path) noexcept; | ||
|
||
extern "C" CCCL_C_API CUresult cccl_device_reduce( | ||
cccl_device_reduce_build_result_t build, | ||
void* d_temp_storage, | ||
size_t* temp_storage_bytes, | ||
cccl_iterator_t d_in, | ||
cccl_iterator_t d_out, | ||
unsigned long long num_items, | ||
cccl_op_t op, | ||
cccl_value_t init, | ||
CUstream stream) noexcept; | ||
|
||
extern "C" CCCL_C_API CUresult cccl_device_reduce_cleanup(cccl_device_reduce_build_result_t* bld_ptr); | ||
|
||
#endif // CCCL_C_EXPERIMENTAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of CUDA Experimental in CUDA C++ Core Libraries, | ||
// under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#ifndef CCCL_C_EXPERIMENTAL | ||
# warning "C exposure is experimental and subject to change. Define CCCL_C_EXPERIMENTAL to acknowledge this warning." | ||
#else // ^^^ !CCCL_C_EXPERIMENTAL ^^^ / vvv CCCL_C_EXPERIMENTAL vvv | ||
|
||
# if defined(_WIN32) | ||
# define CCCL_C_API __declspec(dllexport) | ||
# else | ||
# define CCCL_C_API __attribute__((visibility("default"))) | ||
# endif | ||
|
||
enum class cccl_type_enum | ||
{ | ||
INT8 = 0, | ||
INT16 = 1, | ||
INT32 = 2, | ||
INT64 = 3, | ||
UINT8 = 4, | ||
UINT16 = 5, | ||
UINT32 = 6, | ||
UINT64 = 7, | ||
FLOAT32 = 8, | ||
FLOAT64 = 9, | ||
STORAGE = 10 | ||
}; | ||
|
||
struct cccl_type_info | ||
{ | ||
int size; | ||
int alignment; | ||
cccl_type_enum type; | ||
}; | ||
|
||
enum class cccl_op_kind_t | ||
{ | ||
stateless, | ||
stateful | ||
}; | ||
|
||
struct cccl_op_t | ||
{ | ||
cccl_op_kind_t type; | ||
const char* name; | ||
const char* ltoir; | ||
int ltoir_size; | ||
int size; | ||
int alignment; | ||
void* state; | ||
}; | ||
|
||
enum class cccl_iterator_kind_t | ||
{ | ||
pointer, | ||
iterator | ||
}; | ||
|
||
struct cccl_value_t | ||
{ | ||
cccl_type_info type; | ||
void* state; | ||
}; | ||
|
||
struct cccl_iterator_t | ||
{ | ||
int size; | ||
int alignment; | ||
cccl_iterator_kind_t type; | ||
cccl_op_t advance; | ||
cccl_op_t dereference; | ||
cccl_type_info value_type; | ||
void* state; | ||
}; | ||
|
||
#endif // CCCL_C_EXPERIMENTAL |
Oops, something went wrong.