Skip to main content

singe_cuda/
dim.rs

1//! Three-dimensional CUDA grid, block, and cluster dimensions.
2
3use singe_cuda_sys::runtime;
4
5/// Three unsigned 32-bit axis values for CUDA grids, blocks, or clusters.
6///
7/// The interpretation depends on the receiving API.
8/// The default value has all axes set to zero; launch geometry constructors reject zero dimensions.
9#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
10pub struct Dim3 {
11    /// Value along the x axis.
12    pub x: u32,
13    /// Value along the y axis.
14    pub y: u32,
15    /// Value along the z axis.
16    pub z: u32,
17}
18
19impl Dim3 {
20    /// Creates axis values without validating launch dimensions or device limits.
21    #[must_use]
22    pub const fn new(x: u32, y: u32, z: u32) -> Self {
23        Self { x, y, z }
24    }
25}
26
27impl From<runtime::dim3> for Dim3 {
28    fn from(dim: runtime::dim3) -> Self {
29        Self {
30            x: dim.x,
31            y: dim.y,
32            z: dim.z,
33        }
34    }
35}
36
37impl From<Dim3> for runtime::dim3 {
38    fn from(dim: Dim3) -> Self {
39        Self {
40            x: dim.x,
41            y: dim.y,
42            z: dim.z,
43        }
44    }
45}