cera 0.5.2

Rust-native LLM inference engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include <metal_stdlib>
#include <metal_math>
#include <metal_texture>
using namespace metal;

#line 112 "cera/src/backend/shaders/slang/conv1d_fused_batch.slang"
struct KernelContext_0
{
    uint device* par_buf_0;
    float device* w_buf_0;
    float device* rbuf_0;
    float device* proj_buf_0;
    float device* out_buf_0;
};


#line 70
[[kernel]] void conv1d_fused_batch(uint3 gid_0 [[thread_position_in_grid]], uint device* par_buf_1 [[buffer(4)]], float device* w_buf_1 [[buffer(2)]], float device* rbuf_1 [[buffer(1)]], float device* proj_buf_1 [[buffer(0)]], float device* out_buf_1 [[buffer(3)]])
{

#line 70
    thread KernelContext_0 kernelContext_0;

#line 70
    (&kernelContext_0)->par_buf_0 = par_buf_1;

#line 70
    (&kernelContext_0)->w_buf_0 = w_buf_1;

#line 70
    (&kernelContext_0)->rbuf_0 = rbuf_1;

#line 70
    (&kernelContext_0)->proj_buf_0 = proj_buf_1;

#line 70
    (&kernelContext_0)->out_buf_0 = out_buf_1;
    uint ch_0 = gid_0.x;
    uint hs_0 = par_buf_1[int(0)];
    uint ks_0 = par_buf_1[int(1)];
    uint d_conv_0 = par_buf_1[int(2)];
    uint _S1 = par_buf_1[int(3)];
    uint _S2 = par_buf_1[int(4)];
    uint _S3 = par_buf_1[int(5)];

    if(ch_0 >= hs_0)
    {

#line 80
        return;
    }

#line 80
    bool _S4;



    if(ks_0 > 4U)
    {

#line 84
        _S4 = true;

#line 84
    }
    else
    {

#line 84
        _S4 = d_conv_0 > 3U;

#line 84
    }

#line 84
    if(_S4)
    {

#line 85
        return;
    }

#line 101
    thread array<float, int(4)> w_local_0;

#line 101
    w_local_0[int(0)] = 0.0f;

#line 101
    w_local_0[int(1)] = 0.0f;

#line 101
    w_local_0[int(2)] = 0.0f;

#line 101
    w_local_0[int(3)] = 0.0f;


    if(0U <= d_conv_0)
    {

#line 104
        _S4 = 0U < ks_0;

#line 104
    }
    else
    {

#line 104
        _S4 = false;

#line 104
    }

#line 104
    if(_S4)
    {

#line 105
        w_local_0[0U] = (&kernelContext_0)->w_buf_0[ch_0 * ks_0];

#line 104
    }

#line 104
    if(1U <= d_conv_0)
    {

#line 104
        _S4 = 1U < ks_0;

#line 104
    }
    else
    {

#line 104
        _S4 = false;

#line 104
    }

#line 104
    if(_S4)
    {

#line 105
        w_local_0[1U] = (&kernelContext_0)->w_buf_0[ch_0 * ks_0 + 1U];

#line 104
    }

#line 104
    if(2U <= d_conv_0)
    {

#line 104
        _S4 = 2U < ks_0;

#line 104
    }
    else
    {

#line 104
        _S4 = false;

#line 104
    }

#line 104
    if(_S4)
    {

#line 105
        w_local_0[2U] = (&kernelContext_0)->w_buf_0[ch_0 * ks_0 + 2U];

#line 104
    }

#line 104
    if(3U <= d_conv_0)
    {

#line 104
        _S4 = 3U < ks_0;

#line 104
    }
    else
    {

#line 104
        _S4 = false;

#line 104
    }

#line 104
    if(_S4)
    {

#line 105
        w_local_0[3U] = (&kernelContext_0)->w_buf_0[ch_0 * ks_0 + 3U];

#line 104
    }



    thread array<float, int(3)> rb_0;

#line 108
    rb_0[int(0)] = 0.0f;

#line 108
    rb_0[int(1)] = 0.0f;

#line 108
    rb_0[int(2)] = 0.0f;


    bool _S5 = 0U < d_conv_0;

#line 111
    if(_S5)
    {

#line 112
        rb_0[0U] = *((&kernelContext_0)->rbuf_0+ch_0);

#line 111
    }

#line 111
    bool _S6 = 1U < d_conv_0;

#line 111
    if(_S6)
    {

#line 112
        rb_0[1U] = *((&kernelContext_0)->rbuf_0+(hs_0 + ch_0));

#line 111
    }

#line 111
    bool _S7 = 2U < d_conv_0;

#line 111
    if(_S7)
    {

#line 112
        rb_0[2U] = *((&kernelContext_0)->rbuf_0+(2U * hs_0 + ch_0));

#line 111
    }

#line 110
    uint t_0 = 0U;

#line 116
    for(;;)
    {

#line 116
        if(t_0 < _S1)
        {
        }
        else
        {

#line 116
            break;
        }

#line 117
        uint base_0 = t_0 * _S2;

#line 123
        float c_val_0 = (&kernelContext_0)->proj_buf_0[base_0 + hs_0 + ch_0];

        float bx_0 = (&kernelContext_0)->proj_buf_0[base_0 + ch_0] * (&kernelContext_0)->proj_buf_0[base_0 + 2U * hs_0 + ch_0];

#line 125
        float sum_0;

#line 130
        if(_S5)
        {

#line 130
            sum_0 = rb_0[0U] * w_local_0[0U];

#line 130
        }
        else
        {

#line 130
            sum_0 = 0.0f;

#line 130
        }

#line 129
        float sum_1;
        if(_S6)
        {

#line 130
            sum_1 = sum_0 + rb_0[1U] * w_local_0[1U];

#line 130
        }
        else
        {

#line 130
            sum_1 = sum_0;

#line 130
        }

#line 129
        float sum_2;
        if(_S7)
        {

#line 130
            sum_2 = sum_1 + rb_0[2U] * w_local_0[2U];

#line 130
        }
        else
        {

#line 130
            sum_2 = sum_1;

#line 130
        }

#line 140
        float sum_3 = sum_2 + bx_0 * w_local_0[d_conv_0];

#line 145
        if(_S6)
        {

#line 146
            rb_0[0U] = rb_0[1U];

#line 145
        }

#line 145
        if(_S7)
        {

#line 146
            rb_0[1U] = rb_0[2U];

#line 145
        }



        if(d_conv_0 > 0U)
        {

#line 150
            rb_0[d_conv_0 - 1U] = bx_0;

#line 149
        }



        *((&kernelContext_0)->out_buf_0+(t_0 * _S3 + ch_0)) = c_val_0 * sum_3;

#line 116
        t_0 = t_0 + 1U;

#line 116
    }

#line 159
    if(_S5)
    {

#line 160
        *((&kernelContext_0)->rbuf_0+ch_0) = rb_0[0U];

#line 159
    }

#line 159
    if(_S6)
    {

#line 160
        *((&kernelContext_0)->rbuf_0+(hs_0 + ch_0)) = rb_0[1U];

#line 159
    }

#line 159
    if(_S7)
    {

#line 160
        *((&kernelContext_0)->rbuf_0+(2U * hs_0 + ch_0)) = rb_0[2U];

#line 159
    }



    return;
}