class

OCL(T)

Inherits Num::Backend::Storage / Reference / Object

Constructors

new(shape : Array(Int), order : Num::OrderType, value : T)

Initialize an OpenCL storage from an initial capacity and an initial value, which will fill the buffer

Arguments

  • shape : Array(Int) - Shape for parent Tensor
  • order : Num::OrderType - Memory layout for parent Tensor
  • value : T - Value to initially populate the buffer

Examples

OCL.new([10, 10], Num::RowMajor, 3.4)
Source
new(shape : Array(Int), strides : Array(Int), value : T)

Initialize an OpenCL storage from an initial capacity and an initial value, which will fill the buffer

Arguments

  • shape : Array(Int) - Shape for parent Tensor
  • strides : Array(Int) - Strides for parent Tensor
  • value : T - Value to initially populate the buffer

Examples

OCL.new([10, 10], [10, 1], 3.4)
Source
new(hostptr : Pointer(T), shape : Array(Int), strides : Array(Int))

Initialize an OpenCL storage from a standard library Crystal pointer

Arguments

  • hostptr : Pointer(T) - Stdlib Crystal pointer containing the Tensors data
  • shape : Array(Int) - Shape for parent Tensor
  • strides : Array(Int) - Strides for parent Tensor

Examples

ptr = Pointer(Int32).malloc(9)
OCL.new(ptr, [3, 3], [3, 1])
Source
new(shape : Array(Int), order : Num::OrderType)

Initialize an OpenCL storage from an initial capacity. The data will be filled with zeros

Arguments

  • shape : Array(Int) - Shape for parent Tensor
  • order : Num::OrderType - Memory layout for parent Tensor

Examples

OCL.new([100], Num::RowMajor)
Source
new(shape : Array(Int), strides : Array(Int))

Initialize an OpenCL storage from an initial capacity. The data will be filled with zeros

Arguments

  • shape : Array(Int) - Shape for parent Tensor
  • strides : Array(Int) - Strides for parent Tensor

Examples

OCL.new([100], [1])
Source

Class methods

base(dtype : U.class) : OCL(U).class forall U

Return a generic class of a specific generic type, to allow for explicit return types in functions that return a different storage type than the parent Tensor

a = OCL(Float32).new([10])

# Cannot do
# a.class.new ...

a.class.base(Float64).new([10])
Source

Instance methods

data

Data buffer containing the data associated with the parent Tensor

Source
finalize

Releases the underlying LibCL::ClMem buffers containing the data for a Tensor, as well as the buffers containing the shape and strides for the Tensor

Source
shape

Data buffer containing the shape associated with the parent Tensor

Source
strides

Data buffer containing the strides associated with the parent Tensor

Source
to_unsafe

Returns the underlying OpenCL memory buffer associated with a Tensor

Source
total_size

Total size of the underlying data buffer. Keeps track of the total size of a buffer if a Tensor has been sliced

Source
update_metadata(shape : Array(Int32), strides : Array(Int32))
Source