CIRCT 23.0.0git
Loading...
Searching...
No Matches
kanagawa_demo.py
Go to the documentation of this file.
1import esi
2from esi.types import FunctionPort
3
4import random
5import sys
6from typing import List, cast
7
8platform = sys.argv[1]
9acc_conn = esi.AcceleratorConnection(platform, sys.argv[2])
10acc = acc_conn.build_accelerator()
11
12print("***** Testing add function")
13
14add = cast(FunctionPort, acc.ports[esi.AppID("add")])
15add.connect()
16
17
18def add_golden(a: int, b: int, arr: List[int]) -> int:
19 return (a + b + sum(arr)) % 2**8
20
21
22for _ in range(10):
23 a = random.randint(0, 2**8 - 1)
24 b = random.randint(0, 2**8 - 1)
25 arr = [random.randint(0, 2**8 - 1) for _ in range(16)]
26
27 expected = add_golden(a=a, b=b, arr=arr)
28 print(f"call(a={a}, b={b}, arr={arr})")
29
30 resp = add(a=a, b=b, arr=arr).result()
31 if resp != expected:
32 print(f" = {resp} (expected {expected})")
33 else:
34 print(f" = {resp} (matches Python result)")
35
36print()
37input("Press Enter to continue...")
38print()
39print()
40print("***** Testing compute_crc function")
41
42compute_crc = cast(FunctionPort, acc.ports[esi.AppID("crc")])
43compute_crc.connect()
44
45data = [random.randint(0, 2**8 - 1) for _ in range(64)]
46crc = compute_crc(identifier=0, input=data, input_bytes=64, reset=1).result()
47print(f"crc({data})")
48print(f" = 0x{crc:x}")
49
50new_data = [random.randint(0, 2**8 - 1) for _ in range(64)]
51crc = compute_crc(identifier=0, input=new_data, input_bytes=64,
52 reset=0).result()
53print(f"crc({new_data})")
54print(f" = 0x{crc:x}")
static void print(TypedAttr val, llvm::raw_ostream &os)
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:89
int add_golden(int a, int b, List[int] arr)