From 2e8dfa1e34d70f1b7096426ab796640c38cd9fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkovsky@mmg.fjfi.cvut.cz> Date: Sun, 21 Jun 2020 17:31:27 +0200 Subject: [PATCH] Cleanup: removed multimaps classes as they were superseded with sparse binary matrices --- .../Multimaps/EllpackIndexMultimap.h | 116 ------- .../Multimaps/EllpackIndexMultimap.hpp | 321 ------------------ .../Multimaps/EllpackIndexMultimapValues.h | 121 ------- .../Multimaps/EllpackIndexMultimapValues.hpp | 293 ---------------- .../Multimaps/MultimapPermutationApplier.h | 90 ----- .../Multimaps/StaticEllpackIndexMultimap.h | 113 ------ .../Multimaps/StaticEllpackIndexMultimap.hpp | 277 --------------- .../StaticEllpackIndexMultimapValues.h | 108 ------ .../StaticEllpackIndexMultimapValues.hpp | 285 ---------------- src/UnitTests/Containers/CMakeLists.txt | 1 - .../Containers/Multimaps/CMakeLists.txt | 10 - .../Containers/Multimaps/MultimapTest.cpp | 154 --------- .../Multimaps/StaticMultimapTest.cpp | 102 ------ 13 files changed, 1991 deletions(-) delete mode 100644 src/TNL/Containers/Multimaps/EllpackIndexMultimap.h delete mode 100644 src/TNL/Containers/Multimaps/EllpackIndexMultimap.hpp delete mode 100644 src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h delete mode 100644 src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.hpp delete mode 100644 src/TNL/Containers/Multimaps/MultimapPermutationApplier.h delete mode 100644 src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.h delete mode 100644 src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.hpp delete mode 100644 src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.h delete mode 100644 src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.hpp delete mode 100644 src/UnitTests/Containers/Multimaps/CMakeLists.txt delete mode 100644 src/UnitTests/Containers/Multimaps/MultimapTest.cpp delete mode 100644 src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp diff --git a/src/TNL/Containers/Multimaps/EllpackIndexMultimap.h b/src/TNL/Containers/Multimaps/EllpackIndexMultimap.h deleted file mode 100644 index 8684ba3b1e..0000000000 --- a/src/TNL/Containers/Multimaps/EllpackIndexMultimap.h +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************** - EllpackIndexMultimap.h - description - ------------------- - begin : Sep 9, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/Vector.h> -#include <TNL/Containers/Multimaps/EllpackIndexMultimapValues.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< typename Device > -struct EllpackIndexMultimapSliceSizeGetter -{ - static constexpr int SliceSize = 1; -}; - -template<> -struct EllpackIndexMultimapSliceSizeGetter< Devices::Cuda > -{ - static constexpr int SliceSize = 32; -}; - -template< typename Index = int, - typename Device = Devices::Host, - typename LocalIndex = Index, - int SliceSize = EllpackIndexMultimapSliceSizeGetter< Device >::SliceSize > -class EllpackIndexMultimap - : public Object -{ - public: - using DeviceType = Device; - using IndexType = Index; - using LocalIndexType = LocalIndex; - using ValuesAccessorType = EllpackIndexMultimapValues< IndexType, DeviceType, LocalIndexType, SliceSize >; - using ConstValuesAccessorType = EllpackIndexMultimapValues< const IndexType, DeviceType, LocalIndexType, SliceSize >; - using ValuesAllocationVectorType = Vector< LocalIndexType, DeviceType, IndexType >; - - EllpackIndexMultimap() = default; - - template< typename Device_ > - EllpackIndexMultimap( const EllpackIndexMultimap< Index, Device_, LocalIndex, SliceSize >& other ); - - template< typename Device_ > - EllpackIndexMultimap& operator=( const EllpackIndexMultimap< Index, Device_, LocalIndex, SliceSize >& other ); - - void setKeysRange( const IndexType& keysRange ); - - __cuda_callable__ - const IndexType getKeysRange() const; - - void allocate( const LocalIndexType& maxValuesCount ); - - void allocate( const ValuesAllocationVectorType& valuesCounts ); - - template< typename Device_, int SliceSize_ > - void setLike( const EllpackIndexMultimap< Index, Device_, LocalIndex, SliceSize_ >& other ); - - __cuda_callable__ - ValuesAccessorType getValues( const IndexType& inputIndex ); - - __cuda_callable__ - ConstValuesAccessorType getValues( const IndexType& inputIndex ) const; - - __cuda_callable__ - LocalIndexType getValuesCount( const IndexType& inputIndex ) const; - - __cuda_callable__ - IndexType getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const; - - bool operator==( const EllpackIndexMultimap& other ) const; - - void save( File& file ) const; - - void load( File& file ); - - using Object::load; - - using Object::save; - - void print( std::ostream& str ) const; - - protected: - Vector< IndexType, DeviceType, IndexType > values; - ValuesAllocationVectorType valuesCounts; - - IndexType keysRange = 0; - LocalIndexType maxValuesCount = 0; - - __cuda_callable__ - IndexType getAllocationKeysRange( IndexType keysRange ) const; - - // friend class is needed for templated assignment operators - template< typename Index_, typename Device_, typename LocalIndex_, int SliceSize_ > - friend class EllpackIndexMultimap; -}; - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -std::ostream& operator << ( std::ostream& str, const EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >& multimap ); - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL - -#include <TNL/Containers/Multimaps/EllpackIndexMultimap.hpp> diff --git a/src/TNL/Containers/Multimaps/EllpackIndexMultimap.hpp b/src/TNL/Containers/Multimaps/EllpackIndexMultimap.hpp deleted file mode 100644 index 0872d85012..0000000000 --- a/src/TNL/Containers/Multimaps/EllpackIndexMultimap.hpp +++ /dev/null @@ -1,321 +0,0 @@ -/*************************************************************************** - EllpackIndexMultimap_impl.h - description - ------------------- - begin : Sep 9, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/Multimaps/EllpackIndexMultimap.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > - template< typename Device_ > -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -EllpackIndexMultimap( const EllpackIndexMultimap< Index, Device_, LocalIndex, SliceSize >& other ) -{ - operator=( other ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > - template< typename Device_ > -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >& -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -operator=( const EllpackIndexMultimap< Index, Device_, LocalIndex, SliceSize >& other ) -{ - values = other.values; - valuesCounts = other.valuesCounts; - keysRange = other.keysRange; - maxValuesCount = other.maxValuesCount; - return *this; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -setKeysRange( const IndexType& keysRange ) -{ - TNL_ASSERT( keysRange >= 0, ); - this->keysRange = keysRange; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -const Index -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -getKeysRange() const -{ - return this->keysRange; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -allocate( const LocalIndexType& maxValuesCount ) -{ - TNL_ASSERT( maxValuesCount >= 0, ); - this->maxValuesCount = maxValuesCount; - const IndexType ldSize = getAllocationKeysRange( this->getKeysRange() ); - this->values.setSize( ldSize * this->maxValuesCount ); - this->valuesCounts.setSize( this->getKeysRange() ); - if( this->valuesCounts.getSize() > 0 ) - this->valuesCounts.setValue( maxValuesCount ); - - // extra cost at initialization, which allows to have much simpler operator== - if( this->values.getSize() > 0 ) - values.setValue( 0 ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -allocate( const ValuesAllocationVectorType& valuesCounts ) -{ - TNL_ASSERT( valuesCounts.getSize() == this->keysRange, - std::cerr << "valuesCounts.getSize() = " << valuesCounts.getSize() - << "this->keysRange = " << this->keysRange - << std::endl; ); - this->maxValuesCount = max( valuesCounts ); - - TNL_ASSERT( this->maxValuesCount >= 0, - std::cerr << "this->maxValuesCount = " << this->maxValuesCount << std::endl; ); - const IndexType ldSize = getAllocationKeysRange( this->getKeysRange() ); - this->values.setSize( ldSize * this->maxValuesCount ); - this->valuesCounts.setSize( this->getKeysRange() ); - this->valuesCounts = valuesCounts; - - // extra cost at initialization, which allows to have much simpler operator== - if( this->values.getSize() > 0 ) - values.setValue( 0 ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > - template< typename Device_, int SliceSize_ > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -setLike( const EllpackIndexMultimap< Index, Device_, LocalIndex, SliceSize_ >& other ) -{ - const IndexType ldSize = getAllocationKeysRange( other.getKeysRange() ); - values.setSize( ldSize * other.maxValuesCount ); - valuesCounts.setLike( other.valuesCounts ); - valuesCounts = other.valuesCounts; - keysRange = other.keysRange; - maxValuesCount = other.maxValuesCount; - - // extra cost at initialization, which allows to have much simpler operator== - if( this->values.getSize() > 0 ) - values.setValue( 0 ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -typename EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >::ValuesAccessorType -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -getValues( const IndexType& inputIndex ) -{ - TNL_ASSERT( inputIndex < this->getKeysRange(), - std::cerr << "inputIndex = " << inputIndex << std::endl - << "this->getKeysRange() = " << this->getKeysRange() - << std::endl; ); - TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * this->maxValuesCount == this->values.getSize() && this->getKeysRange() == this->valuesCounts.getSize(), - std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl - << "this->maxValuesCount = " << this->maxValuesCount << std::endl - << "this->values.getSize() = " << this->values.getSize() << std::endl - << "this->valuesCounts.getSize() = " << this->valuesCounts.getSize() << std::endl; ); - const IndexType sliceIdx = inputIndex / SliceSize; - const IndexType sliceOffset = sliceIdx * SliceSize * this->maxValuesCount; - const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize; - return ValuesAccessorType( &this->values[ offset ], &this->valuesCounts[ inputIndex ], this->maxValuesCount ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -typename EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >::ConstValuesAccessorType -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -getValues( const IndexType& inputIndex ) const -{ - TNL_ASSERT( inputIndex < this->getKeysRange(), - std::cerr << "inputIndex = " << inputIndex << std::endl - << "this->getKeysRange() = " << this->getKeysRange() - << std::endl; ); - TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * this->maxValuesCount == this->values.getSize() && this->getKeysRange() == this->valuesCounts.getSize(), - std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl - << "this->maxValuesCount = " << this->maxValuesCount << std::endl - << "this->values.getSize() = " << this->values.getSize() << std::endl - << "this->valuesCounts.getSize() = " << this->valuesCounts.getSize() << std::endl; ); - const IndexType sliceIdx = inputIndex / SliceSize; - const IndexType sliceOffset = sliceIdx * SliceSize * this->maxValuesCount; - const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize; - return ConstValuesAccessorType( &this->values[ offset ], &this->valuesCounts[ inputIndex ], this->maxValuesCount ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -LocalIndex -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -getValuesCount( const IndexType& inputIndex ) const -{ - return valuesCounts[ inputIndex ]; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -Index -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const -{ - TNL_ASSERT( inputIndex < this->getKeysRange(), - std::cerr << "inputIndex = " << inputIndex << std::endl - << "this->getKeysRange() = " << this->getKeysRange() - << std::endl; ); - TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * this->maxValuesCount == this->values.getSize() && this->getKeysRange() == this->valuesCounts.getSize(), - std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl - << "this->maxValuesCount = " << this->maxValuesCount << std::endl - << "this->values.getSize() = " << this->values.getSize() << std::endl - << "this->valuesCounts.getSize() = " << this->valuesCounts.getSize() << std::endl; ); - const IndexType sliceIdx = inputIndex / SliceSize; - const IndexType sliceOffset = sliceIdx * SliceSize * this->maxValuesCount; - const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize; - return this->values[ offset + portIndex * SliceSize ]; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -bool -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -operator==( const EllpackIndexMultimap& other ) const -{ -// if( ! ( this->keysRange == other.keysRange && -// this->maxValuesCount == other.maxValuesCount && -// this->valuesCounts == other.valuesCounts ) ) -// return false; -// // compare values for each key separately - the sizes may vary -// for( IndexType i = 0; i < this->keysRange; i++ ) -// if( this->getValues( i ) != other.getValues( i ) ) -// return false; -// return true; - - // we assume that invalid entries in the ellpack format are always 0 - return this->keysRange == other.keysRange && - this->maxValuesCount == other.maxValuesCount && - this->valuesCounts == other.valuesCounts && - this->values == other.values; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -save( File& file ) const -{ - Object::save( file ); - file.save( &this->keysRange ); - file.save( &this->maxValuesCount ); - file << this->values << this->valuesCounts; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -load( File& file ) -{ - Object::load( file ); - file.load( &this->keysRange ); - file.load( &this->maxValuesCount ); - file >> this->values >> this->valuesCounts; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -print( std::ostream& str ) const -{ - str << "[ "; - if( this->getKeysRange() > 0 ) - { - str << this->getValues( 0 ); - for( Index i = 1; i < this->getKeysRange(); i++ ) - str << ",\n " << this->getValues( i ); - } - str << " ]"; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -Index -EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >:: -getAllocationKeysRange( IndexType keysRange ) const -{ - return SliceSize * roundUpDivision( keysRange, SliceSize ); -} - - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -std::ostream& operator << ( std::ostream& str, const EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >& multimap ) -{ - multimap.print( str ); - return str; -} - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL diff --git a/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h b/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h deleted file mode 100644 index 9be47980d1..0000000000 --- a/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.h +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************** - EllpackIndexMultimapValues.h - description - ------------------- - begin : Sep 10, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <type_traits> -#include <ostream> - -#include <TNL/Cuda/CudaCallable.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -class EllpackIndexMultimap; - -template< typename Index, - typename Device, - typename LocalIndex, - int step = 1 > -class EllpackIndexMultimapValues -{ - public: - using DeviceType = Device; - using IndexType = Index; - using LocalIndexType = LocalIndex; - using NetworkType = EllpackIndexMultimap< IndexType, DeviceType, LocalIndexType, step >; - - __cuda_callable__ - EllpackIndexMultimapValues(); - - __cuda_callable__ - EllpackIndexMultimapValues( EllpackIndexMultimapValues&& other ); - - __cuda_callable__ - EllpackIndexMultimapValues& operator=( const EllpackIndexMultimapValues& ); - - // converting assignment, needed for 'const int' -> 'int' etc. - template< typename Index_, typename LocalIndex_, int step_ > - __cuda_callable__ - EllpackIndexMultimapValues& operator=( const EllpackIndexMultimapValues< Index_, Device, LocalIndex_, step_ >& other ); - - __cuda_callable__ - EllpackIndexMultimapValues& operator=( EllpackIndexMultimapValues&& other ); - - __cuda_callable__ - void bind( const EllpackIndexMultimapValues& other ); - - __cuda_callable__ - void setSize( const LocalIndexType& portsCount ); - - __cuda_callable__ - LocalIndexType getSize() const; - - __cuda_callable__ - LocalIndexType getAllocatedSize() const; - - __cuda_callable__ - void setValue( const LocalIndexType& portIndex, - const IndexType& value ); - - __cuda_callable__ - IndexType getValue( const LocalIndexType& portIndex ) const; - - __cuda_callable__ - IndexType& operator[]( const LocalIndexType& portIndex ); - - __cuda_callable__ - const IndexType& operator[]( const LocalIndexType& portIndex ) const; - - __cuda_callable__ - bool operator==( const EllpackIndexMultimapValues& other ) const; - - __cuda_callable__ - bool operator!=( const EllpackIndexMultimapValues& other ) const; - - void print( std::ostream& str ) const; - - protected: - using ValuesCountType = typename std::conditional< std::is_const< IndexType >::value, - std::add_const_t< LocalIndexType >, - LocalIndexType >::type; - - __cuda_callable__ - EllpackIndexMultimapValues( IndexType* values, - ValuesCountType* valuesCount, - const LocalIndexType& allocatedSize ); - - IndexType* values; - - ValuesCountType* valuesCount; - - // TODO: this is useless for a const-accessor (without setSize etc.) - LocalIndexType allocatedSize; - - friend EllpackIndexMultimap< IndexType, DeviceType, LocalIndexType, step >; - friend EllpackIndexMultimap< typename std::remove_const< IndexType >::type, DeviceType, LocalIndexType, step >; -}; - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -std::ostream& operator << ( std::ostream& str, const EllpackIndexMultimapValues< Index, Device, LocalIndex, step >& ports ); - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL - -#include <TNL/Containers/Multimaps/EllpackIndexMultimapValues.hpp> diff --git a/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.hpp b/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.hpp deleted file mode 100644 index 6b98927fb8..0000000000 --- a/src/TNL/Containers/Multimaps/EllpackIndexMultimapValues.hpp +++ /dev/null @@ -1,293 +0,0 @@ -/*************************************************************************** - EllpackIndexMultimapValues_impl.h - description - ------------------- - begin : Sep 10, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include "EllpackIndexMultimapValues.h" - -#include <TNL/Assert.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -EllpackIndexMultimapValues() -: values( nullptr ), valuesCount( nullptr ), allocatedSize( 0 ) -{ -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -EllpackIndexMultimapValues( EllpackIndexMultimapValues&& other ) -: values( other.values ), valuesCount( other.valuesCount ), allocatedSize( other.allocatedSize ) -{ - other.values = nullptr; - other.valuesCount = nullptr; - other.allocatedSize = 0; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -EllpackIndexMultimapValues( IndexType* values, - ValuesCountType* valuesCount, - const LocalIndexType& allocatedSize ) -: values( values ), valuesCount( valuesCount ), allocatedSize( allocatedSize ) -{ - TNL_ASSERT( *(this->valuesCount) <= allocatedSize, ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >& -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator=( const EllpackIndexMultimapValues& other ) -{ - TNL_ASSERT( this->getAllocatedSize() >= other.getSize(), ); - this->setSize( other.getSize() ); - if( this->values != other.values ) { - for( LocalIndexType i = 0; i < this->getSize(); i++ ) - this->setValue( i, other[ i ] ); - } - return *this; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > - template< typename Index_, typename LocalIndex_, int step_ > -__cuda_callable__ -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >& -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator=( const EllpackIndexMultimapValues< Index_, Device, LocalIndex_, step_ >& other ) -{ - TNL_ASSERT( this->getAllocatedSize() >= other.getSize(), ); - this->setSize( other.getSize() ); - for( LocalIndexType i = 0; i < this->getSize(); i++ ) - this->setValue( i, other[ i ] ); - return *this; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >& -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator=( EllpackIndexMultimapValues&& other ) -{ - this->values = other.values; - this->valuesCount = other.valuesCount; - this->allocatedSize = other.allocatedSize; - other.values = nullptr; - other.valuesCount = nullptr; - other.allocatedSize = 0; - return *this; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -void -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -bind( const EllpackIndexMultimapValues& other ) -{ - this->values = other.values; - this->valuesCount = other.valuesCount; - this->allocatedSize = other.allocatedSize; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -void -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -setSize( const LocalIndexType& size ) -{ - TNL_ASSERT( this->valuesCount, - std::cerr << "Uninitialized 'valuesCount' pointer in EllpackIndexMultimapValues." << std::endl; ); - TNL_ASSERT( size >= 0 && size <= this->allocatedSize, - std::cerr << "size = " << size << ", allocatedSize = " << this->allocatedSize << std::endl; ); - *valuesCount = size; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -LocalIndex -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -getSize() const -{ - if( ! valuesCount ) - return 0; - return *valuesCount; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -LocalIndex -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -getAllocatedSize() const -{ - return this->allocatedSize; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -void -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -setValue( const LocalIndexType& portIndex, - const IndexType& value ) -{ - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - this->values[ portIndex * step ] = value; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -Index -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -getValue( const LocalIndexType& portIndex ) const -{ - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - return this->values[ portIndex * step ]; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -Index& -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator[]( const LocalIndexType& portIndex ) -{ - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - return this->values[ portIndex * step ]; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -const Index& -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator[]( const LocalIndexType& portIndex ) const -{ - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - return this->values[ portIndex * step ]; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -bool -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator==( const EllpackIndexMultimapValues& other ) const -{ - if( this->getSize() != other.getSize() ) - return false; - for( LocalIndexType i = 0; i < this->getSize(); i++ ) - if( this->operator[]( i ) != other[ i ] ) - return false; - return true; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -bool -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -operator!=( const EllpackIndexMultimapValues& other ) const -{ - return ! ( *this == other ); -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -void -EllpackIndexMultimapValues< Index, Device, LocalIndex, step >:: -print( std::ostream& str ) const -{ - str << "[ "; - if( this->getSize() > 0 ) - { - str << this->getValue( 0 ); - for( typename std::remove_const< Index >::type i = 1; i < this->getSize(); i++ ) - str << ", " << this->getValue( i ); - } - str << " ]"; -} - -template< typename Index, - typename Device, - typename LocalIndex, - int step > -std::ostream& operator << ( std::ostream& str, const EllpackIndexMultimapValues< Index, Device, LocalIndex, step >& ports ) -{ - ports.print( str ); - return str; -} - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL diff --git a/src/TNL/Containers/Multimaps/MultimapPermutationApplier.h b/src/TNL/Containers/Multimaps/MultimapPermutationApplier.h deleted file mode 100644 index a50d7b3541..0000000000 --- a/src/TNL/Containers/Multimaps/MultimapPermutationApplier.h +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - IndexPermutationApplier.h - description - ------------------- - begin : Mar 10, 2017 - copyright : (C) 2017 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Pointers/DevicePointer.h> -#include <TNL/Algorithms/ParallelFor.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< typename Multimap, - typename PermutationArray > -void permuteMultimapKeys( Multimap& multimap, const PermutationArray& perm ) -{ - static_assert( std::is_same< typename Multimap::DeviceType, typename PermutationArray::DeviceType >::value, - "The multimap and permutation vector must be stored on the same device." ); - using IndexType = typename Multimap::IndexType; - using DeviceType = typename Multimap::DeviceType; - TNL_ASSERT( multimap.getKeysRange() == perm.getSize(), - std::cerr << "multimap keys range is " << multimap.getKeysRange() - << ", permutation size is " << perm.getSize() << std::endl; ); - - // create temporary multimap for the permuted data - Multimap multimapCopy; - multimapCopy.setLike( multimap ); - - // kernel to permute the rows of multimap into multimapCopy - auto kernel = [] __cuda_callable__ - ( IndexType i, - const Multimap* multimap, - Multimap* multimapCopy, - const typename PermutationArray::ValueType* perm ) - { - const auto srcValues = multimap->getValues( perm[ i ] ); - auto destValues = multimapCopy->getValues( i ); - destValues = srcValues; - }; - - Pointers::DevicePointer< Multimap > multimapPointer( multimap ); - Pointers::DevicePointer< Multimap > multimapCopyPointer( multimapCopy ); - - Algorithms::ParallelFor< DeviceType >::exec( (IndexType) 0, multimap.getKeysRange(), - kernel, - &multimapPointer.template getData< DeviceType >(), - &multimapCopyPointer.template modifyData< DeviceType >(), - perm.getData() ); - - // copy the permuted data back into the multimap - multimap = multimapCopy; -} - -template< typename Multimap, - typename PermutationArray > -void permuteMultimapValues( Multimap& multimap, const PermutationArray& iperm ) -{ - static_assert( std::is_same< typename Multimap::DeviceType, typename PermutationArray::DeviceType >::value, - "The multimap and permutation vector must be stored on the same device." ); - using IndexType = typename Multimap::IndexType; - using DeviceType = typename Multimap::DeviceType; - - // kernel to permute the multimap values - auto kernel = [] __cuda_callable__ - ( IndexType i, - Multimap* multimap, - const typename PermutationArray::ValueType* iperm ) - { - auto values = multimap->getValues( i ); - for( typename Multimap::LocalIndexType v = 0; v < values.getSize(); v++ ) - values[ v ] = iperm[ values[ v ] ]; - }; - - Pointers::DevicePointer< Multimap > multimapPointer( multimap ); - Algorithms::ParallelFor< DeviceType >::exec( (IndexType) 0, multimap.getKeysRange(), - kernel, - &multimapPointer.template modifyData< DeviceType >(), - iperm.getData() ); -} - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL diff --git a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.h b/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.h deleted file mode 100644 index c8f2aebaaa..0000000000 --- a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.h +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - StaticEllpackIndexMultimap.h - description - ------------------- - begin : Sep 9, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/Vector.h> -#include <TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< typename Device > -struct StaticEllpackIndexMultimapSliceSizeGetter -{ - static constexpr int SliceSize = 1; -}; - -template<> -struct StaticEllpackIndexMultimapSliceSizeGetter< Devices::Cuda > -{ - static constexpr int SliceSize = 32; -}; - -template< int ValuesCount, - typename Index = int, - typename Device = Devices::Host, - typename LocalIndex = Index, - int SliceSize = StaticEllpackIndexMultimapSliceSizeGetter< Device >::SliceSize > -class StaticEllpackIndexMultimap - : public Object -{ - public: - using DeviceType = Device; - using IndexType = Index; - using LocalIndexType = LocalIndex; - using ValuesAccessorType = StaticEllpackIndexMultimapValues< ValuesCount, IndexType, DeviceType, LocalIndexType, SliceSize >; - using ConstValuesAccessorType = StaticEllpackIndexMultimapValues< ValuesCount, const IndexType, DeviceType, LocalIndexType, SliceSize >; - - StaticEllpackIndexMultimap() = default; - - template< typename Device_ > - StaticEllpackIndexMultimap( const StaticEllpackIndexMultimap< ValuesCount, Index, Device_, LocalIndex, SliceSize >& other ); - - template< typename Device_ > - StaticEllpackIndexMultimap& operator=( const StaticEllpackIndexMultimap< ValuesCount, Index, Device_, LocalIndex, SliceSize >& other ); - - void setKeysRange( const IndexType& keysRange ); - - __cuda_callable__ - const IndexType getKeysRange() const; - - void allocate(); - - template< typename Device_ > - void setLike( const StaticEllpackIndexMultimap< ValuesCount, Index, Device_, LocalIndex, SliceSize >& other ); - - __cuda_callable__ - ValuesAccessorType getValues( const IndexType& inputIndex ); - - __cuda_callable__ - ConstValuesAccessorType getValues( const IndexType& inputIndex ) const; - - __cuda_callable__ - constexpr LocalIndexType getValuesCount( const IndexType& inputIndex ) const; - - __cuda_callable__ - IndexType getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const; - - bool operator==( const StaticEllpackIndexMultimap& other ) const; - - void save( File& file ) const; - - void load( File& file ); - - using Object::load; - - using Object::save; - - void print( std::ostream& str ) const; - - protected: - Vector< IndexType, DeviceType, IndexType > values; - - IndexType keysRange = 0; - - __cuda_callable__ - IndexType getAllocationKeysRange( IndexType keysRange ) const; - - // friend class is needed for templated assignment operators - template< int ValuesCount_, typename Index_, typename Device_, typename LocalIndex_, int SliceSize_ > - friend class StaticEllpackIndexMultimap; -}; - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -std::ostream& operator << ( std::ostream& str, const StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >& multimap ); - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL - -#include <TNL/Containers/Multimaps/StaticEllpackIndexMultimap.hpp> diff --git a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.hpp b/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.hpp deleted file mode 100644 index 8654ac0a7b..0000000000 --- a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimap.hpp +++ /dev/null @@ -1,277 +0,0 @@ -/*************************************************************************** - StaticEllpackIndexMultimap_impl.h - description - ------------------- - begin : Sep 9, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/Multimaps/StaticEllpackIndexMultimap.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > - template< typename Device_ > -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -StaticEllpackIndexMultimap( const StaticEllpackIndexMultimap< ValuesCount, Index, Device_, LocalIndex, SliceSize >& other ) -{ - operator=( other ); -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > - template< typename Device_ > -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >& -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -operator=( const StaticEllpackIndexMultimap< ValuesCount, Index, Device_, LocalIndex, SliceSize >& other ) -{ - values = other.values; - keysRange = other.keysRange; - return *this; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -setKeysRange( const IndexType& keysRange ) -{ - TNL_ASSERT( keysRange >= 0, ); - this->keysRange = keysRange; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -const Index -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -getKeysRange() const -{ - return this->keysRange; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -allocate() -{ - const IndexType ldSize = getAllocationKeysRange( this->getKeysRange() ); - values.setSize( ldSize * ValuesCount ); - - // extra cost at initialization, which allows to have much simpler operator== - if( ldSize > 0 ) - values.setValue( 0 ); -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > - template< typename Device_ > -void -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -setLike( const StaticEllpackIndexMultimap< ValuesCount, Index, Device_, LocalIndex, SliceSize >& other ) -{ - const IndexType ldSize = getAllocationKeysRange( other.getKeysRange() ); - values.setSize( ldSize * ValuesCount ); - - // extra cost at initialization, which allows to have much simpler operator== - if( ldSize > 0 ) - values.setValue( 0 ); - - keysRange = other.keysRange; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -typename StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >::ValuesAccessorType -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -getValues( const IndexType& inputIndex ) -{ - TNL_ASSERT( inputIndex < this->getKeysRange(), - std::cerr << "inputIndex = " << inputIndex << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl; ); - TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * ValuesCount == this->values.getSize(), - std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl - << "this->values.getSize() = " << this->values.getSize() << std::endl; ); - const IndexType sliceIdx = inputIndex / SliceSize; - const IndexType sliceOffset = sliceIdx * SliceSize * ValuesCount; - const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize; - return ValuesAccessorType( &this->values[ offset ] ); -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -typename StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >::ConstValuesAccessorType -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -getValues( const IndexType& inputIndex ) const -{ - TNL_ASSERT( inputIndex < this->getKeysRange(), - std::cerr << "inputIndex = " << inputIndex << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl; ); - TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * ValuesCount == this->values.getSize(), - std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl - << "this->values.getSize() = " << this->values.getSize() << std::endl; ); - const IndexType sliceIdx = inputIndex / SliceSize; - const IndexType sliceOffset = sliceIdx * SliceSize * ValuesCount; - const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize; - return ConstValuesAccessorType( &this->values[ offset ] ); -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -constexpr LocalIndex -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -getValuesCount( const IndexType& inputIndex ) const -{ - return ValuesCount; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -Index -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const -{ - TNL_ASSERT( inputIndex < this->getKeysRange(), - std::cerr << "inputIndex = " << inputIndex << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl; ); - TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * ValuesCount == this->values.getSize(), - std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl - << "this->getKeysRange() = " << this->getKeysRange() << std::endl - << "this->values.getSize() = " << this->values.getSize() << std::endl; ); - const IndexType sliceIdx = inputIndex / SliceSize; - const IndexType sliceOffset = sliceIdx * SliceSize * ValuesCount; - const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize; - return this->values[ offset + portIndex * SliceSize ]; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -bool -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -operator==( const StaticEllpackIndexMultimap& other ) const -{ - return ( this->keysRange == other.keysRange && this->values == other.values ); -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -save( File& file ) const -{ - Object::save( file ); - file.save( &this->keysRange ); - file << this->values; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -load( File& file ) -{ - Object::load( file ); - file.load( &this->keysRange ); - file >> this->values; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -void -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -print( std::ostream& str ) const -{ - str << "[ "; - if( this->getKeysRange() > 0 ) - { - str << this->getValues( 0 ); - for( Index i = 1; i < this->getKeysRange(); i++ ) - str << ",\n " << this->getValues( i ); - } - str << " ]"; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -__cuda_callable__ -Index -StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >:: -getAllocationKeysRange( IndexType keysRange ) const -{ - return SliceSize * roundUpDivision( keysRange, SliceSize ); -} - - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int SliceSize > -std::ostream& operator << ( std::ostream& str, const StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex, SliceSize >& multimap ) -{ - multimap.print( str ); - return str; -} - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL diff --git a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.h b/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.h deleted file mode 100644 index efae4f0517..0000000000 --- a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.h +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************** - StaticEllpackIndexMultimapValues.h - description - ------------------- - begin : Sep 10, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <type_traits> -#include <ostream> - -#include <TNL/Cuda/CudaCallable.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -class StaticEllpackIndexMultimap; - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -class StaticEllpackIndexMultimapValues -{ - public: - using DeviceType = Device; - using IndexType = Index; - using LocalIndexType = LocalIndex; - using NetworkType = StaticEllpackIndexMultimap< ValuesCount, IndexType, DeviceType, LocalIndexType, step >; - - __cuda_callable__ - StaticEllpackIndexMultimapValues(); - - __cuda_callable__ - StaticEllpackIndexMultimapValues( StaticEllpackIndexMultimapValues&& other ); - - __cuda_callable__ - StaticEllpackIndexMultimapValues& operator=( const StaticEllpackIndexMultimapValues& other ); - - // converting assignment, needed for 'const int' -> 'int' etc. - template< typename Index_, typename LocalIndex_, int step_ > - __cuda_callable__ - StaticEllpackIndexMultimapValues& operator=( const StaticEllpackIndexMultimapValues< ValuesCount, Index_, Device, LocalIndex_, step_ >& other ); - - __cuda_callable__ - StaticEllpackIndexMultimapValues& operator=( StaticEllpackIndexMultimapValues&& other ); - - __cuda_callable__ - void bind( const StaticEllpackIndexMultimapValues& other ); - - constexpr LocalIndexType getSize() const; - - constexpr LocalIndexType getAllocatedSize() const; - - __cuda_callable__ - void setValue( const LocalIndexType& portIndex, - const IndexType& value ); - - __cuda_callable__ - IndexType getValue( const LocalIndexType& portIndex ) const; - - __cuda_callable__ - IndexType& operator[]( const LocalIndexType& portIndex ); - - __cuda_callable__ - const IndexType& operator[]( const LocalIndexType& portIndex ) const; - - __cuda_callable__ - bool operator==( const StaticEllpackIndexMultimapValues& other ) const; - - __cuda_callable__ - bool operator!=( const StaticEllpackIndexMultimapValues& other ) const; - - void print( std::ostream& str ) const; - - protected: - __cuda_callable__ - StaticEllpackIndexMultimapValues( IndexType* values ); - - IndexType* values; - - friend StaticEllpackIndexMultimap< ValuesCount, IndexType, DeviceType, LocalIndexType, step >; - friend StaticEllpackIndexMultimap< ValuesCount, typename std::remove_const< IndexType >::type, DeviceType, LocalIndexType, step >; -}; - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -std::ostream& operator << ( std::ostream& str, const StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >& ports ); - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL - -#include <TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.hpp> diff --git a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.hpp b/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.hpp deleted file mode 100644 index 2f3bd4df9f..0000000000 --- a/src/TNL/Containers/Multimaps/StaticEllpackIndexMultimapValues.hpp +++ /dev/null @@ -1,285 +0,0 @@ -/*************************************************************************** - StaticEllpackIndexMultimapValues_impl.h - description - ------------------- - begin : Sep 10, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include "StaticEllpackIndexMultimapValues.h" - -#include <TNL/Assert.h> - -namespace TNL { -namespace Containers { -namespace Multimaps { - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -StaticEllpackIndexMultimapValues() -: values( nullptr ) -{ -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -StaticEllpackIndexMultimapValues( StaticEllpackIndexMultimapValues&& other ) -: values( other.values ) -{ - other.values = nullptr; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -StaticEllpackIndexMultimapValues( IndexType* values ) -: values( values ) -{ -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >& -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator=( const StaticEllpackIndexMultimapValues& other ) -{ - if( this->values != other.values ) { - for( LocalIndexType i = 0; i < this->getSize(); i++ ) - this->setValue( i, other[ i ] ); - } - return *this; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > - template< typename Index_, typename LocalIndex_, int step_ > -__cuda_callable__ -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >& -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator=( const StaticEllpackIndexMultimapValues< ValuesCount, Index_, Device, LocalIndex_, step_ >& other ) -{ - for( LocalIndexType i = 0; i < this->getSize(); i++ ) - this->setValue( i, other[ i ] ); - return *this; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >& -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator=( StaticEllpackIndexMultimapValues&& other ) -{ - this->values = other.values; - other.values = nullptr; - return *this; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -void -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -bind( const StaticEllpackIndexMultimapValues& other ) -{ - this->values = other.values; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -constexpr LocalIndex -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -getSize() const -{ - return ValuesCount; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -constexpr LocalIndex -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -getAllocatedSize() const -{ - return ValuesCount; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -void -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -setValue( const LocalIndexType& portIndex, - const IndexType& value ) -{ - TNL_ASSERT( this->values, - std::cerr << "This instance is not bound to any multimap." << std::endl; ); - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - this->values[ portIndex * step ] = value; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -Index -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -getValue( const LocalIndexType& portIndex ) const -{ - TNL_ASSERT( this->values, - std::cerr << "This instance is not bound to any multimap." << std::endl; ); - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - return this->values[ portIndex * step ]; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -Index& -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator[]( const LocalIndexType& portIndex ) -{ - TNL_ASSERT( this->values, - std::cerr << "This instance is not bound to any multimap." << std::endl; ); - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - return this->values[ portIndex * step ]; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -const Index& -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator[]( const LocalIndexType& portIndex ) const -{ - TNL_ASSERT( this->values, - std::cerr << "This instance is not bound to any multimap." << std::endl; ); - TNL_ASSERT( portIndex < this->getSize(), - std::cerr << " portIndex = " << portIndex - << " getSize() = " << this->getSize() - << std::endl ); - return this->values[ portIndex * step ]; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -bool -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator==( const StaticEllpackIndexMultimapValues& other ) const -{ - if( this->values == other.values ) - return true; - if( ! this->values || ! other.values ) - return false; - for( LocalIndexType i = 0; i < this->getSize(); i++ ) - if( this->operator[]( i ) != other[ i ] ) - return false; - return true; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -__cuda_callable__ -bool -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -operator!=( const StaticEllpackIndexMultimapValues& other ) const -{ - return ! ( *this == other ); -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -void -StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >:: -print( std::ostream& str ) const -{ - str << "[ "; - if( this->getSize() > 0 ) - { - str << this->getValue( 0 ); - for( typename std::remove_const< Index >::type i = 1; i < this->getSize(); i++ ) - str << ", " << this->getValue( i ); - } - str << " ]"; -} - -template< int ValuesCount, - typename Index, - typename Device, - typename LocalIndex, - int step > -std::ostream& operator << ( std::ostream& str, const StaticEllpackIndexMultimapValues< ValuesCount, Index, Device, LocalIndex, step >& ports ) -{ - ports.print( str ); - return str; -} - -} // namespace Multimaps -} // namespace Containers -} // namespace TNL diff --git a/src/UnitTests/Containers/CMakeLists.txt b/src/UnitTests/Containers/CMakeLists.txt index 21be3ded15..ae3c1b0e71 100644 --- a/src/UnitTests/Containers/CMakeLists.txt +++ b/src/UnitTests/Containers/CMakeLists.txt @@ -108,7 +108,6 @@ ADD_TEST( StaticVectorOperationsTest ${EXECUTABLE_OUTPUT_PATH}/StaticVectorOpera ADD_TEST( StaticVectorOfStaticVectorsTest ${EXECUTABLE_OUTPUT_PATH}/StaticVectorOfStaticVectorsTest${CMAKE_EXECUTABLE_SUFFIX} ) -ADD_SUBDIRECTORY( Multimaps ) ADD_SUBDIRECTORY( ndarray ) diff --git a/src/UnitTests/Containers/Multimaps/CMakeLists.txt b/src/UnitTests/Containers/Multimaps/CMakeLists.txt deleted file mode 100644 index 0cf3ae7466..0000000000 --- a/src/UnitTests/Containers/Multimaps/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -ADD_EXECUTABLE( MultimapTest MultimapTest.cpp ) -TARGET_COMPILE_OPTIONS( MultimapTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( MultimapTest ${GTEST_BOTH_LIBRARIES} ) - -ADD_EXECUTABLE( StaticMultimapTest StaticMultimapTest.cpp ) -TARGET_COMPILE_OPTIONS( StaticMultimapTest PRIVATE ${CXX_TESTS_FLAGS} ) -TARGET_LINK_LIBRARIES( StaticMultimapTest ${GTEST_BOTH_LIBRARIES} ) - -ADD_TEST( MultimapTest ${EXECUTABLE_OUTPUT_PATH}/MultimapTest${CMAKE_EXECUTABLE_SUFFIX} ) -ADD_TEST( StaticMultimapTest ${EXECUTABLE_OUTPUT_PATH}/MultimapTest${CMAKE_EXECUTABLE_SUFFIX} ) diff --git a/src/UnitTests/Containers/Multimaps/MultimapTest.cpp b/src/UnitTests/Containers/Multimaps/MultimapTest.cpp deleted file mode 100644 index 0ba26092d3..0000000000 --- a/src/UnitTests/Containers/Multimaps/MultimapTest.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include <TNL/Containers/Multimaps/EllpackIndexMultimap.h> - -using namespace TNL; -using namespace TNL::Containers::Multimaps; - -using IndexType = int; -using Device = Devices::Host; -using LocalIndexType = short; - -static const char* TEST_FILE_NAME = "test_MultimapTest.tnl"; - -#ifdef HAVE_GTEST -#include <gtest/gtest.h> - -TEST( MultimapTest, TestTypedefs ) -{ - using MultimapType = EllpackIndexMultimap< IndexType, Device, LocalIndexType >; - const bool same_index = std::is_same< typename MultimapType::IndexType, IndexType >::value; - ASSERT_TRUE( same_index ); - const bool same_device = std::is_same< typename MultimapType::DeviceType, Device >::value; - ASSERT_TRUE( same_device ); - const bool same_localindex = std::is_same< typename MultimapType::LocalIndexType, LocalIndexType >::value; - ASSERT_TRUE( same_localindex ); -} - -TEST( MultimapTest, TestSettingSizes ) -{ - using MultimapType = EllpackIndexMultimap< IndexType, Device, LocalIndexType >; - - IndexType inputs = 10; - LocalIndexType valuesGlobalMax = 3; - LocalIndexType valuesLocalMax = 2; - - MultimapType map; - map.setKeysRange( inputs ); - ASSERT_EQ( map.getKeysRange(), inputs ); - - typename MultimapType::ValuesAllocationVectorType allocationRanges; - allocationRanges.setSize( inputs ); - allocationRanges.setValue( valuesGlobalMax ); - allocationRanges[ 0 ] = 0; - allocationRanges[ 1 ] = 1; - map.allocate( allocationRanges ); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - const auto constValues = ( (const MultimapType&) map ).getValues( i ); - - // uninitialized should be equal to the value from the allocation vector - ASSERT_EQ( values.getSize(), allocationRanges[ i ] ); - // This does not work with Array deep copy constructor - ASSERT_EQ( constValues.getSize(), allocationRanges[ i ] ); - - // setting lower sizes - values.setSize( valuesLocalMax ); - ASSERT_EQ( values.getSize(), valuesLocalMax ); - // This does not work with Array deep copy constructor - ASSERT_EQ( constValues.getSize(), valuesLocalMax ); - - // setting global max - values.setSize( valuesGlobalMax ); - ASSERT_EQ( values.getSize(), valuesGlobalMax ); - // This does not work with Array deep copy constructor - ASSERT_EQ( constValues.getSize(), valuesGlobalMax ); - } -} - -TEST( MultimapTest, TestSettingValues ) -{ - using MultimapType = EllpackIndexMultimap< IndexType, Device, LocalIndexType >; - - IndexType inputs = 10; - LocalIndexType allocatedValues = 2; - - MultimapType map; - map.setKeysRange( inputs ); - ASSERT_EQ( map.getKeysRange(), inputs ); - - typename MultimapType::ValuesAllocationVectorType allocationRanges; - allocationRanges.setSize( inputs ); - allocationRanges.setValue( allocatedValues ); - map.allocate( allocationRanges ); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - const auto constValues = ( (const MultimapType&) map ).getValues( i ); - - values.setSize( allocatedValues ); - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) - values.setValue( o, i + o ); - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) { - ASSERT_EQ( values.getValue( o ), i + o ); - ASSERT_EQ( values[ o ], i + o ); - ASSERT_EQ( constValues.getValue( o ), i + o ); - ASSERT_EQ( constValues[ o ], i + o ); - } - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) - values[ o ] = i * o; - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) { - ASSERT_EQ( values.getValue( o ), i * o ); - ASSERT_EQ( values[ o ], i * o ); - ASSERT_EQ( constValues.getValue( o ), i * o ); - ASSERT_EQ( constValues[ o ], i * o ); - } - } -} - -TEST( MultimapTest, TestSaveAndLoad ) -{ - using MultimapType = EllpackIndexMultimap< IndexType, Device, LocalIndexType >; - - IndexType inputs = 10; - LocalIndexType allocatedValues = 2; - - MultimapType map, map2; - map.setKeysRange( inputs ); - ASSERT_EQ( map.getKeysRange(), inputs ); - - typename MultimapType::ValuesAllocationVectorType allocationRanges; - allocationRanges.setSize( inputs ); - allocationRanges.setValue( allocatedValues ); - map.allocate( allocationRanges ); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - for( LocalIndexType o = 0; o < allocatedValues; o++ ) - values.setValue( o, i + o ); - } - - map.save( TEST_FILE_NAME ); - map2.load( TEST_FILE_NAME ); - - EXPECT_EQ( map, map2 ); - EXPECT_EQ( map.getKeysRange(), map2.getKeysRange() ); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - auto values2 = map2.getValues( i ); - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) { - ASSERT_EQ( values[ o ], i + o ); - ASSERT_EQ( values2[ o ], i + o ); - } - } - - EXPECT_EQ( std::remove( TEST_FILE_NAME ), 0 ); -} -#endif - -#include "../../main.h" diff --git a/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp b/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp deleted file mode 100644 index 86d5c0cb4b..0000000000 --- a/src/UnitTests/Containers/Multimaps/StaticMultimapTest.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include <TNL/Containers/Multimaps/StaticEllpackIndexMultimap.h> - -using namespace TNL; -using namespace TNL::Containers::Multimaps; - -using IndexType = int; -using Device = Devices::Host; -using LocalIndexType = short; - -static const char* TEST_FILE_NAME = "test_StaticMultimapTest.tnl"; - -#ifdef HAVE_GTEST -#include <gtest/gtest.h> - -TEST( MultimapTest, TestTypedefs ) -{ - using MultimapType = StaticEllpackIndexMultimap< 4, IndexType, Device, LocalIndexType >; - const bool same_index = std::is_same< typename MultimapType::IndexType, IndexType >::value; - ASSERT_TRUE( same_index ); - const bool same_device = std::is_same< typename MultimapType::DeviceType, Device >::value; - ASSERT_TRUE( same_device ); - const bool same_localindex = std::is_same< typename MultimapType::LocalIndexType, LocalIndexType >::value; - ASSERT_TRUE( same_localindex ); -} - -TEST( MultimapTest, TestSettingValues ) -{ - using MultimapType = StaticEllpackIndexMultimap< 4, IndexType, Device, LocalIndexType >; - - const IndexType inputs = 10; - const LocalIndexType allocatedValues = 4; - - MultimapType map; - map.setKeysRange( inputs ); - ASSERT_EQ( map.getKeysRange(), inputs ); - map.allocate(); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - const auto constValues = ( (const MultimapType) map ).getValues( i ); - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) - values.setValue( o, i + o ); - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) { - ASSERT_EQ( values.getValue( o ), i + o ); - ASSERT_EQ( values[ o ], i + o ); - ASSERT_EQ( constValues.getValue( o ), i + o ); - ASSERT_EQ( constValues[ o ], i + o ); - } - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) - values[ o ] = i * o; - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) { - ASSERT_EQ( values.getValue( o ), i * o ); - ASSERT_EQ( values[ o ], i * o ); - ASSERT_EQ( constValues.getValue( o ), i * o ); - ASSERT_EQ( constValues[ o ], i * o ); - } - } -} - -TEST( MultimapTest, TestSaveAndLoad ) -{ - using MultimapType = StaticEllpackIndexMultimap< 4, IndexType, Device, LocalIndexType >; - - const IndexType inputs = 10; - const LocalIndexType allocatedValues = 4; - - MultimapType map, map2; - map.setKeysRange( inputs ); - ASSERT_EQ( map.getKeysRange(), inputs ); - map.allocate(); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - for( LocalIndexType o = 0; o < allocatedValues; o++ ) - values.setValue( o, i + o ); - } - - map.save( TEST_FILE_NAME ); - map2.load( TEST_FILE_NAME ); - - EXPECT_EQ( map, map2 ); - EXPECT_EQ( map.getKeysRange(), map2.getKeysRange() ); - - for( IndexType i = 0; i < inputs; i++ ) { - auto values = map.getValues( i ); - auto values2 = map2.getValues( i ); - - for( LocalIndexType o = 0; o < allocatedValues; o++ ) { - ASSERT_EQ( values[ o ], i + o ); - ASSERT_EQ( values2[ o ], i + o ); - } - } - - EXPECT_EQ( std::remove( TEST_FILE_NAME ), 0 ); -} -#endif - -#include "../../main.h" -- GitLab