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 / bench / omc_efficiency / kernels / matmul.c

36 lines · 1605 bytes Raw Blame History
1/* matmul.c -- REFERENCE TWIN ONLY (gcc oracle) of kernels/matmul.om: same matrices, same output. */
2#include <stdio.h>
3#include <stdint.h>
4#include <time.h>
5static void putnum(uint64_t v) { printf("%llu\n", (unsigned long long)v); }
6/* OMC-EFF-2: the computation is timed in process with CLOCK_MONOTONIC and the nanoseconds go to stderr.
7 The empty asm statements are compiler barriers: they keep the timed work between the two clock reads. */
8static uint64_t nowns(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return (uint64_t)t.tv_sec * 1000000000u + (uint64_t)t.tv_nsec; }
9static void putns(uint64_t t0, uint64_t t1) { fprintf(stderr, "%llu\n", (unsigned long long)(t1 - t0)); }
10static uint64_t ma[90000], mb[90000], mc[90000];
11int main(void) {
12 uint64_t t0 = nowns();
13 __asm__ volatile("" : : : "memory");
14 for (uint64_t i = 0; i < 300; i++)
15 for (uint64_t j = 0; j < 300; j++) {
16 ma[i * 300 + j] = (i + j * 2) % 13;
17 mb[i * 300 + j] = (i * 3 + j) % 11;
18 }
19 for (uint64_t i = 0; i < 300; i++) {
20 uint64_t r = i * 300;
21 for (uint64_t j = 0; j < 300; j++) {
22 uint64_t s = 0, q = j;
23 for (uint64_t k = 0; k < 300; k++) { s += ma[r + k] * mb[q]; q += 300; }
24 mc[r + j] = s;
25 }
26 }
27 uint64_t tot = 0, tr = 0;
28 for (uint64_t i = 0; i < 300; i++) {
29 for (uint64_t j = 0; j < 300; j++) tot += mc[i * 300 + j];
30 tr += mc[i * 301];
31 }
32 __asm__ volatile("" : : "r"(tot), "r"(tr) : "memory");
33 putns(t0, nowns());
34 putnum(tot); putnum(tr);
35 return 0;
36}