Skip to content

Commit 6bdffdd

Browse files
committed
[genvectorx] Add Invariant Masses test
1 parent 8bb0389 commit 6bdffdd

File tree

3 files changed

+106
-22
lines changed

3 files changed

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

0 commit comments

Comments
 (0)