#define ROOT_MATH_ARCH MathSYCL
#define ROOT_MATH_SYCL
#include <sycl/sycl.hpp>
#include <vector>
int ntest = 0;
int nfail = 0;
int ok = 0;
int compare(
double v1,
double v2,
double scale = 1.0)
{
ntest = ntest + 1;
double eps = scale * std::numeric_limits<double>::epsilon();
int iret = 0;
if (delta < 0)
delta = -delta;
if (
v1 == 0 ||
v2 == 0) {
if (delta > eps) {
iret = 1;
}
}
else {
if (delta /
d > eps && delta > eps)
iret = 1;
}
return iret;
}
template <class Transform>
bool IsEqual(
const Transform &
t1,
const Transform &t2,
unsigned int size)
{
std::vector<double> x1(
size);
std::vector<double> x2(
size);
t1.GetComponents(x1.begin(), x1.end());
t2.GetComponents(x2.begin(), x2.end());
unsigned int i = 0;
std::abs(x1[i] - x2[i]) < std::numeric_limits<double>::epsilon() * (std::abs(x1[i]) + std::abs(x2[i]));
i++;
}
}
int testVector3D()
{
std::cout << "\n************************************************************************\n " << " Vector 3D Test"
<< "\n************************************************************************\n";
sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
sycl::default_selector device_selector;
sycl::queue queue(device_selector);
{
queue.submit([&](sycl::handler &cgh) {
auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
cgh.single_task<class testVector3D>([=]() {
GlobalXYZVector vg(1., 2., 3.);
GlobalXYZVector vg2(vg);
GlobalPolar3DVector vpg(vg);
ok_device[0] += compare(vpg.R(), vg2.R());
ok_device[0] += compare(
r, vg.Mag2());
GlobalXYZVector vcross = vg.Cross(vpg);
ok_device[0] += compare(vcross.R(), 0.0, 10);
GlobalXYZVector vg3 = vg + vpg;
ok_device[0] += compare(vg3.R(), 2 * vg.R());
GlobalXYZVector vg4 = vg - vpg;
ok_device[0] += compare(vg4.R(), 0.0, 10);
});
});
}
if (ok == 0)
std::cout << "\t\t OK " << std::endl;
return ok;
}
int testPoint3D()
{
std::cout << "\n************************************************************************\n " << " Point 3D Tests"
<< "\n************************************************************************\n";
sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
sycl::default_selector device_selector;
sycl::queue queue(device_selector);
{
queue.submit([&](sycl::handler &cgh) {
auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
cgh.single_task<class testPoint3D>([=]() {
GlobalXYZPoint pg(1., 2., 3.);
GlobalXYZPoint pg2(pg);
GlobalPolar3DPoint ppg(pg);
ok_device[0] += compare(ppg.R(), pg2.R());
GlobalXYZVector vg(pg);
ok_device[0] += compare(
r, pg.Mag2());
GlobalPolar3DVector vpg(pg);
GlobalXYZPoint pcross = pg.Cross(vpg);
ok_device[0] += compare(pcross.R(), 0.0, 10);
GlobalPolar3DPoint pg3 = ppg + vg;
ok_device[0] += compare(pg3.R(), 2 * pg.R());
GlobalXYZVector vg4 = pg - ppg;
ok_device[0] += compare(vg4.R(), 0.0, 10);
});
});
}
if (ok == 0)
std::cout << "\t OK " << std::endl;
return ok;
}
int testLorentzVector()
{
std::cout << "\n************************************************************************\n "
<< " Lorentz Vector Tests"
<< "\n************************************************************************\n";
sycl::buffer<int, 1> ok_buf(&ok, 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<sycl::info::device::name>() << std::endl;
{
queue.submit([&](sycl::handler &cgh) {
auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
cgh.single_task<class testRotations3D>([=]() {
ok_device[0] += compare(
v1.DeltaR(
v2), 4.60575f);
ok_device[0] += compare(
v.M(), 62.03058f);
});
});
}
if (ok == 0)
std::cout << "\tOK\n";
else
std::cout << "\t FAILED\n";
return ok;
}
void mathcoreGenVectorSYCL()
{
testVector3D();
testPoint3D();
testLorentzVector();
std::cout << "\n\nNumber of tests " << ntest << " failed = " << nfail << std::endl;
}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Class describing a generic displacement vector in 3 dimensions.
Tag for identifying vectors based on a global coordinate system.
Tag for identifying vectors based on a local coordinate system.
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Class describing a generic position vector (point) in 3 dimensions.
Global Helper functions for generic Vector classes.
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZPoint
3D Point based on the cartesian coordinates x,y,z in double precision
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)