Table of Contents

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

x int

The X dimension size

y int

The Y dimension size

z int

The Z dimension size

Fields

One

A 1D work group of size 1

public static readonly WorkGroupSize One

Field Value

WorkGroupSize

Size1024

A common 1D work group size of 1024

public static readonly WorkGroupSize Size1024

Field Value

WorkGroupSize

Size16x16

A common 2D work group size of 16x16

public static readonly WorkGroupSize Size16x16

Field Value

WorkGroupSize

Size256

A common 1D work group size of 256

public static readonly WorkGroupSize Size256

Field Value

WorkGroupSize

Size32x32

A common 2D work group size of 32x32

public static readonly WorkGroupSize Size32x32

Field Value

WorkGroupSize

Size512

A common 1D work group size of 512

public static readonly WorkGroupSize Size512

Field Value

WorkGroupSize

X

The X dimension size

public readonly int X

Field Value

int

Y

The Y dimension size

public readonly int Y

Field Value

int

Z

The Z dimension size

public readonly int Z

Field Value

int

Properties

Dimensions

Gets the number of dimensions

public int Dimensions { get; }

Property Value

int

Is1D

Gets whether this is a 1D work group

public bool Is1D { get; }

Property Value

bool

Is2D

Gets whether this is a 2D work group

public bool Is2D { get; }

Property Value

bool

Is3D

Gets whether this is a 3D work group

public bool Is3D { get; }

Property Value

bool

TotalSize

Gets the total number of work items in the work group

public int TotalSize { get; }

Property Value

int

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

problemSize int

The total problem size

maxWorkGroupSize int

The 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

width int

The width of the problem

height int

The height of the problem

maxWorkGroupSize int

The maximum work group size supported by the device

Returns

WorkGroupSize

An optimal WorkGroupSize

Equals(WorkGroupSize)

Equality comparison

public bool Equals(WorkGroupSize other)

Parameters

other WorkGroupSize

Returns

bool

Equals(object?)

Equality comparison

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FromInt32(int)

Named alternative for implicit conversion from int to 1D WorkGroupSize (CA2225).

public static WorkGroupSize FromInt32(int size)

Parameters

size int

The 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

size (int x, int y, int z)

The 3D size tuple.

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

size (int x, int y)

The 2D size tuple.

Returns

WorkGroupSize

A new WorkGroupSize.

GetHashCode()

Gets the hash code

public override int GetHashCode()

Returns

int

IsValidFor(int, int[])

Checks if this work group size is valid for the given device constraints

public bool IsValidFor(int maxWorkGroupSize, int[] maxWorkItemSizes)

Parameters

maxWorkGroupSize int

Maximum work group size

maxWorkItemSizes int[]

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

x int

The 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

x int

The size in the X dimension

y int

The size in the Y dimension

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

x int

The size in the X dimension

y int

The size in the Y dimension

z int

The 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

string

Operators

operator ==(WorkGroupSize, WorkGroupSize)

Equality operator

public static bool operator ==(WorkGroupSize left, WorkGroupSize right)

Parameters

left WorkGroupSize
right WorkGroupSize

Returns

bool

implicit operator WorkGroupSize(int)

Implicit conversion from int to 1D WorkGroupSize

public static implicit operator WorkGroupSize(int size)

Parameters

size int

Returns

WorkGroupSize

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

size (int x, int y, int z)

Returns

WorkGroupSize

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

size (int x, int y)

Returns

WorkGroupSize

operator !=(WorkGroupSize, WorkGroupSize)

Inequality operator

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

Parameters

left WorkGroupSize
right WorkGroupSize

Returns

bool