Table of Contents

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

x int

The X dimension (width).

y int

The Y dimension (height). Defaults to 1.

z int

The 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

int

X

Gets the X dimension (width).

public int X { get; init; }

Property Value

int

Y

Gets the Y dimension (height). Defaults to 1 for 1D grids.

public int Y { get; init; }

Property Value

int

Z

Gets the Z dimension (depth). Defaults to 1 for 1D/2D grids.

public int Z { get; init; }

Property Value

int

Methods

Equals(GridDimensions)

Determines whether this instance is equal to another GridDimensions.

public bool Equals(GridDimensions other)

Parameters

other GridDimensions

The other GridDimensions to compare.

Returns

bool

true if the dimensions are equal; otherwise, false.

Equals(object?)

Determines whether this instance is equal to another object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare.

Returns

bool

true if 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

size int

The 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

tuple (int x, int y, int z)

A tuple containing (x, y, z) dimensions.

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

size int

The 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

width int

The width (X dimension).

height int

The height (Y dimension).

depth int

The 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

width int

The width (X dimension).

height int

The height (Y dimension).

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

left GridDimensions
right GridDimensions

Returns

bool

implicit operator GridDimensions(int)

Implicitly converts a single integer to a 1D GridDimensions.

public static implicit operator GridDimensions(int size)

Parameters

size int

The size of the 1D grid.

Returns

GridDimensions

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

tuple (int x, int y, int z)

A tuple containing (x, y, z) dimensions.

Returns

GridDimensions

operator !=(GridDimensions, GridDimensions)

Determines whether two GridDimensions instances are not equal.

public static bool operator !=(GridDimensions left, GridDimensions right)

Parameters

left GridDimensions
right GridDimensions

Returns

bool