Struct WorkGroupSize
- Namespace
- DotCompute.Abstractions.Kernels
- Assembly
- DotCompute.Abstractions.dll
Represents the work group size for kernel execution
public readonly struct WorkGroupSize : IEquatable<WorkGroupSize>
- Implements
- Inherited Members
Constructors
WorkGroupSize(int, int, int)
Creates a new WorkGroupSize with the specified dimensions
public WorkGroupSize(int x, int y = 1, int z = 1)
Parameters
Fields
One
A 1D work group of size 1
public static readonly WorkGroupSize One
Field Value
Size1024
A common 1D work group size of 1024
public static readonly WorkGroupSize Size1024
Field Value
Size16x16
A common 2D work group size of 16x16
public static readonly WorkGroupSize Size16x16
Field Value
Size256
A common 1D work group size of 256
public static readonly WorkGroupSize Size256
Field Value
Size32x32
A common 2D work group size of 32x32
public static readonly WorkGroupSize Size32x32
Field Value
Size512
A common 1D work group size of 512
public static readonly WorkGroupSize Size512
Field Value
X
The X dimension size
public readonly int X
Field Value
Y
The Y dimension size
public readonly int Y
Field Value
Z
The Z dimension size
public readonly int Z
Field Value
Properties
Dimensions
Gets the number of dimensions
public int Dimensions { get; }
Property Value
Is1D
Gets whether this is a 1D work group
public bool Is1D { get; }
Property Value
Is2D
Gets whether this is a 2D work group
public bool Is2D { get; }
Property Value
Is3D
Gets whether this is a 3D work group
public bool Is3D { get; }
Property Value
TotalSize
Gets the total number of work items in the work group
public int TotalSize { get; }
Property Value
Methods
CalculateOptimal(int, int)
Calculates the optimal work group size for a given problem size
public static WorkGroupSize CalculateOptimal(int problemSize, int maxWorkGroupSize = 1024)
Parameters
problemSizeintThe total problem size
maxWorkGroupSizeintThe maximum work group size supported by the device
Returns
- WorkGroupSize
An optimal WorkGroupSize
CalculateOptimal2D(int, int, int)
Calculates the optimal 2D work group size for given dimensions
public static WorkGroupSize CalculateOptimal2D(int width, int height, int maxWorkGroupSize = 1024)
Parameters
widthintThe width of the problem
heightintThe height of the problem
maxWorkGroupSizeintThe maximum work group size supported by the device
Returns
- WorkGroupSize
An optimal WorkGroupSize
Equals(WorkGroupSize)
Equality comparison
public bool Equals(WorkGroupSize other)
Parameters
otherWorkGroupSize
Returns
Equals(object?)
Equality comparison
public override bool Equals(object? obj)
Parameters
objobject
Returns
FromInt32(int)
Named alternative for implicit conversion from int to 1D WorkGroupSize (CA2225).
public static WorkGroupSize FromInt32(int size)
Parameters
sizeintThe 1D size.
Returns
- WorkGroupSize
A new WorkGroupSize.
FromValueTuple((int x, int y, int z))
Named alternative for implicit conversion from (int, int, int) tuple to 3D WorkGroupSize (CA2225).
public static WorkGroupSize FromValueTuple((int x, int y, int z) size)
Parameters
Returns
- WorkGroupSize
A new WorkGroupSize.
FromValueTuple((int x, int y))
Named alternative for implicit conversion from (int, int) tuple to 2D WorkGroupSize (CA2225).
public static WorkGroupSize FromValueTuple((int x, int y) size)
Parameters
Returns
- WorkGroupSize
A new WorkGroupSize.
GetHashCode()
Gets the hash code
public override int GetHashCode()
Returns
IsValidFor(int, int[])
Checks if this work group size is valid for the given device constraints
public bool IsValidFor(int maxWorkGroupSize, int[] maxWorkItemSizes)
Parameters
maxWorkGroupSizeintMaximum work group size
maxWorkItemSizesint[]Maximum work item sizes for each dimension
Returns
- bool
True if valid, false otherwise
Size1D(int)
Creates a 1D work group size
public static WorkGroupSize Size1D(int x)
Parameters
xintThe size in the X dimension
Returns
- WorkGroupSize
A new WorkGroupSize
Size2D(int, int)
Creates a 2D work group size
public static WorkGroupSize Size2D(int x, int y)
Parameters
Returns
- WorkGroupSize
A new WorkGroupSize
Size3D(int, int, int)
Creates a 3D work group size
public static WorkGroupSize Size3D(int x, int y, int z)
Parameters
xintThe size in the X dimension
yintThe size in the Y dimension
zintThe size in the Z dimension
Returns
- WorkGroupSize
A new WorkGroupSize
ToArray()
Returns the work group size as an array
public int[] ToArray()
Returns
- int[]
An array containing [X, Y, Z]
ToString()
String representation
public override string ToString()
Returns
Operators
operator ==(WorkGroupSize, WorkGroupSize)
Equality operator
public static bool operator ==(WorkGroupSize left, WorkGroupSize right)
Parameters
leftWorkGroupSizerightWorkGroupSize
Returns
implicit operator WorkGroupSize(int)
Implicit conversion from int to 1D WorkGroupSize
public static implicit operator WorkGroupSize(int size)
Parameters
sizeint
Returns
implicit operator WorkGroupSize((int x, int y, int z))
Implicit conversion from (int, int, int) tuple to 3D WorkGroupSize
public static implicit operator WorkGroupSize((int x, int y, int z) size)
Parameters
Returns
implicit operator WorkGroupSize((int x, int y))
Implicit conversion from (int, int) tuple to 2D WorkGroupSize
public static implicit operator WorkGroupSize((int x, int y) size)
Parameters
Returns
operator !=(WorkGroupSize, WorkGroupSize)
Inequality operator
public static bool operator !=(WorkGroupSize left, WorkGroupSize right)
Parameters
leftWorkGroupSizerightWorkGroupSize