Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
76a8f9d
Template the GenVector Plane3D, Transform3D and Translation3D classes…
cjones051073 Feb 25, 2017
7e9c2b7
Use the 'using namespace std' trick with Cartesian3D and Plane3D to f…
cjones051073 Feb 25, 2017
b15d62a
Extend the 'using namespace std' trick to a few more classes
cjones051073 Feb 25, 2017
2b2fc17
Change class to typename
cjones051073 Feb 25, 2017
2e74f0d
Explicitly cast some constants to the scalar type (needed for Vc types)
cjones051073 Feb 25, 2017
c3175c6
Remove empty implementation files
cjones051073 Feb 25, 2017
9bdfb8e
Template the Boost classes
cjones051073 Feb 25, 2017
c97245c
Remove empty implementation files for Boost classes
cjones051073 Feb 25, 2017
f12d368
Clean up some indentations
cjones051073 Feb 25, 2017
bbbbbd0
Add some missing template types to the Boost classes
cjones051073 Feb 25, 2017
9a0ee77
Remove empty Boost implementation file
cjones051073 Feb 25, 2017
371d50d
Small cleanups
cjones051073 Feb 25, 2017
dcb0b30
Clean up some initialisations
cjones051073 Feb 25, 2017
29e7e30
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Feb 27, 2017
14e73b4
Add Scalar/Vector Plane3D::Normalise() methods using SFINAE
cjones051073 Feb 27, 2017
27bbb57
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Feb 27, 2017
196a00b
Roll back some changes for now, as they are causing problems in the t…
cjones051073 Feb 27, 2017
0ad5828
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Feb 27, 2017
1928c75
Add specific vectorised implementations of a few methods
cjones051073 Feb 28, 2017
5ccdaea
Extend ostream operator for Displacement and Position vectors to supp…
cjones051073 Feb 28, 2017
ef1aea9
Fix the vector abs method (not fabs) and Vector Unit() for vectorised…
cjones051073 Feb 28, 2017
6cac16a
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Feb 28, 2017
68ba28a
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 1, 2017
939b7cb
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 4, 2017
d9b810b
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 6, 2017
776ce1a
Add override qualifier
cjones051073 Mar 6, 2017
fbe74d2
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 10, 2017
12b43b0
Fix initialisation bug
cjones051073 Mar 10, 2017
8367bdf
remove space
cjones051073 Mar 10, 2017
0f404ba
Some small changes following review comments
cjones051073 Mar 10, 2017
65a701d
remove spaces
cjones051073 Mar 10, 2017
4ba8a1b
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 10, 2017
ff94a5a
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 11, 2017
b8ca822
Fix formatting using clang-format
cjones051073 Mar 11, 2017
b32cb6a
some more 'using namespace std' updates
cjones051073 Mar 11, 2017
febe783
Fix more clang format issues
cjones051073 Mar 11, 2017
a628a2a
fix (hopefully) one more clang format issue
cjones051073 Mar 11, 2017
89b2d26
clang format is picky...
cjones051073 Mar 11, 2017
6bf0368
Merge branch 'master' of github.com:root-mirror/root into GenVector-A…
cjones051073 Mar 11, 2017
bd96bd0
revert changes in VectorUtils.h
cjones051073 Mar 13, 2017
dea8d05
Add new test for GenVector with Vc types
cjones051073 Mar 13, 2017
a18221a
extend test to 96 photons
cjones051073 Mar 13, 2017
eb0b8ed
reorder headers
cjones051073 Mar 13, 2017
7da1945
remove comment that number of test photons must be multiple of 8, as …
cjones051073 Mar 13, 2017
a271eab
Add <cmath> header includes
cjones051073 Mar 13, 2017
decbe11
revert back to using std:: as it seems to cause issues with gcc build…
cjones051073 Mar 14, 2017
58c6315
Include Vc before ROOT in test application. Needed for std:: support...
cjones051073 Mar 14, 2017
17f42a3
Add some more missing std::
cjones051073 Mar 14, 2017
434396d
More math updates
cjones051073 Mar 14, 2017
b145899
Change enable_if implementation in GenVector
cjones051073 Mar 14, 2017
ad8d3a5
update comment
cjones051073 Mar 14, 2017
b018a03
Extend the GenVector Vc test with a timing test that asserts that the…
cjones051073 Mar 14, 2017
bb1e386
add fabs on timing diff and extend Vc genvector expected diff to 25%
cjones051073 Mar 14, 2017
1786383
do not return a failure from the Vc speed test, as test could be run …
cjones051073 Mar 14, 2017
380dd35
Update enable_if pattern in GenVector Vc test
cjones051073 Mar 15, 2017
ccd81f3
resolve conflicts
cjones051073 Mar 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extend the GenVector Vc test with a timing test that asserts that the…
… expect speed up based on the SIMD register size is observed (with 10% safety factor)
  • Loading branch information
cjones051073 committed Mar 14, 2017
commit b018a039c306f86a6e882f38fee676a75b6def8f
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ if(ROOT_vc_FOUND)
ROOT_ADD_CXX_FLAG(vc_flags -Wno-mismatched-tags)
ROOT_ADD_CXX_FLAG(vc_flags -Wno-undefined-var-template)
set_source_files_properties(testGenVectorVc.cxx PROPERTIES COMPILE_FLAGS "${vc_flags}")
ROOT_EXECUTABLE(testGenVectorVc testGenVectorVc.cxx LIBRARIES GenVector ${Vc_LIBRARIES} BUILTINS Vc)
ROOT_EXECUTABLE(testGenVectorVc testGenVectorVc.cxx LIBRARIES Physics GenVector ${Vc_LIBRARIES} BUILTINS Vc)
ROOT_ADD_TEST(test-GenVector-Vc COMMAND testGenVectorVc FAILREGEX "FAILED|Error in")
endif()

Expand Down
232 changes: 146 additions & 86 deletions test/testGenVectorVc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Math/GenVector/DisplacementVector3D.h"
#include "Math/GenVector/Plane3D.h"
#include "Math/GenVector/Transform3D.h"
#include "TStopwatch.h"

// STL
#include <random>
Expand Down Expand Up @@ -203,97 +204,156 @@ int main(int /*argc*/, char ** /*argv*/)
{
int ret = 0;

const unsigned int nPhotons = 100;
std::cout << "Creating " << nPhotons << " random photons ..." << std::endl;

// Scalar Types
Data<Point<double>, Vector<double>, Plane<double>, double>::Vector scalar_data(nPhotons);

// Vc Types
Data<Point<Vc::double_v>, Vector<Vc::double_v>, Plane<Vc::double_v>, Vc::double_v>::Vector vc_data;
// Clone the exact random values from the Scalar vector
// Note we are making the same number of entries in the container, but each entry is a vector entry
// with Vc::double_t::Size entries.
fill(scalar_data, vc_data);

// Loop over the two containers and compare
std::cout << "Ray Tracing :-" << std::endl;
for (size_t i = 0; i < nPhotons; ++i) {
auto &sc = scalar_data[i];
auto &vc = vc_data[i];

// ray tracing
reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius);
reflectPlane(sc.position, sc.direction, sc.plane);
reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius);
reflectPlane(vc.position, vc.direction, vc.plane);

std::cout << "Position " << sc.position << " " << vc.position << std::endl;
std::cout << "Direction " << sc.direction << " " << vc.direction << std::endl;

for (std::size_t j = 0; j < Vc::double_v::Size; ++j) {
ret |= compare(sc.position.x(), vc.position.x()[j]);
ret |= compare(sc.position.y(), vc.position.y()[j]);
ret |= compare(sc.position.z(), vc.position.z()[j]);
ret |= compare(sc.direction.x(), vc.direction.x()[j]);
ret |= compare(sc.direction.y(), vc.direction.y()[j]);
ret |= compare(sc.direction.z(), vc.direction.z()[j]);
{

const unsigned int nPhotons = 100;
std::cout << "Creating " << nPhotons << " random photons ..." << std::endl;

// Scalar Types
Data<Point<double>, Vector<double>, Plane<double>, double>::Vector scalar_data(nPhotons);

// Vc Types
Data<Point<Vc::double_v>, Vector<Vc::double_v>, Plane<Vc::double_v>, Vc::double_v>::Vector vc_data;
// Clone the exact random values from the Scalar vector
// Note we are making the same number of entries in the container, but each entry is a vector entry
// with Vc::double_t::Size entries.
fill(scalar_data, vc_data);

// Loop over the two containers and compare
std::cout << "Ray Tracing :-" << std::endl;
for (size_t i = 0; i < nPhotons; ++i) {
auto &sc = scalar_data[i];
auto &vc = vc_data[i];

// ray tracing
reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius);
reflectPlane(sc.position, sc.direction, sc.plane);
reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius);
reflectPlane(vc.position, vc.direction, vc.plane);

std::cout << "Position " << sc.position << " " << vc.position << std::endl;
std::cout << "Direction " << sc.direction << " " << vc.direction << std::endl;

for (std::size_t j = 0; j < Vc::double_v::Size; ++j) {
ret |= compare(sc.position.x(), vc.position.x()[j]);
ret |= compare(sc.position.y(), vc.position.y()[j]);
ret |= compare(sc.position.z(), vc.position.z()[j]);
ret |= compare(sc.direction.x(), vc.direction.x()[j]);
ret |= compare(sc.direction.y(), vc.direction.y()[j]);
ret |= compare(sc.direction.z(), vc.direction.z()[j]);
}
}

// Now test Transformation3D
std::cout << "Transforms :-" << std::endl;
for (size_t i = 0; i < nPhotons; ++i) {
auto &sc = scalar_data[i];
auto &vc = vc_data[i];

// make 6 random scalar Points
Point<double> sp1(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp2(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp3(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp4(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp5(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp6(p_x(gen), p_y(gen), p_z(gen));
// clone to Vc versions
Point<Vc::double_v> vp1(sp1.x(), sp1.y(), sp1.z());
Point<Vc::double_v> vp2(sp2.x(), sp2.y(), sp2.z());
Point<Vc::double_v> vp3(sp3.x(), sp3.y(), sp3.z());
Point<Vc::double_v> vp4(sp4.x(), sp4.y(), sp4.z());
Point<Vc::double_v> vp5(sp5.x(), sp5.y(), sp5.z());
Point<Vc::double_v> vp6(sp6.x(), sp6.y(), sp6.z());

// Make transformations from points
// note warnings about axis not having the same angles expected here...
// point is to check scalar and vector versions do the same thing
ROOT::Math::Impl::Transform3D<double> st(sp1, sp2, sp3, sp4, sp5, sp6);
ROOT::Math::Impl::Transform3D<Vc::double_v> vt(vp1, vp2, vp3, vp4, vp5, vp6);

// transform the vectors
const auto sv = st * sc.direction;
const auto vv = vt * vc.direction;
std::cout << "Transformed Direction " << sv << " " << vv << std::endl;

// invert the transformations
st.Invert();
vt.Invert();

// Move the points back
const auto sv_i = st * sv;
const auto vv_i = vt * vv;
std::cout << "Transformed Back Direction " << sc.direction << " " << sv_i << " " << vv_i << std::endl;

for (std::size_t j = 0; j < Vc::double_v::Size; ++j) {
ret |= compare(sv.x(), vv.x()[j]);
ret |= compare(sv.y(), vv.y()[j]);
ret |= compare(sv.z(), vv.z()[j]);
ret |= compare(sc.direction.x(), vv_i.x()[j]);
ret |= compare(sc.direction.y(), vv_i.y()[j]);
ret |= compare(sc.direction.z(), vv_i.z()[j]);
}

ret |= compare(sc.direction.x(), sv_i.x());
ret |= compare(sc.direction.y(), sv_i.y());
ret |= compare(sc.direction.z(), sv_i.z());
}
}

// Now test Transformation3D
std::cout << "Transforms :-" << std::endl;
for (size_t i = 0; i < nPhotons; ++i) {
auto &sc = scalar_data[i];
auto &vc = vc_data[i];

// make 6 random scalar Points
Point<double> sp1(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp2(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp3(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp4(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp5(p_x(gen), p_y(gen), p_z(gen));
Point<double> sp6(p_x(gen), p_y(gen), p_z(gen));
// clone to Vc versions
Point<Vc::double_v> vp1(sp1.x(), sp1.y(), sp1.z());
Point<Vc::double_v> vp2(sp2.x(), sp2.y(), sp2.z());
Point<Vc::double_v> vp3(sp3.x(), sp3.y(), sp3.z());
Point<Vc::double_v> vp4(sp4.x(), sp4.y(), sp4.z());
Point<Vc::double_v> vp5(sp5.x(), sp5.y(), sp5.z());
Point<Vc::double_v> vp6(sp6.x(), sp6.y(), sp6.z());

// Make transformations from points
// note warnings about axis not having the same angles expected here...
// point is to check scalar and vector versions do the same thing
ROOT::Math::Impl::Transform3D<double> st(sp1, sp2, sp3, sp4, sp5, sp6);
ROOT::Math::Impl::Transform3D<Vc::double_v> vt(vp1, vp2, vp3, vp4, vp5, vp6);

// transform the vectors
const auto sv = st * sc.direction;
const auto vv = vt * vc.direction;
std::cout << "Transformed Direction " << sv << " " << vv << std::endl;

// invert the transformations
st.Invert();
vt.Invert();

// Move the points back
const auto sv_i = st * sv;
const auto vv_i = vt * vv;
std::cout << "Transformed Back Direction " << sc.direction << " " << sv_i << " " << vv_i << std::endl;

for (std::size_t j = 0; j < Vc::double_v::Size; ++j) {
ret |= compare(sv.x(), vv.x()[j]);
ret |= compare(sv.y(), vv.y()[j]);
ret |= compare(sv.z(), vv.z()[j]);
ret |= compare(sc.direction.x(), vv_i.x()[j]);
ret |= compare(sc.direction.y(), vv_i.y()[j]);
ret |= compare(sc.direction.z(), vv_i.z()[j]);
// now run some timing tests
{
const unsigned int nPhotons = 96000; // Must be multiple of 16 to avoid padding issues below...

const unsigned int nTests = 1000; // number of tests to run

// scalar data
Data<Point<double>, Vector<double>, Plane<double>, double>::Vector scalar_data(nPhotons);
// vector data with total equal number of photons (including vectorised size)
Data<Point<Vc::double_v>, Vector<Vc::double_v>, Plane<Vc::double_v>, Vc::double_v>::Vector vc_data(
nPhotons / Vc::double_v::Size);

TStopwatch t;

double best_time_scalar{9e30}, best_time_vector{9e30};

// time the scalar implementation
for (unsigned int i = 0; i < nTests; ++i) {
t.Start();
for (auto &sc : scalar_data) {
reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius);
reflectPlane(sc.position, sc.direction, sc.plane);
}
t.Stop();
const auto time = t.RealTime();
if (time < best_time_scalar) {
best_time_scalar = time;
}
}

ret |= compare(sc.direction.x(), sv_i.x());
ret |= compare(sc.direction.y(), sv_i.y());
ret |= compare(sc.direction.z(), sv_i.z());
// time the Vc implementation
for (unsigned int i = 0; i < nTests; ++i) {
t.Start();
for (auto &vc : vc_data) {
reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius);
reflectPlane(vc.position, vc.direction, vc.plane);
}
t.Stop();
const auto time = t.RealTime();
if (time < best_time_vector) {
best_time_vector = time;
}
}

std::cout << "Scalar best time = " << best_time_scalar << std::endl;
std::cout << "Vectorised Vc best time = " << best_time_vector << std::endl;
std::cout << "Vectorised Vc SIMD size = " << Vc::double_v::Size << std::endl;
std::cout << "Vectorised Vc speedup = " << best_time_scalar / best_time_vector << std::endl;

// assert that the vector time is roughly Vc::double_v::Size times smaller than the scalar time
// allow 10% for 'safety'
if ((best_time_vector * Vc::double_v::Size) - best_time_scalar > 0.1 * best_time_scalar) {
++ret;
}
}

if (ret)
Expand Down