-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OffloadPC (CUDA GPU) #3784
base: master
Are you sure you want to change the base?
OffloadPC (CUDA GPU) #3784
Conversation
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this file as discussed.
@@ -55,6 +55,8 @@ def __init__(self, A, *, P=None, solver_parameters=None, | |||
solver_parameters = solving_utils.set_defaults(solver_parameters, | |||
A.arguments(), | |||
ksp_defaults=self.DEFAULT_KSP_PARAMETERS) | |||
# todo: add offload to solver parameters - how? prefix? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs addressing somehow. Not quite sure what is meant by this comment.
# u.getArray() | ||
|
||
# else: | ||
# instead: preconditioner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
from firedrake.petsc import PETSc | ||
from firedrake.ufl_expr import TestFunction, TrialFunction | ||
import firedrake.dmhooks as dmhooks | ||
from firedrake.dmhooks import get_function_space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably an unnecessary import.
|
||
|
||
class OffloadPC(PCBase): | ||
"""Offload PC from CPU to GPU and back. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring could perhaps contain more detail about what is actually happening and even perhaps why one may wish to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. This is only for CUDA GPUs
x_cu = PETSc.Vec() | ||
x_cu.createCUDAWithArrays(x) # end | ||
with PETSc.Log.Event("Event: solve"): | ||
self.pc.apply(x_cu, y_cu) # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.pc.apply(x_cu, y_cu) # | |
self.pc.apply(x_cu, y_cu) |
with PETSc.Log.Event("Event: solve"): | ||
self.pc.apply(x_cu, y_cu) # | ||
with PETSc.Log.Event("Event: vectors copy back"): | ||
y.copy(y_cu) # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y.copy(y_cu) # | |
y.copy(y_cu) |
y.copy(y_cu) # | ||
|
||
def applyTranspose(self, pc, X, Y): | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe have a useful error message? Not sure what the usual approach is here.
|
||
def view(self, pc, viewer=None): | ||
super().view(pc, viewer) | ||
print("viewing PC") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print("viewing PC") |
if not isinstance(A, firedrake.matrix.AssembledMatrix): | ||
# linear MG doesn't need RHS, supply zero. | ||
lvp = vs.LinearVariationalProblem(a=A.a, L=0, u=x, bcs=A.bcs) | ||
mat_type = A.mat_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointless line to have, delete and use A.mat_type
below
Description
This adds an offloading preconditioner.