Loading src/TNL/Containers/Algorithms/ArrayAssignment.h +37 −16 Original line number Diff line number Diff line Loading @@ -16,42 +16,63 @@ namespace TNL { namespace Containers { namespace Algorithms { namespace Details { /** * \brief Specialization for array-array assignment * SFINAE for checking if T has getArrayData method */ template< typename T > class HasGetArrayData { private: typedef char YesType[1]; typedef char NoType[2]; template< typename C > static YesType& test( decltype(&C::getArrayData) ) ; template< typename C > static NoType& test(...); public: enum { value = sizeof( test< T >(0) ) == sizeof( YesType ) }; }; } // namespace Details template< typename Array, typename T, bool hasGetArrayData = Details::HasGetArrayData< T >::value > struct ArrayAssignment{}; /** * \brief Specialization for array-array assignment with containers implementing * getArrayData method. */ template< typename Array, typename T > struct ArrayAssignment struct ArrayAssignment< Array, T, true > { static void assign( Array& a, const T& t, const typename T::ValueType* ) static void assign( Array& a, const T& t ) { /*a.setSize( t.getSize() ); ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template copyMemory< typename Array::ValueType, typename T::ValueType, typename T::IndexType > ( a.getData(), t.getData(), t.getSize() );*/ }; static void assign( Array& a, const T& t, const void* ) { copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > ( a.getArrayData(), t.getArrayData(), t.getSize() ); }; }; /** * \brief Specialization for array-value assignment * \brief Specialization for array-value assignment for other types. We assume * thet T is convertible to Array::ValueType. */ /*template< typename Array, template< typename Array, typename T > struct ArrayAssignment< Array, T, void > struct ArrayAssignment< Array, T, false > { static void assign( Array& a, const T& t ) { ArrayOperations< typename Array::DeviceType >::template setMemory< typename Array::ValueType, typename Array::IndexType > ( a.getData(), ( typename Array::ValueType ) t, t.getSize() ); ( a.getArrayData(), ( typename Array::ValueType ) t, a.getSize() ); }; }; };*/ } // namespace Algorithms Loading src/TNL/Containers/Array.h +25 −0 Original line number Diff line number Diff line Loading @@ -292,6 +292,31 @@ class Array : public Object */ __cuda_callable__ Value* getData(); /** * \brief Data pointer getter for constant instances. * * Use this method in algorithms where you want to emphasize that * C-style array pointer is required. * * This method can be called from device kernels. * * \return Pointer to array data. */ __cuda_callable__ const Value* getArrayData() const; /** * \brief Data pointer getter. * * Use this method in algorithms where you want to emphasize that * C-style array pointer is required. * * This method can be called from device kernels. * * \return Pointer to array data. */ __cuda_callable__ Value* getArrayData(); /** * \brief Array elements setter - change value of an element at position \e i. * Loading src/TNL/Containers/Array.hpp +18 −0 Original line number Diff line number Diff line Loading @@ -399,6 +399,24 @@ Value* Array< Value, Device, Index >::getData() return this->data; } template< typename Value, typename Device, typename Index > __cuda_callable__ const Value* Array< Value, Device, Index >::getArrayData() const { return this->data; } template< typename Value, typename Device, typename Index > __cuda_callable__ Value* Array< Value, Device, Index >::getArrayData() { return this->data; } template< typename Value, typename Device, typename Index > Loading src/TNL/Containers/ArrayView.h +6 −2 Original line number Diff line number Diff line Loading @@ -97,10 +97,8 @@ public: template< typename Array > ArrayView& operator=( const Array& array ); static String getType(); __cuda_callable__ void swap( ArrayView& view ); Loading @@ -113,6 +111,12 @@ public: __cuda_callable__ Value* getData(); __cuda_callable__ const Value* getArrayData() const; __cuda_callable__ Value* getArrayData(); __cuda_callable__ Index getSize() const; Loading src/TNL/Containers/ArrayView_impl.h +22 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,28 @@ getData() return data; } template< typename Value, typename Device, typename Index > __cuda_callable__ const Value* ArrayView< Value, Device, Index >:: getArrayData() const { return data; } template< typename Value, typename Device, typename Index > __cuda_callable__ Value* ArrayView< Value, Device, Index >:: getArrayData() { return data; } template< typename Value, typename Device, typename Index > Loading Loading
src/TNL/Containers/Algorithms/ArrayAssignment.h +37 −16 Original line number Diff line number Diff line Loading @@ -16,42 +16,63 @@ namespace TNL { namespace Containers { namespace Algorithms { namespace Details { /** * \brief Specialization for array-array assignment * SFINAE for checking if T has getArrayData method */ template< typename T > class HasGetArrayData { private: typedef char YesType[1]; typedef char NoType[2]; template< typename C > static YesType& test( decltype(&C::getArrayData) ) ; template< typename C > static NoType& test(...); public: enum { value = sizeof( test< T >(0) ) == sizeof( YesType ) }; }; } // namespace Details template< typename Array, typename T, bool hasGetArrayData = Details::HasGetArrayData< T >::value > struct ArrayAssignment{}; /** * \brief Specialization for array-array assignment with containers implementing * getArrayData method. */ template< typename Array, typename T > struct ArrayAssignment struct ArrayAssignment< Array, T, true > { static void assign( Array& a, const T& t, const typename T::ValueType* ) static void assign( Array& a, const T& t ) { /*a.setSize( t.getSize() ); ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template copyMemory< typename Array::ValueType, typename T::ValueType, typename T::IndexType > ( a.getData(), t.getData(), t.getSize() );*/ }; static void assign( Array& a, const T& t, const void* ) { copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > ( a.getArrayData(), t.getArrayData(), t.getSize() ); }; }; /** * \brief Specialization for array-value assignment * \brief Specialization for array-value assignment for other types. We assume * thet T is convertible to Array::ValueType. */ /*template< typename Array, template< typename Array, typename T > struct ArrayAssignment< Array, T, void > struct ArrayAssignment< Array, T, false > { static void assign( Array& a, const T& t ) { ArrayOperations< typename Array::DeviceType >::template setMemory< typename Array::ValueType, typename Array::IndexType > ( a.getData(), ( typename Array::ValueType ) t, t.getSize() ); ( a.getArrayData(), ( typename Array::ValueType ) t, a.getSize() ); }; }; };*/ } // namespace Algorithms Loading
src/TNL/Containers/Array.h +25 −0 Original line number Diff line number Diff line Loading @@ -292,6 +292,31 @@ class Array : public Object */ __cuda_callable__ Value* getData(); /** * \brief Data pointer getter for constant instances. * * Use this method in algorithms where you want to emphasize that * C-style array pointer is required. * * This method can be called from device kernels. * * \return Pointer to array data. */ __cuda_callable__ const Value* getArrayData() const; /** * \brief Data pointer getter. * * Use this method in algorithms where you want to emphasize that * C-style array pointer is required. * * This method can be called from device kernels. * * \return Pointer to array data. */ __cuda_callable__ Value* getArrayData(); /** * \brief Array elements setter - change value of an element at position \e i. * Loading
src/TNL/Containers/Array.hpp +18 −0 Original line number Diff line number Diff line Loading @@ -399,6 +399,24 @@ Value* Array< Value, Device, Index >::getData() return this->data; } template< typename Value, typename Device, typename Index > __cuda_callable__ const Value* Array< Value, Device, Index >::getArrayData() const { return this->data; } template< typename Value, typename Device, typename Index > __cuda_callable__ Value* Array< Value, Device, Index >::getArrayData() { return this->data; } template< typename Value, typename Device, typename Index > Loading
src/TNL/Containers/ArrayView.h +6 −2 Original line number Diff line number Diff line Loading @@ -97,10 +97,8 @@ public: template< typename Array > ArrayView& operator=( const Array& array ); static String getType(); __cuda_callable__ void swap( ArrayView& view ); Loading @@ -113,6 +111,12 @@ public: __cuda_callable__ Value* getData(); __cuda_callable__ const Value* getArrayData() const; __cuda_callable__ Value* getArrayData(); __cuda_callable__ Index getSize() const; Loading
src/TNL/Containers/ArrayView_impl.h +22 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,28 @@ getData() return data; } template< typename Value, typename Device, typename Index > __cuda_callable__ const Value* ArrayView< Value, Device, Index >:: getArrayData() const { return data; } template< typename Value, typename Device, typename Index > __cuda_callable__ Value* ArrayView< Value, Device, Index >:: getArrayData() { return data; } template< typename Value, typename Device, typename Index > Loading