Loading src/Examples/Containers/ArrayExample.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -22,19 +22,23 @@ void arrayExample() */ for( int i = 0; i< size; i++ ) a1.setElement( i, i ); std::cout << "a1 = " << a1 << std::endl; /*** * You may also assign value to all array elements ... */ a2 = 0.0; std::cout << "a2 = " << a2 << std::endl; /*** * ... or assign STL list and vector. */ std::list< float > l = { 1.0, 2.0, 3.0 }; std::vector< float > v = { 5.0, 6.0, 7.0 }; a1 = v; a1 = l; std::cout << "a1 = " << a1 << std::endl; a1 = v; std::cout << "a1 = " << a1 << std::endl; /*** * Simple array values checks can be done as follows ... Loading src/TNL/Containers/Algorithms/ArrayAssignment.h +2 −2 Original line number Diff line number Diff line Loading @@ -74,10 +74,10 @@ struct ArrayAssignment< Array, T, false > { static void resize( Array& a, const T& t ) { TNL_ASSERT_TRUE( !a.empty(), "Cannot assign value to empty array." ); }; static void assign( Array& a, const T& t ) { TNL_ASSERT_FALSE( a.empty(), "Cannot assign value to empty array." ); ArrayOperations< typename Array::DeviceType >::template setMemory< typename Array::ValueType, typename Array::IndexType > ( a.getArrayData(), ( typename Array::ValueType ) t, a.getSize() ); Loading src/TNL/Containers/Array.hpp +5 −4 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ Array( const std::initializer_list< InValue >& list ) // Here we assume that the underlying array for initializer_list is const T[N] // as noted here: // https://en.cppreference.com/w/cpp/utility/initializer_list Algorithms::ArrayOperations< Device >::copyMemory( this->getData(), &( *list.begin() ), list.size() ); Algorithms::ArrayOperations< Device, Devices::Host >::copyMemory( this->getData(), &( *list.begin() ), list.size() ); } template< typename Value, Loading Loading @@ -172,7 +172,7 @@ Array( const std::vector< InValue >& vector ) referenceCounter( 0 ) { this->setSize( vector.size() ); Algorithms::ArrayOperations< Device >::copyMemory( this->getData(), vector.data(), vector.size() ); Algorithms::ArrayOperations< Device, Devices::Host >::copyMemory( this->getData(), vector.data(), vector.size() ); } template< typename Value, Loading Loading @@ -622,10 +622,11 @@ template< typename Value, typename Device, typename Index > bool __cuda_callable__ Array< Value, Device, Index >:: empty() const { return data; return ( data == nullptr ); } template< typename Value, Loading src/TNL/Containers/ArrayView.h +12 −12 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ template< int Size, typename Value > class StaticArray; /** * \brief ArrayView serves for accessing array of data allocated by TNL::Array or * \brief ArrayView serves for managing array of data allocated by TNL::Array or * another way. It makes no data deallocation at the end of its life cycle. Compared * to TNL Array, it is lighter data structure and therefore it is more efficient * especially when it is being passed on GPU. The ArrayView can also be created Loading @@ -39,17 +39,17 @@ class StaticArray; * In the \e Device type, the Array remembers where the memory is allocated. * This ensures the compile-time checks of correct pointers manipulation. * Methods defined as \ref __cuda_callable__ can be called even from kernels * running on device. Array elements can be changed either using the \ref operator[] * which is more efficient but it can be called from CPU only for arrays * allocated on host (CPU). If the array is allocated on GPU, the operator[] * can be called only from kernels running on the device (GPU). On the other * hand, methods \ref setElement and \ref getElement, can be called only from the * host (CPU) does not matter if the array resides on the host or the device. * In the latter case, explicit data transfer between host and device (via PCI * express or NVlink in more lucky systems) is invoked and so it can be very * slow. In not time critical parts of code, this is not an issue, however. * Another way to change data being accessed by the ArrayView is \ref evaluate which evaluates * given lambda function. This is performed at the same place where the array is * running on device. Array elements can be changed either using the \ref operator[]. * This can be called from CPU only for arrays allocated on host (CPU). If the * array is allocated on GPU, the operator[] can be called only from kernels * running on the device (GPU). On the other hand, methods \ref setElement and * \ref getElement, can be called only from the host (CPU) does not matter if * the array resides on the host or the device. In the latter case, explicit data * transfer between host and device (via PCI express or NVlink in more lucky * systems) is invoked and so it can be very slow. In not time critical parts * of code, this is not an issue, however. Another way to change data being * accessed by the ArrayView is \ref evaluate which evaluates given lambda * function. This is performed at the same place where the array is * allocated i.e. it is efficient even on GPU. For simple checking of the array * contents, one may use methods \ref containValue and \ref containsValue and * \ref containsOnlyValue. Loading src/TNL/Containers/ArrayView.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -364,7 +364,7 @@ bool ArrayView< Value, Device, Index >:: empty() const { return data; return ( data == nullptr ); } template< typename Value, Loading Loading
src/Examples/Containers/ArrayExample.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -22,19 +22,23 @@ void arrayExample() */ for( int i = 0; i< size; i++ ) a1.setElement( i, i ); std::cout << "a1 = " << a1 << std::endl; /*** * You may also assign value to all array elements ... */ a2 = 0.0; std::cout << "a2 = " << a2 << std::endl; /*** * ... or assign STL list and vector. */ std::list< float > l = { 1.0, 2.0, 3.0 }; std::vector< float > v = { 5.0, 6.0, 7.0 }; a1 = v; a1 = l; std::cout << "a1 = " << a1 << std::endl; a1 = v; std::cout << "a1 = " << a1 << std::endl; /*** * Simple array values checks can be done as follows ... Loading
src/TNL/Containers/Algorithms/ArrayAssignment.h +2 −2 Original line number Diff line number Diff line Loading @@ -74,10 +74,10 @@ struct ArrayAssignment< Array, T, false > { static void resize( Array& a, const T& t ) { TNL_ASSERT_TRUE( !a.empty(), "Cannot assign value to empty array." ); }; static void assign( Array& a, const T& t ) { TNL_ASSERT_FALSE( a.empty(), "Cannot assign value to empty array." ); ArrayOperations< typename Array::DeviceType >::template setMemory< typename Array::ValueType, typename Array::IndexType > ( a.getArrayData(), ( typename Array::ValueType ) t, a.getSize() ); Loading
src/TNL/Containers/Array.hpp +5 −4 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ Array( const std::initializer_list< InValue >& list ) // Here we assume that the underlying array for initializer_list is const T[N] // as noted here: // https://en.cppreference.com/w/cpp/utility/initializer_list Algorithms::ArrayOperations< Device >::copyMemory( this->getData(), &( *list.begin() ), list.size() ); Algorithms::ArrayOperations< Device, Devices::Host >::copyMemory( this->getData(), &( *list.begin() ), list.size() ); } template< typename Value, Loading Loading @@ -172,7 +172,7 @@ Array( const std::vector< InValue >& vector ) referenceCounter( 0 ) { this->setSize( vector.size() ); Algorithms::ArrayOperations< Device >::copyMemory( this->getData(), vector.data(), vector.size() ); Algorithms::ArrayOperations< Device, Devices::Host >::copyMemory( this->getData(), vector.data(), vector.size() ); } template< typename Value, Loading Loading @@ -622,10 +622,11 @@ template< typename Value, typename Device, typename Index > bool __cuda_callable__ Array< Value, Device, Index >:: empty() const { return data; return ( data == nullptr ); } template< typename Value, Loading
src/TNL/Containers/ArrayView.h +12 −12 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ template< int Size, typename Value > class StaticArray; /** * \brief ArrayView serves for accessing array of data allocated by TNL::Array or * \brief ArrayView serves for managing array of data allocated by TNL::Array or * another way. It makes no data deallocation at the end of its life cycle. Compared * to TNL Array, it is lighter data structure and therefore it is more efficient * especially when it is being passed on GPU. The ArrayView can also be created Loading @@ -39,17 +39,17 @@ class StaticArray; * In the \e Device type, the Array remembers where the memory is allocated. * This ensures the compile-time checks of correct pointers manipulation. * Methods defined as \ref __cuda_callable__ can be called even from kernels * running on device. Array elements can be changed either using the \ref operator[] * which is more efficient but it can be called from CPU only for arrays * allocated on host (CPU). If the array is allocated on GPU, the operator[] * can be called only from kernels running on the device (GPU). On the other * hand, methods \ref setElement and \ref getElement, can be called only from the * host (CPU) does not matter if the array resides on the host or the device. * In the latter case, explicit data transfer between host and device (via PCI * express or NVlink in more lucky systems) is invoked and so it can be very * slow. In not time critical parts of code, this is not an issue, however. * Another way to change data being accessed by the ArrayView is \ref evaluate which evaluates * given lambda function. This is performed at the same place where the array is * running on device. Array elements can be changed either using the \ref operator[]. * This can be called from CPU only for arrays allocated on host (CPU). If the * array is allocated on GPU, the operator[] can be called only from kernels * running on the device (GPU). On the other hand, methods \ref setElement and * \ref getElement, can be called only from the host (CPU) does not matter if * the array resides on the host or the device. In the latter case, explicit data * transfer between host and device (via PCI express or NVlink in more lucky * systems) is invoked and so it can be very slow. In not time critical parts * of code, this is not an issue, however. Another way to change data being * accessed by the ArrayView is \ref evaluate which evaluates given lambda * function. This is performed at the same place where the array is * allocated i.e. it is efficient even on GPU. For simple checking of the array * contents, one may use methods \ref containValue and \ref containsValue and * \ref containsOnlyValue. Loading
src/TNL/Containers/ArrayView.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -364,7 +364,7 @@ bool ArrayView< Value, Device, Index >:: empty() const { return data; return ( data == nullptr ); } template< typename Value, Loading