Class: TensorStream::OpenCLBuffer::LazyBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/tensor_stream/opencl/opencl_buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_type, size) ⇒ LazyBuffer

Returns a new instance of LazyBuffer.



7
8
9
10
# File 'lib/tensor_stream/opencl/opencl_buffer.rb', line 7

def initialize(data_type, size)
  @data_type = data_type
  @size = size
end

Instance Attribute Details

#data_typeObject (readonly)

Returns the value of attribute data_type.



5
6
7
# File 'lib/tensor_stream/opencl/opencl_buffer.rb', line 5

def data_type
  @data_type
end

Instance Method Details

#buffer_size_for_type(data_type) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tensor_stream/opencl/opencl_buffer.rb', line 20

def buffer_size_for_type(data_type)
  case data_type
  when :float, :float32, :float16
    4
  when :float64
    8
  when :int, :int32, :int64, :uint64, :uint32 # NArray does not have 64 bit int types
    4
  when :int16, :uint16
    2
  when :uint8, :int8
    1
  when :boolean
    1
  when :string
    1
  when :unknown
    nil
  else
    raise "unsupported type #{data_type}"
  end
end

#element_sizeObject



16
17
18
# File 'lib/tensor_stream/opencl/opencl_buffer.rb', line 16

def element_size
  buffer_size_for_type(@data_type)
end

#sizeObject



12
13
14
# File 'lib/tensor_stream/opencl/opencl_buffer.rb', line 12

def size
  @size
end