pub struct Linker { /* private fields */ }Expand description
RAII wrapper around the CUDA link state (CUlinkState).
The linker accumulates PTX, cubin, and fatbin inputs via the add_*
methods and then produces a single linked binary via complete.
On macOS, a synthetic implementation stores the inputs in memory and produces a synthetic cubin on completion.
§Drop behaviour
Dropping the linker calls cuLinkDestroy on platforms with a real
CUDA driver. If complete() was already called, Drop is still safe
because the cubin data has been copied into the LinkedModule.
Implementations§
Source§impl Linker
impl Linker
Sourcepub fn new(options: LinkerOptions) -> CudaResult<Self>
pub fn new(options: LinkerOptions) -> CudaResult<Self>
Sourcepub fn add_ptx(&mut self, ptx: &str, name: &str) -> CudaResult<()>
pub fn add_ptx(&mut self, ptx: &str, name: &str) -> CudaResult<()>
Adds PTX source code to the linker.
The PTX is compiled and linked when complete is
called.
§Arguments
ptx— PTX source code (must not contain interior null bytes).name— A descriptive name for this input (used in error messages).
§Errors
CudaError::InvalidValueifptxcontains interior null bytes.- Other
CudaErrorvariants ifcuLinkAddDatafails.
Sourcepub fn add_cubin(&mut self, data: &[u8], name: &str) -> CudaResult<()>
pub fn add_cubin(&mut self, data: &[u8], name: &str) -> CudaResult<()>
Adds compiled cubin data to the linker.
§Arguments
data— Raw cubin binary data.name— A descriptive name for this input.
§Errors
CudaError::InvalidValueifnamecontains interior null bytes ordatais empty.- Other
CudaErrorvariants ifcuLinkAddDatafails.
Sourcepub fn add_fatbin(&mut self, data: &[u8], name: &str) -> CudaResult<()>
pub fn add_fatbin(&mut self, data: &[u8], name: &str) -> CudaResult<()>
Adds a fat binary to the linker.
§Arguments
data— Raw fatbin binary data.name— A descriptive name for this input.
§Errors
CudaError::InvalidValueifnamecontains interior null bytes ordatais empty.- Other
CudaErrorvariants ifcuLinkAddDatafails.
Sourcepub fn add_object(&mut self, data: &[u8], name: &str) -> CudaResult<()>
pub fn add_object(&mut self, data: &[u8], name: &str) -> CudaResult<()>
Adds a relocatable device object to the linker.
§Arguments
data— Raw object binary data.name— A descriptive name for this input.
§Errors
CudaError::InvalidValueifnamecontains interior null bytes ordatais empty.
Sourcepub fn add_library(&mut self, data: &[u8], name: &str) -> CudaResult<()>
pub fn add_library(&mut self, data: &[u8], name: &str) -> CudaResult<()>
Adds a device code library to the linker.
§Arguments
data— Raw library binary data.name— A descriptive name for this input.
§Errors
CudaError::InvalidValueifnamecontains interior null bytes ordatais empty.
Sourcepub fn input_count(&self) -> usize
pub fn input_count(&self) -> usize
Returns the number of inputs added to the linker.
Sourcepub fn input_names(&self) -> &[String]
pub fn input_names(&self) -> &[String]
Returns the names of all inputs added so far.
Sourcepub fn options(&self) -> &LinkerOptions
pub fn options(&self) -> &LinkerOptions
Returns a reference to the linker options.
Sourcepub fn complete(self) -> CudaResult<LinkedModule>
pub fn complete(self) -> CudaResult<LinkedModule>
Completes the link, producing a LinkedModule.
This consumes the linker. The resulting cubin data is copied into
the LinkedModule before the underlying CUlinkState is destroyed
(by Drop).
§Errors
CudaError::InvalidValueif no inputs have been added.- Other
CudaErrorvariants ifcuLinkCompletefails.