7 #ifndef CUDA_API_WRAPPERS_LINK_HPP_ 8 #define CUDA_API_WRAPPERS_LINK_HPP_ 13 #if __cplusplus >= 201703L 50 bool take_ownership =
false) noexcept;
73 CAW_SET_SCOPE_CONTEXT(context_handle);
74 auto status = cuLinkDestroy(handle);
76 ::std::string(
"Failed destroying the link ") + cuda::detail_::ptr_as_hex(handle)
77 +
" in " + context::detail_::identify(context_handle)
78 +
" on " + device::detail_::identify(device_id));
97 {
return device_id_; };
101 {
return context_handle_; }
123 void *cubin_output_start;
124 size_t cubin_output_size;
125 auto status = cuLinkComplete(handle_, &cubin_output_start, &cubin_output_size);
127 "Failed completing the link with state at address " + cuda::detail_::ptr_as_hex(handle_));
143 auto marshalled_options = link::detail_::marshal(ptx_compilation_options);
144 auto status = cuLinkAddData(
146 static_cast<CUjitInputType>(image.
type),
150 marshalled_options.count(),
151 const_cast<link::detail_::option_t *
>(marshalled_options.options()),
152 const_cast<void **>(marshalled_options.values())
155 "Failed adding input " + ::std::string(image.name) +
" of type " 156 + ::std::to_string(static_cast<int>(image.
type)) +
" to a link.");
172 auto marshalled_options = link::detail_::marshal(options);
173 auto status = cuLinkAddFile(
175 static_cast<CUjitInputType_enum>(file_input.type),
177 marshalled_options.count(),
178 const_cast<link::detail_::option_t *
>(marshalled_options.options()),
179 const_cast<void **>(marshalled_options.values())
182 "Failed loading an object of type " + ::std::to_string(static_cast<int>(file_input.type))
183 +
" from file " + file_input.path);
192 return add_file(link_file_spec, options);
195 #if __cplusplus >= 201703L 197 const ::std::filesystem::path& path,
201 return add_file(path.c_str(), file_contents_type, options);
213 bool take_ownership) noexcept
214 : device_id_(device_id), context_handle_(context), handle_(handle), options_(options), owning(take_ownership)
226 link_t(other.device_id_, other.context_handle_, other.handle_, other.options_, other.owning)
228 other.owning =
false;
231 ~
link_t() DESTRUCTOR_EXCEPTION_SPEC
233 if (not owning) {
return; }
234 #ifndef THROW_IN_DESTRUCTORS 238 link::detail_::destroy(handle_, context_handle_, device_id_);
240 #ifndef THROW_IN_DESTRUCTORS 251 ::std::swap(device_id_, other.device_id_);
252 ::std::swap(context_handle_, other.context_handle_);
253 ::std::swap(handle_, other.handle_);
254 ::std::swap(options_, other.options_);
255 ::std::swap(owning, owning);
275 auto marshalled_options = link::detail_::marshal(options);
276 auto status = cuLinkCreate(
277 marshalled_options.count(),
278 const_cast<link::detail_::option_t *
>(marshalled_options.options()),
279 const_cast<void **>(marshalled_options.values()),
283 auto do_take_ownership =
true;
284 auto context_handle = context::current::detail_::get_handle();
285 auto device_id = context::current::detail_::get_device_id();
299 bool take_ownership) noexcept
301 return link_t{device_id, context_handle, handle, options, take_ownership};
308 #endif // CUDA_API_WRAPPERS_LINK_HPP_ CUlinkState handle_t
A raw CUDA driver handle for a linking-process.
Definition: link.hpp:38
A convenience class for holding, setting and inspecting options for a CUDA binary code linking proces...
Definition: link_options.hpp:130
link_t create(const link::options_t &options=link::options_t{})
Create a new link-process (before adding any compiled images or or image-files)
Definition: link.hpp:272
Wrapper class for a CUDA context.
Definition: context.hpp:249
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:1974
Compiled device-class-specific device code.
CUcontext handle_t
Raw CUDA driver handle for a context; see {context_t}.
Definition: types.hpp:880
input_kind_t
Kinds of images which can be used by the linker (some may require driver compilation work) ...
Definition: link.hpp:29
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:104
CUdevice id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:852
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:141
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:100
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:294
#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:327
Wrapper class for a CUDA link (a process of linking compiled code together into an executable binary...
Definition: link.hpp:92
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:121
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:96
A bundle of multiple cubin and/or PTX inputs; typically.