Project
Loading...
Searching...
No Matches
o2::gpu::IrregularSpline1D Class Reference

#include <IrregularSpline1D.h>

Inherits o2::gpu::FlatObject.

Classes

struct  Knot
 The struct represents a knot(i) and interval [ knot(i), knot(i+1) ]. More...
 

Public Member Functions

 IrregularSpline1D ()
 _____________ Constructors / destructors __________________________
 
 IrregularSpline1D (const IrregularSpline1D &)=delete
 Copy constructor: disabled to avoid ambiguity. Use cloneFromObject instead.
 
IrregularSpline1Doperator= (const IrregularSpline1D &)=delete
 Assignment operator: disabled to avoid ambiguity. Use cloneFromObject instead.
 
 ~IrregularSpline1D ()=default
 Destructor.
 
void cloneFromObject (const IrregularSpline1D &obj, char *newFlatBufferPtr)
 Construction interface.
 
void destroy ()
 
void construct (int32_t numberOfKnots, const float knots[], int32_t numberOfAxisBins)
 _______________ Construction interface ________________________
 
void constructRegular (int32_t numberOfKnotsU)
 Constructor for a regular spline.
 
template<typename T >
 GPUd () void correctEdges(T *data) const
 _______________ Main functionality ________________________
 
template<typename T >
GPUd() static T getSpline(const IrregularSpline1D GPUd () T getSpline(const T correctedData[]
 Get interpolated value for f(u) using spline at knot "knot1" and function values at knots {knot_0,knot_1,knot_2,knot_3}.
 
 GPUd () int32_t getNumberOfKnots() const
 Get number of knots.
 
 GPUd () int32_t getKnotIndex(float u) const
 
 GPUd () const IrregularSpline1D
 Get i-th knot, no border check performed!
 
 GPUd () const int32_t *getBin2KnotMap() const
 technical stuff
 
int32_t getNumberOfAxisBins () const
 Get number of axis bins.
 
 GPUd () static void getEdgeCorrectionCoefficients(double u0
 
void print () const
 Print method.
 
charreleaseInternalBuffer ()
 Making the data buffer external.
 
void moveBufferTo (char *newBufferPtr)
 
void setActualBufferAddress (char *actualFlatBufferPtr)
 Moving the class with its external buffer to another location.
 
void setFutureBufferAddress (char *futureFlatBufferPtr)
 
- Public Member Functions inherited from o2::gpu::FlatObject
 FlatObject ()=default
 _____________ Constructors / destructors __________________________
 
 ~FlatObject ()
 
 FlatObject (const FlatObject &)=delete
 
FlatObjectoperator= (const FlatObject &)=delete
 
void destroy ()
 _______________ Utilities _______________________________________________
 
size_t getFlatBufferSize () const
 Gives size of the flat buffer.
 
const chargetFlatBufferPtr () const
 Gives pointer to the flat buffer.
 
bool isConstructed () const
 Tells if the object is constructed.
 
bool isBufferInternal () const
 Tells if the buffer is internal.
 
void adoptInternalBuffer (char *buf)
 
void clearInternalBufferPtr ()
 
void printC () const
 Print the content of the flat buffer.
 

Static Public Member Functions

static constexpr size_t getBufferAlignmentBytes ()
 Get minimal required alignment for the flat buffer.
 
static constexpr size_t getDataAlignmentBytes ()
 Get minimal required alignment for the spline data.
 
static constexpr size_t getBufferAlignmentBytes ()
 _____________ FlatObject functionality, see FlatObject class for description ____________
 
static constexpr size_t getClassAlignmentBytes ()
 _____________ Memory alignment __________________________
 
- Static Public Member Functions inherited from o2::gpu::FlatObject
static size_t alignSize (size_t sizeBytes, size_t alignmentBytes)
 _______________ Generic utilities _______________________________________________
 
template<class T >
static T * relocatePointer (const char *oldBase, char *newBase, const T *ptr)
 Relocates a pointer inside a buffer to the new buffer address.
 
template<class T , class TFile >
static int32_t writeToFile (T &obj, TFile &outf, const char *name)
 write a child class object to the file
 
template<class T , class TFile >
static T * readFromFile (TFile &inpf, const char *name)
 read a child class object from the file
 
template<class T >
static std::string stressTest (T &obj)
 Test the flat object functionality for a child class T.
 

Public Attributes

GPUd() static T getSpline(const IrregularSpline1D float u const
 
double u1
 
double double u2
 
double double double u3
 
double double double double & c0
 
double double double double double & c1
 
double double double double double double & c2
 
double double double double double double double & c3
 

Additional Inherited Members

- Protected Types inherited from o2::gpu::FlatObject
enum  ConstructionState : uint32_t { NotConstructed = 0x0 , Constructed = 0x1 , InProgress = 0x2 }
 GPUCA_GPUCODE. More...
 
- Protected Member Functions inherited from o2::gpu::FlatObject
void startConstruction ()
 _____________ Construction _________
 
void finishConstruction (int32_t flatBufferSize)
 
void cloneFromObject (const FlatObject &obj, char *newFlatBufferPtr)
 
charreleaseInternalBuffer ()
 _____________ Methods for making the data buffer external __________________________
 
void moveBufferTo (char *newBufferPtr)
 
void setActualBufferAddress (char *actualFlatBufferPtr)
 _____________ Methods for moving the class with its external buffer to another location __________________________
 
void setFutureBufferAddress (char *futureFlatBufferPtr)
 
 ClassDefNV (FlatObject, 1)
 Pointer to the flat buffer.
 
- Static Protected Member Functions inherited from o2::gpu::FlatObject
static constexpr size_t getClassAlignmentBytes ()
 _____________ Memory alignment __________________________
 
static constexpr size_t getBufferAlignmentBytes ()
 Gives minimal alignment in bytes required for the flat buffer.
 
- Protected Attributes inherited from o2::gpu::FlatObject
int32_t mFlatBufferSize = 0
 size of the flat buffer
 
uint32_t mConstructionMask = ConstructionState::NotConstructed
 mask for constructed object members, first two bytes are used by this class
 
charmFlatBufferContainer = nullptr
 
charmFlatBufferPtr = nullptr
 

Detailed Description

The IrregularSpline1D class represents one-dimensional spline interpolation on nonunifom (irregular) grid.

The class is flat C structure. No virtual methods, no ROOT types are used. It is designed for spline parameterisation of TPC transformation.


The spline interpolates a generic function F:[0,1]->R.

Let's call the function parameter U, the function value F. The interpolation is performed on n knots {U0==0., U1, .., Un==1.} with given function values {F0, ..., Fn} at the knots.

An interpolation in each interval between two knots is performed by 3-th degree polynom. The polynoms cross the Fi values at the knots and have contnious 1-th derivative. For performance reasons, the polynoms are created locally on-the-fly using only four values of F at four neighbouring knots. Therefore unlike the classical splines, the second derivative may not be continious.

The knots should belong to interval [0,1], the distance between knots is (almost) arbitrary.

Nothing which depends on F is stored in the class. Therefore one can use the same class for different F functions. The function values {F0,..Fn} have to be provided by user for each call.

The class performs a fast search of a spline interval: (float U ) -> [int32_t iKnot, int32_t iKnot+1 ). For that purpose, initial U coordinates of the knots are rounded to the closest i*1./nAxisBins values.

The minimal number of knots is 5, the minimal number of axis bins is 4

Knots U0=0. and Un=1. are always present. They are added automatically when they are not set by an user.

Number of knots and they U coordinates may change during initialisation!

User should provide function values Fi for all !constructed! knots.

---------— Edge correction ---------—

The function values at both edges should be corrected beforehand via spline.correctEdges( f ); method. It is needed for the fast spline mathematics to work correctly.

Explanation:

To calculate a spline at interval [Ui,U{i+1}), we need to know the function values at 4 knots: {i-1,i,i+1,i+2} As the knots {-1} and {n} do not exist, the edge intervals [U0,U1) and [U{n-2},U{n-1}] need special treatment. Thus, the algorithm needs to have 3 big branches containing different math :(

To avoid the branches in the code, we do a trick:

Function values for the interval [U0,U1) are constructed using a spline polynom from the next interval [U1,U2). To do so, all U values from the first interval are assigned to the second interval [U1,U2) in the U->(knot interval) map.

This approach has no branches, but has another problem: the spline from the second interval [U1,U2) will not necessarily cross the original F0 value at u=U0.

To fix this, we modify the function value F0 in the way, that the spline from [U1,U2) also crosses the original F0 value at u=U0

The same trick is performed for the last interval [U{n-2},U{n-1})


Example of creating a spline:

const int32_t nKnots=5; float knots[nKnots] = {0., 0.25, 0.5, 0.7, 1.}; IrregularSpline1D spline; spline.construct(nKnots, knots, 4); float f[nKnots] = { 3.5, 2.0, 1.4, 3.8, 2.3}; spline.correctEdges( f ); spline.getSpline( f, 0. ); // == 3.5 spline.getSpline( f, 0.1 ); // == some interpolated value spline.getSpline( f, 0.25 ); // == 2.0 spline.getSpline( f, 0.5 ); // == 1.4 spline.getSpline( f, 1. ); // == 2.3

Definition at line 112 of file IrregularSpline1D.h.

Constructor & Destructor Documentation

◆ IrregularSpline1D() [1/2]

IrregularSpline1D::IrregularSpline1D ( )

_____________ Constructors / destructors __________________________

Default constructor. Creates an empty uninitialised object

Default constructor. Creates an empty uninitialised object

Definition at line 29 of file IrregularSpline1D.cxx.

◆ IrregularSpline1D() [2/2]

o2::gpu::IrregularSpline1D::IrregularSpline1D ( const IrregularSpline1D )
delete

Copy constructor: disabled to avoid ambiguity. Use cloneFromObject instead.

◆ ~IrregularSpline1D()

o2::gpu::IrregularSpline1D::~IrregularSpline1D ( )
default

Destructor.

Member Function Documentation

◆ cloneFromObject()

void IrregularSpline1D::cloneFromObject ( const IrregularSpline1D obj,
char newFlatBufferPtr 
)

Construction interface.

See FlatObject for description

Definition at line 43 of file IrregularSpline1D.cxx.

◆ construct()

void IrregularSpline1D::construct ( int32_t  numberOfKnots,
const float  knots[],
int32_t  numberOfAxisBins 
)

_______________ Construction interface ________________________

Constructor

Number of knots created and their values may differ from the input values:

  • Edge knots 0.f and 1.f will be added if they are not present.
  • Knot values are rounded to closest axis bins: k*1./numberOfAxisBins.
  • Knots which are too close to each other will be merged
  • At least 5 knots and at least 4 axis bins will be created for consistency reason
Parameters
numberOfKnotsNumber of knots in knots[] array
knotsArray of knots.
numberOfAxisBinsNumber of axis bins to map U coordinate to an appropriate [knot(i),knot(i+1)] interval. The knot positions have a "granularity" of 1./numberOfAxisBins

Constructor. Initialises the spline with a grid with numberOfKnots knots in the interval [0,1] array inputKnots[] has numberOfKnots entries, ordered from 0. to 1. knots on the edges u==0. & u==1. are obligatory

The number of knots created and their values may change during initialisation:

  • Edge knots 0.f and 1.f will be added if they are not present.
  • Knot values are rounded to closest axis bins: k*1./numberOfAxisBins.
  • Knots which are too close to each other will be merged
  • At least 5 knots and at least 4 axis bins will be created for consistency reason
Parameters
numberOfKnotsNumber of knots in knots[] array
knotsArray of knots.
numberOfAxisBinsNumber of axis bins to map U coordinate to an appropriate [knot(i),knot(i+1)] interval. The knot positions have a "granularity" of 1./(numberOfAxisBins-1)

Definition at line 52 of file IrregularSpline1D.cxx.

◆ constructRegular()

void IrregularSpline1D::constructRegular ( int32_t  numberOfKnotsU)

Constructor for a regular spline.

Constructor for a regular spline

Parameters
numberOfKnotsNumber of knots

Definition at line 187 of file IrregularSpline1D.cxx.

◆ destroy()

void IrregularSpline1D::destroy ( )

See FlatObject for description

Definition at line 34 of file IrregularSpline1D.cxx.

◆ getBufferAlignmentBytes() [1/2]

static constexpr size_t o2::gpu::FlatObject::getBufferAlignmentBytes ( )
inlinestaticconstexpr

_____________ FlatObject functionality, see FlatObject class for description ____________

Memory alignment

Definition at line 197 of file FlatObject.h.

◆ getBufferAlignmentBytes() [2/2]

static constexpr size_t o2::gpu::IrregularSpline1D::getBufferAlignmentBytes ( )
inlinestaticconstexpr

Get minimal required alignment for the flat buffer.

Definition at line 227 of file IrregularSpline1D.h.

◆ getClassAlignmentBytes()

static constexpr size_t o2::gpu::FlatObject::getClassAlignmentBytes ( )
inlinestaticconstexpr

_____________ Memory alignment __________________________

Gives minimal alignment in bytes required for the class object

Definition at line 194 of file FlatObject.h.

◆ getDataAlignmentBytes()

static constexpr size_t o2::gpu::IrregularSpline1D::getDataAlignmentBytes ( )
inlinestaticconstexpr

Get minimal required alignment for the spline data.

Definition at line 230 of file IrregularSpline1D.h.

◆ getNumberOfAxisBins()

int32_t o2::gpu::IrregularSpline1D::getNumberOfAxisBins ( ) const
inline

Get number of axis bins.

Definition at line 238 of file IrregularSpline1D.h.

◆ GPUd() [1/7]

o2::gpu::IrregularSpline1D::GPUd ( ) const
inline

technical stuff

Get a map (U axis bin index) -> (corresponding knot index)

Definition at line 235 of file IrregularSpline1D.h.

◆ GPUd() [2/7]

o2::gpu::IrregularSpline1D::GPUd ( ) const
inline

Get i-th knot, no border check performed!

Definition at line 218 of file IrregularSpline1D.h.

◆ GPUd() [3/7]

o2::gpu::IrregularSpline1D::GPUd ( ) const

Get index of associated knot for a given U coordinate.

Note: U values from the first interval are mapped to the second inrerval. Values from the last interval are mapped to the previous interval.

◆ GPUd() [4/7]

o2::gpu::IrregularSpline1D::GPUd ( ) const
inline

Get number of knots.

Definition at line 208 of file IrregularSpline1D.h.

◆ GPUd() [5/7]

o2::gpu::IrregularSpline1D::GPUd ( )

Get coefficients for edge correction

Let's the interpolated function has values f0, f1, f2, f3 at knots u0, u1, u2, u3 The corrected value of f0 is calculated as: f0_corr = c0*f0 + c1*f1 + c2*f2 + c3*f3

The coefficients ci are calculated in double precision because they are temporary and used only at the initialisation phase. So we can pay a price for the higher accuracy here.

◆ GPUd() [6/7]

template<typename T >
GPUd() static T getSpline(const IrregularSpline1D o2::gpu::IrregularSpline1D::GPUd ( ) const

Get interpolated value for f(u) using spline at knot "knot1" and function values at knots {knot_0,knot_1,knot_2,knot_3}.

Get interpolated value for f(u) using data array correctedData[getNumberOfKnots()] with corrected edges

◆ GPUd() [7/7]

template<typename T >
o2::gpu::IrregularSpline1D::GPUd ( ) const

_______________ Main functionality ________________________

Correction of data values at both edge knots.

It is needed for the fast spline mathematics to work correctly. See explanation at the class comment above.

Parameters
dataarray of function values. It has the size of getNumberOfKnots()

◆ moveBufferTo()

void o2::gpu::FlatObject::moveBufferTo ( char newBufferPtr)
inline

Sets buffer pointer to the new address, move the buffer content there. A daughter class must relocate all the pointers inside th buffer

sets buffer pointer to the new address, move the buffer content there.

Definition at line 225 of file FlatObject.h.

◆ operator=()

IrregularSpline1D & o2::gpu::IrregularSpline1D::operator= ( const IrregularSpline1D )
delete

Assignment operator: disabled to avoid ambiguity. Use cloneFromObject instead.

◆ print()

void IrregularSpline1D::print ( ) const

Print method.

Definition at line 207 of file IrregularSpline1D.cxx.

◆ releaseInternalBuffer()

char * o2::gpu::FlatObject::releaseInternalBuffer ( )
inline

Making the data buffer external.

Definition at line 220 of file FlatObject.h.

◆ setActualBufferAddress()

void o2::gpu::FlatObject::setActualBufferAddress ( char actualFlatBufferPtr)
inline

Moving the class with its external buffer to another location.

Definition at line 234 of file FlatObject.h.

◆ setFutureBufferAddress()

void o2::gpu::FlatObject::setFutureBufferAddress ( char futureFlatBufferPtr)
inline

Sets a future location of the external flat buffer before moving it to this location (i.e. when copying to GPU).

The object can be used immidiatelly after the move, call of setActualFlatBufferAddress() is not needed.

A daughter class should already relocate all the pointers inside the current buffer to the future location. It should not touch memory in the future location, since it may be not yet available.

!!! Information about the actual buffer location will be lost. !!! Most of the class methods may be called only after the buffer will be moved to its new location. !!! To undo call setActualFlatBufferAddress()

Sets a future location of the external flat buffer before moving it to this location.

A daughter class should already reset all the pointers inside the current buffer to the future location without touching memory in the future location.

Definition at line 247 of file FlatObject.h.

Member Data Documentation

◆ c0

double double double double& o2::gpu::IrregularSpline1D::c0

Definition at line 249 of file IrregularSpline1D.h.

◆ c1

double double double double double& o2::gpu::IrregularSpline1D::c1

Definition at line 249 of file IrregularSpline1D.h.

◆ c2

double double double double double double& o2::gpu::IrregularSpline1D::c2

Definition at line 249 of file IrregularSpline1D.h.

◆ c3

double double double double double double double& o2::gpu::IrregularSpline1D::c3

Definition at line 249 of file IrregularSpline1D.h.

◆ const

GPUd() static T getSpline(const IrregularSpline1D float u o2::gpu::IrregularSpline1D::const

Definition at line 205 of file IrregularSpline1D.h.

◆ u1

double o2::gpu::IrregularSpline1D::u1

Definition at line 249 of file IrregularSpline1D.h.

◆ u2

double double o2::gpu::IrregularSpline1D::u2

Definition at line 249 of file IrregularSpline1D.h.

◆ u3

double double double o2::gpu::IrregularSpline1D::u3

Definition at line 249 of file IrregularSpline1D.h.


The documentation for this class was generated from the following files: