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
capacityintThe initial capacity for arguments.
Exceptions
- ArgumentOutOfRangeException
Thrown when
capacityis negative.
KernelArguments(params object?[])
Initializes a new instance of the KernelArguments class with the specified initial arguments.
public KernelArguments(params object?[] arguments)
Parameters
argumentsobject[]The initial arguments to store.
Exceptions
- ArgumentNullException
Thrown when
argumentsis 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
indexintThe zero-based index of the argument to get or set.
Property Value
- object
The argument at the specified index.
Exceptions
- ArgumentOutOfRangeException
Thrown when
indexis 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
argumentobjectThe argument to add. Can be null.
AddBuffer(IUnifiedMemoryBuffer)
Adds a buffer argument to the kernel arguments.
public void AddBuffer(IUnifiedMemoryBuffer buffer)
Parameters
bufferIUnifiedMemoryBufferThe 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
scalarobjectThe 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
buffersIEnumerable<IUnifiedMemoryBuffer>The buffer arguments.
scalarsIEnumerable<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
capacityintThe initial capacity for arguments.
Returns
- KernelArguments
A new KernelArguments instance with the specified capacity.
Exceptions
- ArgumentOutOfRangeException
Thrown when
capacityis negative.
Create(params object?[])
Creates a new KernelArguments instance with the specified arguments.
public static KernelArguments Create(params object?[] arguments)
Parameters
argumentsobject[]The initial arguments to store.
Returns
- KernelArguments
A new KernelArguments instance with the specified arguments.
Exceptions
- ArgumentNullException
Thrown when
argumentsis null.
Get(int)
Gets the argument at the specified index without type conversion.
public object? Get(int index)
Parameters
indexintThe zero-based index of the argument to get.
Returns
- object
The raw argument at the specified index.
Exceptions
- ArgumentOutOfRangeException
Thrown when
indexis 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
indexintThe zero-based index of the argument to get.
Returns
- T
The argument at the specified index cast to the specified type.
Type Parameters
TThe expected type of the argument.
Exceptions
- ArgumentOutOfRangeException
Thrown when
indexis 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
indexintThe zero-based index of the argument to set.
valueobjectThe value to set at the specified index. Can be null.
Exceptions
- ArgumentOutOfRangeException
Thrown when
indexis negative or greater than or equal to Count.- InvalidOperationException
Thrown when trying to set an argument on an uninitialized KernelArguments instance.