Skip to content
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

Hypre, outerloop & CUDA changes #2397

Merged
merged 481 commits into from
Jun 23, 2022
Merged

Conversation

bendudson
Copy link
Contributor

@bendudson bendudson commented Aug 10, 2021

Ready for review & merge

Quite a large PR, adding support for GPUs in BOUT++. The two main parts are

  1. A way to write physics models using "outerloop" operators, which merges loops together into larger kernels. This requires new datatypes FieldAccessor and CoordinatesAccessor for efficient access to field and coordinates data respectively.
  2. A 3D phi solver using Hypre. The latest versions of Hypre can run at least in part on GPUs, so this solve can be on the GPU

Includes manual and tests.

…ject/BOUT-dev into next-hypre-outerloop-cuda-merged
Duplicate versions of various field files, VIM temporary
files committed to the repo.
Small changes to spacing adding noise, backup files not needed
Otherwise Coordinates is an incomplete type
Whitespace changes and some comments
dz has now changed to being a Coordinates::FieldMetric type,
2D or 3D depending on compile-time option.
In FieldAccessor was only set if the field had parallel slices
In Field2DAccessor never set
Needs a field to construct a valid object, so don't allow
default construction.
Coordinates fields can now be 2D or 3D, depending on compile-time
switch. f2d prefix would just be confusing if it could then be Field3D.
These definitions are repeated in several places, so just move
to one location.
Coordinate fields can now be 2D or 3D, depending on compile-time flag
BOUT_USE_METRIC_3D. This puts the logic for indexing these fields in
one place.
The Field2DAccessor code was almost the same as FieldAccessor.
Rather than having two implementations, use the same implementation
and specialise on Field2D types.
`f_data` was a duplicate of `data`, and other `f_` prefixes aren't
needed.
Moved to field_accessor.hxx rather than single_index_ops.hxx
These changes make the API more similar to the Fields.
Uses the build flags, hopefully will work for all cases on the GPU
Just indexes data array, so `fa[i]` is equivalent to `fa.data[i]`
Compiler errors, include Mesh header
Bugs in `b0xGrad_dot_Grad`, `D2DY2` etc. fixed
Renamed, removing `_g` postfix. Functions can take either an `int` or
an `Ind3D`. The `int` argument is assumed to be a 3D index in all cases.
Compiles with 2D metrics and no RAJA (CPU only).
Document FieldAccessor and CoordinateFieldAccessor
A simple wrapper around `BoutReal*`, which has an indexing (subscript)
operator for `int` and `Ind3D` types (const and non-const).
Code can be the same, but the surrounding loop is currently different.
Now compiles again without RAJA & CUDA. Previously also had braces in
the wrong location.
Can be used by both LaplaceXY2 and LaplaceXY2Hypre, so put
into a common header file
f2dinit member variable no longer needed for initialisation
The PetscMatrix API (constructor args) had changed, but this
LaplaceXY2 implementation had not been updated. Now compiles again,
though not tested that it runs or produces correct result.
bendudson and others added 10 commits May 16, 2022 16:58
Outerloop suggestions - resolve merge conflicts
Previously nvcc would fail claiming that symbols were
defined multiple times. Now needs these symbols to be
defined or linker errors result.
HYPRE_SOLVER_TYPE can't be directly formatted with nvcc compiler,
but needs to be first converted to a string.
@bendudson
Copy link
Contributor Author

@ZedThree @johnomotani @jonesholger @dschwoerer I think this is now finally ready to be merged!

Comment on lines +96 to +97
#if 0 // disable temporarily until reconcile iteration space for parallel_forall under
// nvcc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this?

Comment on lines +228 to +230
// Don't currently know why this test fails, and also causes segfault when unwinding the
// tests
#if 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this #2406 ?

@ZedThree
Copy link
Member

I've got most of the way through this, will finish it when I get back from holiday! But I have a feeling it's "good enough". There's a few bits and pieces that could be tidied up -- we should probably make issues for them and try and clean them up later perhaps.

  • malloc/free in the Hypre interface
  • malloc in tests
  • a few #if 0/1 scattered in places that should be removed or at least investigated/issues made

@bendudson
Copy link
Contributor Author

Thanks @ZedThree, have a good holiday!

ZedThree
ZedThree previously approved these changes Jun 13, 2022
Copy link
Member

@ZedThree ZedThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Obviously this is a really big PR, but I think the general shape is good.

There's a few things that I'd really like to fix at some point, so noting here perhaps for future issues:

include/bout/invert/laplacexy2.hxx Outdated Show resolved Hide resolved
bendudson and others added 3 commits June 15, 2022 10:07
- Added to CMakeLists; previously wasn't compiled with CMake builds
- Removed shared_ptr around PetscMatrix
- Moved initialisation of indexConverter and matrix to initializer list
ZedThree
ZedThree previously approved these changes Jun 22, 2022
Only makes sense with 2D metrics, fails to compile if 3D metrics are enabled.
@bendudson
Copy link
Contributor Author

ok @ZedThree I think this is now finally ready to go in

@ZedThree
Copy link
Member

clang-tidy-review failed because: "CMake 3.17 or higher is required. You are running version 3.16.3"

We can update that elsewhere.

@ZedThree ZedThree merged commit d34cd44 into next Jun 23, 2022
@ZedThree ZedThree deleted the next-hypre-outerloop-cuda-merged branch June 23, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants