From f3ccba8007dec8de88d7fed7172ef7c648756783 Mon Sep 17 00:00:00 2001 From: mdessole Date: Fri, 14 Nov 2025 10:44:10 +0100 Subject: [PATCH 1/3] [genvector] Change coordinate system --- math/genvector/test/testGenVector.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/genvector/test/testGenVector.cxx b/math/genvector/test/testGenVector.cxx index 2b3ebf38a786c..87585f3c97581 100644 --- a/math/genvector/test/testGenVector.cxx +++ b/math/genvector/test/testGenVector.cxx @@ -814,7 +814,7 @@ int testLorentzVector() iret |= compare(v1.DeltaR(v2), 4.60575f); // Result cross-validated using: // TLorentzVector t1, t2; - // t1.SetPtEtaPhiE(1,2,3,4); t2.SetPtEtaPhiE(5,6,7,8); + // t1.SetPtEtaPhiM(1,2,3,4); t2.SetPtEtaPhiM(5,6,7,8); // t1.DeltaR(t2) // test structured bindings From 8bb03892788dea60ad11acce46079bf091b4a0f2 Mon Sep 17 00:00:00 2001 From: mdessole Date: Fri, 14 Nov 2025 10:46:07 +0100 Subject: [PATCH 2/3] [genvectorx] Offload testLorentzVector to device --- .../genvectorx/test/testGenVectorSYCL.cxx | 87 ++++++++++++++----- math/genvector/test/testGenVector.cxx | 2 +- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/math/experimental/genvectorx/test/testGenVectorSYCL.cxx b/math/experimental/genvectorx/test/testGenVectorSYCL.cxx index d99921e7659c4..4511b6f01514c 100644 --- a/math/experimental/genvectorx/test/testGenVectorSYCL.cxx +++ b/math/experimental/genvectorx/test/testGenVectorSYCL.cxx @@ -105,12 +105,16 @@ int testVector3D() { int iret_host = 0; - std::cout << "testing Vector3D \t:\t"; + std::cout << "testing Vector3D \t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::default_selector device_selector; sycl::queue queue(device_selector); + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -167,12 +171,16 @@ int testPoint3D() int iret_host = 0; - std::cout << "testing Point3D \t:\t"; + std::cout << "testing Point3D \t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::default_selector device_selector; sycl::queue queue(device_selector); + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -240,12 +248,16 @@ int testVector2D() int iret_host = 0; - std::cout << "testing Vector2D \t:\t"; + std::cout << "testing Vector2D \t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::default_selector device_selector; sycl::queue queue(device_selector); + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -316,11 +328,15 @@ int testPoint2D() int iret_host = 0; - std::cout << "testing Point2D \t:\t"; + std::cout << "testing Point2D \t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::queue queue{sycl::default_selector_v}; + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -391,12 +407,16 @@ int testRotations3D() { int iret_host = 0; - std::cout << "testing 3D Rotations\t:\t"; + std::cout << "testing 3D Rotations\t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::default_selector device_selector; sycl::queue queue(device_selector); + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -529,12 +549,16 @@ int testTransform3D() { int iret_host = 0; - std::cout << "testing 3D Transform\t:\t"; + std::cout << "testing 3D Transform\t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::default_selector device_selector; sycl::queue queue(device_selector); + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -757,12 +781,16 @@ int testTransform3D() int testVectorUtil() { int iret_host = 0; - std::cout << "testing VectorUtil \t:\t"; + std::cout << "testing VectorUtil \t:\n"; sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); sycl::default_selector device_selector; sycl::queue queue(device_selector); + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + { queue.submit([&](sycl::handler &cgh) { auto iret = iret_buf.get_access(cgh); @@ -834,20 +862,39 @@ int testVectorUtil() int testLorentzVector() { - std::cout << "testing LorentzVector \t:\t"; - int iret = 0; - LorentzVector> v1(1, 2, 3, 4); - LorentzVector> v2(5, 6, 7, 8); - iret |= compare(v1.DeltaR(v2), 4.60575f); - // Result cross-validated using: - // TLorentzVector t1, t2; - // t1.SetPtEtaPhiE(1,2,3,4); t2.SetPtEtaPhiE(5,6,7,8); - // t1.DeltaR(t2) - if (iret == 0) - std::cout << "\t\t\tOK\n"; + int iret_host = 0; + std::cout << "testing LorentzVector \t:\n"; + + sycl::buffer iret_buf(&iret_host, sycl::range<1>(1)); + sycl::default_selector device_selector; + sycl::queue queue(device_selector); + + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() + << std::endl; + + { + queue.submit([&](sycl::handler &cgh) { + auto iret = iret_buf.get_access(cgh); + cgh.single_task([=]() { + LorentzVector> v1(1, 2, 3, 4); + LorentzVector> v2(5, 6, 7, 8); + iret[0] |= compare(v1.DeltaR(v2), 4.60575f); + + LorentzVector> v = v1+v2; + iret[0] |= compare(v.M(), 62.03058f); + + }); + }); + } + + if (iret_host == 0) + std::cout << "\tOK\n"; else - std::cout << "\t\t\t\t\t\tFAILED\n"; - return iret; + std::cout << "\t FAILED\n"; + + return iret_host; + } int testGenVector() diff --git a/math/genvector/test/testGenVector.cxx b/math/genvector/test/testGenVector.cxx index 87585f3c97581..1a4e73764aa44 100644 --- a/math/genvector/test/testGenVector.cxx +++ b/math/genvector/test/testGenVector.cxx @@ -816,7 +816,7 @@ int testLorentzVector() // TLorentzVector t1, t2; // t1.SetPtEtaPhiM(1,2,3,4); t2.SetPtEtaPhiM(5,6,7,8); // t1.DeltaR(t2) - + // test structured bindings auto const [x, y, z, E] = v1; iret |= (x != v1.X()); From 21a19d9fa44be1fa0cd9c0070e5367bc3e5b8bb3 Mon Sep 17 00:00:00 2001 From: mdessole Date: Fri, 14 Nov 2025 10:47:47 +0100 Subject: [PATCH 3/3] [genvectorx] Add Invariant Masses test --- .../genvectorx/test/CMakeLists.txt | 14 ++- .../genvectorx/test/testGenVectorSYCL.cxx | 28 ++--- .../test/testGenVectorSYCLInvMasses.cxx | 102 ++++++++++++++++++ 3 files changed, 122 insertions(+), 22 deletions(-) create mode 100644 math/experimental/genvectorx/test/testGenVectorSYCLInvMasses.cxx diff --git a/math/experimental/genvectorx/test/CMakeLists.txt b/math/experimental/genvectorx/test/CMakeLists.txt index c6fbe4aa55952..9030cc2bf1eea 100644 --- a/math/experimental/genvectorx/test/CMakeLists.txt +++ b/math/experimental/genvectorx/test/CMakeLists.txt @@ -8,14 +8,22 @@ ROOT_EXECUTABLE(testGenvectorSYCL testGenVectorSYCL.cxx) # LIBRARIES GenVectorSYCL) - if (oneapi) - target_link_options(testGenvectorSYCL PUBLIC -E) - endif() target_link_libraries(testGenvectorSYCL PUBLIC GenVectorSYCL ) add_sycl_to_root_target(TARGET testGenvectorSYCL SOURCES testGenVectorSYCL.cxx COMPILE_DEFINITIONS ROOT_MATH_SYCL DEPENDENCIES GenVectorSYCL ) + + + ROOT_EXECUTABLE(testGenvectorSYCLInvMasses testGenVectorSYCLInvMasses.cxx) # LIBRARIES GenVectorSYCL) + target_link_libraries(testGenvectorSYCLInvMasses PUBLIC GenVectorSYCL ) + add_sycl_to_root_target(TARGET testGenvectorSYCLInvMasses + SOURCES testGenvectorSYCLInvMasses.cxx + COMPILE_DEFINITIONS ROOT_MATH_SYCL + DEPENDENCIES GenVectorSYCL + ) + ROOT_ADD_TEST(test-genvector-genvectorsycl COMMAND testGenvectorSYCL) + ROOT_ADD_TEST(test-genvector-genvectorsyclinvmasses COMMAND testGenvectorSYCLInvMasses) diff --git a/math/experimental/genvectorx/test/testGenVectorSYCL.cxx b/math/experimental/genvectorx/test/testGenVectorSYCL.cxx index 4511b6f01514c..f5ee27ff4cf02 100644 --- a/math/experimental/genvectorx/test/testGenVectorSYCL.cxx +++ b/math/experimental/genvectorx/test/testGenVectorSYCL.cxx @@ -112,8 +112,7 @@ int testVector3D() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -178,8 +177,7 @@ int testPoint3D() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -255,8 +253,7 @@ int testVector2D() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -334,8 +331,7 @@ int testPoint2D() sycl::queue queue{sycl::default_selector_v}; std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -414,8 +410,7 @@ int testRotations3D() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -556,8 +551,7 @@ int testTransform3D() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -788,8 +782,7 @@ int testVectorUtil() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -870,8 +863,7 @@ int testLorentzVector() sycl::queue queue(device_selector); std::cout << "sycl::queue check - selected device:\n" - << queue.get_device().get_info() - << std::endl; + << queue.get_device().get_info() << std::endl; { queue.submit([&](sycl::handler &cgh) { @@ -881,9 +873,8 @@ int testLorentzVector() LorentzVector> v2(5, 6, 7, 8); iret[0] |= compare(v1.DeltaR(v2), 4.60575f); - LorentzVector> v = v1+v2; + LorentzVector> v = v1 + v2; iret[0] |= compare(v.M(), 62.03058f); - }); }); } @@ -894,7 +885,6 @@ int testLorentzVector() std::cout << "\t FAILED\n"; return iret_host; - } int testGenVector() diff --git a/math/experimental/genvectorx/test/testGenVectorSYCLInvMasses.cxx b/math/experimental/genvectorx/test/testGenVectorSYCLInvMasses.cxx new file mode 100644 index 0000000000000..61e0df407e19f --- /dev/null +++ b/math/experimental/genvectorx/test/testGenVectorSYCLInvMasses.cxx @@ -0,0 +1,102 @@ +#include "MathX/LorentzRotation.h" +#include "MathX/PtEtaPhiM4D.h" +#include "MathX/LorentzVector.h" + +#include "Math/LorentzRotation.h" +#include "Math/PtEtaPhiM4D.h" +#include "Math/LorentzVector.h" + +#include "MathX/GenVectorX/AccHeaders.h" + +#include + +#include + +using namespace ROOT::ROOT_MATH_ARCH; + +typedef LorentzVector> vec4dSYCL; +typedef ROOT::Math::LorentzVector> vec4d; + +template +vec4d *GenVectors(int n) +{ + vec4d *vectors = new vec4d[n]; + + // generate n -4 momentum quantities + for (int i = 0; i < n; ++i) { + // fill vectors + vectors[i] = {1., 1., 1., 1.}; + } + + return vectors; +} + +double *InvariantMassesSYCL(int N) +{ + sycl::default_selector device_selector; + sycl::queue queue(device_selector); + + auto v1 = GenVectors>>(N); + auto v2 = GenVectors>>(N); + double *invMasses = new double[N]; + + std::cout << "sycl::queue check - selected device:\n" + << queue.get_device().get_info() << std::endl; + + { + + vec4dSYCL *d_v1 = sycl::malloc_device(N, queue); + vec4dSYCL *d_v2 = sycl::malloc_device(N, queue); + double *d_invMasses = sycl::malloc_device(N, queue); + + queue.memcpy(d_v1, v1, N * sizeof(vec4dSYCL)); + queue.memcpy(d_v2, v2, N * sizeof(vec4dSYCL)); + queue.wait(); + + queue.submit([&](sycl::handler &cgh) { + cgh.parallel_for(sycl::range<1>(N), [=](sycl::id<1> indx) { + vec4dSYCL v = d_v2[indx] + d_v2[indx]; + d_invMasses[indx] = v.M(); + }); + }); + + queue.wait(); + queue.memcpy(invMasses, d_invMasses, N * sizeof(double)); + queue.wait(); + } + + return invMasses; +} + +double *InvariantMasses(int N) +{ + auto v1 = GenVectors>>(N); + auto v2 = GenVectors>>(N); + double *invMasses = new double[N]; + + for (int i = 0; i < N; i++) { + invMasses[i] = (v1[i] + v2[i]).M(); + } + + return invMasses; +} + +int main() +{ + int n = 128; + std::cout << "testing Invariant Masses Computation \t:\n"; + double *msycl = InvariantMassesSYCL(n); + double *m = InvariantMasses(n); + + int iret = 0; + + for (int i = 0; i < n; i++) { + iret += (std::abs(msycl[i] - m[i]) > 1e-5); + } + + if (iret) + std::cerr << "\t\t\t\t\t FAILED\n " << std::endl; + else + std::cout << "\t\t\t\t\t OK\n " << std::endl; + return iret; +}