@@ -159,7 +159,7 @@ class GMG(object):
159159 [4] https://netlib.org/utk/people/JackDongarra/PAPERS/HPCG-benchmark.pdf
160160 """ # noqa: E501
161161
162- def __init__ (self , A , shape , levels , smoother , gridop ):
162+ def __init__ (self , A , shape , levels , smoother , gridop , machine ):
163163 self .A = A
164164 self .shape = shape
165165 self .N = numpy .product (self .shape )
@@ -171,9 +171,8 @@ def __init__(self, A, shape, levels, smoother, gridop):
171171 self .smoother = {"symgs" : SYMGS , "jacobi" : WeightedJacobi }[smoother ]()
172172 self .operators = self .compute_operators (A )
173173 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
177176
178177 def compute_operators (self , A ):
179178 operators = []
@@ -394,38 +393,47 @@ def required_driver_memory(N):
394393
395394
396395def execute (N , data , smoother , gridop , levels , maxiter , tol , verbose , timer ):
396+ build , solve = get_phase_procs (use_legate )
397397 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" )
411408
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."
414412
415- else :
416- callback = None
413+ if verbose :
417414
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 ))} " )
421417
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" )
429437
430438 # Warm up the runtime.
431439 float (
@@ -446,6 +454,8 @@ def callback(x):
446454 )
447455 )
448456 )
457+ # Make another call to random here as well.
458+ float (np .linalg .norm (np .random .rand (b .shape [0 ])))
449459
450460 timer .start ()
451461 x , iters = linalg .cg (
0 commit comments