Trait SafeGpuConfig
pub trait SafeGpuConfig: GPUConfig + 'static {
const CONFIG_CHECK: () = _;
const BDIM_X: u32 = _;
const BDIM_Y: u32 = _;
const BDIM_Z: u32 = _;
const GDIM_X: u32 = _;
const GDIM_Y: u32 = _;
const GDIM_Z: u32 = _;
const SMEM_SIZE: u32 = _;
// Provided methods
fn runtime_check(&self, cu_dev_prop: CUdevprop_st, max_dynamic_size: i32) { ... }
fn is_static(&self) -> bool { ... }
fn grid_dim_x(&self) -> u32 { ... }
fn grid_dim_y(&self) -> u32 { ... }
fn grid_dim_z(&self) -> u32 { ... }
fn block_dim_x(&self) -> u32 { ... }
fn block_dim_y(&self) -> u32 { ... }
fn block_dim_z(&self) -> u32 { ... }
fn shared_size(&self) -> u32 { ... }
}Expand description
A safe wrapper for GPUConfig providing compile-time and runtime validation.
§Compile-Time Checks
Ensures that all static values comply with the hardware limits defined in [CU_DEV_PROP].
If kernel execution uses a type implementing this GPUConfig manually, or created via
gpu_config!, Rust compiler will automatically perform these checks.
§Example
- Define unused invalid static config with manual impl.
struct InvalidConfig;
impl cuda_bindings::GPUConfig for InvalidConfig {
const BLOCK_DIM_Z: u32 = 1025;
}
let config = InvalidConfig; // No errors since it is not used.- Use invalid static config with manual impl.
use cuda_bindings::SafeGpuConfig;
struct InvalidConfig;
impl cuda_bindings::GPUConfig for InvalidConfig {
const BLOCK_DIM_Z: u32 = 1025;
}
let config = InvalidConfig;
config.block_dim_z();See more in gpu_config! macro documentation.
§Runtime Checks
Ensures that dynamic values are within the hardware limits at execution time.
This guarantees that kernels launched with dynamic configurations remain safe.
The runtime_check method verifies:
cu_dev_prop: Actual device properties queried from the GPU.max_dynamic_size: Maximum dynamic shared memory size supported by the kernel.
Provided Associated Constants§
const CONFIG_CHECK: () = _
const BDIM_X: u32 = _
const BDIM_Y: u32 = _
const BDIM_Z: u32 = _
const GDIM_X: u32 = _
const GDIM_Y: u32 = _
const GDIM_Z: u32 = _
const SMEM_SIZE: u32 = _
Provided Methods§
fn runtime_check(&self, cu_dev_prop: CUdevprop_st, max_dynamic_size: i32)
fn runtime_check(&self, cu_dev_prop: CUdevprop_st, max_dynamic_size: i32)
Dynamic block size must be valid. If the static block size is invalid, it will cause a compilation error. If the block size is dynamic, we defer the check to runtime.
fn is_static(&self) -> bool
fn grid_dim_x(&self) -> u32
fn grid_dim_y(&self) -> u32
fn grid_dim_z(&self) -> u32
fn block_dim_x(&self) -> u32
fn block_dim_y(&self) -> u32
fn block_dim_z(&self) -> u32
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T> SafeGpuConfig for Twhere
T: GPUConfig + ?Sized,
Do not allow override SafeGpuConfig.