-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.spi
42 lines (38 loc) · 1.21 KB
/
main.spi
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
open inv
open upmem
open upmem_loop
open utils_real
open utils
// Maps the input array inplace.
inl map_inp f = run fun input output =>
global "#include <mram.h>"
global "__mram_noinit uint8_t buffer[1024*1024*64];"
inl block_size = 8
// Creates the WRAM buffers as inverse arrays.
inl buf_in = create block_size
inl buf_out = create block_size
inl len = length input
forBy {from=0; nearTo=len; by=block_size} fun from =>
inl nearTo = min len (from + block_size)
// Reads the MRAM into the WRAM buffer.
mram_read input buf_in {from nearTo}
for {from=0; nearTo=nearTo - from} fun i =>
set buf_out i (f (index buf_in i))
mram_write buf_out output {from nearTo}
0
// Maps the input array.
inl map f input = inl output = create (length input) in map_inp f input output . output
inl main () =
global "import os"
global "from io import StringIO"
global "from sys import stdout"
global "import struct"
inl test_size = 16
inl input =
zip (arange test_size)
<| zip (arange test_size)
<| arange test_size
$"print(!input)"
inl output = map (fun x, y, z => x+y+z,x*y*z) input
$"print(!output)"
()