Struct GridDimensions
- Namespace
- DotCompute.Abstractions.Interfaces
- Assembly
- DotCompute.Abstractions.dll
Represents 3D grid or block dimensions for kernel execution.
public readonly struct GridDimensions : IEquatable<GridDimensions>
- Implements
- Inherited Members
Remarks
Grid dimensions specify how many thread blocks to launch (CUDA) or threadgroups to dispatch (Metal). Block dimensions specify how many threads per block/threadgroup. Supports 1D, 2D, and 3D configurations for flexible workload mapping.
Constructors
GridDimensions(int, int, int)
Initializes a new instance of the GridDimensions struct.
public GridDimensions(int x, int y = 1, int z = 1)
Parameters
xintThe X dimension (width).
yintThe Y dimension (height). Defaults to 1.
zintThe Z dimension (depth). Defaults to 1.
Exceptions
- ArgumentOutOfRangeException
Thrown when any dimension is less than or equal to zero.
Properties
TotalElements
Gets the total number of elements (X × Y × Z).
public int TotalElements { get; }
Property Value
X
Gets the X dimension (width).
public int X { get; init; }
Property Value
Y
Gets the Y dimension (height). Defaults to 1 for 1D grids.
public int Y { get; init; }
Property Value
Z
Gets the Z dimension (depth). Defaults to 1 for 1D/2D grids.
public int Z { get; init; }
Property Value
Methods
Equals(GridDimensions)
Determines whether this instance is equal to another GridDimensions.
public bool Equals(GridDimensions other)
Parameters
otherGridDimensionsThe other GridDimensions to compare.
Returns
- bool
trueif the dimensions are equal; otherwise,false.
Equals(object?)
Determines whether this instance is equal to another object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare.
Returns
- bool
trueif the object is a GridDimensions with equal dimensions; otherwise,false.
FromInt32(int)
Creates a 1D GridDimensions from an integer (alternate for implicit operator).
public static GridDimensions FromInt32(int size)
Parameters
sizeintThe size of the 1D grid.
Returns
- GridDimensions
A GridDimensions with X=size and Y=Z=1.
FromValueTuple((int x, int y, int z))
Creates a GridDimensions from a value tuple (alternate for implicit operator).
public static GridDimensions FromValueTuple((int x, int y, int z) tuple)
Parameters
Returns
- GridDimensions
A GridDimensions with the specified dimensions.
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code combining X, Y, and Z dimensions.
OneDimensional(int)
Creates a 1D grid dimension.
public static GridDimensions OneDimensional(int size)
Parameters
sizeintThe size of the 1D grid.
Returns
- GridDimensions
A GridDimensions with the specified X dimension and Y=Z=1.
ThreeDimensional(int, int, int)
Creates a 3D grid dimension.
public static GridDimensions ThreeDimensional(int width, int height, int depth)
Parameters
widthintThe width (X dimension).
heightintThe height (Y dimension).
depthintThe depth (Z dimension).
Returns
- GridDimensions
A GridDimensions with all three dimensions specified.
ToString()
Returns a string representation of this instance.
public override string ToString()
Returns
- string
A string in the format "(X, Y, Z)" for debugging.
TwoDimensional(int, int)
Creates a 2D grid dimension.
public static GridDimensions TwoDimensional(int width, int height)
Parameters
Returns
- GridDimensions
A GridDimensions with the specified X and Y dimensions and Z=1.
Operators
operator ==(GridDimensions, GridDimensions)
Determines whether two GridDimensions instances are equal.
public static bool operator ==(GridDimensions left, GridDimensions right)
Parameters
leftGridDimensionsrightGridDimensions
Returns
implicit operator GridDimensions(int)
Implicitly converts a single integer to a 1D GridDimensions.
public static implicit operator GridDimensions(int size)
Parameters
sizeintThe size of the 1D grid.
Returns
implicit operator GridDimensions((int x, int y, int z))
Implicitly converts a tuple to GridDimensions.
public static implicit operator GridDimensions((int x, int y, int z) tuple)
Parameters
Returns
operator !=(GridDimensions, GridDimensions)
Determines whether two GridDimensions instances are not equal.
public static bool operator !=(GridDimensions left, GridDimensions right)
Parameters
leftGridDimensionsrightGridDimensions