Struct DeviceMemory<T>
- Namespace
- DotCompute.Abstractions.Memory
- Assembly
- DotCompute.Abstractions.dll
Represents a reference to device memory that can be accessed as a span.
public readonly struct DeviceMemory<T> : IEquatable<DeviceMemory<T>> where T : unmanaged
Type Parameters
TThe unmanaged type stored in memory.
- Implements
- Inherited Members
Remarks
Initializes a new instance of the DeviceMemory<T> struct.
Constructors
DeviceMemory(T*, int)
Represents a reference to device memory that can be accessed as a span.
public DeviceMemory(T* devicePtr, int length)
Parameters
devicePtrT*Pointer to the device memory.
lengthintLength in elements.
Remarks
Initializes a new instance of the DeviceMemory<T> struct.
Properties
IsEmpty
Gets whether this memory reference is empty.
public bool IsEmpty { get; }
Property Value
Length
Gets the length of the memory region in elements.
public int Length { get; }
Property Value
Pointer
Gets the raw pointer to device memory.
public T* Pointer { get; }
Property Value
- T*
ReadOnlySpan
Gets a read-only span representing the device memory. WARNING: This should only be used when device memory is accessible from host.
public ReadOnlySpan<T> ReadOnlySpan { get; }
Property Value
- ReadOnlySpan<T>
Span
Gets a span representing the device memory. WARNING: This should only be used when device memory is accessible from host.
public Span<T> Span { get; }
Property Value
- Span<T>
Methods
Equals(DeviceMemory<T>)
Determines whether the current instance is equal to another DeviceMemory instance.
public bool Equals(DeviceMemory<T> other)
Parameters
otherDeviceMemory<T>The DeviceMemory instance to compare with this instance.
Returns
- bool
true if the instances are equal; otherwise, false.
Equals(object?)
Determines whether the current instance is equal to a specified object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with this instance.
Returns
- bool
true if obj is a DeviceMemory and is equal to this instance; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for the current instance.
Slice(int, int)
Creates a slice of this device memory.
public DeviceMemory<T> Slice(int start, int length)
Parameters
Returns
- DeviceMemory<T>
A new DeviceMemory representing the slice.
Operators
operator ==(DeviceMemory<T>, DeviceMemory<T>)
Determines whether two DeviceMemory instances are equal.
public static bool operator ==(DeviceMemory<T> left, DeviceMemory<T> right)
Parameters
leftDeviceMemory<T>The first instance to compare.
rightDeviceMemory<T>The second instance to compare.
Returns
- bool
true if the instances are equal; otherwise, false.
operator !=(DeviceMemory<T>, DeviceMemory<T>)
Determines whether two DeviceMemory instances are not equal.
public static bool operator !=(DeviceMemory<T> left, DeviceMemory<T> right)
Parameters
leftDeviceMemory<T>The first instance to compare.
rightDeviceMemory<T>The second instance to compare.
Returns
- bool
true if the instances are not equal; otherwise, false.