class OCL(T)
inherits Num::Backend::Storage
#
Constructors#
.new(shape : Array(Int), order : Num::OrderType, value : T)
#
(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 parentTensor
- order :
Num::OrderType
- Memory layout for parentTensor
- value :
T
- Value to initially populate the buffer
Examples#
OCL.new([10, 10], Num::RowMajor, 3.4)
.new(shape : Array(Int), strides : Array(Int), value : T)
#
(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 parentTensor
- strides :
Array(Int)
- Strides for parentTensor
- value :
T
- Value to initially populate the buffer
Examples#
OCL.new([10, 10], [10, 1], 3.4)
.new(hostptr : Pointer(T), shape : Array(Int), strides : Array(Int))
#
(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 theTensor
s data - shape :
Array(Int)
- Shape for parentTensor
- strides :
Array(Int)
- Strides for parentTensor
Examples#
ptr = Pointer(Int32).malloc(9)
OCL.new(ptr, [3, 3], [3, 1])
.new(shape : Array(Int), order : Num::OrderType)
#
(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 parentTensor
- order :
Num::OrderType
- Memory layout for parentTensor
Examples#
OCL.new([100], Num::RowMajor)
.new(shape : Array(Int), strides : Array(Int))
#
(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 parentTensor
- strides :
Array(Int)
- Strides for parentTensor
Examples#
OCL.new([100], [1])
Class methods#
.base(dtype : U.class) : OCL(U).class forall U
#
(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])
Methods#
#data : LibCL::ClMem
#
: LibCL::ClMem
Data buffer containing the data associated with the parent Tensor
#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
#shape : LibCL::ClMem
#
: LibCL::ClMem
Data buffer containing the shape associated with the parent Tensor
#strides : LibCL::ClMem
#
: LibCL::ClMem
Data buffer containing the strides associated with the parent Tensor
#to_unsafe : LibCL::ClMem
#
: LibCL::ClMem
Returns the underlying OpenCL memory buffer associated with a Tensor
#total_size : Int32
#
: Int32
Total size of the underlying data buffer. Keeps track of the total
size of a buffer if a Tensor
has been sliced