Chapter 3.2 : Template Usage
This mode can address some issues we can have when dealing with several Devices (for example CPU and GPU). Let's say we want to manage some temporaries used in an analysis or a simulation. For debugging purpose we would like a version of the generated code compilable on GPU an other on CPU and a way to copy data between the two. But, there is a probleme : which allocation function to use ? which copy function to use ? some for CUDA with cudaMalloc and cudaMemcpy or others ?
In this case, columns allocation has to be handled by a template parameter. Some are provided by Phoenix in file phoenix_allocator.h :
- PhoenixAllocator : a bacis allocator
- PhoenixAlignedAllocator : an allocator with aligned pointers
- PhoenixVectorAllocator : an allocator which uses std::vector (if you need to make one for thrust::vector )
Template class prodives also a phoenix_copy function. By default it uses PhoenixMemCpy which encapsulate a simple memcpy.
Example : Let's use this configuration TableVertex.ph5 :
1 2 3 4 5 6 7 8 9 10 11 |
///Table of values TableVertex{ ///Event id size_t eventId; ///Timestamp double timestamp; ///Image Tensor(float, nbPixel) image; ///Float value Tensor(float, nbValue, 2) matValue; } |
We can generate files with --template or -z :
phoenix_hdf5 -i TableVertex.ph5 --template
It will create :
- TableVertex.h : header of class TableVertex
- TableVertex_impl.h : source of class TableVertex
- TableVertex_hdf5.h : header of HDF5 backend (TableVertexH5) for class TableVertex
- TableVertex_hdf5_impl.h : source of HDF5 backend (TableVertexH5) for class TableVertex
- TableVertex_test.cpp : Unit Tests to check if generated class is well used and this gives also an example of how to use it
- phoenix_allocator.h : Contains default allocator to be used with the generated classes
Classes can be used with :
1 2 3 4 5 6 7 |
#include "TableVertex.h" ... TableVertex<PhoenixAllocator> table; TableVertexH5<PhoenixAllocator> tableH5; ... |
Having HDF5 backend can be usefull to debug a program on GPU and flush all steps of the ongoing computation.
As in standard mode : If you are using class with multi-dimensions columns, make sure to use setAllDim method before calling resize, otherwise multi-dimensions columns will be empty