pub struct Dim3 {
pub x: u32,
pub y: u32,
pub z: u32,
}Expand description
3-dimensional size specification for grids and blocks.
Used to specify the number of thread blocks in a grid and the number of threads in a block. Dimensions default to 1 when not explicitly provided.
§Examples
use oxicuda_launch::Dim3;
// 1D: 256 threads
let block = Dim3::x(256);
assert_eq!(block.x, 256);
assert_eq!(block.y, 1);
assert_eq!(block.z, 1);
// 2D: 16x16 threads
let block = Dim3::xy(16, 16);
assert_eq!(block.total(), 256);
// 3D
let block = Dim3::new(8, 8, 4);
assert_eq!(block.total(), 256);
// From conversions
let block: Dim3 = 256u32.into();
assert_eq!(block, Dim3::x(256));
let block: Dim3 = (16u32, 16u32).into();
assert_eq!(block, Dim3::xy(16, 16));
let block: Dim3 = (8u32, 8u32, 4u32).into();
assert_eq!(block, Dim3::new(8, 8, 4));Fields§
§x: u32X dimension.
y: u32Y dimension (default 1).
z: u32Z dimension (default 1).
Implementations§
Source§impl Dim3
impl Dim3
Sourcepub fn new(x: u32, y: u32, z: u32) -> Self
pub fn new(x: u32, y: u32, z: u32) -> Self
Creates a new Dim3 with explicit values for all three dimensions.
Sourcepub fn x(x: u32) -> Self
pub fn x(x: u32) -> Self
Creates a 1-dimensional Dim3 with the given X value.
Y and Z are set to 1.
Sourcepub fn xy(x: u32, y: u32) -> Self
pub fn xy(x: u32, y: u32) -> Self
Creates a 2-dimensional Dim3 with the given X and Y values.
Z is set to 1.
Sourcepub fn total_u64(&self) -> u64
pub fn total_u64(&self) -> u64
Total number of elements (x * y * z) widened to u64, saturating
at u64::MAX on overflow.
Note that the product of three arbitrary u32 values does not
always fit in a u64 (e.g. u32::MAX cubed is far larger than
u64::MAX), so the multiplication is carried out in u128 — which
is always wide enough for three u32 factors — before narrowing
back down, exactly mirroring how total narrows
this value to u32.