7 #ifndef CUDA_API_WRAPPERS_LINK_HPP_ 8 #define CUDA_API_WRAPPERS_LINK_HPP_ 15 #if __cplusplus >= 201703L 52 bool take_ownership =
false) noexcept;
54 inline
link_t create(const
void *image, const link::
options_t &options);
87 {
return device_id_; };
91 {
return context_handle_; }
113 void *cubin_output_start;
114 size_t cubin_output_size;
115 auto status = cuLinkComplete(handle_, &cubin_output_start, &cubin_output_size);
117 "Failed completing the link with state at address " + cuda::detail_::ptr_as_hex(handle_));
133 auto marshalled_options = link::detail_::marshal(ptx_compilation_options);
134 auto status = cuLinkAddData(
136 static_cast<CUjitInputType>(image.
type),
140 marshalled_options.count(),
141 const_cast<link::detail_::option_t *
>(marshalled_options.options()),
142 const_cast<void **>(marshalled_options.values())
145 "Failed adding input " + ::std::string(image.name) +
" of type " 146 + ::std::to_string(static_cast<int>(image.
type)) +
" to a link.");
162 auto marshalled_options = link::detail_::marshal(options);
163 auto status = cuLinkAddFile(
165 static_cast<CUjitInputType_enum>(file_input.type),
167 marshalled_options.count(),
168 const_cast<link::detail_::option_t *
>(marshalled_options.options()),
169 const_cast<void **>(marshalled_options.values())
172 "Failed loading an object of type " + ::std::to_string(static_cast<int>(file_input.type))
173 +
" from file " + file_input.path);
182 return add_file(link_file_spec, options);
185 #if __cplusplus >= 201703L 187 const ::std::filesystem::path& path,
191 return add_file(path.c_str(), file_contents_type, options);
203 bool take_ownership) noexcept
204 : device_id_(device_id), context_handle_(context), handle_(handle), options_(options), owning(take_ownership)
216 link_t(other.device_id_, other.context_handle_, other.handle_, other.options_, other.owning)
218 other.owning =
false;
224 CAW_SET_SCOPE_CONTEXT(context_handle_);
225 auto status = cuLinkDestroy(handle_);
227 ::std::string(
"Failed destroying the link ") + detail_::ptr_as_hex(handle_) +
228 " in " + context::detail_::identify(context_handle_, device_id_));
238 ::std::swap(device_id_, other.device_id_);
239 ::std::swap(context_handle_, other.context_handle_);
240 ::std::swap(handle_, other.handle_);
241 ::std::swap(options_, other.options_);
242 ::std::swap(owning, owning);
262 auto marshalled_options = link::detail_::marshal(options);
263 auto status = cuLinkCreate(
264 marshalled_options.count(),
265 const_cast<link::detail_::option_t *
>(marshalled_options.options()),
266 const_cast<void **>(marshalled_options.values()),
270 auto do_take_ownership =
true;
271 auto context_handle = context::current::detail_::get_handle();
272 auto device_id = context::current::detail_::get_device_id();
286 bool take_ownership) noexcept
288 return link_t{device_id, context_handle, handle, options, take_ownership};
295 #endif // CUDA_API_WRAPPERS_LINK_HPP_ CUlinkState handle_t
A raw CUDA driver handle for a linking-process.
Definition: link.hpp:40
A convenience class for holding, setting and inspecting options for a CUDA binary code linking proces...
Definition: link_options.hpp:130
Wrappers for working with modules of compiled CUDA code.
Wrapper class for a CUDA context.
Definition: context.hpp:244
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
detail_::region_helper< memory::region_t > region_t
A child class of the generic region_t with some managed-memory-specific functionality.
Definition: memory.hpp:1960
Compiled device-class-specific device code.
CUcontext handle_t
Raw CUDA driver handle for a context; see {context_t}.
Definition: types.hpp:878
input_kind_t
Kinds of images which can be used by the linker (some may require driver compilation work) ...
Definition: link.hpp:31
bool is_owning() const noexcept
True if this wrapper is responsible for telling CUDA to destroy the link upon the wrapper's own destr...
Definition: link.hpp:94
CUdevice id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:850
void add(link::input::image_t image, const link::options_t &ptx_compilation_options={}) const
Add another linkable image, from memory, to this linking-process.
Definition: link.hpp:131
PTX (microarchitecture-inspecific intermediate representation)
context::handle_t context_handle() const noexcept
The raw CUDA handle for the context in which the represented stream is defined.
Definition: link.hpp:90
link_t wrap(device::id_t device_id, context::handle_t context_handle, link::handle_t handle, const link::options_t &options, bool take_ownership=false) noexcept
Wrap an existing CUDA link-process in a link_t wrapper class instance.
Definition: link.hpp:281
#define throw_if_error_lazy(status__,...)
A macro for only throwing an error if we've failed - which also ensures no string is constructed unle...
Definition: error.hpp:316
Wrapper class for a CUDA link (a process of linking compiled code together into an executable binary...
Definition: link.hpp:82
A host-side binary object with embedded device code; a .o file.
Contains cuda::link::options_t class and related definitions.
Wrapper class for a CUDA device.
Definition: device.hpp:135
memory::region_t complete() const
Complete a linking process, producing a completely-linked cubin image (for loading into modules)...
Definition: link.hpp:111
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 link is defined.
Definition: link.hpp:86
A bundle of multiple cubin and/or PTX inputs; typically.