-
Notifications
You must be signed in to change notification settings - Fork 193
Minor updates to OffloadPC #5164
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
base: main
Are you sure you want to change the base?
Changes from all commits
f3b58a6
79447e9
4ab1ef4
b525364
5aad145
98b415d
acbd7c8
1b9c16a
a586acf
034f5ea
49d0e3c
c5d9d96
6a723c3
0b9cd2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
|
|
||
| from firedrake import * | ||
| import pytest | ||
| import numpy as np | ||
|
|
||
|
|
||
| @pytest.mark.skipnogpu | ||
| @pytest.mark.parametrize( | ||
| "ksp_type, pc_type", | ||
| [("cg", "sor"), ("cg", "gamg"), ("preonly", "lu")] | ||
| ) | ||
| @pytest.mark.parallel([1, 2]) | ||
| def test_advection_offload(ksp_type, pc_type): | ||
| mesh = PeriodicIntervalMesh(100, length=2) | ||
| x = SpatialCoordinate(mesh)[0] | ||
| u_init = sin(2*pi*x) | ||
|
|
||
| nested_parameters = { | ||
| "pc_type": "ksp", | ||
| "ksp": { | ||
| "ksp_type": ksp_type, | ||
| "ksp_max_it": 50, | ||
| "ksp_rtol": 1e-5, | ||
| "ksp_monitor": None, | ||
| "pc_type": pc_type, | ||
| 'ksp_converged_reason': None, | ||
| }, | ||
| } | ||
| parameters = { | ||
| "snes_type": "ksponly", | ||
| "ksp_type": "preonly", | ||
| "pc_type": "python", | ||
| "pc_python_type": "firedrake.OffloadPC", | ||
| "offload": nested_parameters, | ||
| } | ||
|
|
||
| nu = Constant(1e-2) | ||
|
|
||
| V = FunctionSpace(mesh, "Lagrange", 2) | ||
|
|
||
| u_n1 = Function(V, name="u^{n+1}") | ||
| u_n = Function(V, name="u^{n}") | ||
| v = TestFunction(V) | ||
|
|
||
| u_n.interpolate(u_init) | ||
| dt = 0.01 | ||
|
|
||
| F = (((u_n1 - u_n)/dt) * v + u_n1 * u_n1.dx(0) * v + nu*u_n1.dx(0)*v.dx(0))*dx | ||
|
|
||
| problem = NonlinearVariationalProblem(F, u_n1) | ||
| solver = NonlinearVariationalSolver(problem, solver_parameters=parameters) | ||
|
|
||
| t = 0 | ||
| steps = 600 | ||
| t_end = steps * dt | ||
|
|
||
| while t <= t_end: | ||
| solver.solve() | ||
| maxchange = sqrt(assemble((u_n - u_n1)**2 * dx)) | ||
| u_n.assign(u_n1) | ||
| t += dt | ||
| if maxchange < 1e-4 or np.isnan(maxchange): | ||
| break | ||
| assert maxchange < 1e-4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| from firedrake import * | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.skipnogpu | ||
| def test_matfree_A_does_not_offload(): | ||
| length = 10 | ||
| n = 3 | ||
| mesh = RectangleMesh(2**n, 2**n, length, 1) | ||
|
|
||
| P1 = FiniteElement("CG", cell=mesh.ufl_cell(), degree=1) | ||
| B = FiniteElement("B", cell=mesh.ufl_cell(), degree=3) | ||
| mini = P1 + B | ||
| V = VectorFunctionSpace(mesh, mini) | ||
| P = FunctionSpace(mesh, 'CG', 1) | ||
|
|
||
| W = V*P | ||
|
|
||
| u, p = TrialFunctions(W) | ||
| v, q = TestFunctions(W) | ||
|
|
||
| a = inner(grad(u), grad(v)) * dx - inner(p, div(v)) * dx + inner(div(u), q) * dx | ||
|
|
||
| f = Constant((0, 0)) | ||
| L = inner(f, v) * dx | ||
|
|
||
| # No-slip velocity boundary condition on top and bottom, | ||
| # y == 0 and y == 1 | ||
| noslip = Constant((0, 0)) | ||
| bc0 = DirichletBC(W[0], noslip, (3, 4)) | ||
|
|
||
| # Parabolic inflow y(1-y) at x = 0 in positive x direction | ||
| x = SpatialCoordinate(W.mesh()) | ||
| inflow = as_vector((x[1]*(1 - x[1]), 0.0)) | ||
| bc1 = DirichletBC(W[0], inflow, 1) | ||
|
|
||
| # Zero pressure at outflow at x = 1 | ||
| bc2 = DirichletBC(W[1], 0.0, 2) | ||
|
|
||
| bcs = [bc0, bc1, bc2] | ||
|
|
||
| w = Function(W) | ||
|
|
||
| u, p = w.subfunctions | ||
|
|
||
| iterative_stokes_solver_parameters = { | ||
| "snes_type": "ksponly", | ||
| "mat_type": "matfree", | ||
| "ksp_type": "preonly", | ||
| "pc_type": "fieldsplit", | ||
| "pc_fieldsplit_type": "schur", | ||
| "pc_fieldsplit_schur_type": "full", | ||
| "fieldsplit_0": { | ||
| "ksp_type": "preonly", | ||
| "pc_type": "python", | ||
| "pc_python_type": "firedrake.AssembledPC", | ||
| "assembled": { | ||
| "pc_type": "python", | ||
| "pc_python_type": "firedrake.OffloadPC", | ||
| "offload": { | ||
| "pc_type": "none", | ||
| "ksp_type": "preonly", | ||
| } | ||
| } | ||
| }, | ||
| "fieldsplit_1": { | ||
| "ksp_type": "preonly", | ||
| "pc_type": "none", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the right thing to do here? Isn't this just solving a zero matrix because PETSc will default to building the Schur complement from If it isn't doing that, then how many iterations does this take? Doesn't the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took this from from the when run with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't care about the solution then you can add |
||
| }, | ||
| } | ||
|
|
||
| problem = LinearVariationalProblem(a, L, w, bcs=bcs) | ||
| solver = LinearVariationalSolver(problem, solver_parameters=iterative_stokes_solver_parameters) | ||
| solver.solve() | ||
|
|
||
| ksp0 = solver.snes.ksp.pc.getFieldSplitSchurGetSubKSP()[0] | ||
| assembled_ctx = ksp0.pc.getPythonContext() | ||
| offload_ctx = assembled_ctx.pc.getPythonContext() | ||
| A, P = offload_ctx.pc.getOperators() | ||
| assert P.type == "seqaijcusparse" | ||
| assert A.type == "python" | ||
Uh oh!
There was an error while loading. Please reload this page.