-
Notifications
You must be signed in to change notification settings - Fork 150
Mixed-precision improvements #7224
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
Open
nrseman
wants to merge
39
commits into
OPM:master
Choose a base branch
from
haugenlabs:mixed-42
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,036
−270
Open
Changes from 29 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7c53477
mixed: matrix now supports 4x4 blocks
4d5b892
mixed: matrix now supports 2x2 blocks
1549a3e
mixed: matrix now has fallback for blocks larger than 4x4
5ed2e45
mixed: replace binary literals with hex counterparts
ef37609
mixed: preconditioner checks block size
ea06d8a
mixed: inverse and matrix multiplications for 4x4 blocks
2edec27
mixed: ilu0 and dilu now supports 4x4 blocks
405cf26
mixed: ilu0 and dilu now supports 2x2 blocks
1a02413
mixed: avx2 version of 4x4 inverse
d674391
mixed: legacy implementation now supports 4x4 blocks
84485e2
mixed: ilu0/dilu apply supports blocks larger than 4x4
ba6e3f4
mixed: ilu0/dilu update supports blocks larger than 4x4
216368b
mixed: support WellModelMatrixAdapter
6fade30
mixed: custom MixedGhostLastMatrixAdapter
2416dff
mixed: verify local cell count in GhostLastScalarProduct
0f3200a
mixed: custom WellModelMixedGhostLastMatrixAdapter
4cd3122
mixed: post-rebase fixes
56decac
mixed: move scalar products to separate file
51fa7a0
mixed: scalar products documentation
23a8b9d
mixed: matrix wrapper documentation
03c65b0
mixed: move linear operators to separate file
461e279
mixed: preconditioner documentation
7803766
mixed: solver adapter documentation
0c39c2d
mixed: improved naming convention
8c828ac
mixed: update README file
74888b2
mixed: replace project calls in linear operators
6d47f52
mixed: move scalar product to c for avx2 support
fed6fae
mixed: enable mixed-cprw solver option
a8d00e1
mixed: update README file
e62acf5
mixed: documentation and clean-up
fc2c2db
mixed: delete unnecessary virtual keywords
0bd0e8d
mixed: minor improvements
3e599ec
mixed: more clean-up
e9687bc
mixed: aligned and buffered allocations
185232c
mixed: consolidate ilu0 and dilu factorization
88770b7
mixed: generic legacy bicgstab implementation
3413cb8
mixed: removing vec_bdot, i.e. buffered dot product
a0d2fd7
mixed: match declaration and init order
5764124
mixed: update README file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| #ifndef OPM_SCALAR_PRODUCTS_HEADER_INCLUDED | ||
| #define OPM_SCALAR_PRODUCTS_HEADER_INCLUDED | ||
|
|
||
| #include <opm/simulators/linalg/mixed/dot.h> | ||
|
|
||
| namespace Dune | ||
| { | ||
|
|
||
| /// A parallel scalar product that takes advantage of the fact that all | ||
| /// elements associated with ghost cells are located at the end of the | ||
| /// vector. This allows us to ignore the block structure of the vector | ||
| /// and eliminate the use of a mask to exclude ghost entries from being | ||
| /// included in the scalar product | ||
| template<class Vector, class Comm> | ||
| class GhostLastScalarProduct : public ScalarProduct<Vector> | ||
| { | ||
| public: | ||
|
|
||
| ///Exctract block size from vector type | ||
| static constexpr auto block_size = Vector::block_type::dimension; | ||
|
|
||
| /*! \brief constructor | ||
| * \param com The communication object for syncing overlap and copy | ||
| * data points. | ||
| * \param cat parallel solver category (nonoverlapping or overlapping) | ||
| */ | ||
| GhostLastScalarProduct (std::shared_ptr<const Comm> com, SolverCategory::Category cat) | ||
| : _communication(com), _category(cat) | ||
| { | ||
| count_ = getLocalCount(); // number or local cells | ||
| int verify = verifyLocalCount(); // redundant check on numbef of local cells | ||
| if (count_ != verify) OPM_THROW(std::runtime_error, "Inconsistent local node count!!\n"); | ||
| } | ||
|
|
||
| /*! \brief constructor | ||
| * \param com The communication object for syncing overlap and copy | ||
| * data points. | ||
| * \param cat parallel solver category (nonoverlapping or overlapping) | ||
| * \note if you use this constructor you have to make sure com stays alive | ||
| */ | ||
| GhostLastScalarProduct (const Comm& com, SolverCategory::Category cat) | ||
| : GhostLastScalarProduct(stackobject_to_shared_ptr(com), cat) | ||
| {} | ||
|
|
||
| /*! \brief Dot product of two vectors. | ||
| * \param vx first input vector | ||
| * \param vy second input vector | ||
| */ | ||
| virtual double dot (const Vector& vx, const Vector& vy) const override | ||
| { | ||
|
|
||
| // access underlying data | ||
| double const *x = &vx[0][0]; | ||
| double const *y = &vy[0][0]; | ||
|
|
||
| // total array length | ||
| int NN = block_size*count_; | ||
| #if 0 | ||
| // unroll loop in multiples of 8 | ||
| int n=NN/8; | ||
| int N=8*n; | ||
| double agg[8]; | ||
| for(int i=0;i<8;i++) agg[i]=0.0; | ||
| for(int i=0;i<N;i+=8) for(int j=0;j<8;j++) agg[j]+=x[i+j]*y[i+j]; | ||
| for(int j=0;j<4;j++) agg[j]+=agg[j+4]; | ||
| for(int j=0;j<2;j++) agg[j]+=agg[j+2]; | ||
| for(int j=0;j<1;j++) agg[j]+=agg[j+1]; | ||
|
|
||
| // loop-peeling of trailing end | ||
| for(int j=N;j<NN;j++) agg[0]+=x[j]*y[j]; | ||
|
|
||
| // Global summation | ||
| auto cc = _communication->communicator(); | ||
| double result = cc.sum(agg[0]); | ||
| return result; | ||
| #else | ||
| auto cc = _communication->communicator(); | ||
| return cc.sum(vec_dot(x,y,NN)); | ||
| #endif | ||
| //return cc.sum(vec_dot(x,y,NN)); | ||
| } | ||
|
|
||
| /*! \brief Vector L2-norm. | ||
| * \param vx input vector | ||
| */ | ||
| virtual double norm (const Vector& vx) const override | ||
| { | ||
| return sqrt(dot(vx,vx)); | ||
| } | ||
|
|
||
| //! Category of the scalar product (see SolverCategory::Category) | ||
| virtual SolverCategory::Category category() const override | ||
| { | ||
| return _category; | ||
| } | ||
|
|
||
| private: | ||
| std::shared_ptr<const Comm> _communication; | ||
| SolverCategory::Category _category; | ||
| int count_; | ||
|
|
||
| /*! \brief Count number of local cells. | ||
| */ | ||
| int getLocalCount() const | ||
| { | ||
| int count = 0; | ||
| // Loop over index set | ||
| auto indexSet = _communication->indexSet(); | ||
| for (auto idx = indexSet.begin(); idx!=indexSet.end(); ++idx) { | ||
| if (idx->local().attribute()==1) count++; // count non-local indices | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| /*! \brief Infer number of local cells from largest local index. | ||
| */ | ||
| int verifyLocalCount() const | ||
| { | ||
| auto indexSet = _communication->indexSet(); | ||
|
|
||
| size_t is = 0; | ||
| // Loop over index set | ||
| for (auto idx = indexSet.begin(); idx!=indexSet.end(); ++idx) { | ||
| //Only take "owner" indices | ||
| if (idx->local().attribute()==1) { | ||
| //get local index | ||
| auto loc = idx->local().local(); | ||
| // if loc is higher than "old interior size", update it | ||
| if (loc > is) { | ||
| is = loc; | ||
| } | ||
| } | ||
| } | ||
| return is + 1; //size is plus 1 since we start at 0 | ||
| } | ||
|
|
||
| }; | ||
|
|
||
|
|
||
|
|
||
| /// A sequential scalar product that ignores block structure of the vector | ||
| /// to facilitate well-known optimization techniques | ||
| template<class Vector> | ||
| class SeqOptmizedProduct : public Dune::SeqScalarProduct<Vector> | ||
| { | ||
| public: | ||
|
|
||
| // extract block size | ||
| static constexpr auto block_size = Vector::block_type::dimension; | ||
|
|
||
| /*! \brief Dot product of two vectors. | ||
| * \param vx first input vector | ||
| * \param vy second input vector | ||
| */ | ||
| virtual double dot(const Vector& vx, const Vector& vy) const override | ||
| { | ||
| // access underlying data | ||
| double const *x = &vx[0][0]; | ||
| double const *y = &vy[0][0]; | ||
|
|
||
| // total array length | ||
| int NN = block_size*vx.N(); | ||
| #if 1 | ||
| // unroll loop in multiples of 8 | ||
| int n=NN/8; | ||
| int N=8*n; | ||
| double agg[8]; | ||
| for(int i=0;i<8;i++) agg[i]=0.0; | ||
| for(int i=0;i<N;i+=8) for(int j=0;j<8;j++) agg[j]+=x[i+j]*y[i+j]; | ||
| for(int j=0;j<4;j++) agg[j]+=agg[j+4]; | ||
| for(int j=0;j<2;j++) agg[j]+=agg[j+2]; | ||
| for(int j=0;j<1;j++) agg[j]+=agg[j+1]; | ||
|
|
||
| // loop-peeling of trailing end | ||
| for(int j=N;j<NN;j++) agg[0]+=x[j]*y[j]; | ||
|
|
||
| return agg[0]; | ||
| #else | ||
| return vec_dot(x,y,NN); | ||
| #endif | ||
| } | ||
|
|
||
| /*! \brief Vector L2-norm. | ||
| * \param vx input vector | ||
| */ | ||
| virtual double norm(const Vector& vx) const override { | ||
| return std::sqrt(this->dot(vx, vx)); | ||
| } | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif //OPM_SCALAR_PRODUCTS_HEADER_INCLUDED | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.