Loading src/Examples/CMakeLists.txt +4 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ ADD_EXECUTABLE( ListExample ListExample.cpp ) ADD_EXECUTABLE( LoggerExample LoggerExample.cpp ) ADD_EXECUTABLE( MathExample MathExample.cpp ) ADD_EXECUTABLE( ObjectExample_getType ObjectExample_getType.cpp ) ADD_CUSTOM_COMMAND( COMMAND ObjectExample_getType > ObjectExample_getType.out OUTPUT ObjectExample_getType.out ) ADD_EXECUTABLE( ParameterContainerExample ParameterContainerExample.cpp ) ADD_EXECUTABLE( StringExample StringExample.cpp ) Loading Loading @@ -55,6 +58,7 @@ ADD_CUSTOM_COMMAND( COMMAND TimerExampleLogger > TimerExampleLogger.out OUTPUT T ADD_EXECUTABLE( VectorExample VectorExample.cpp ) ADD_CUSTOM_TARGET( run ALL DEPENDS ObjectExample_getType.out StringExample.out StringExampleGetAllocatedSize.out StringExampleReplace.out Loading src/Examples/ObjectExample_getType.cpp 0 → 100644 +63 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/param-types.h> #include <TNL/Object.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> using namespace TNL; using namespace std; template< typename Value, typename Device > class MyArray : public Object { public: using HostType = MyArray< Value, Devices::Host >; static String getType() { return "MyArray< " + TNL::getType< Value >() + ", " + TNL::getType< Device >() + " >"; } String getTypeVirtual() const { return getType(); } static String getSerializationType() { return HostType::getType(); } String getSerializationTypeVirtual() const { return getSerializationType(); } }; int main() { using HostArray = MyArray< int, Devices::Host >; using CudaArray = MyArray< int, Devices::Cuda >; HostArray hostArray; CudaArray cudaArray; Object* hostArrayPtr = &hostArray; Object* cudaArrayPtr = &cudaArray; // Object types cout << "HostArray type is " << HostArray::getType() << endl; cout << "hostArrayPtr type is " << hostArrayPtr->getTypeVirtual() << endl; cout << "CudaArray type is " << CudaArray::getType() << endl; cout << "cudaArrayPtr type is " << cudaArrayPtr->getTypeVirtual() << endl; // Object serialization types cout << "HostArray serialization type is " << HostArray::getSerializationType() << endl; cout << "hostArrayPtr serialization type is " << hostArrayPtr->getSerializationTypeVirtual() << endl; cout << "CudaArray serialization type is " << CudaArray::getSerializationType() << endl; cout << "cudaArrayPtr serialization type is " << cudaArrayPtr->getSerializationTypeVirtual() << endl; } src/TNL/Devices/Cuda.h +3 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ class Cuda static inline String getDeviceType(); // TODO: Remove getDeviceType(); static inline String getType() { return getDeviceType();}; static inline void configSetup( Config::ConfigDescription& config, const String& prefix = "" ); static inline bool setup( const Config::ParameterContainer& parameters, Loading src/TNL/Devices/Cuda_impl.h +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ namespace Devices { inline String Cuda::getDeviceType() { return String( "Cuda" ); return String( "Devices::Cuda" ); } inline void Loading src/TNL/Devices/Host.h +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ public: return String( "Devices::Host" ); } // TODO: Remove getDeviceType(); static inline String getType() { return getDeviceType();}; static void disableOMP() { ompEnabled = false; Loading Loading
src/Examples/CMakeLists.txt +4 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ ADD_EXECUTABLE( ListExample ListExample.cpp ) ADD_EXECUTABLE( LoggerExample LoggerExample.cpp ) ADD_EXECUTABLE( MathExample MathExample.cpp ) ADD_EXECUTABLE( ObjectExample_getType ObjectExample_getType.cpp ) ADD_CUSTOM_COMMAND( COMMAND ObjectExample_getType > ObjectExample_getType.out OUTPUT ObjectExample_getType.out ) ADD_EXECUTABLE( ParameterContainerExample ParameterContainerExample.cpp ) ADD_EXECUTABLE( StringExample StringExample.cpp ) Loading Loading @@ -55,6 +58,7 @@ ADD_CUSTOM_COMMAND( COMMAND TimerExampleLogger > TimerExampleLogger.out OUTPUT T ADD_EXECUTABLE( VectorExample VectorExample.cpp ) ADD_CUSTOM_TARGET( run ALL DEPENDS ObjectExample_getType.out StringExample.out StringExampleGetAllocatedSize.out StringExampleReplace.out Loading
src/Examples/ObjectExample_getType.cpp 0 → 100644 +63 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/param-types.h> #include <TNL/Object.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> using namespace TNL; using namespace std; template< typename Value, typename Device > class MyArray : public Object { public: using HostType = MyArray< Value, Devices::Host >; static String getType() { return "MyArray< " + TNL::getType< Value >() + ", " + TNL::getType< Device >() + " >"; } String getTypeVirtual() const { return getType(); } static String getSerializationType() { return HostType::getType(); } String getSerializationTypeVirtual() const { return getSerializationType(); } }; int main() { using HostArray = MyArray< int, Devices::Host >; using CudaArray = MyArray< int, Devices::Cuda >; HostArray hostArray; CudaArray cudaArray; Object* hostArrayPtr = &hostArray; Object* cudaArrayPtr = &cudaArray; // Object types cout << "HostArray type is " << HostArray::getType() << endl; cout << "hostArrayPtr type is " << hostArrayPtr->getTypeVirtual() << endl; cout << "CudaArray type is " << CudaArray::getType() << endl; cout << "cudaArrayPtr type is " << cudaArrayPtr->getTypeVirtual() << endl; // Object serialization types cout << "HostArray serialization type is " << HostArray::getSerializationType() << endl; cout << "hostArrayPtr serialization type is " << hostArrayPtr->getSerializationTypeVirtual() << endl; cout << "CudaArray serialization type is " << CudaArray::getSerializationType() << endl; cout << "cudaArrayPtr serialization type is " << cudaArrayPtr->getSerializationTypeVirtual() << endl; }
src/TNL/Devices/Cuda.h +3 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ class Cuda static inline String getDeviceType(); // TODO: Remove getDeviceType(); static inline String getType() { return getDeviceType();}; static inline void configSetup( Config::ConfigDescription& config, const String& prefix = "" ); static inline bool setup( const Config::ParameterContainer& parameters, Loading
src/TNL/Devices/Cuda_impl.h +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ namespace Devices { inline String Cuda::getDeviceType() { return String( "Cuda" ); return String( "Devices::Cuda" ); } inline void Loading
src/TNL/Devices/Host.h +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ public: return String( "Devices::Host" ); } // TODO: Remove getDeviceType(); static inline String getType() { return getDeviceType();}; static void disableOMP() { ompEnabled = false; Loading