Skip to content

Commit 6a2cc7e

Browse files
authored
Add SMatrixGPU compatibility to trackParCov (#13602)
* Add SMatrixGPU compatibility to trackParCov * Hide TrackParCov<double> from GPU code * Remove SMatrix.h as not needed anymore
1 parent b797c12 commit 6a2cc7e

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

Common/MathUtils/include/MathUtils/SMatrixGPU.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ class SMatrixGPU
446446
GPUdi() SMatrixGPU(SMatrixNoInit) {}
447447
GPUd() SMatrixGPU(SMatrixIdentity);
448448
GPUd() SMatrixGPU(const SMatrixGPU<T, D1, D2, R>& rhs);
449+
template <class R2>
450+
GPUd() SMatrixGPU(const SMatrixGPU<T, D1, D2, R2>& rhs);
449451
template <class A, class R2>
450452
GPUd() SMatrixGPU(const Expr<A, T, D1, D2, R2>& rhs);
451453
template <class M>
@@ -497,6 +499,11 @@ class SMatrixGPU
497499
GPUd() SMatrixRowGPU operator[](unsigned int i) { return SMatrixRowGPU(*this, i); }
498500
template <class R2>
499501
GPUd() SMatrixGPU<T, D1, D2, R>& operator+=(const SMatrixGPU<T, D1, D2, R2>& rhs);
502+
GPUd() SMatrixGPU<T, D1, D2, R>& operator*=(const T& rhs);
503+
template <class R2>
504+
GPUd() SMatrixGPU<T, D1, D2, R>& operator*=(const SMatrixGPU<T, D1, D2, R2>& rhs);
505+
template <class A, class R2>
506+
GPUd() SMatrixGPU<T, D1, D2, R>& operator*=(const Expr<A, T, D1, D2, R2>& rhs);
500507

501508
GPUd() bool Invert();
502509
GPUd() bool IsInUse(const T* p) const;
@@ -528,6 +535,13 @@ GPUdi() SMatrixGPU<T, D1, D2, R>::SMatrixGPU(const SMatrixGPU<T, D1, D2, R>& rhs
528535
mRep = rhs.mRep;
529536
}
530537

538+
template <class T, unsigned int D1, unsigned int D2, class R>
539+
template <class R2>
540+
GPUd() SMatrixGPU<T, D1, D2, R>::SMatrixGPU(const SMatrixGPU<T, D1, D2, R2>& rhs)
541+
{
542+
operator=(rhs);
543+
}
544+
531545
template <class T, unsigned int D1, unsigned int D2, class R>
532546
GPUdi() T* SMatrixGPU<T, D1, D2, R>::begin()
533547
{
@@ -1387,6 +1401,29 @@ GPUdi() SMatrixGPU<T, D1, D2, R>& SMatrixGPU<T, D1, D2, R>::operator+=(const SMa
13871401
return *this;
13881402
}
13891403

1404+
template <class T, unsigned int D1, unsigned int D2, class R>
1405+
GPUdi() SMatrixGPU<T, D1, D2, R>& SMatrixGPU<T, D1, D2, R>::operator*=(const T & rhs)
1406+
{
1407+
for (unsigned int i = 0; i < R::kSize; ++i) {
1408+
mRep.Array()[i] *= rhs;
1409+
}
1410+
return *this;
1411+
}
1412+
1413+
template <class T, unsigned int D1, unsigned int D2, class R>
1414+
template <class R2>
1415+
GPUdi() SMatrixGPU<T, D1, D2, R>& SMatrixGPU<T, D1, D2, R>::operator*=(const SMatrixGPU<T, D1, D2, R2>& rhs)
1416+
{
1417+
return operator=(*this* rhs);
1418+
}
1419+
1420+
template <class T, unsigned int D1, unsigned int D2, class R>
1421+
template <class A, class R2>
1422+
GPUdi() SMatrixGPU<T, D1, D2, R>& SMatrixGPU<T, D1, D2, R>::operator*=(const Expr<A, T, D1, D2, R2>& rhs)
1423+
{
1424+
return operator=(*this* rhs);
1425+
}
1426+
13901427
template <class T, unsigned int D1, unsigned int D2, class R>
13911428
struct TranspPolicyGPU {
13921429
enum {

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKPARAMETRIZATIONWITHERROR_H_
1919

2020
#include "ReconstructionDataFormats/TrackParametrization.h"
21+
#include <MathUtils/Cartesian.h>
2122

2223
namespace o2
2324
{
@@ -38,8 +39,8 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
3839
#endif
3940

4041
using covMat_t = gpu::gpustd::array<value_t, kCovMatSize>;
41-
using MatrixDSym5 = ROOT::Math::SMatrix<double, kNParams, kNParams, ROOT::Math::MatRepSym<double, kNParams>>;
42-
using MatrixD5 = ROOT::Math::SMatrix<double, kNParams, kNParams, ROOT::Math::MatRepStd<double, kNParams, kNParams>>;
42+
using MatrixDSym5 = o2::math_utils::SMatrix<double, kNParams, kNParams, o2::math_utils::MatRepSym<double, kNParams>>;
43+
using MatrixD5 = o2::math_utils::SMatrix<double, kNParams, kNParams, o2::math_utils::MatRepStd<double, kNParams, kNParams>>;
4344

4445
GPUd() TrackParametrizationWithError();
4546
GPUd() TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par, const covMat_t& cov, int charge = 1, const PID pid = PID::Pion);
@@ -100,12 +101,12 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
100101
template <typename T>
101102
GPUd() value_t getPredictedChi2(const BaseCluster<T>& p) const;
102103

103-
void buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const;
104-
value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const;
104+
GPUd() void buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const;
105+
GPUd() value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const;
105106
GPUd() value_t getPredictedChi2(const TrackParametrizationWithError& rhs) const;
106107
GPUd() value_t getPredictedChi2Quiet(const TrackParametrizationWithError& rhs) const;
107-
bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv);
108-
bool update(const TrackParametrizationWithError& rhs);
108+
GPUd() bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv);
109+
GPUd() bool update(const TrackParametrizationWithError& rhs);
109110

110111
GPUd() bool update(const dim2_t& p, const dim3_t& cov);
111112
GPUd() bool update(const value_t* p, const value_t* cov);

DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
#include "ReconstructionDataFormats/DCA.h"
1515
#include <GPUCommonLogger.h>
1616

17+
#ifndef __OPENCL__
18+
#include <cfloat>
19+
#else
20+
#include <float.h>
21+
#endif
22+
1723
#ifndef GPUCA_GPUCODE_DEVICE
1824
#include <iostream>
19-
#ifndef GPUCA_STANDALONE
20-
#include "Math/SMatrix.h"
21-
#endif
2225
#endif
2326

2427
#ifndef GPUCA_ALIGPUCODE
@@ -754,11 +757,17 @@ GPUd() auto TrackParametrizationWithError<value_T>::getPredictedChi2Quiet(const
754757
return (d * (szz * d - sdz * z) + z * (sdd * z - d * sdz)) / det;
755758
}
756759

757-
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // Disable function relying on ROOT SMatrix on GPU
760+
//______________________________________________
761+
template <typename value_T>
762+
GPUd() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const TrackParametrizationWithError<value_T>& rhs) const -> value_t
763+
{
764+
MatrixDSym5 cov; // perform matrix operations in double!
765+
return getPredictedChi2(rhs, cov);
766+
}
758767

759768
//______________________________________________
760769
template <typename value_T>
761-
void TrackParametrizationWithError<value_T>::buildCombinedCovMatrix(const TrackParametrizationWithError<value_T>& rhs, MatrixDSym5& cov) const
770+
GPUd() void TrackParametrizationWithError<value_T>::buildCombinedCovMatrix(const TrackParametrizationWithError<value_T>& rhs, MatrixDSym5& cov) const
762771
{
763772
// fill combined cov.matrix (NOT inverted)
764773
cov(kY, kY) = static_cast<double>(getSigmaY2()) + static_cast<double>(rhs.getSigmaY2());
@@ -778,14 +787,6 @@ void TrackParametrizationWithError<value_T>::buildCombinedCovMatrix(const TrackP
778787
cov(kQ2Pt, kQ2Pt) = static_cast<double>(getSigma1Pt2()) + static_cast<double>(rhs.getSigma1Pt2());
779788
}
780789

781-
//______________________________________________
782-
template <typename value_T>
783-
GPUd() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const TrackParametrizationWithError<value_T>& rhs) const -> value_t
784-
{
785-
MatrixDSym5 cov; // perform matrix operations in double!
786-
return getPredictedChi2(rhs, cov);
787-
}
788-
789790
//______________________________________________
790791
template <typename value_T>
791792
GPUd() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const TrackParametrizationWithError<value_T>& rhs, MatrixDSym5& covToSet) const -> value_t
@@ -867,7 +868,7 @@ GPUd() bool TrackParametrizationWithError<value_T>::update(const TrackParametriz
867868
}
868869

869870
// updated covariance: Cov0 = Cov0 - K*Cov0
870-
matK *= ROOT::Math::SMatrix<double, kNParams, kNParams, ROOT::Math::MatRepStd<double, kNParams>>(matC0);
871+
matK *= o2::math_utils::SMatrix<double, kNParams, kNParams, o2::math_utils::MatRepStd<double, kNParams>>(matC0);
871872
mC[kSigY2] -= matK(kY, kY);
872873
mC[kSigZY] -= matK(kZ, kY);
873874
mC[kSigZ2] -= matK(kZ, kZ);
@@ -901,8 +902,6 @@ GPUd() bool TrackParametrizationWithError<value_T>::update(const TrackParametriz
901902
return update(rhs, covI);
902903
}
903904

904-
#endif
905-
906905
//______________________________________________
907906
template <typename value_T>
908907
GPUd() bool TrackParametrizationWithError<value_T>::update(const value_t* p, const value_t* cov)

0 commit comments

Comments
 (0)