-
Notifications
You must be signed in to change notification settings - Fork 255
/
matmul-vsl.v
64 lines (59 loc) · 1.16 KB
/
matmul-vsl.v
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
import os
import math
import net
import vsl.la
fn matgen(n int, seed f64) &la.Matrix[f64] {
n2 := n * n
mut a := []f64{len: n2}
tmp := seed / n2
mut c := 0
for i in 0 .. n {
for j in 0 .. n {
v := tmp * f64(i - j) * f64(i + j)
a[c] = v
c++
}
}
return la.Matrix.raw(n, n, a)
}
@[inline]
fn matmul(a &la.Matrix[f64], b &la.Matrix[f64]) &la.Matrix[f64] {
mut c := la.Matrix.new[f64](a.m, b.n)
la.matrix_matrix_mul(mut c, 1.0, a, b)
return c
}
fn notify(msg string) {
mut sock := net.dial_tcp('127.0.0.1:9001') or { return }
defer {
sock.close() or {}
}
sock.write_string(msg) or {}
}
fn calc(n int) f64 {
size := n / 2 * 2
a := matgen(size, 1.0)
b := matgen(size, 2.0)
c := matmul(a, b)
return c.get(size / 2, size / 2)
}
fn main() {
n := if os.args.len > 1 { os.args[1].int() } else { 100 }
left := calc(101)
right := -18.67
if math.abs(left - right) > 0.1 {
panic('${left} != ${right}')
}
mut label := 'VSL'
mut compiler := 'gcc'
$if clang {
compiler = 'clang'
}
$if cblas ? {
label = 'VSL + CBLAS'
}
mut lang := 'V/${compiler} (${label})'
notify('${lang}\t${C.getpid()}')
results := calc(n)
notify('stop')
println(results)
}