Table of Contents

Class KernelArguments

Namespace
DotCompute.Abstractions.Kernels
Assembly
DotCompute.Abstractions.dll

Represents kernel execution arguments that are passed to a compute kernel during execution. Provides type-safe access to arguments with validation and error handling.

public class KernelArguments : IEnumerable<object?>, IEnumerable
Inheritance
KernelArguments
Implements
Inherited Members

Constructors

KernelArguments()

Initializes a new instance of the KernelArguments class with an empty argument list.

public KernelArguments()

KernelArguments(int)

Initializes a new instance of the KernelArguments class with the specified initial capacity. The arguments list will be pre-filled with null values to match the capacity.

public KernelArguments(int capacity)

Parameters

capacity int

The initial capacity for arguments.

Exceptions

ArgumentOutOfRangeException

Thrown when capacity is negative.

KernelArguments(params object?[])

Initializes a new instance of the KernelArguments class with the specified initial arguments.

public KernelArguments(params object?[] arguments)

Parameters

arguments object[]

The initial arguments to store.

Exceptions

ArgumentNullException

Thrown when arguments is null.

Properties

Arguments

Gets a read-only view of all arguments currently stored in this instance.

public IReadOnlyList<object?> Arguments { get; }

Property Value

IReadOnlyList<object>

A read-only list containing all arguments.

Buffers

Gets or sets the buffer arguments for kernel execution.

public IEnumerable<IUnifiedMemoryBuffer> Buffers { get; set; }

Property Value

IEnumerable<IUnifiedMemoryBuffer>

A collection of memory buffers to be passed to the kernel.

Count

Gets the number of arguments currently stored in this instance.

public int Count { get; }

Property Value

int

The total count of arguments.

this[int]

Gets or sets the argument at the specified index.

public object? this[int index] { get; set; }

Parameters

index int

The zero-based index of the argument to get or set.

Property Value

object

The argument at the specified index.

Exceptions

ArgumentOutOfRangeException

Thrown when index is negative or greater than or equal to Count.

InvalidOperationException

Thrown when trying to access arguments on an uninitialized KernelArguments instance.

LaunchConfiguration

Gets or sets the kernel launch configuration including shared memory settings.

public KernelLaunchConfiguration? LaunchConfiguration { get; set; }

Property Value

KernelLaunchConfiguration

The launch configuration for advanced kernel execution features.

Length

Gets the number of arguments (alias for Count for compatibility).

public int Length { get; }

Property Value

int

The total length of arguments, identical to Count.

ScalarArguments

Gets or sets the scalar arguments for kernel execution.

public IEnumerable<object> ScalarArguments { get; set; }

Property Value

IEnumerable<object>

A collection of scalar values to be passed to the kernel.

Methods

Add(object?)

Adds an argument to the end of the argument list.

public void Add(object? argument)

Parameters

argument object

The argument to add. Can be null.

AddBuffer(IUnifiedMemoryBuffer)

Adds a buffer argument to the kernel arguments.

public void AddBuffer(IUnifiedMemoryBuffer buffer)

Parameters

buffer IUnifiedMemoryBuffer

The memory buffer to add.

Exceptions

ArgumentNullException

Thrown when buffer is null.

AddScalar(object)

Adds a scalar argument to the kernel arguments.

public void AddScalar(object scalar)

Parameters

scalar object

The scalar value to add.

Exceptions

ArgumentNullException

Thrown when scalar is null.

Clear()

Removes all arguments from this instance, resetting the Count to zero.

public void Clear()

Create(IEnumerable<IUnifiedMemoryBuffer>, IEnumerable<object>)

Creates a new KernelArguments instance with separate buffers and scalar arguments.

public static KernelArguments Create(IEnumerable<IUnifiedMemoryBuffer> buffers, IEnumerable<object> scalars)

Parameters

buffers IEnumerable<IUnifiedMemoryBuffer>

The buffer arguments.

scalars IEnumerable<object>

The scalar arguments.

Returns

KernelArguments

A new KernelArguments instance.

Create(int)

Creates a new KernelArguments instance with the specified initial capacity. The arguments list will be pre-filled with null values.

public static KernelArguments Create(int capacity)

Parameters

capacity int

The initial capacity for arguments.

Returns

KernelArguments

A new KernelArguments instance with the specified capacity.

Exceptions

ArgumentOutOfRangeException

Thrown when capacity is negative.

Create(params object?[])

Creates a new KernelArguments instance with the specified arguments.

public static KernelArguments Create(params object?[] arguments)

Parameters

arguments object[]

The initial arguments to store.

Returns

KernelArguments

A new KernelArguments instance with the specified arguments.

Exceptions

ArgumentNullException

Thrown when arguments is null.

Get(int)

Gets the argument at the specified index without type conversion.

public object? Get(int index)

Parameters

index int

The zero-based index of the argument to get.

Returns

object

The raw argument at the specified index.

Exceptions

ArgumentOutOfRangeException

Thrown when index is negative or greater than or equal to Count.

InvalidOperationException

Thrown when trying to access arguments on an uninitialized KernelArguments instance.

GetEnumerator()

Returns an enumerator that iterates through the arguments.

public IEnumerator<object?> GetEnumerator()

Returns

IEnumerator<object>

An enumerator for the arguments.

GetLaunchConfiguration()

Gets the launch configuration for backend-specific kernel execution.

public KernelLaunchConfiguration? GetLaunchConfiguration()

Returns

KernelLaunchConfiguration

The launch configuration or null if not set.

Get<T>(int)

Gets the argument at the specified index with type safety and automatic casting.

public T Get<T>(int index)

Parameters

index int

The zero-based index of the argument to get.

Returns

T

The argument at the specified index cast to the specified type.

Type Parameters

T

The expected type of the argument.

Exceptions

ArgumentOutOfRangeException

Thrown when index is negative or greater than or equal to Count.

InvalidOperationException

Thrown when trying to access arguments on an uninitialized KernelArguments instance.

InvalidCastException

Thrown when the argument cannot be cast to the specified type.

Set(int, object?)

Sets the argument at the specified index to the given value.

public void Set(int index, object? value)

Parameters

index int

The zero-based index of the argument to set.

value object

The value to set at the specified index. Can be null.

Exceptions

ArgumentOutOfRangeException

Thrown when index is negative or greater than or equal to Count.

InvalidOperationException

Thrown when trying to set an argument on an uninitialized KernelArguments instance.