7 #ifndef CUDA_API_WRAPPERS_LINK_HPP_ 8 #define CUDA_API_WRAPPERS_LINK_HPP_ 15 #if __cplusplus >= 201703L 31 enum class input_kind_t {
39 using handle_t = CUlinkState;
44 context::handle_t context_handle,
45 link::handle_t handle,
46 const link::options_t &options,
47 bool take_ownership =
false) noexcept;
49 inline link_t create(const
void *image, const link::options_t &options);
60 link::input_kind_t type;
65 link::input_kind_t type;
84 {
return device_id_; };
88 {
return context_handle_; }
95 device_t device()
const;
110 void *cubin_output_start;
111 size_t cubin_output_size;
112 auto status = cuLinkComplete(handle_, &cubin_output_start, &cubin_output_size);
113 throw_if_error_lazy(status,
114 "Failed completing the link with state at address " + cuda::detail_::ptr_as_hex(handle_));
121 auto marshalled_options = marshal(ptx_compilation_options);
122 auto status = cuLinkAddData(
124 static_cast<CUjitInputType>(image.type),
128 marshalled_options.count(),
129 const_cast<link::option_t *
>(marshalled_options.options()),
130 const_cast<void **>(marshalled_options.values())
132 throw_if_error_lazy(status,
133 "Failed adding input " + ::std::string(image.name) +
" of type " 134 + ::std::to_string(static_cast<int>(image.type)) +
" to a link.");
139 auto marshalled_options = marshal(options);
140 auto status = cuLinkAddFile(
142 static_cast<CUjitInputType_enum>(file_input.type),
144 marshalled_options.count(),
145 const_cast<link::option_t *
>(marshalled_options.options()),
146 const_cast<void **>(marshalled_options.values())
148 throw_if_error_lazy(status,
149 "Failed loading an object of type " + ::std::to_string(static_cast<int>(file_input.type))
150 +
" from file " + file_input.path);
153 #if __cplusplus >= 201703L 154 void add_file(const ::std::filesystem::path& path, link::input_kind_t file_contents_type)
const 156 return add_file(path.c_str(), file_contents_type);
164 context::handle_t context,
165 link::handle_t handle,
167 bool take_ownership) noexcept
168 : device_id_(device_id), context_handle_(context), handle_(handle), options_(options), owning(take_ownership)
180 link_t(other.device_id_, other.context_handle_, other.handle_, other.options_, other.owning)
182 other.owning =
false;
188 CAW_SET_SCOPE_CONTEXT(context_handle_);
189 auto status = cuLinkDestroy(handle_);
190 throw_if_error_lazy(status,
191 ::std::string(
"Failed destroying the link ") + detail_::ptr_as_hex(handle_) +
192 " in " + context::detail_::identify(context_handle_, device_id_));
202 ::std::swap(device_id_, other.device_id_);
203 ::std::swap(context_handle_, other.context_handle_);
204 ::std::swap(handle_, other.handle_);
205 ::std::swap(options_, other.options_);
206 ::std::swap(owning, owning);
212 context::handle_t context_handle_;
213 link::handle_t handle_;
224 handle_t new_link_handle;
225 auto marshalled_options = marshal(options);
226 auto status = cuLinkCreate(
227 marshalled_options.count(),
228 const_cast<link::option_t *
>(marshalled_options.options()),
229 const_cast<void **>(marshalled_options.values()),
232 throw_if_error_lazy(status,
"Failed creating a new link ");
233 auto do_take_ownership =
true;
234 auto context_handle = context::current::detail_::get_handle();
235 auto device_id = context::current::detail_::get_device_id();
247 context::handle_t context_handle,
248 link::handle_t handle,
250 bool take_ownership) noexcept
252 return link_t{device_id, context_handle, handle, options, take_ownership};
259 #endif // CUDA_API_WRAPPERS_LINK_HPP_ Definition: link_options.hpp:90
Wrappers for working with modules of compiled CUDA code.
array_t< T, NumDimensions > wrap(device::id_t device_id, context::handle_t context_handle, handle_t handle, dimensions_t< NumDimensions > dimensions) noexcept
Wrap an existing CUDA array in an array_t instance.
Definition: array.hpp:248
Wrapper class for a CUDA context.
Definition: context.hpp:220
All definitions and functionality wrapping the CUDA Runtime API.
Definition: array.hpp:22
bool is_owning() const noexcept
True if this wrapper is responsible for telling CUDA to destroy the event upon the wrapper's own dest...
Definition: link.hpp:91
CUdevice id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:752
context::handle_t context_handle() const noexcept
The raw CUDA handle for the context in which the represented stream is defined.
Definition: link.hpp:87
Wrapper class for a CUDA link (a process of linking compiled code together into an executable binary...
Definition: link.hpp:79
Definitions and utility functions relating to just-in-time compilation and linking of CUDA code...
memory::region_t complete() const
Complete a linking process, producing a completely-linked cubin image (for loading into modules)...
Definition: link.hpp:108
Definition: region.hpp:128
freestanding wrapper functions for working with CUDA's various kinds of memory spaces, arranged into a relevant namespace hierarchy.
device::id_t device_id() const noexcept
The raw CUDA ID for the device w.r.t. which the event is defined.
Definition: link.hpp:83