34 template<
typename POLICY,
typename T >
36 void atomicAdd( POLICY, T *
const acc, T
const & val )
37 { RAJA::atomicAdd< POLICY >( acc, val ); }
48 template<
typename T >
50 void atomicAdd( RAJA::seq_atomic, T * acc, T
const & val )
73 template<
typename >
class BUFFER_TYPE
77 using ColTypeNC = std::remove_const_t< COL_TYPE >;
88 static_assert( !std::is_const< T >::value ||
89 (std::is_const< COL_TYPE >::value && std::is_const< INDEX_TYPE >::value),
90 "When T is const COL_TYPE and INDEX_TYPE must also be const." );
132 ColTypeNC
const nCols,
133 BUFFER_TYPE< INDEX_TYPE >
const & offsets,
134 BUFFER_TYPE< SIZE_TYPE >
const & nnz,
135 BUFFER_TYPE< COL_TYPE >
const & columns,
136 BUFFER_TYPE< T >
const & entries ):
137 ParentClass( nRows, nCols, offsets, nnz, columns ),
226 using ParentClass::numRows;
227 using ParentClass::numColumns;
228 using ParentClass::numNonZeros;
229 using ParentClass::nonZeroCapacity;
230 using ParentClass::empty;
248 &this->m_sizes[ row ],
258 return m_entries.data();
262 template<
typename POLICY >
264 bool NaNCheck( )
const 266 RAJA::ReduceMax< typename RAJAHelper< POLICY >::ReducePolicy,
int > anyNaN( 0 );
268 RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, numRows() ),
273 anyNaN.max( std::isnan( value ) ? 1 : 0 );
276 return anyNaN.get() == 1;
280 using ParentClass::getColumns;
281 using ParentClass::getOffsets;
282 using ParentClass::getSizes;
301 bool insertNonZero( INDEX_TYPE
const row, ColTypeNC
const col, T
const & entry )
const 302 {
return ParentClass::insertIntoSetImpl( row, col,
CallBacks( *
this, row, &entry ) ); }
317 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
318 T
const *
const LVARRAY_RESTRICT entriesToInsert,
319 ColTypeNC
const ncols )
const 320 {
return ParentClass::insertIntoSetImpl( row, cols, cols + ncols,
CallBacks( *
this, row, entriesToInsert ) ); }
330 {
return ParentClass::removeFromSetImpl( row, col,
CallBacks( *
this, row,
nullptr )); }
343 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
344 ColTypeNC
const ncols )
const 346 T *
const entries = getEntries( row );
347 INDEX_TYPE
const rowNNZ = numNonZeros( row );
348 INDEX_TYPE
const nRemoved = ParentClass::removeFromSetImpl( row, cols, cols + ncols,
CallBacks( *
this, row,
nullptr ) );
367 template<
typename POLICY >
371 RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, numRows() ),
378 { entries[ i ] = value; }
394 #if !defined( LVARRAY_USE_UMPIRE ) 395 LVARRAY_ERROR_IF_NE_MSG( m_entries.getPreviousSpace(), MemorySpace::host,
"Without Umpire only host memory is supported." );
398 if( m_entries.capacity() > 0 )
400 ParentClass::move( m_entries.getPreviousSpace(), false );
401 m_entries.move( m_entries.getPreviousSpace(), true );
403 size_t const numBytes = m_entries.capacity() *
sizeof( T );
405 umpireInterface::memset( m_entries.data(), 0, numBytes );
422 template<
typename AtomicPolicy >
425 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
426 T
const *
const LVARRAY_RESTRICT vals,
427 ColTypeNC
const nCols )
const 429 INDEX_TYPE
const nnz = numNonZeros( row );
430 if( nCols < nnz / 4 && nnz > 64 )
432 addToRowBinarySearch< AtomicPolicy >( row, cols, vals, nCols );
436 addToRowLinearSearch< AtomicPolicy >( row, cols, vals, nCols );
452 template<
typename AtomicPolicy >
455 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
456 T
const *
const LVARRAY_RESTRICT vals,
457 ColTypeNC
const nCols )
const 461 INDEX_TYPE
const nnz = numNonZeros( row );
462 COL_TYPE
const *
const columns = getColumns( row );
463 T *
const entries = getEntries( row );
472 internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
489 template<
typename AtomicPolicy >
492 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
493 T
const *
const LVARRAY_RESTRICT vals,
494 ColTypeNC
const nCols )
const 498 INDEX_TYPE
const nnz = numNonZeros( row );
499 COL_TYPE
const *
const columns = getColumns( row );
500 T *
const entries = getEntries( row );
507 if( columns[ j ] == cols[ i ] )
514 internal::atomicAdd( AtomicPolicy{}, entries + curPos, vals[ i ] );
530 template<
typename AtomicPolicy >
533 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
534 T
const *
const LVARRAY_RESTRICT vals,
535 ColTypeNC
const nCols )
const 537 INDEX_TYPE
const nnz = numNonZeros( row );
538 COL_TYPE
const *
const columns = getColumns( row );
539 T *
const entries = getEntries( row );
547 internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
566 ParentClass::move( space, touch );
567 m_entries.move( space, touch );
588 template<
typename U >
591 ParentClass::template setName< U >( name );
592 m_entries.template setName< U >( name +
"/entries" );
616 INDEX_TYPE
const row, T
const *
const entriesToInsert ):
619 m_rowNNZ( crsMV.numNonZeros( row ) ),
620 m_rowCapacity( crsMV.nonZeroCapacity( row ) ),
621 m_entries( crsMV.getEntries( row ) ),
622 m_entriesToInsert( entriesToInsert )
634 ColTypeNC *
incrementSize( ColTypeNC *
const curPtr, INDEX_TYPE
const nToAdd )
const 637 #ifdef LVARRAY_BOUNDS_CHECK 642 return m_crsMV.getSetValues( m_row );
652 void insert( INDEX_TYPE
const insertPos )
const 664 void set( INDEX_TYPE
const pos, ColTypeNC
const colPos )
const 665 {
new (&m_entries[ pos ]) T( m_entriesToInsert[ colPos ] ); }
678 void insert( INDEX_TYPE
const nLeftToInsert,
679 ColTypeNC
const colPos,
681 ColTypeNC
const prevPos )
const 684 new (&m_entries[pos + nLeftToInsert - 1]) T( m_entriesToInsert[colPos] );
694 void remove( ColTypeNC removePos )
const 708 void remove( INDEX_TYPE
const nRemoved,
709 ColTypeNC
const curPos,
710 ColTypeNC
const nextPos )
const #define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:79
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
Definition: Macros.hpp:223
LVARRAY_HOST_DEVICE constexpr CRSMatrixView(INDEX_TYPE const nRows, ColTypeNC const nCols, BUFFER_TYPE< INDEX_TYPE > const &offsets, BUFFER_TYPE< SIZE_TYPE > const &nnz, BUFFER_TYPE< COL_TYPE > const &columns, BUFFER_TYPE< T > const &entries)
Construct a new CRSMatrixView from the given buffers.
Definition: CRSMatrixView.hpp:131
This class provides a view into a compressed row storage sparsity pattern.
Definition: SparsityPatternView.hpp:61
CRSMatrixView const & m_crsMV
A reference to the associated CRSMatrixView.
Definition: CRSMatrixView.hpp:715
INDEX_TYPE IndexType
The integer type used for indexing.
Definition: ArrayOfArraysView.hpp:188
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE std::ptrdiff_t find(T const *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, T const &value, Compare &&comp=Compare())
Definition: sortedArrayManipulation.hpp:411
#define ARRAYOFARRAYS_CHECK_BOUNDS(i)
Check that i is a valid array index.
Definition: ArrayOfArraysView.hpp:106
LVARRAY_HOST_DEVICE bool removeNonZero(INDEX_TYPE const row, ColTypeNC const col) const
Remove a non-zero entry at the given position.
Definition: CRSMatrixView.hpp:329
LVARRAY_HOST_DEVICE T const * getEntries() const
Definition: CRSMatrixView.hpp:256
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const
Definition: CRSMatrixView.hpp:165
LVARRAY_HOST_DEVICE void addToRowLinearSearch(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Definition: CRSMatrixView.hpp:491
CRSMatrixView(bool)
Protected constructor to be used by the CRSMatrix class.
Definition: CRSMatrixView.hpp:578
void move(MemorySpace const space, bool const touch=true) const
Move this matrix to the given memory space and touch the values, sizes and offsets.
Definition: CRSMatrixView.hpp:564
LVARRAY_HOST_DEVICE void addToRowBinarySearch(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Definition: CRSMatrixView.hpp:454
LVARRAY_HOST_DEVICE CallBacks(CRSMatrixView const &crsMV, INDEX_TYPE const row, T const *const entriesToInsert)
Constructor.
Definition: CRSMatrixView.hpp:615
LVARRAY_HOST_DEVICE void addToRowBinarySearchUnsorted(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Definition: CRSMatrixView.hpp:532
This class provides the callbacks for the sortedArrayManipulation routines.
Definition: CRSMatrixView.hpp:604
#define LVARRAY_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
Definition: Macros.hpp:554
#define LVARRAY_ERROR_IF_NE_MSG(lhs, rhs, msg)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:344
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void forValuesInSlice(T &value, LAMBDA &&f)
Apply the given function to the given value.
Definition: sliceHelpers.hpp:31
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void insert(INDEX_TYPE const nLeftToInsert, ColTypeNC const colPos, ColTypeNC const pos, ColTypeNC const prevPos) const
Used with the sortedArrayManipulation::insertSorted routine this callback signals that the given colu...
Definition: CRSMatrixView.hpp:678
void setValues(T const &value) const
Set all the entries in the matrix to the given value.
Definition: CRSMatrixView.hpp:368
Contains the LvArray umpire interface. This is only used to keep umpire/ResourceManager.hpp out of the includes for most headers.
LVARRAY_HOST_DEVICE bool insertNonZero(INDEX_TYPE const row, ColTypeNC const col, T const &entry) const
Insert a non-zero entry at the given position.
Definition: CRSMatrixView.hpp:301
std::conditional_t< CONST_SIZES, INDEX_TYPE const, INDEX_TYPE_NC > SIZE_TYPE
The type contained by the m_sizes buffer.
Definition: ArrayOfArraysView.hpp:177
T *const m_entries
A pointer to the entries in the row.
Definition: CRSMatrixView.hpp:727
void zero() const
Use memset to set all the values in the matrix to 0.
Definition: CRSMatrixView.hpp:392
LVARRAY_HOST_DEVICE ColTypeNC * incrementSize(ColTypeNC *const curPtr, INDEX_TYPE const nToAdd) const
Callback signaling that the size of the row has increased.
Definition: CRSMatrixView.hpp:634
LVARRAY_HOST_DEVICE void insert(INDEX_TYPE const insertPos) const
Used with sortedArrayManipulation::insert routine this callback signals that the column was inserted ...
Definition: CRSMatrixView.hpp:652
BUFFER_TYPE< T > m_entries
Holds the entries of the matrix, of length numNonZeros().
Definition: CRSMatrixView.hpp:596
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void erase(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n=1)
Shift the values in the array at or above the given position down by the given amount overwriting the...
Definition: arrayManipulation.hpp:396
Contains the implementation of LvArray::ArraySlice.
LVARRAY_HOST_DEVICE constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &
Definition: CRSMatrixView.hpp:210
Contains the implementation of LvArray:SparsityPatternView.
INDEX_TYPE const m_row
The associated row.
Definition: CRSMatrixView.hpp:718
LVARRAY_HOST_DEVICE INDEX_TYPE_NC numNonZeros() const
Definition: SparsityPatternView.hpp:211
LVARRAY_HOST_DEVICE void atomicAdd(POLICY, T *const acc, T const &val)
Wrapper around RAJA::atomicAdd.
Definition: CRSMatrixView.hpp:36
Contains some portable math functions.
void setName(std::string const &name)
Set the name to be displayed whenever the underlying Buffer's user call back is called.
Definition: CRSMatrixView.hpp:589
INDEX_TYPE const m_rowCapacity
The non zero capacity of the row.
Definition: CRSMatrixView.hpp:724
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const
Definition: CRSMatrixView.hpp:195
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool isSortedUnique(ITER first, ITER const last, Compare &&comp=Compare())
Definition: sortedArrayManipulation.hpp:374
camp::resources::Platform MemorySpace
an alias for camp::resources::Platform.
Definition: bufferManipulation.hpp:31
Contains functions for manipulating a contiguous array of values.
#define LVARRAY_DEBUG_VAR(X)
Mark X as an debug variable, used to silence compiler warnings.
Definition: Macros.hpp:85
LVARRAY_HOST_DEVICE INDEX_TYPE_NC insertNonZeros(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT entriesToInsert, ColTypeNC const ncols) const
Insert a non-zero entries into the given row.
Definition: CRSMatrixView.hpp:316
T const *const m_entriesToInsert
A pointer to the entries to insert.
Definition: CRSMatrixView.hpp:730
The top level namespace.
Definition: Array.hpp:24
#define LVARRAY_ERROR_IF_GT_MSG(lhs, rhs, msg)
Raise a hard error if one value compares greater than the other.
Definition: Macros.hpp:376
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE INDEX_TYPE_NC removeNonZeros(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, ColTypeNC const ncols) const
Remove non-zero entries from the given row.
Definition: CRSMatrixView.hpp:342
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void shiftDown(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position down by the given amount overwriting the...
Definition: arrayManipulation.hpp:363
COL_TYPE ColType
The integer type used to enumerate the columns.
Definition: SparsityPatternView.hpp:79
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
Definition: arrayManipulation.hpp:152
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void shiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position up by the given amount. New uninitialized values take their place.
Definition: arrayManipulation.hpp:326
LVARRAY_HOST_DEVICE ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
Definition: CRSMatrixView.hpp:244
LVARRAY_HOST_DEVICE void addToRow(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix. The columns must be sorted...
Definition: CRSMatrixView.hpp:424
INDEX_TYPE const m_rowNNZ
The number of non zero entries in the row.
Definition: CRSMatrixView.hpp:721
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:614
#define LVARRAY_HOST_DEVICE_HIP
Mark a function for both host and device usage when using HIP only.
Definition: Macros.hpp:602
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const
Definition: CRSMatrixView.hpp:180
typename ParentClass::INDEX_TYPE_NC INDEX_TYPE_NC
Since INDEX_TYPE should always be const we need an alias for the non const version.
Definition: ArrayOfSetsView.hpp:47
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void emplace(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ARGS &&... args)
Insert into the array constructing the new value in place.
Definition: arrayManipulation.hpp:478
T EntryType
The type of the entries in the matrix.
Definition: CRSMatrixView.hpp:93
#define LVARRAY_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
Definition: Macros.hpp:524
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600
This class provides a view into a compressed row storage matrix.
Definition: CRSMatrixView.hpp:75