interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / ng / bench / kernels / linear.c

32 lines · 1365 bytes Raw Blame History
1/* linear.c -- REFERENCE TWIN ONLY (gcc oracle) of linear.om: omega-bridge pytorch/kernels/linear.om
2 (o[M,N] = c[N] + a[M,K] @ w[N,K]^T, each sum in double from the bias, rounded once to float) at
3 M 64, K 256, N 256, with the same inputs, 40 passes and the same checksum line. */
4#include <stdio.h>
5#include <stdint.h>
6#include <string.h>
7#define M 64
8#define K 256
9#define N 256
10static float c[N], a[M * K], w[N * K], o[M * N];
11static double lindot(uint64_t i, uint64_t j) {
12 double s = (double)c[j];
13 uint64_t ia = i * K, iw = j * K;
14 for (uint64_t k = 0; k < K; k++) { s += (double)a[ia] * (double)w[iw]; ia++; iw++; }
15 return s;
16}
17static void linear(void) {
18 for (uint64_t i = 0; i < M; i++) for (uint64_t j = 0; j < N; j++) o[i * N + j] = (float)lindot(i, j);
19}
20int main(void) {
21 for (uint64_t i = 0; i < N; i++) c[i] = (float)((int64_t)((i * 5) % 11) - 5) / 4.0f;
22 for (uint64_t i = 0; i < M * K; i++) a[i] = (float)((int64_t)((i * 7) % 13) - 6) / 8.0f;
23 for (uint64_t i = 0; i < N * K; i++) w[i] = (float)((int64_t)((i * 3) % 17) - 8) / 16.0f;
24 uint64_t s = 0;
25 for (uint64_t r = 0; r < 40; r++) {
26 c[r % 256] += 1.0f;
27 linear();
28 for (uint64_t i = 0; i < M * N; i++) { uint32_t b; memcpy(&b, &o[i], 4); s += (uint64_t)b * (i + 1); }
29 }
30 printf("%llu\n", (unsigned long long)s);
31 return 0;
32}