@@ -80,6 +80,7 @@ def calc_arrayfire(A, b, x0, maxiter=10):
80
80
beta_num = af .dot (r , r )
81
81
beta = beta_num / alpha_num
82
82
p = r + af .tile (beta , p .dims ()[0 ]) * p
83
+ af .eval (x )
83
84
res = x0 - x
84
85
return x , af .dot (res , res )
85
86
@@ -137,11 +138,11 @@ def timeit(calc, iters, args):
137
138
138
139
def test ():
139
140
print ("\n Testing benchmark functions..." )
140
- A , b , x0 = setup_input (50 ) # dense A
141
+ A , b , x0 = setup_input (50 , 7 ) # dense A
141
142
Asp = to_sparse (A )
142
143
x1 , _ = calc_arrayfire (A , b , x0 )
143
144
x2 , _ = calc_arrayfire (Asp , b , x0 )
144
- if af .sum (af .abs (x1 - x2 )/ x2 > 1e-6 ):
145
+ if af .sum (af .abs (x1 - x2 )/ x2 > 1e-5 ):
145
146
raise ValueError ("arrayfire test failed" )
146
147
if np :
147
148
An = to_numpy (A )
@@ -162,11 +163,13 @@ def test():
162
163
163
164
164
165
def bench (n = 4 * 1024 , sparsity = 7 , maxiter = 10 , iters = 10 ):
166
+
165
167
# generate data
166
168
print ("\n Generating benchmark data for n = %i ..." % n )
167
169
A , b , x0 = setup_input (n , sparsity ) # dense A
168
170
Asp = to_sparse (A ) # sparse A
169
171
input_info (A , Asp )
172
+
170
173
# make benchmarks
171
174
print ("Benchmarking CG solver for n = %i ..." % n )
172
175
t1 = timeit (calc_arrayfire , iters , args = (A , b , x0 , maxiter ))
@@ -192,9 +195,8 @@ def bench(n=4*1024, sparsity=7, maxiter=10, iters=10):
192
195
if (len (sys .argv ) > 1 ):
193
196
af .set_device (int (sys .argv [1 ]))
194
197
195
- af .info ()
196
-
198
+ af .info ()
197
199
test ()
198
-
200
+
199
201
for n in (128 , 256 , 512 , 1024 , 2048 , 4096 ):
200
202
bench (n )
0 commit comments