Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mathcoreGenVectorSYCL.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_math
3/// \notebook -nodraw
4/// Example macro testing available methods and operation of the GenVectorX classes.
5///
6/// \note This tutorial requires ROOT to be built with **SYCL support** and **GenVectorX** enabled.
7/// Configure CMake with:
8/// `-Dexperimental_adaptivecpp=ON -Dexperimental_genvectorx=ON`
9///
10/// The results are compared and checked
11/// The macro is divided in 3 parts:
12/// - testVector3D : tests of the 3D Vector classes
13/// - testPoint3D : tests of the 3D Point classes
14/// - testLorentzVector : tests of the 4D LorentzVector classes
15///
16/// \macro_code
17///
18/// \author Devajith Valaparambil Sreeramaswamy (CERN)
19
20#define ROOT_MATH_ARCH MathSYCL
21#define ROOT_MATH_SYCL
22
23#include "MathX/Vector3D.h"
24#include "MathX/Point3D.h"
25
26#include "MathX/Vector2D.h"
27#include "MathX/Point2D.h"
28
29#include "MathX/EulerAngles.h"
30
31#include "MathX/Transform3D.h"
32#include "MathX/Translation3D.h"
33
34#include "MathX/Rotation3D.h"
35#include "MathX/RotationX.h"
36#include "MathX/RotationY.h"
37#include "MathX/RotationZ.h"
38#include "MathX/Quaternion.h"
39#include "MathX/AxisAngle.h"
40#include "MathX/RotationZYX.h"
41
43#include "MathX/PtEtaPhiM4D.h"
44#include "MathX/LorentzVector.h"
45
46#include "MathX/VectorUtil.h"
47
48#include <sycl/sycl.hpp>
49
50#include <vector>
51
52using namespace ROOT::ROOT_MATH_ARCH;
54
58
63
64int ntest = 0;
65int nfail = 0;
66int ok = 0;
67
68int compare(double v1, double v2, double scale = 1.0)
69{
70 ntest = ntest + 1;
71
72 // numerical double limit for epsilon
73 double eps = scale * std::numeric_limits<double>::epsilon();
74 int iret = 0;
75 double delta = v2 - v1;
76 double d = 0;
77 if (delta < 0)
78 delta = -delta;
79 if (v1 == 0 || v2 == 0) {
80 if (delta > eps) {
81 iret = 1;
82 }
83 }
84 // skip case v1 or v2 is infinity
85 else {
86 d = v1;
87
88 if (v1 < 0)
89 d = -d;
90 // add also case when delta is small by default
91 if (delta / d > eps && delta > eps)
92 iret = 1;
93 }
94
95 return iret;
96}
97
98template <class Transform>
99bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
100{
101 // size should be an enum of the Transform class
102 std::vector<double> x1(size);
103 std::vector<double> x2(size);
104 t1.GetComponents(x1.begin(), x1.end());
105 t2.GetComponents(x2.begin(), x2.end());
106 bool ret = true;
107 unsigned int i = 0;
108 while (ret && i < size) {
109 // from TMath::AreEqualRel(x1,x2,2*eps)
110 bool areEqual =
111 std::abs(x1[i] - x2[i]) < std::numeric_limits<double>::epsilon() * (std::abs(x1[i]) + std::abs(x2[i]));
112 ret &= areEqual;
113 i++;
114 }
115 return ret;
116}
117
118int testVector3D()
119{
120 std::cout << "\n************************************************************************\n " << " Vector 3D Test"
121 << "\n************************************************************************\n";
122
123 sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
124 sycl::default_selector device_selector;
125 sycl::queue queue(device_selector);
126
127 {
128 queue.submit([&](sycl::handler &cgh) {
129 auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
130 cgh.single_task<class testVector3D>([=]() {
131 // test the vector tags
132
133 GlobalXYZVector vg(1., 2., 3.);
136
137 ok_device[0] += compare(vpg.R(), vg2.R());
138
139 // std::cout << vg2 << std::endl;
140
141 double r = vg.Dot(vpg);
142 ok_device[0] += compare(r, vg.Mag2());
143
144 GlobalXYZVector vcross = vg.Cross(vpg);
145 ok_device[0] += compare(vcross.R(), 0.0, 10);
146
147 // std::cout << vg.Dot(vpg) << std::endl;
148 // std::cout << vg.Cross(vpg) << std::endl;
149
151 ok_device[0] += compare(vg3.R(), 2 * vg.R());
152
154 ok_device[0] += compare(vg4.R(), 0.0, 10);
155 });
156 });
157 }
158
159 if (ok == 0)
160 std::cout << "\t\t OK " << std::endl;
161
162 return ok;
163}
164
165int testPoint3D()
166{
167 std::cout << "\n************************************************************************\n " << " Point 3D Tests"
168 << "\n************************************************************************\n";
169
170 sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
171 sycl::default_selector device_selector;
172 sycl::queue queue(device_selector);
173
174 {
175 queue.submit([&](sycl::handler &cgh) {
176 auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
177 cgh.single_task<class testPoint3D>([=]() {
178 // test the vector tags
179
180 GlobalXYZPoint pg(1., 2., 3.);
182
184
185 ok_device[0] += compare(ppg.R(), pg2.R());
186 // std::cout << pg2 << std::endl;
187
189
190 double r = pg.Dot(vg);
191 ok_device[0] += compare(r, pg.Mag2());
192
194 GlobalXYZPoint pcross = pg.Cross(vpg);
195 ok_device[0] += compare(pcross.R(), 0.0, 10);
196
198 ok_device[0] += compare(pg3.R(), 2 * pg.R());
199
201 ok_device[0] += compare(vg4.R(), 0.0, 10);
202
203 // operator -
204 XYZPoint q1(1., 2., 3.);
205 XYZPoint q2 = -1. * q1;
207 ok_device[0] += compare(XYZVector(q2) == v2, true);
208 });
209 });
210 }
211
212 if (ok == 0)
213 std::cout << "\t OK " << std::endl;
214
215 return ok;
216}
217
219{
220 std::cout << "\n************************************************************************\n "
221 << " Lorentz Vector Tests"
222 << "\n************************************************************************\n";
223
224 sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
225 sycl::default_selector device_selector;
226 sycl::queue queue(device_selector);
227
228 std::cout << "sycl::queue check - selected device:\n"
229 << queue.get_device().get_info<sycl::info::device::name>() << std::endl;
230
231 {
232 queue.submit([&](sycl::handler &cgh) {
233 auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
234 cgh.single_task<class testRotations3D>([=]() {
237 ok_device[0] += compare(v1.DeltaR(v2), 4.60575f);
238
240 ok_device[0] += compare(v.M(), 62.03058f);
241 });
242 });
243 }
244
245 if (ok == 0)
246 std::cout << "\tOK\n";
247 else
248 std::cout << "\t FAILED\n";
249
250 return ok;
251}
252
254{
255
256 testVector3D();
257 testPoint3D();
259
260 std::cout << "\n\nNumber of tests " << ntest << " failed = " << nfail << std::endl;
261}
#define d(i)
Definition RSha256.hxx:102
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Tag for identifying vectors based on a global coordinate system.
Tag for identifying vectors based on a local coordinate system.
Global Helper functions for generic Vector classes.
Definition VectorUtil.h:45
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Definition Vector3Dfwd.h:49
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)
auto * t1
Definition textangle.C:20