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

Enhancements for ArrayOf[Arrays|Sets] construction/assimilation #256

Merged
merged 3 commits into from
Apr 3, 2022

Conversation

klevzoff
Copy link
Contributor

Related to: GEOS-DEV/GEOS#1847

  • Add execution policy template parameter to ArrayOfSets::assimilate() (can be host or device policy).
  • Add new method ArrayOfArrays::resizeFromOffsets(). This is useful when a new ArrayOfArrays needs to "inherit" capacity allocations from another existing one (can be extracted via ArrayOfArraysView::getOffsets()), but otherwise be resized to empty state.

@klevzoff klevzoff requested review from rrsettgast and corbett5 March 30, 2022 04:16
@klevzoff klevzoff self-assigned this Mar 30, 2022
Comment on lines -723 to -725
// const_cast needed until for RAJA bug.
RAJA::inclusive_scan< POLICY >( const_cast< INDEX_TYPE * >( capacities ),
const_cast< INDEX_TYPE * >( capacities + numSubArrays ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Casts seem no longer needed with current version of RAJA we're using

Comment on lines 744 to 747
template< typename ... BUFFERS >
void resizeFromOffsets( INDEX_TYPE const numSubArrays,
INDEX_TYPE const * const offsets,
BUFFERS & ... buffers )
Copy link
Contributor Author

@klevzoff klevzoff Mar 30, 2022

Choose a reason for hiding this comment

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

I still need to add a unit test for it. But I'd like to get the idea approved first. Usage is as follows:

newAofA.resizeFromOffsets( otherAofA.size(), otherAofA.toView().getOffsets() );

We could also implement duplicateSparsity instead, taking a whole AofA (view) as input. Let me know your preferences. It's not clear to me though, whether that method would need to also copy sizes and default construct values. I wouldn't want that to be the case, the new object is meant to be filled via emplaceBacks, not overwriting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah now that I think about it (in the context of a CRSMatrix at least) duplicateSparsity would have a different meaning. You'd basically copy all the data wholesale, except set the new values to zero. resizeFromOffsets seems like the correct name, although I'm not a huge fan of passing the pointer and size around, but it's not a big deal.

this->m_offsets,
this->m_sizes,
this->m_values );
BUFFER_TYPE< INDEX_TYPE > const sizes = this->m_sizes;
Copy link
Contributor Author

@klevzoff klevzoff Mar 30, 2022

Choose a reason for hiding this comment

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

There seems to be no way to manually "resize" a single sub-array through view after value deduplication. So I just capture sizes separately and overwrite them, seems to work well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks good to me.

Comment on lines +831 to +832
// This is not a View test, but it needs a POLICY type argument, so it's placed here for convenience
void assimilate( IndexType const maxValue, IndexType const maxInserts, sortedArrayManipulation::Description const desc )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lmk if you'd like a separate test sub-class to contain these assimilation tests (I moved them from ArrayOfSetsTest to ArrayOfSetsViewTest for reason stated in the code comment).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope that sounds just fine. I've done similar things elsewhere.

destroyValues( 0, m_numArrays, buffers ... );

bufferManipulation::reserve( m_sizes, m_numArrays, MemorySpace::host, numSubArrays );
std::fill_n( m_sizes.data(), numSubArrays, 0 );
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this is just copied from above but maybe this should use umpireInterface::memset. I don't think it's important at the moment but if eventually we want to be able to do this without allocating anything on host it'll be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done

// const_cast needed until for RAJA bug.
RAJA::inclusive_scan< POLICY >( const_cast< INDEX_TYPE * >( capacities ),
const_cast< INDEX_TYPE * >( capacities + numSubArrays ),
RAJA::inclusive_scan< POLICY >( capacities,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function should probably call resizeFromOffsets once the scan has been performed I think.

Copy link
Contributor Author

@klevzoff klevzoff Mar 30, 2022

Choose a reason for hiding this comment

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

So I couldn't just call it, because the result of the scan is written straight into m_offsets, but its old values are still needed in resizeFromOffsets, plus it would then perform a self-copy of m_offsets. I ended up pulling all the shared code into a private function resizeFromOffsetsImpl, which both resizeFromOffsets and resizeFromCapacities delegate to, passing a callback that is invoked when new offsets must be populated.

this->m_offsets,
this->m_sizes,
this->m_values );
BUFFER_TYPE< INDEX_TYPE > const sizes = this->m_sizes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks good to me.

Comment on lines +831 to +832
// This is not a View test, but it needs a POLICY type argument, so it's placed here for convenience
void assimilate( IndexType const maxValue, IndexType const maxInserts, sortedArrayManipulation::Description const desc )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope that sounds just fine. I've done similar things elsewhere.

@klevzoff klevzoff force-pushed the feature/klevzoff/arrayofsets-assimilate-policy branch from 88ac3c1 to 5103a6f Compare March 30, 2022 08:36
@klevzoff klevzoff merged commit 9d44561 into develop Apr 3, 2022
@klevzoff klevzoff deleted the feature/klevzoff/arrayofsets-assimilate-policy branch April 3, 2022 05:53
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.

2 participants