cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
types.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef SRC_CUDA_NVRTC_TYPES_HPP_
8 #define SRC_CUDA_NVRTC_TYPES_HPP_
9 
10 #include "../api/types.hpp"
11 
12 #include <nvrtc.h>
13 #if CUDA_VERSION >= 11010
14 #include <nvPTXCompiler.h>
15 #endif // CUDA_VERSION >= 11010
16 
17 #include <vector>
18 
19 #if __cplusplus >= 201703L
20 #include <string_view>
21 namespace cuda {
23 using string_view = ::std::string_view;
25 }
26 #else
27 #include <cuda/rtc/detail/string_view.hpp>
28 namespace cuda {
30 using string_view = bpstd::string_view;
32 }
33 #endif
34 
35 namespace cuda {
36 
41  cuda_cpp = 0,
44  ptx = 1
45 };
46 
47 //
48 // An easy alternative might be using a non-initializing allocator;
49 // see: https://stackoverflow.com/a/15966795/1593077
50 // this is not entirely sufficient, as we should probably not
51 // provide a container which may then be resized.
52 
54 namespace rtc {
55 
57 using const_cstrings_span = span<const char* const>;
58 
60 namespace program {
61 
62 namespace detail_ {
63 
64 constexpr char const *kind_name(source_kind_t kind)
65 {
66  return (kind == cuda_cpp) ? "CUDA C++" : "PTX";
67 }
68 
69 } // namespace detail_
70 
71 } // namespace program
72 
73 namespace detail_ {
74 
75 template <source_kind_t Kind> struct types {};
76 
77 template <> struct types<cuda_cpp> {
78  using handle_type = nvrtcProgram;
79  using status_type = nvrtcResult;
80  enum named_status : ::std::underlying_type<status_type>::type {
81  success = NVRTC_SUCCESS,
82  out_of_memory = NVRTC_ERROR_OUT_OF_MEMORY,
83  program_creation_failure = NVRTC_ERROR_OUT_OF_MEMORY,
84  invalid_input = NVRTC_ERROR_PROGRAM_CREATION_FAILURE,
85  invalid_program = NVRTC_ERROR_INVALID_PROGRAM,
86  invalid_option = NVRTC_ERROR_INVALID_OPTION,
87  compilation_failure = NVRTC_ERROR_COMPILATION,
88  builtin_operation_failure = NVRTC_ERROR_BUILTIN_OPERATION_FAILURE,
89  no_registered_globals_after_compilation = NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION,
90  no_lowered_names_before_compilation = NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION,
91  invalid_expression_to_register_as_global = NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID,
92  internal_error = NVRTC_ERROR_INTERNAL_ERROR,
93  };
94 };
95 
96 #if CUDA_VERSION >= 11010
97 template <> struct types<ptx> {
98  using handle_type = nvPTXCompilerHandle;
99  using status_type = nvPTXCompileResult;
100  enum named_status : ::std::underlying_type<status_type>::type {
101  success = NVPTXCOMPILE_SUCCESS,
102  invalid_handle = NVPTXCOMPILE_ERROR_INVALID_COMPILER_HANDLE,
103  invalid_program_handle = NVPTXCOMPILE_ERROR_INVALID_COMPILER_HANDLE,
104  out_of_memory = NVPTXCOMPILE_ERROR_OUT_OF_MEMORY,
105  invalid_input = NVPTXCOMPILE_ERROR_INVALID_INPUT,
106  compilation_invocation_incomplete = NVPTXCOMPILE_ERROR_COMPILER_INVOCATION_INCOMPLETE,
107  compilation_failure = NVPTXCOMPILE_ERROR_COMPILATION_FAILURE,
108  unsupported_ptx_version = NVPTXCOMPILE_ERROR_UNSUPPORTED_PTX_VERSION,
109  internal_error = NVPTXCOMPILE_ERROR_INTERNAL,
110 #if CUDA_VERSION >= 12010
111  unsupported_device_side_sync = NVPTXCOMPILE_ERROR_UNSUPPORTED_DEVSIDE_SYNC,
112 #endif
113  };
114 };
115 #endif // CUDA_VERSION >= 11010
116 
117 } // namespace detail_
118 
119 namespace program {
120 
123 template <source_kind_t Kind>
124 using handle_t = typename cuda::rtc::detail_::types<Kind>::handle_type;
125 
126 } // namespace program
127 
130 template <source_kind_t Kind>
131 using status_t = typename detail_::types<Kind>::status_type;
132 
133 } // namespace rtc
134 
135 } // namespace cuda
136 
137 #endif /* SRC_CUDA_NVRTC_TYPES_HPP_ */
The CUDA variant of C++, accepted by the NVRTC library.
Definition: types.hpp:41
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
typename cuda::rtc::detail_::types< Kind >::handle_type handle_t
Raw program handle used by the NVIDIA run-time compilation libraries&#39;s API calls: // The NVRTC librar...
Definition: types.hpp:124
source_kind_t
The API wrappers support different kinds of source code, accepted by different NVIDIA run-time compil...
Definition: types.hpp:39
typename detail_::types< Kind >::status_type status_t
Status values returned by the NVIDIA run-time compilation libraries&#39;s API calls: The NVRTC library fo...
Definition: types.hpp:131
NVIDIA&#39;s architecture-inspecific intermediate program representation language, known as PTX or Parall...
Definition: types.hpp:44
span< const char *const > const_cstrings_span
A span of C-style strings the contents of which must not be modified.
Definition: types.hpp:57