Class: TensorStream::OpenCLBuffer
- Includes:
- ArrayOpsHelper
- Defined in:
- lib/tensor_stream/evaluator/opencl/opencl_buffer.rb
Overview
Buffer used by the OpenCL evaluator
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#cl_buffer ⇒ Object
Returns the value of attribute cl_buffer.
-
#op ⇒ Object
Returns the value of attribute op.
-
#shape ⇒ Object
Returns the value of attribute shape.
Attributes inherited from Buffer
Instance Method Summary collapse
-
#initialize(data_type:, shape:, buffer:, cl_buffer:, op: nil, name: nil) ⇒ OpenCLBuffer
constructor
A new instance of OpenCLBuffer.
- #to_ruby ⇒ Object
Methods included from ArrayOpsHelper
#_reduced_shape, #broadcast, #broadcast_dimensions, #get_rank, #last_axis, #process_function_op, #shape_diff, #slice_tensor, #softmax, #softmax_grad, #tile_arr, #truncate, #vector_op
Constructor Details
#initialize(data_type:, shape:, buffer:, cl_buffer:, op: nil, name: nil) ⇒ OpenCLBuffer
Returns a new instance of OpenCLBuffer.
8 9 10 11 12 13 14 15 |
# File 'lib/tensor_stream/evaluator/opencl/opencl_buffer.rb', line 8 def initialize(data_type:, shape:, buffer:, cl_buffer:, op: nil, name: nil) @data_type = data_type @shape = shape @buffer = buffer @cl_buffer = cl_buffer @name = name @op = op end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
6 7 8 |
# File 'lib/tensor_stream/evaluator/opencl/opencl_buffer.rb', line 6 def buffer @buffer end |
#cl_buffer ⇒ Object
Returns the value of attribute cl_buffer.
6 7 8 |
# File 'lib/tensor_stream/evaluator/opencl/opencl_buffer.rb', line 6 def cl_buffer @cl_buffer end |
#op ⇒ Object
Returns the value of attribute op.
6 7 8 |
# File 'lib/tensor_stream/evaluator/opencl/opencl_buffer.rb', line 6 def op @op end |
#shape ⇒ Object
Returns the value of attribute shape.
6 7 8 |
# File 'lib/tensor_stream/evaluator/opencl/opencl_buffer.rb', line 6 def shape @shape end |
Instance Method Details
#to_ruby ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tensor_stream/evaluator/opencl/opencl_buffer.rb', line 17 def to_ruby return [] if buffer.empty? if shape.empty? return buffer[0] != 0 if data_type == :boolean return buffer[0] end if dirty op.command_queue.enqueue_read_buffer(cl_buffer, buffer, event_wait_list: [op].compact) op.command_queue.finish self.dirty = false end result = buffer.reshape(*shape.map(&:to_i).reverse).to_a result = process_function_op(result, ->(a, _b) { a != 0 }) if data_type == :boolean result end |