-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gpu_lisp.py
More file actions
56 lines (45 loc) · 1.91 KB
/
Copy pathtest_gpu_lisp.py
File metadata and controls
56 lines (45 loc) · 1.91 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from charon.gpu_lisp import *
def test_gpu_lisp():
symbol = gpu_lisp_symbol(["r","n","year","month","day","x","y"])
l = gpu_lisp(symbol)
c = l.create_constant({
"r":10,
"n":4,
"year":1986,
"month":3,
"day":27,
"x":5,
"y":4,
})
area = l.parse("(* 3.141592654 (* r r))")
area2 = l.parse("(+ (* (+ r r) (+ (* (* r 0.559966) (- (+ 0.0930217 0.352407) 0.0850601)) (- r r))) (* (/ r 0.365197) (+ (* (+ (* r (- 0.443465 0.0850601)) (- r r)) (- r r)) r)))")
stirling = l.parse("(* (sqrt (* 2 3.141592654 n)) (pow (/ n (exp 1)) n) (+ 1 (/ 1 (* 12 n))))")
pi = l.parse("(* 4 (- (atan (/ 10822096 8641597)) (+ (atan (/ 1 year)) (* month (atan (/ 1 day))))))")
test_max = l.parse("(sign -1.23)")
debug = l.parse("(+ x (* (* x x) (sign x)))")
print(debug.tree_size())
print(debug.copy_node(2))
print(debug.to_string())
debug.replace_node(1,debug.copy_node(2))
print(debug.to_string())
print(debug.run(c))
print(area.to_string(), area.run(c)) # compute area of circle of radius 10
print(area2.run(c))
print(stirling.to_string(), stirling.run(c)) # approximate 4!
print(pi.to_string(), pi.run(c)) # compute pi from my birthday
print(test_max.to_string(), test_max.run(c) , l.map(test_max,[c]))
print(debug.to_string(), debug.run(c))
symbol = gpu_lisp_symbol(["n"])
l = gpu_lisp(symbol,32,16,1)
stirling = l.parse("(* (sqrt (* 2 3.141592654 n)) (pow (/ n (exp 1)) n) (+ 1 (/ 1 (* 12 n))))")
carray = [l.create_constant({"n":n}) for n in range(2,10)]
ret = l.map(stirling,carray)
print("CPU",ret)
for i in range(len(ret)):
print("%d! ~= %f" % (i+2,ret[i]))
ret = l.gpu_map(stirling,carray)
print("GPU",ret)
for i in range(len(ret)):
print("%d! ~= %f" % (i+2,ret[i]))
if __name__ == "__main__":
test_gpu_lisp()