-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhadamard-bm.py
33 lines (24 loc) · 929 Bytes
/
hadamard-bm.py
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
import torch
import numpy as np
from fileio_utils import *
import os, sys
import argparse
import tempfile
parser = argparse.ArgumentParser()
parser.add_argument('num', type=int)
parser.add_argument('dim', type=int)
if __name__ == '__main__':
args = parser.parse_args()
with tempfile.TemporaryDirectory() as tempdir:
NUM, DIM = args.num, args.dim
for i in range(NUM):
A = torch.randn(DIM).cuda()
B = torch.randn(DIM).cuda()
save_int(A, 65536, os.path.join(tempdir, f'A_{i}.bin'))
save_int(B, 65536, os.path.join(tempdir, f'B_{i}.bin'))
compilation_error = os.system('make hadamard-bm')
if compilation_error:
print('Compilation error')
sys.exit(1)
prefix_A, prefix_B = os.path.join(tempdir, f'A_'), os.path.join(tempdir, f'B_')
os.system(f'./hadamard-bm {prefix_A} {prefix_B} {NUM} {DIM}')