Project
Loading...
Searching...
No Matches
SymMatrixSolver.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#include "SymMatrixSolver.h"
18#include "GPUCommonLogger.h"
19
20#include <iostream>
21#include <random>
22#include <iomanip>
23#include <chrono>
24
25using namespace std;
26using namespace o2::gpu;
27
29
31{
32 // Upper Triangulization
33 for (int32_t i = 0; i < mN; i++) {
34 double* rowI = &mA[i * mShift];
35 double* rowIb = &mA[i * mShift + mN];
36 double c = (fabs(rowI[i]) > 1.e-10) ? 1. / rowI[i] : 0.;
37 double* rowJ = rowI + mShift;
38 for (int32_t j = i + 1; j < mN; j++, rowJ += mShift) { // row j
39 if (rowI[j] != 0.) {
40 double aij = c * rowI[j]; // A[i][j] / A[i][i]
41 for (int32_t k = j; k < mShift; k++) {
42 rowJ[k] -= aij * rowI[k]; // A[j][k] -= A[i][k]/A[i][i]*A[j][i]
43 }
44 rowI[j] = aij; // A[i][j] /= A[i][i]
45 }
46 }
47 for (int32_t k = 0; k < mM; k++) {
48 rowIb[k] *= c;
49 }
50 }
51 // Diagonalization
52 for (int32_t i = mN - 1; i >= 0; i--) {
53 double* rowIb = &mA[i * mShift + mN];
54 double* rowJb = rowIb - mShift;
55 for (int32_t j = i - 1; j >= 0; j--, rowJb -= mShift) { // row j
56 double aji = mA[j * mShift + i];
57 if (aji != 0.) {
58 for (int32_t k = 0; k < mM; k++) {
59 rowJb[k] -= aji * rowIb[k];
60 }
61 }
62 }
63 }
64}
65
67{
68 for (int32_t i = 0; i < mN; i++) {
69 LOG(info) << "";
70 for (int32_t j = 0; j < mN; j++) {
71 LOG(info) << std::fixed << std::setw(5) << std::setprecision(2) << A(i, j) << " ";
72 }
73 LOG(info) << " | ";
74 for (int32_t j = 0; j < mM; j++) {
75 LOG(info) << std::fixed << std::setw(5) << std::setprecision(2) << B(i, j) << " ";
76 }
77 }
78 LOG(info) << std::setprecision(-1);
79}
80
82{
83 constexpr int32_t n = 30;
84 constexpr int32_t d = 3;
85
86 // std::random_device rd; // Will be used to obtain a seed for the random
87 std::mt19937 gen(1); // Standard mersenne_twister_engine seeded with 1
88 std::uniform_real_distribution<> uniform(-.999, .999);
89
90 double maxDiff = 0.;
91 int32_t nTries = 10000;
92
93 auto tmpTime = std::chrono::high_resolution_clock::now();
94 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(tmpTime - tmpTime);
95 auto durationMult = duration;
96
97 for (int32_t iter = 0; iter < nTries; iter++) {
98
99 double x[n][d];
100 double A[n][n];
101 {
102 for (int32_t i = 0; i < n; i++) {
103 for (int32_t j = 0; j < d; j++) {
104 x[i][j] = 1. * uniform(gen);
105 }
106 }
107 for (int32_t i = 0; i < n; i++) {
108 A[i][i] = fabs(2. + uniform(gen));
109 }
110 for (int32_t i = 0; i < n; i++) {
111 for (int32_t j = i + 1; j < n; j++) {
112 A[i][j] = A[i][i] * A[j][j] * uniform(gen);
113 A[j][i] = A[i][j];
114 }
115 }
116 for (int32_t i = 0; i < n; i++) {
117 A[i][i] = A[i][i] * A[i][i];
118 }
119 if (prn && iter == nTries - 1) {
120 for (int32_t i = 0; i < n; i++) {
121 LOG(info) << "";
122 for (int32_t j = 0; j < n; j++) {
123 LOG(info) << std::fixed << std::setw(5) << std::setprecision(2) << A[i][j] << " ";
124 }
125 }
126 LOG(info) << "";
127 }
128 }
129 double b[n][d];
130 auto startMult = std::chrono::high_resolution_clock::now();
131 for (int32_t i = 0; i < n; i++) {
132 for (int32_t k = 0; k < d; k++) {
133 b[i][k] = 0.;
134 }
135 for (int32_t j = 0; j < n; j++) {
136 for (int32_t k = 0; k < d; k++) {
137 b[i][k] += x[j][k] * A[i][j];
138 }
139 }
140 }
141 auto stopMult = std::chrono::high_resolution_clock::now();
142 durationMult += std::chrono::duration_cast<std::chrono::nanoseconds>(stopMult - startMult);
143
144 SymMatrixSolver sym(n, d);
145
146 for (int32_t i = 0; i < n; i++) {
147 for (int32_t k = 0; k < d; k++) {
148 sym.B(i, k) = b[i][k];
149 }
150 for (int32_t j = i; j < n; j++) {
151 sym.A(i, j) = A[i][j];
152 }
153 }
154
155 auto start = std::chrono::high_resolution_clock::now();
156 sym.solve();
157 auto stop = std::chrono::high_resolution_clock::now();
158 duration += std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
159
160 double diff = 0.;
161 for (int32_t i = 0; i < n; i++) {
162 for (int32_t k = 0; k < d; k++) {
163 double t = fabs(x[i][k] - sym.B(i, k));
164 if (diff < t) {
165 diff = t;
166 }
167 }
168 }
169 if (maxDiff < diff) {
170 maxDiff = diff;
171 }
172 // LOG(info) << std::defaultfloat ;
173 // LOG(info) << "\n\n max diff " <<diff << "\n";
174 }
175
176 int32_t ok = (maxDiff < 1.e-7);
177
178 if (prn || !ok) {
179 LOG(info) << std::defaultfloat;
180 LOG(info) << "\n\n Overall max diff " << maxDiff << "\n";
181 LOG(info) << " time " << duration.count() / nTries;
182 LOG(info) << " time multiplication " << durationMult.count() / nTries;
183 }
184 return ok;
185}
default_random_engine gen(dev())
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
ClassImp(o2::gpu::SymMatrixSolver)
Definition of SymMatrixSolver class.
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Definition A.h:16
Definition B.h:16
double & B(int32_t i, int32_t j)
access to B elements
double & A(int32_t i, int32_t j)
access to A elements
static int32_t test(bool prn=0)
Test the class functionality. Returns 1 when ok, 0 when not ok.
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"