Class: FFNFFICacheMetal
- Inherits:
-
Object
- Object
- FFNFFICacheMetal
- 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
-
#d_ff ⇒ Object
Returns the value of attribute d_ff.
-
#d_model ⇒ Object
Returns the value of attribute d_model.
-
#realized ⇒ Object
Returns the value of attribute realized.
-
#sess ⇒ Object
Returns the value of attribute sess.
-
#t_h ⇒ Object
Returns the value of attribute t_h.
-
#t_hidden ⇒ Object
Returns the value of attribute t_hidden.
-
#t_out ⇒ Object
Returns the value of attribute t_out.
-
#t_pre ⇒ Object
Returns the value of attribute t_pre.
-
#t_seq ⇒ Object
Returns the value of attribute t_seq.
-
#t_w1_t ⇒ Object
Returns the value of attribute t_w1_t.
-
#t_w2_t ⇒ Object
Returns the value of attribute t_w2_t.
Instance Method Summary collapse
-
#initialize ⇒ FFNFFICacheMetal
constructor
A new instance of FFNFFICacheMetal.
- #realize_for(t_seq, d_model, d_ff) ⇒ Object
Constructor Details
#initialize ⇒ FFNFFICacheMetal
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_ff ⇒ Object
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_model ⇒ Object
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 |
#realized ⇒ Object
Returns the value of attribute realized.
33 34 35 |
# File 'lib/toy/ffi/tinynn_metal.rb', line 33 def realized @realized end |
#sess ⇒ Object
Returns the value of attribute sess.
33 34 35 |
# File 'lib/toy/ffi/tinynn_metal.rb', line 33 def sess @sess end |
#t_h ⇒ Object
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_hidden ⇒ Object
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_out ⇒ Object
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_pre ⇒ Object
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_seq ⇒ Object
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_t ⇒ Object
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_t ⇒ Object
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 |