Skip to content

Commit 21a19d9

Browse files
committed
[genvectorx] Add Invariant Masses test
1 parent 8bb0389 commit 21a19d9

File tree

3 files changed

+122
-22
lines changed

3 files changed

+122
-22
lines changed

math/experimental/genvectorx/test/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88

99

1010
ROOT_EXECUTABLE(testGenvectorSYCL testGenVectorSYCL.cxx) # LIBRARIES GenVectorSYCL)
11-
if (oneapi)
12-
target_link_options(testGenvectorSYCL PUBLIC -E)
13-
endif()
1411
target_link_libraries(testGenvectorSYCL PUBLIC GenVectorSYCL )
1512
add_sycl_to_root_target(TARGET testGenvectorSYCL
1613
SOURCES testGenVectorSYCL.cxx
1714
COMPILE_DEFINITIONS ROOT_MATH_SYCL
1815
DEPENDENCIES GenVectorSYCL
1916
)
17+
18+
19+
ROOT_EXECUTABLE(testGenvectorSYCLInvMasses testGenVectorSYCLInvMasses.cxx) # LIBRARIES GenVectorSYCL)
20+
target_link_libraries(testGenvectorSYCLInvMasses PUBLIC GenVectorSYCL )
21+
add_sycl_to_root_target(TARGET testGenvectorSYCLInvMasses
22+
SOURCES testGenvectorSYCLInvMasses.cxx
23+
COMPILE_DEFINITIONS ROOT_MATH_SYCL
24+
DEPENDENCIES GenVectorSYCL
25+
)
26+
2027
ROOT_ADD_TEST(test-genvector-genvectorsycl COMMAND testGenvectorSYCL)
28+
ROOT_ADD_TEST(test-genvector-genvectorsyclinvmasses COMMAND testGenvectorSYCLInvMasses)
2129

math/experimental/genvectorx/test/testGenVectorSYCL.cxx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ int testVector3D()
112112
sycl::queue queue(device_selector);
113113

114114
std::cout << "sycl::queue check - selected device:\n"
115-
<< queue.get_device().get_info<sycl::info::device::name>()
116-
<< std::endl;
115+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
117116

118117
{
119118
queue.submit([&](sycl::handler &cgh) {
@@ -178,8 +177,7 @@ int testPoint3D()
178177
sycl::queue queue(device_selector);
179178

180179
std::cout << "sycl::queue check - selected device:\n"
181-
<< queue.get_device().get_info<sycl::info::device::name>()
182-
<< std::endl;
180+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
183181

184182
{
185183
queue.submit([&](sycl::handler &cgh) {
@@ -255,8 +253,7 @@ int testVector2D()
255253
sycl::queue queue(device_selector);
256254

257255
std::cout << "sycl::queue check - selected device:\n"
258-
<< queue.get_device().get_info<sycl::info::device::name>()
259-
<< std::endl;
256+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
260257

261258
{
262259
queue.submit([&](sycl::handler &cgh) {
@@ -334,8 +331,7 @@ int testPoint2D()
334331
sycl::queue queue{sycl::default_selector_v};
335332

336333
std::cout << "sycl::queue check - selected device:\n"
337-
<< queue.get_device().get_info<sycl::info::device::name>()
338-
<< std::endl;
334+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
339335

340336
{
341337
queue.submit([&](sycl::handler &cgh) {
@@ -414,8 +410,7 @@ int testRotations3D()
414410
sycl::queue queue(device_selector);
415411

416412
std::cout << "sycl::queue check - selected device:\n"
417-
<< queue.get_device().get_info<sycl::info::device::name>()
418-
<< std::endl;
413+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
419414

420415
{
421416
queue.submit([&](sycl::handler &cgh) {
@@ -556,8 +551,7 @@ int testTransform3D()
556551
sycl::queue queue(device_selector);
557552

558553
std::cout << "sycl::queue check - selected device:\n"
559-
<< queue.get_device().get_info<sycl::info::device::name>()
560-
<< std::endl;
554+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
561555

562556
{
563557
queue.submit([&](sycl::handler &cgh) {
@@ -788,8 +782,7 @@ int testVectorUtil()
788782
sycl::queue queue(device_selector);
789783

790784
std::cout << "sycl::queue check - selected device:\n"
791-
<< queue.get_device().get_info<sycl::info::device::name>()
792-
<< std::endl;
785+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
793786

794787
{
795788
queue.submit([&](sycl::handler &cgh) {
@@ -870,8 +863,7 @@ int testLorentzVector()
870863
sycl::queue queue(device_selector);
871864

872865
std::cout << "sycl::queue check - selected device:\n"
873-
<< queue.get_device().get_info<sycl::info::device::name>()
874-
<< std::endl;
866+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
875867

876868
{
877869
queue.submit([&](sycl::handler &cgh) {
@@ -881,9 +873,8 @@ int testLorentzVector()
881873
LorentzVector<PtEtaPhiM4D<float>> v2(5, 6, 7, 8);
882874
iret[0] |= compare(v1.DeltaR(v2), 4.60575f);
883875

884-
LorentzVector<PtEtaPhiM4D<float>> v = v1+v2;
876+
LorentzVector<PtEtaPhiM4D<float>> v = v1 + v2;
885877
iret[0] |= compare(v.M(), 62.03058f);
886-
887878
});
888879
});
889880
}
@@ -894,7 +885,6 @@ int testLorentzVector()
894885
std::cout << "\t FAILED\n";
895886

896887
return iret_host;
897-
898888
}
899889

900890
int testGenVector()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "MathX/LorentzRotation.h"
2+
#include "MathX/PtEtaPhiM4D.h"
3+
#include "MathX/LorentzVector.h"
4+
5+
#include "Math/LorentzRotation.h"
6+
#include "Math/PtEtaPhiM4D.h"
7+
#include "Math/LorentzVector.h"
8+
9+
#include "MathX/GenVectorX/AccHeaders.h"
10+
11+
#include <sycl/sycl.hpp>
12+
13+
#include <vector>
14+
15+
using namespace ROOT::ROOT_MATH_ARCH;
16+
17+
typedef LorentzVector<PtEtaPhiM4D<double>> vec4dSYCL;
18+
typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>> vec4d;
19+
20+
template <class vec4d>
21+
vec4d *GenVectors(int n)
22+
{
23+
vec4d *vectors = new vec4d[n];
24+
25+
// generate n -4 momentum quantities
26+
for (int i = 0; i < n; ++i) {
27+
// fill vectors
28+
vectors[i] = {1., 1., 1., 1.};
29+
}
30+
31+
return vectors;
32+
}
33+
34+
double *InvariantMassesSYCL(int N)
35+
{
36+
sycl::default_selector device_selector;
37+
sycl::queue queue(device_selector);
38+
39+
auto v1 = GenVectors<LorentzVector<PtEtaPhiM4D<double>>>(N);
40+
auto v2 = GenVectors<LorentzVector<PtEtaPhiM4D<double>>>(N);
41+
double *invMasses = new double[N];
42+
43+
std::cout << "sycl::queue check - selected device:\n"
44+
<< queue.get_device().get_info<sycl::info::device::name>() << std::endl;
45+
46+
{
47+
48+
vec4dSYCL *d_v1 = sycl::malloc_device<vec4dSYCL>(N, queue);
49+
vec4dSYCL *d_v2 = sycl::malloc_device<vec4dSYCL>(N, queue);
50+
double *d_invMasses = sycl::malloc_device<double>(N, queue);
51+
52+
queue.memcpy(d_v1, v1, N * sizeof(vec4dSYCL));
53+
queue.memcpy(d_v2, v2, N * sizeof(vec4dSYCL));
54+
queue.wait();
55+
56+
queue.submit([&](sycl::handler &cgh) {
57+
cgh.parallel_for(sycl::range<1>(N), [=](sycl::id<1> indx) {
58+
vec4dSYCL v = d_v2[indx] + d_v2[indx];
59+
d_invMasses[indx] = v.M();
60+
});
61+
});
62+
63+
queue.wait();
64+
queue.memcpy(invMasses, d_invMasses, N * sizeof(double));
65+
queue.wait();
66+
}
67+
68+
return invMasses;
69+
}
70+
71+
double *InvariantMasses(int N)
72+
{
73+
auto v1 = GenVectors<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>>>(N);
74+
auto v2 = GenVectors<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>>>(N);
75+
double *invMasses = new double[N];
76+
77+
for (int i = 0; i < N; i++) {
78+
invMasses[i] = (v1[i] + v2[i]).M();
79+
}
80+
81+
return invMasses;
82+
}
83+
84+
int main()
85+
{
86+
int n = 128;
87+
std::cout << "testing Invariant Masses Computation \t:\n";
88+
double *msycl = InvariantMassesSYCL(n);
89+
double *m = InvariantMasses(n);
90+
91+
int iret = 0;
92+
93+
for (int i = 0; i < n; i++) {
94+
iret += (std::abs(msycl[i] - m[i]) > 1e-5);
95+
}
96+
97+
if (iret)
98+
std::cerr << "\t\t\t\t\t FAILED\n " << std::endl;
99+
else
100+
std::cout << "\t\t\t\t\t OK\n " << std::endl;
101+
return iret;
102+
}

0 commit comments

Comments
 (0)