Skip to content

Commit 86f143b

Browse files
Mark1626Quasorglow
andauthored
feat: Add Calyx bindings (#11)
Co-authored-by: Swethaa <[email protected]>
1 parent 9605ec0 commit 86f143b

25 files changed

+25556
-21
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ test-*/
1414
test_generator/build
1515
PositTestGenerator
1616

17+
lib/P16
18+
lib/P32
19+
lib/P64
20+
lib/posit_*.sv

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ P64toP32 \
8484
define test_template
8585

8686
test-$(1)/Eval_$(1).v: src/main/scala/*.scala
87-
sbt "run $(1) -td test-$(1)"
87+
sbt "run tb $(1) -td test-$(1)"
8888

8989
test-$(1)/dut.mk: test-$(1)/Eval_$(1).v
9090
$(VERILATOR) -cc --prefix dut --Mdir test-$(1) -CFLAGS "$(VERILATOR_CFLAGS) -include ../csrc/test-$(1).h" test-$(1)/Eval_Posit$(1).v --exe csrc/test-$(3).cpp

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ For more information about Universal numbers and Posit arithmetic and to follow
2121
[Posit Hub] \
2222
[Unum-computing Google group]
2323

24+
## Calyx Binding
25+
26+
Calyx is an infrastructure for accelerator design. This repo has bindings for Calyx Native. These bindings can allow Posit arithmetic for Calyx frontends such as Dahlia.
27+
28+
More information about the Calyx binding and it's usage is in the [lib directory](./lib/README.md)
29+
2430
## Unit Testing
2531

2632
The posit arithmetic modules have been unit tested using Chisel IO testers. For better coverage a random test generator is also available enabled by the [universal] C++ template library. The test generator supplies tests to the hardware units which are simulated using [verilator].

lib/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
all: posit_16.sv posit_32.sv posit_64.sv
2+
3+
posit_%.sv: P%
4+
rm -f $@
5+
cat $</*.sv > $@
6+
7+
.PHONY = posit_16.sv posit_32.sv posit_64.sv

lib/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Calyx Bindings for Hardposit
2+
3+
## Build Instructions
4+
5+
1. To generate the System Verilog from the Chisel modules, from the root folder run
6+
7+
```
8+
# From the root folder of the project
9+
sbt run gen P32 full
10+
11+
# For 64 bit posit and 16 bit posit
12+
sbt run gen P32 full
13+
```
14+
15+
For Posit 32, this will create a folder `P32` with one SV file per module.
16+
17+
2. Combine all the SV modules to create a single SV
18+
19+
```
20+
# From lib/
21+
make
22+
```
23+
24+
## Examples
25+
26+
The examples folder contains examples of using the binding in Calyx Native
27+
28+
```
29+
fud e --to dat vector_add.futil -s verilog.data vector_add.fuse.data --through verilog
30+
```
31+
32+
## Frontends
33+
34+
Calyx frontends will have to emit these primitive to use the Hardposit modules.

lib/examples/vector_add.fuse.data

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"a": {
3+
"data": [
4+
0,
5+
1,
6+
2,
7+
3,
8+
0,
9+
1,
10+
2,
11+
3
12+
],
13+
"format": {
14+
"numeric_type": "bitnum",
15+
"is_signed": false,
16+
"width": 32
17+
}
18+
},
19+
"b": {
20+
"data": [
21+
1,
22+
2,
23+
2,
24+
3,
25+
1,
26+
2,
27+
2,
28+
3
29+
],
30+
"format": {
31+
"numeric_type": "bitnum",
32+
"is_signed": false,
33+
"width": 32
34+
}
35+
},
36+
"c": {
37+
"data": [
38+
0,
39+
0,
40+
0,
41+
0,
42+
0,
43+
0,
44+
0,
45+
0
46+
],
47+
"format": {
48+
"numeric_type": "bitnum",
49+
"is_signed": false,
50+
"width": 32
51+
}
52+
}
53+
}

lib/examples/vector_add.futil

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import "primitives/core.futil";
2+
import "primitives/memories/seq.futil";
3+
import "primitives/binary_operators.futil";
4+
import "../posit_32.futil";
5+
component main() -> () {
6+
cells {
7+
@external(1) a = seq_mem_d1(32,8,4);
8+
a_read0_0 = std_reg(32);
9+
add0 = posit_32_add();
10+
add1 = std_add(4);
11+
@external(1) b = seq_mem_d1(32,8,4);
12+
b_read0_0 = std_reg(32);
13+
@external(1) c = seq_mem_d1(32,8,4);
14+
const0 = std_const(4,0);
15+
const1 = std_const(4,7);
16+
const2 = std_const(4,1);
17+
i0 = std_reg(4);
18+
le0 = std_le(4);
19+
}
20+
wires {
21+
comb group cond0 {
22+
le0.left = i0.out;
23+
le0.right = const1.out;
24+
}
25+
group let0<"promotable"=1> {
26+
i0.in = const0.out;
27+
i0.write_en = 1'd1;
28+
let0[done] = i0.done;
29+
}
30+
group let1<"promotable"=2> {
31+
a_read0_0.in = a.read_data;
32+
a_read0_0.write_en = a.done;
33+
let1[done] = a_read0_0.done;
34+
a.content_en = 1'd1;
35+
a.addr0 = i0.out;
36+
}
37+
group let2<"promotable"=2> {
38+
b_read0_0.in = b.read_data;
39+
b_read0_0.write_en = b.done;
40+
let2[done] = b_read0_0.done;
41+
b.content_en = 1'd1;
42+
b.addr0 = i0.out;
43+
}
44+
group upd0<"promotable"=1> {
45+
c.content_en = 1'd1;
46+
c.addr0 = i0.out;
47+
c.write_en = 1'd1;
48+
add0.io_num1 = a_read0_0.out;
49+
add0.io_num2 = b_read0_0.out;
50+
add0.io_sub = 1'd0;
51+
c.write_data = add0.io_out;
52+
upd0[done] = c.done;
53+
}
54+
group upd1<"promotable"=1> {
55+
i0.write_en = 1'd1;
56+
add1.left = i0.out;
57+
add1.right = const2.out;
58+
i0.in = add1.out;
59+
upd1[done] = i0.done;
60+
}
61+
}
62+
control {
63+
seq {
64+
@pos(0) let0;
65+
@bound(8) while le0.out with cond0 {
66+
seq {
67+
par {
68+
@pos(1) let1;
69+
@pos(2) let2;
70+
}
71+
@pos(3) upd0;
72+
@pos(0) upd1;
73+
}
74+
}
75+
}
76+
}
77+
}
78+
metadata #{
79+
0: for (let i: ubit<4> = 0..8) {
80+
1: c[i] := a[i] + b[i];
81+
2: c[i] := a[i] + b[i];
82+
3: c[i] := a[i] + b[i];
83+
}#

lib/posit_16.futil

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
extern "posit_16.sv" {
2+
comb primitive posit_16_add[](
3+
@write_together(1) io_num1: 16,
4+
@write_together(1) io_num2: 16,
5+
@write_together(1) io_sub: 1,
6+
@clk clock: 1,
7+
@reset reset: 1
8+
) -> (
9+
io_isZero: 1,
10+
io_isNaR : 1,
11+
io_out: 16
12+
);
13+
14+
comb primitive posit_16_mul[](
15+
@write_together(1) io_num1: 16,
16+
@write_together(1) io_num2: 16,
17+
@clk clock: 1,
18+
@reset reset: 1
19+
) -> (
20+
io_isZero: 1,
21+
io_isNaR : 1,
22+
io_out: 16
23+
);
24+
25+
comb primitive posit_16_compare[](
26+
@write_together(1) io_num1: 16,
27+
@write_together(1) io_num2: 16,
28+
@clk clock: 1,
29+
@reset reset: 1
30+
) -> (
31+
io_lt: 1,
32+
io_eq : 1,
33+
io_gt: 1
34+
);
35+
36+
primitive posit_16_divsqrt[](
37+
@write_together(1) io_num1: 16,
38+
@write_together(1) io_num2: 16,
39+
@write_together(1) @interval(1) @go(1) io_validIn: 1,
40+
@write_together(1) io_sqrtOp: 1,
41+
@clk clock: 1,
42+
@reset reset: 1
43+
) -> (
44+
io_readyIn: 1,
45+
io_out: 16,
46+
io_isZero: 1,
47+
io_isNaR : 1,
48+
@done io_validOut_div: 1,
49+
@done io_validOut_sqrt: 1,
50+
io_exceptions: 4,
51+
);
52+
}

lib/posit_32.futil

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
extern "posit_32.sv" {
2+
comb primitive posit_32_add[](
3+
@write_together(1) io_num1: 32,
4+
@write_together(1) io_num2: 32,
5+
@write_together(1) io_sub: 1,
6+
@clk clock: 1,
7+
@reset reset: 1
8+
) -> (
9+
io_isZero: 1,
10+
io_isNaR : 1,
11+
io_out: 32
12+
);
13+
14+
comb primitive posit_32_mul[](
15+
@write_together(1) io_num1: 32,
16+
@write_together(1) io_num2: 32,
17+
@clk clock: 1,
18+
@reset reset: 1
19+
) -> (
20+
io_isZero: 1,
21+
io_isNaR : 1,
22+
io_out: 32
23+
);
24+
25+
comb primitive posit_32_compare[](
26+
@write_together(1) io_num1: 32,
27+
@write_together(1) io_num2: 32,
28+
@clk clock: 1,
29+
@reset reset: 1
30+
) -> (
31+
io_lt: 1,
32+
io_eq : 1,
33+
io_gt: 1
34+
);
35+
36+
primitive posit_32_divsqrt[](
37+
@write_together(1) io_num1: 32,
38+
@write_together(1) io_num2: 32,
39+
@write_together(1) @interval(1) @go(1) io_validIn: 1,
40+
@write_together(1) io_sqrtOp: 1,
41+
@clk clock: 1,
42+
@reset reset: 1
43+
) -> (
44+
io_readyIn: 1,
45+
io_out: 32,
46+
io_isZero: 1,
47+
io_isNaR : 1,
48+
@done io_validOut_div: 1,
49+
@done io_validOut_sqrt: 1,
50+
io_exceptions: 4,
51+
);
52+
}

lib/posit_64.futil

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
extern "posit_64.sv" {
2+
comb primitive posit_64_add[](
3+
@write_together(1) io_num1: 64,
4+
@write_together(1) io_num2: 64,
5+
@write_together(1) io_sub: 1,
6+
@clk clock: 1,
7+
@reset reset: 1
8+
) -> (
9+
io_isZero: 1,
10+
io_isNaR : 1,
11+
io_out: 64
12+
);
13+
14+
comb primitive posit_64_mul[](
15+
@write_together(1) io_num1: 64,
16+
@write_together(1) io_num2: 64,
17+
@clk clock: 1,
18+
@reset reset: 1
19+
) -> (
20+
io_isZero: 1,
21+
io_isNaR : 1,
22+
io_out: 64
23+
);
24+
25+
comb primitive posit_64_compare[](
26+
@write_together(1) io_num1: 64,
27+
@write_together(1) io_num2: 64,
28+
@clk clock: 1,
29+
@reset reset: 1
30+
) -> (
31+
io_lt: 1,
32+
io_eq : 1,
33+
io_gt: 1
34+
);
35+
36+
primitive posit_64_divsqrt[](
37+
@write_together(1) io_num1: 64,
38+
@write_together(1) io_num2: 64,
39+
@write_together(1) @interval(1) @go(1) io_validIn: 1,
40+
@write_together(1) io_sqrtOp: 1,
41+
@clk clock: 1,
42+
@reset reset: 1
43+
) -> (
44+
io_readyIn: 1,
45+
io_out: 64,
46+
io_isZero: 1,
47+
io_isNaR : 1,
48+
@done io_validOut_div: 1,
49+
@done io_validOut_sqrt: 1,
50+
io_exceptions: 4,
51+
);
52+
}

0 commit comments

Comments
 (0)