Commit dbfa5d11 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Serialization in TNL::File: File::save and File::load are specialized by...

Serialization in TNL::File: File::save and File::load are specialized by Allocator instead of Device
parent 399f9627
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ int main()
    */
   File file;
   file.open( "file-example-cuda-test-file.tnl", std::ios_base::out | std::ios_base::trunc );
   file.save< double, double, Devices::Host >( doubleArray, size );
   file.save< double, double, Allocators::Host< double > >( doubleArray, size );
   file.close();

   /***
@@ -31,7 +31,7 @@ int main()
    * Read array from the file to device
    */
   file.open( "file-example-cuda-test-file.tnl", std::ios_base::in );
   file.load< double, double, Devices::Cuda >( deviceArray, size );
   file.load< double, double, Allocators::Cuda< double > >( deviceArray, size );
   file.close();

   /***
+3 −3
Original line number Diff line number Diff line
@@ -18,21 +18,21 @@ int main()
    */
   File file;
   file.open( "test-file.tnl", std::ios_base::out | std::ios_base::trunc );
   file.save< double, float, Devices::Host >( doubleArray, size );
   file.save< double, float >( doubleArray, size );
   file.close();

   /***
    * Load the array of floats from the file.
    */
   file.open( "test-file.tnl", std::ios_base::in );
   file.load< float, float, Devices::Host >( floatArray, size );
   file.load< float, float >( floatArray, size );
   file.close();

   /***
    * Load the array of floats from the file and convert them to integers.
    */
   file.open( "test-file.tnl", std::ios_base::in );
   file.load< int, float, Devices::Host >( intArray, size );
   file.load< int, float >( intArray, size );
   file.close();

   /***
+2 −2
Original line number Diff line number Diff line
@@ -228,13 +228,13 @@ class Array

      /**
       * \brief Returns a \ref String representation of the array type in C++ style,
       * where device is always \ref Devices::Host.
       * with a placeholder in place of \e Device and \e Allocator.
       */
      static String getSerializationType();

      /**
       * \brief Returns a \ref String representation of the array type in C++ style,
       * where device is always \ref Devices::Host.
       * with a placeholder in place of \e Device and \e Allocator.
       */
      virtual String getSerializationTypeVirtual() const;

+2 −2
Original line number Diff line number Diff line
@@ -759,7 +759,7 @@ std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index,
template< typename Value, typename Device, typename Index, typename Allocator >
File& operator<<( File& file, const Array< Value, Device, Index, Allocator >& array )
{
   using IO = detail::ArrayIO< Value, Device, Index >;
   using IO = detail::ArrayIO< Value, Index, Allocator >;
   saveObjectType( file, IO::getSerializationType() );
   const Index size = array.getSize();
   file.save( &size );
@@ -778,7 +778,7 @@ File& operator<<( File&& file, const Array< Value, Device, Index, Allocator >& a
template< typename Value, typename Device, typename Index, typename Allocator >
File& operator>>( File& file, Array< Value, Device, Index, Allocator >& array )
{
   using IO = detail::ArrayIO< Value, Device, Index >;
   using IO = detail::ArrayIO< Value, Index, Allocator >;
   const String type = getObjectType( file );
   if( type != IO::getSerializationType() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + IO::getSerializationType() + ", found " + type + ")." );
+3 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <TNL/Algorithms/MultiDeviceMemoryOperations.h>
#include <TNL/Containers/detail/ArrayIO.h>
#include <TNL/Containers/detail/ArrayAssignment.h>
#include <TNL/Allocators/Default.h>

#include "ArrayView.h"

@@ -383,7 +384,7 @@ load( const String& fileName )
template< typename Value, typename Device, typename Index >
File& operator<<( File& file, const ArrayView< Value, Device, Index > view )
{
   using IO = detail::ArrayIO< Value, Device, Index >;
   using IO = detail::ArrayIO< Value, Index, typename Allocators::Default< Device >::template Allocator< Value > >;
   saveObjectType( file, IO::getSerializationType() );
   const Index size = view.getSize();
   file.save( &size );
@@ -402,7 +403,7 @@ File& operator<<( File&& file, const ArrayView< Value, Device, Index > view )
template< typename Value, typename Device, typename Index >
File& operator>>( File& file, ArrayView< Value, Device, Index > view )
{
   using IO = detail::ArrayIO< Value, Device, Index >;
   using IO = detail::ArrayIO< Value, Index, typename Allocators::Default< Device >::template Allocator< Value > >;
   const String type = getObjectType( file );
   if( type != IO::getSerializationType() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + IO::getSerializationType() + ", found " + type + ")." );
Loading