pub struct Module { /* private fields */ }Expand description
A shared CUDA module and its retained loading context.
Clones, functions, and retained graph owners keep the module alive. An owned native module is unloaded when its last owner is dropped. Library-backed modules instead retain their library; externally borrowed modules rely on the external owner.
Implementations§
Source§impl Module
impl Module
Sourcepub fn artifact_metadata(&self) -> Option<&ArtifactMetadata>
pub fn artifact_metadata(&self) -> Option<&ArtifactMetadata>
Returns the retained producer metadata, or None for modules loaded without it.
Sourcepub unsafe fn prepare<K: KernelSignature>(
&self,
symbol: &str,
config: LaunchConfig,
) -> Result<PreparedLaunch<K>>
pub unsafe fn prepare<K: KernelSignature>( &self, symbol: &str, config: LaunchConfig, ) -> Result<PreparedLaunch<K>>
Binds an existing image entry to the ordinary typed launch contract.
§Safety
K must describe this symbol’s ABI, indexing and semantic requirements.
Producer entry metadata does not prove field layout, bounds, initialization or alias permission.
§Errors
Propagates errors from looking up symbol and validating the typed launch.
Validation can fail if native parameter sizes or offsets disagree with K, parameter layout overflows, the launch violates the signature’s requirements or device limits, or CUDA cannot query the required kernel or device attributes.
Source§impl Module
impl Module
Sourcepub unsafe fn from_borrowed_raw(handle: CUmodule, context: Arc<Context>) -> Self
pub unsafe fn from_borrowed_raw(handle: CUmodule, context: Arc<Context>) -> Self
Borrows an externally owned module.
§Safety
handle must belong to context and stay loaded until every clone, function, prepared launch and graph retaining this wrapper has been released.
Sourcepub fn function(&self, name: &str) -> Result<KernelFunction>
pub fn function(&self, name: &str) -> Result<KernelFunction>
Returns the kernel function with the given name from the module.
§Errors
Returns crate::error::Status::NotFound if the module has no kernel function named name.
Also returns an error if name contains an interior NUL byte, the module context cannot be bound, CUDA rejects the lookup, or a previous asynchronous launch reports an error.
Sourcepub fn function_count(&self) -> Result<usize>
pub fn function_count(&self) -> Result<usize>
Returns the number of functions in this module.
§Errors
Returns an error if CUDA Driver cannot report the function count.
Sourcepub fn as_raw(&self) -> CUmodule
pub fn as_raw(&self) -> CUmodule
Returns the borrowed native module handle without transferring ownership.
Sourcepub fn into_raw(self) -> StdResult<RawModule, Self>
pub fn into_raw(self) -> StdResult<RawModule, Self>
Consumes the module and returns the raw CUDA module handle without unloading it.
The caller becomes responsible for eventually unloading the returned handle with CUDA while retaining the returned context. Returns the unchanged wrapper if functions, graphs or other clones retain this module, or if its native handle is externally owned or owned by a library.
§Errors
Returns Err(self) if the module is externally owned, owned by a library, or still shared with another clone, function, or graph owner.
The returned wrapper remains usable and retains its ownership mode.
Sourcepub fn context(&self) -> &Arc<Context> ⓘ
pub fn context(&self) -> &Arc<Context> ⓘ
Returns the CUDA context in which this module was loaded.
Sourcepub fn global(&self, name: &str) -> Result<Global<'_>>
pub fn global(&self, name: &str) -> Result<Global<'_>>
Returns the base pointer and size of the global with the given name located in the module.
The returned Global borrows this module, so the module remains loaded for at least as long as the global reference is usable.
§Errors
Returns crate::error::Status::NotFound if the module has no global variable named name.
Also returns an error if name contains an interior NUL byte, the module context cannot be bound, CUDA rejects the lookup, or a previous asynchronous launch reports an error.