@@ -159,7 +159,7 @@ class GMG(object):
159
159
[4] https://netlib.org/utk/people/JackDongarra/PAPERS/HPCG-benchmark.pdf
160
160
""" # noqa: E501
161
161
162
- def __init__ (self , A , shape , levels , smoother , gridop ):
162
+ def __init__ (self , A , shape , levels , smoother , gridop , machine ):
163
163
self .A = A
164
164
self .shape = shape
165
165
self .N = numpy .product (self .shape )
@@ -171,9 +171,8 @@ def __init__(self, A, shape, levels, smoother, gridop):
171
171
self .smoother = {"symgs" : SYMGS , "jacobi" : WeightedJacobi }[smoother ]()
172
172
self .operators = self .compute_operators (A )
173
173
self .temp = None
174
- _ , procs = get_phase_procs (use_legate )
175
- self .machine = procs
176
- self .proc_kind = procs .preferred_kind
174
+ self .machine = machine
175
+ self .proc_kind = machine .preferred_kind
177
176
178
177
def compute_operators (self , A ):
179
178
operators = []
@@ -394,38 +393,47 @@ def required_driver_memory(N):
394
393
395
394
396
395
def execute (N , data , smoother , gridop , levels , maxiter , tol , verbose , timer ):
396
+ build , solve = get_phase_procs (use_legate )
397
397
timer .start ()
398
- if data == "poisson" :
399
- A = poisson2D (N ).tocsr ()
400
- b = np .random .rand (N ** 2 )
401
- elif data == "diffusion" :
402
- A = diffusion2D (N ).tocsr ()
403
- b = np .random .rand (N ** 2 )
404
- else :
405
- raise NotImplementedError (data )
406
- print (f"Data creation time: { timer .stop ()} ms" )
407
-
408
- assert smoother == "jacobi" , "Only Jacobi smoother is currently supported."
409
-
410
- if verbose :
398
+ with build :
399
+ if data == "poisson" :
400
+ A = poisson2D (N ).tocsr ()
401
+ b = np .random .rand (N ** 2 )
402
+ elif data == "diffusion" :
403
+ A = diffusion2D (N ).tocsr ()
404
+ b = np .random .rand (N ** 2 )
405
+ else :
406
+ raise NotImplementedError (data )
407
+ print (f"Data creation time: { timer .stop ()} ms" )
411
408
412
- def callback (x ):
413
- print (f"Residual: { np .linalg .norm (b - A .matvec (x ))} " )
409
+ assert (
410
+ smoother == "jacobi"
411
+ ), "Only Jacobi smoother is currently supported."
414
412
415
- else :
416
- callback = None
413
+ if verbose :
417
414
418
- # Make a call to the random API to ensure it is warmed up
419
- # before we utilize it during the build process.
420
- float (np .linalg .norm (np .random .rand (b .shape [0 ])))
415
+ def callback (x ):
416
+ print (f"Residual: { np .linalg .norm (b - A .matvec (x ))} " )
421
417
422
- required_driver_memory (N )
423
- timer .start ()
424
- mg_solver = GMG (
425
- A = A , shape = (N , N ), levels = levels , smoother = smoother , gridop = gridop
426
- )
427
- M = mg_solver .linear_operator ()
428
- print (f"GMG init time: { timer .stop ()} ms" )
418
+ else :
419
+ callback = None
420
+
421
+ # Make a call to the random API to ensure it is warmed up
422
+ # before we utilize it during the build process.
423
+ float (np .linalg .norm (np .random .rand (b .shape [0 ])))
424
+
425
+ required_driver_memory (N )
426
+ timer .start ()
427
+ mg_solver = GMG (
428
+ A = A ,
429
+ shape = (N , N ),
430
+ levels = levels ,
431
+ smoother = smoother ,
432
+ gridop = gridop ,
433
+ machine = solve ,
434
+ )
435
+ M = mg_solver .linear_operator ()
436
+ print (f"GMG init time: { timer .stop ()} ms" )
429
437
430
438
# Warm up the runtime.
431
439
float (
@@ -446,6 +454,8 @@ def callback(x):
446
454
)
447
455
)
448
456
)
457
+ # Make another call to random here as well.
458
+ float (np .linalg .norm (np .random .rand (b .shape [0 ])))
449
459
450
460
timer .start ()
451
461
x , iters = linalg .cg (
0 commit comments