Loading src/TNL/DevicePointer.h +16 −8 Original line number Diff line number Diff line Loading @@ -215,14 +215,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer : pointer( 0 ), cuda_pointer( 0 ), counter( 0 ), last_sync_state( 0 ) { this->counter = new int( 1 ); this->pointer = &obj; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); this->allocate( obj ); } // this is needed only to avoid the default compiler-generated constructor Loading Loading @@ -416,6 +409,21 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer protected: bool allocate( ObjectType& obj ) { this->counter = new int( 1 ); if( ! this->counter ) return false; this->pointer = &obj; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; } void set_last_sync_state() { std::memcpy( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ); Loading src/TNL/SharedPointer.h +25 −37 Original line number Diff line number Diff line Loading @@ -314,19 +314,7 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer counter( 0 ), last_sync_state( 0 ) { if( ! lazy ) { this->counter = new int( 1 ); this->pointer = new Object( args... ); this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); #ifdef TNL_DEBUG_SHARED_POINTERS std::cerr << "Created shared pointer to " << demangle(typeid(ObjectType).name()) << " (cuda_pointer = " << this->cuda_pointer << ")" << std::endl; #endif Devices::Cuda::insertSmartPointer( this ); } this->allocate( args... ); } // this is needed only to avoid the default compiler-generated constructor Loading Loading @@ -386,17 +374,8 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer std::cerr << "Recreating shared pointer to " << demangle(typeid(ObjectType).name()) << std::endl; #endif if( ! this->counter ) { this->counter = new int( 1 ); this->pointer = new ObjectType( args... ); this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; } return this->allocate( args... ); if( *this->counter == 1 ) { /**** Loading @@ -414,17 +393,7 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer // free will just decrement the counter this->free(); this->counter= new int( 1 ); this->pointer = new Object( args... ); if( ! this->pointer || ! this->counter ) return false; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; return this->allocate( args... ); } const Object* operator->() const Loading Loading @@ -584,14 +553,33 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer protected: template< typename... Args > bool allocate( Args... args ) { this->counter = new int( 1 ); this->pointer = new Object( args... ); if( ! this->pointer || ! this->counter ) return false; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); #ifdef TNL_DEBUG_SHARED_POINTERS std::cerr << "Created shared pointer to " << demangle(typeid(ObjectType).name()) << " (cuda_pointer = " << this->cuda_pointer << ")" << std::endl; #endif Devices::Cuda::insertSmartPointer( this ); return true; } void set_last_sync_state() { std::memcpy( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ); std::memcpy( (void*) (this->pointer + 1), (void*) this->pointer, sizeof( ObjectType ) ); } bool modified() { return std::memcmp( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ) != 0; return std::memcmp( (void*) (this->pointer + 1), (void*) this->pointer, sizeof( ObjectType ) ) != 0; } void free() Loading src/TNL/UniquePointer.h +28 −15 Original line number Diff line number Diff line Loading @@ -128,11 +128,7 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer : pointer( 0 ), cuda_pointer( 0 ), last_sync_state( 0 ) { this->pointer = new Object( args... ); this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); this->allocate( args... ); } const Object* operator->() const Loading Loading @@ -186,10 +182,7 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer const ThisType& operator=( ThisType& ptr ) { if( this->pointer ) delete this->pointer; if( this->cuda_pointer ) Devices::Cuda::freeFromDevice( this->cuda_pointer ); this->free(); this->pointer = ptr.pointer; this->cuda_pointer = ptr.cuda_pointer; this->last_sync_state = ptr.last_sync_state; Loading Loading @@ -223,17 +216,27 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer ~UniquePointer() { if( this->pointer ) delete this->pointer; if( this->cuda_pointer ) Devices::Cuda::freeFromDevice( this->cuda_pointer ); if( this->last_sync_state ) ::operator delete( this->last_sync_state ); this->free(); Devices::Cuda::removeSmartPointer( this ); } protected: template< typename... Args > bool allocate( Args... args ) { this->pointer = new Object( args... ); if( ! this->pointer ) return false; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; } void set_last_sync_state() { std::memcpy( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ); Loading @@ -244,6 +247,16 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer return std::memcmp( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ) != 0; } void free() { if( this->pointer ) delete this->pointer; if( this->cuda_pointer ) Devices::Cuda::freeFromDevice( this->cuda_pointer ); if( this->last_sync_state ) ::operator delete( this->last_sync_state ); } Object *pointer, *cuda_pointer; void* last_sync_state; Loading Loading
src/TNL/DevicePointer.h +16 −8 Original line number Diff line number Diff line Loading @@ -215,14 +215,7 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer : pointer( 0 ), cuda_pointer( 0 ), counter( 0 ), last_sync_state( 0 ) { this->counter = new int( 1 ); this->pointer = &obj; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); this->allocate( obj ); } // this is needed only to avoid the default compiler-generated constructor Loading Loading @@ -416,6 +409,21 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer protected: bool allocate( ObjectType& obj ) { this->counter = new int( 1 ); if( ! this->counter ) return false; this->pointer = &obj; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; } void set_last_sync_state() { std::memcpy( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ); Loading
src/TNL/SharedPointer.h +25 −37 Original line number Diff line number Diff line Loading @@ -314,19 +314,7 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer counter( 0 ), last_sync_state( 0 ) { if( ! lazy ) { this->counter = new int( 1 ); this->pointer = new Object( args... ); this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); #ifdef TNL_DEBUG_SHARED_POINTERS std::cerr << "Created shared pointer to " << demangle(typeid(ObjectType).name()) << " (cuda_pointer = " << this->cuda_pointer << ")" << std::endl; #endif Devices::Cuda::insertSmartPointer( this ); } this->allocate( args... ); } // this is needed only to avoid the default compiler-generated constructor Loading Loading @@ -386,17 +374,8 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer std::cerr << "Recreating shared pointer to " << demangle(typeid(ObjectType).name()) << std::endl; #endif if( ! this->counter ) { this->counter = new int( 1 ); this->pointer = new ObjectType( args... ); this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; } return this->allocate( args... ); if( *this->counter == 1 ) { /**** Loading @@ -414,17 +393,7 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer // free will just decrement the counter this->free(); this->counter= new int( 1 ); this->pointer = new Object( args... ); if( ! this->pointer || ! this->counter ) return false; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; return this->allocate( args... ); } const Object* operator->() const Loading Loading @@ -584,14 +553,33 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer protected: template< typename... Args > bool allocate( Args... args ) { this->counter = new int( 1 ); this->pointer = new Object( args... ); if( ! this->pointer || ! this->counter ) return false; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); #ifdef TNL_DEBUG_SHARED_POINTERS std::cerr << "Created shared pointer to " << demangle(typeid(ObjectType).name()) << " (cuda_pointer = " << this->cuda_pointer << ")" << std::endl; #endif Devices::Cuda::insertSmartPointer( this ); return true; } void set_last_sync_state() { std::memcpy( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ); std::memcpy( (void*) (this->pointer + 1), (void*) this->pointer, sizeof( ObjectType ) ); } bool modified() { return std::memcmp( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ) != 0; return std::memcmp( (void*) (this->pointer + 1), (void*) this->pointer, sizeof( ObjectType ) ) != 0; } void free() Loading
src/TNL/UniquePointer.h +28 −15 Original line number Diff line number Diff line Loading @@ -128,11 +128,7 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer : pointer( 0 ), cuda_pointer( 0 ), last_sync_state( 0 ) { this->pointer = new Object( args... ); this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); this->allocate( args... ); } const Object* operator->() const Loading Loading @@ -186,10 +182,7 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer const ThisType& operator=( ThisType& ptr ) { if( this->pointer ) delete this->pointer; if( this->cuda_pointer ) Devices::Cuda::freeFromDevice( this->cuda_pointer ); this->free(); this->pointer = ptr.pointer; this->cuda_pointer = ptr.cuda_pointer; this->last_sync_state = ptr.last_sync_state; Loading Loading @@ -223,17 +216,27 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer ~UniquePointer() { if( this->pointer ) delete this->pointer; if( this->cuda_pointer ) Devices::Cuda::freeFromDevice( this->cuda_pointer ); if( this->last_sync_state ) ::operator delete( this->last_sync_state ); this->free(); Devices::Cuda::removeSmartPointer( this ); } protected: template< typename... Args > bool allocate( Args... args ) { this->pointer = new Object( args... ); if( ! this->pointer ) return false; this->cuda_pointer = Devices::Cuda::passToDevice( *this->pointer ); if( ! this->cuda_pointer ) return false; this->last_sync_state = ::operator new( sizeof( Object ) ); this->set_last_sync_state(); Devices::Cuda::insertSmartPointer( this ); return true; } void set_last_sync_state() { std::memcpy( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ); Loading @@ -244,6 +247,16 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer return std::memcmp( (void*) this->last_sync_state, (void*) this->pointer, sizeof( ObjectType ) ) != 0; } void free() { if( this->pointer ) delete this->pointer; if( this->cuda_pointer ) Devices::Cuda::freeFromDevice( this->cuda_pointer ); if( this->last_sync_state ) ::operator delete( this->last_sync_state ); } Object *pointer, *cuda_pointer; void* last_sync_state; Loading