-
Notifications
You must be signed in to change notification settings - Fork 0
/
threefry.py
32 lines (25 loc) · 1.01 KB
/
threefry.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
import tvm
import tvm.relay
from tvm import relay
import tvm.testing
import tvm.topi
import numpy as np
import sys
import argparse
def threefry_generate():
gen = relay.var("gen", relay.TensorType((10,), "uint64"))
out = relay.random.threefry_generate(gen, (10000000,))
f = relay.Function([gen], out)
return relay.create_executor("graph", tvm.IRModule.from_expr(f), target="llvm", device=tvm.cpu()).evaluate()
def threefry_split_generate():
gen = relay.var("gen", relay.TensorType((10,), "uint64"))
left, right = relay.TupleWrapper(relay.random.threefry_split(gen), 2)
out = relay.random.threefry_generate(right, (16,))
f = relay.Function([gen], out)
return relay.create_executor("graph", tvm.IRModule.from_expr(f), target="llvm", device=tvm.cpu()).evaluate()
f = threefry_generate()
# f = threefry_split_generate()
gen = tvm.nd.array(np.array([0, 0, 0, 0, 0, 0, 0, 0, 1 << 63, 0], dtype="uint64"))
while True:
gen, rands = f(gen)
sys.stdout.buffer.write(bytearray(rands.numpy()))