Class: FFNFFICacheMetal

Inherits:
Object
  • Object
show all
Defined in:
lib/toy/ffi/tinynn_metal.rb

Overview

Same as FFNFFICache / FFNFFICacheCuda — Metal-flavored. Class name differs so drivers requiring multiple backends don’t trip Spinel’s same-class-defined-twice path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFFNFFICacheMetal

Returns a new instance of FFNFFICacheMetal.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/toy/ffi/tinynn_metal.rb', line 37

def initialize
  @realized = false
  @t_seq    = 0
  @d_model  = 0
  @d_ff     = 0
  @sess     = TinyNNMetal.tnn_null_ptr
  @t_h      = TinyNNMetal.tnn_null_ptr
  @t_w1_t   = TinyNNMetal.tnn_null_ptr
  @t_w2_t   = TinyNNMetal.tnn_null_ptr
  @t_pre    = TinyNNMetal.tnn_null_ptr
  @t_hidden = TinyNNMetal.tnn_null_ptr
  @t_out    = TinyNNMetal.tnn_null_ptr
end

Instance Attribute Details

#d_ffObject

Returns the value of attribute d_ff.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def d_ff
  @d_ff
end

#d_modelObject

Returns the value of attribute d_model.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def d_model
  @d_model
end

#realizedObject

Returns the value of attribute realized.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def realized
  @realized
end

#sessObject

Returns the value of attribute sess.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def sess
  @sess
end

#t_hObject

Returns the value of attribute t_h.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_h
  @t_h
end

#t_hiddenObject

Returns the value of attribute t_hidden.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_hidden
  @t_hidden
end

#t_outObject

Returns the value of attribute t_out.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_out
  @t_out
end

#t_preObject

Returns the value of attribute t_pre.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_pre
  @t_pre
end

#t_seqObject

Returns the value of attribute t_seq.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_seq
  @t_seq
end

#t_w1_tObject

Returns the value of attribute t_w1_t.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_w1_t
  @t_w1_t
end

#t_w2_tObject

Returns the value of attribute t_w2_t.



33
34
35
# File 'lib/toy/ffi/tinynn_metal.rb', line 33

def t_w2_t
  @t_w2_t
end

Instance Method Details

#realize_for(t_seq, d_model, d_ff) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/toy/ffi/tinynn_metal.rb', line 51

def realize_for(t_seq, d_model, d_ff)
  @t_seq   = t_seq
  @d_model = d_model
  @d_ff    = d_ff

  @sess   = TinyNNMetal.tnn_session_new(2)
  @t_h    = TinyNNMetal.tnn_input_2d_f32(@sess, t_seq,  d_model)
  @t_w1_t = TinyNNMetal.tnn_input_2d_f32(@sess, d_ff,   d_model)
  @t_w2_t = TinyNNMetal.tnn_input_2d_f32(@sess, d_model, d_ff)
  @t_pre    = TinyNNMetal.tnn_matmul(@sess, @t_w1_t, @t_h)
  @t_hidden = TinyNNMetal.tnn_gelu(@sess, @t_pre)
  @t_out    = TinyNNMetal.tnn_matmul(@sess, @t_w2_t, @t_hidden)
  TinyNNMetal.tnn_set_output(@t_pre)
  TinyNNMetal.tnn_set_output(@t_hidden)
  TinyNNMetal.tnn_set_output(@t_out)
  TinyNNMetal.tnn_realize(@sess, @t_out)
  @realized = true
end