Commit 02653328 authored by incardon's avatar incardon
Browse files

Adding GPU test

parent 64447c56
......@@ -331,9 +331,9 @@ class Graph_CSR
{
// If v1 and v2 does not satisfy some criteria return
if (CheckPolicy::valid(v1, v.size()) == false)
return NO_EDGE;
return (size_t)NO_EDGE;
if (CheckPolicy::valid(v2, v.size()) == false)
return NO_EDGE;
return (size_t)NO_EDGE;
// get the number of adjacent vertex
size_t id_x_end = v_l.template get<0>(v1);
......
......@@ -10,6 +10,8 @@
#include <boost/test/unit_test.hpp>
#include "Grid/map_grid.hpp"
#include "Point_test.hpp"
#include "Grid/grid_util_test.hpp"
#include "cuda_grid_unit_tests_func.cuh"
BOOST_AUTO_TEST_SUITE( grid_gpu_func_test )
......@@ -94,4 +96,275 @@ BOOST_AUTO_TEST_CASE (gpu_computation_func)
}
BOOST_AUTO_TEST_CASE (gpu_computation)
{
#ifdef CUDA_GPU
{
size_t sz[3] = {64,64,64};
grid_gpu<3, Point_test<float> > c3(sz);
c3.setMemory();
test_layout_gridNd<3>(c3,sz[0]);
gpu_grid_3D_compute(c3);
c3.deviceToHost<0>();
auto it = c3.getIterator();
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c3.getGrid().LinId(key) == c3.template get<0>(key);
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
#endif
}
BOOST_AUTO_TEST_CASE (gpu_computation_stencil)
{
#ifdef CUDA_GPU
{
size_t sz[3] = {64,64,64};
grid_gpu<3, Point_test<float> > c3(sz);
grid_gpu<3, Point_test<float> > c2(sz);
grid_key_dx<3> key1({1,1,1});
grid_key_dx<3> key2({62,62,62});
c3.setMemory();
c2.setMemory();
test_layout_gridNd<3>(c3,sz[0]);
test_layout_gridNd<3>(c2,sz[0]);
gpu_grid_3D_one(c2);
// Check property 1 is 1.0
c2.deviceToHost<0>();
{
auto it = c2.getIterator();
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c2.get<0>(key) == 1.0;
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
gpu_grid_3D_compute(c3);
c3.deviceToHost<0>();
{
auto it = c3.getIterator();
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c3.getGrid().LinId(key) == c3.get<0>(key);
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
gpu_grid_3D_compute_stencil(c3,c2,key1,key2);
c2.deviceToHost<0>();
auto it = c2.getIterator(key1,key2);
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c2.get<0>(key) == 0;
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
#endif
}
BOOST_AUTO_TEST_CASE (gpu_computation_grid_stencil)
{
#ifdef CUDA_GPU
{
size_t sz[3] = {64,64,64};
grid_gpu<3, Point_test<float> > c3(sz);
grid_gpu<3, Point_test<float> > c2(sz);
grid_key_dx<3> key1({1,1,1});
grid_key_dx<3> zero({0,0,0});
grid_key_dx<3> key2({62,62,62});
grid_key_dx<3> keyl({63,63,63});
c3.setMemory();
c2.setMemory();
test_layout_gridNd<3>(c3,sz[0]);
test_layout_gridNd<3>(c2,sz[0]);
gpu_grid_3D_one(c2);
// Check property 1 is 1.0
c2.deviceToHost<0>();
{
auto it = c2.getIterator();
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c2.get<0>(key) == 1.0;
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
gpu_grid_3D_compute(c3);
c3.deviceToHost<0>();
{
auto it = c3.getIterator();
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c3.getGrid().LinId(key) == c3.get<0>(key);
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
gpu_grid_3D_compute_grid_stencil(c3,c2,key1,key2);
c2.deviceToHost<0>();
auto it = c2.getIterator(key1,key2);
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c2.get<0>(key) == 0;
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
// We also try to fill a vectorial quantity
gpu_grid_fill_vector(c3,zero,keyl);
}
#endif
}
BOOST_AUTO_TEST_CASE (gpu_computation_grid_stencil_vector)
{
#ifdef CUDA_GPU
{
size_t sz[3] = {64,64,64};
grid_gpu<3, Point_test<float> > c3(sz);
grid_gpu<3, Point_test<float> > c2(sz);
grid_key_dx<3> key1({1,1,1});
grid_key_dx<3> zero({0,0,0});
grid_key_dx<3> key2({62,62,62});
grid_key_dx<3> keyl({63,63,63});
c3.setMemory();
c2.setMemory();
gpu_grid_fill_vector(c3,zero,keyl);
// Check property 1 is 1.0
c3.deviceToHost<4>();
{
auto it = c3.getIterator(key1,key2);
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c3.get<4>(key)[0] == 1.0;
good &= c3.get<4>(key)[1] == 2.0;
good &= c3.get<4>(key)[2] == 3.0;
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
// Fill c3
gpu_grid_3D_compute(c3);
gpu_grid_gradient_vector(c3,c2,key1,key2);
// Check property 1 is 1.0
c2.deviceToHost<4>();
{
auto it = c2.getIterator(key1,key2);
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c2.get<4>(key)[0] == 1.0;
good &= c2.get<4>(key)[1] == 64.0;
good &= c2.get<4>(key)[2] == 4096.0;
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
}
#endif
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -375,7 +375,7 @@ public:
* \param stop end point
*
*/
struct ite_gpu<dim> getGPUIterator(grid_key_dx<dim> & key1, grid_key_dx<dim> & key2, size_t n_thr = 1024)
struct ite_gpu<dim> getGPUIterator(grid_key_dx<dim> & key1, grid_key_dx<dim> & key2, size_t n_thr = 1024) const
{
size_t tot_work = 1;
for (size_t i = 0 ; i < dim ; i++)
......
......@@ -7,7 +7,6 @@
#include "Space/Shape/HyperCube.hpp"
#include "timer.hpp"
#include "grid_util_test.hpp"
#include "gpu_test/cuda_grid_unit_tests.cuh"
#ifdef TEST_COVERAGE_MODE
#define GS_SIZE 8
......@@ -298,232 +297,6 @@ template<unsigned int dim, typename g> void test_layout_gridObjNd(g & c3, size_t
BOOST_REQUIRE_EQUAL(passed,true);
}
template<unsigned int dim, typename g> void test_layout_gridNd(g & c3, size_t sz)
{
#ifdef VERBOSE_TEST
std::cout << dim << "D Array with grid_key (without redundant dimension): " << "\n";
timer t;
t.start();
#endif
//! [Access to an N-dimensional grid with an iterator]
typedef Point_test<float> P;
grid_key_dx_iterator<dim> key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
c3.template get<P::x>(kk) = 1.1f;
c3.template get<P::y>(kk) = 1.2f;
c3.template get<P::z>(kk) = 1.3f;
c3.template get<P::s>(kk) = 1.0f;
c3.template get<P::v>(kk)[0] = 1.0f;
c3.template get<P::v>(kk)[1] = 2.0f;
c3.template get<P::v>(kk)[2] = 3.0f;
c3.template get<P::t>(kk)[0][0] = 1.0f;
c3.template get<P::t>(kk)[0][1] = 2.0f;
c3.template get<P::t>(kk)[0][2] = 3.0f;
c3.template get<P::t>(kk)[1][0] = 4.0f;
c3.template get<P::t>(kk)[1][1] = 5.0f;
c3.template get<P::t>(kk)[1][2] = 6.0f;
c3.template get<P::t>(kk)[2][0] = 7.0f;
c3.template get<P::t>(kk)[2][1] = 8.0f;
c3.template get<P::t>(kk)[2][2] = 9.0f;
++key_it;
}
//! [Access to an N-dimensional grid with an iterator]
#ifdef VERBOSE_TEST
t.stop();
std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getwct() << " MB/s " << "\n";
#endif
/////////////////////////////////// MEM CHECK ////////////////////////////////////////////////////////
bool passed = true;
key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
c3.template get<P::x>(kk) = c3.getGrid().LinId(kk);
c3.template get<P::y>(kk) = c3.getGrid().LinId(kk)+1;
c3.template get<P::z>(kk) = c3.getGrid().LinId(kk)+2;
c3.template get<P::s>(kk) = c3.getGrid().LinId(kk)+3;
c3.template get<P::v>(kk)[0] = c3.getGrid().LinId(kk)+123;
c3.template get<P::v>(kk)[1] = c3.getGrid().LinId(kk)+124;
c3.template get<P::v>(kk)[2] = c3.getGrid().LinId(kk)+125;
c3.template get<P::t>(kk)[0][0] = c3.getGrid().LinId(kk)+567;
c3.template get<P::t>(kk)[0][1] = c3.getGrid().LinId(kk)+568;
c3.template get<P::t>(kk)[0][2] = c3.getGrid().LinId(kk)+569;
c3.template get<P::t>(kk)[1][0] = c3.getGrid().LinId(kk)+570;
c3.template get<P::t>(kk)[1][1] = c3.getGrid().LinId(kk)+571;
c3.template get<P::t>(kk)[1][2] = c3.getGrid().LinId(kk)+572;
c3.template get<P::t>(kk)[2][0] = c3.getGrid().LinId(kk)+573;
c3.template get<P::t>(kk)[2][1] = c3.getGrid().LinId(kk)+574;
c3.template get<P::t>(kk)[2][2] = c3.getGrid().LinId(kk)+575;
++key_it;
}
key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
if (c3.template get<P::x>(kk) != c3.getGrid().LinId(kk)) passed = false;
if (c3.template get<P::y>(kk) != c3.getGrid().LinId(kk)+1) passed = false;
if (c3.template get<P::z>(kk) != c3.getGrid().LinId(kk)+2) passed = false;
if (c3.template get<P::s>(kk) != c3.getGrid().LinId(kk)+3) passed = false;
if (c3.template get<P::v>(kk)[0] != c3.getGrid().LinId(kk)+123) passed = false;
if (c3.template get<P::v>(kk)[1] != c3.getGrid().LinId(kk)+124) passed = false;
if (c3.template get<P::v>(kk)[2] != c3.getGrid().LinId(kk)+125) passed = false;
if (c3.template get<P::t>(kk)[0][0] != c3.getGrid().LinId(kk)+567) passed = false;
if (c3.template get<P::t>(kk)[0][1] != c3.getGrid().LinId(kk)+568) passed = false;
if (c3.template get<P::t>(kk)[0][2] != c3.getGrid().LinId(kk)+569) passed = false;
if (c3.template get<P::t>(kk)[1][0] != c3.getGrid().LinId(kk)+570) passed = false;
if (c3.template get<P::t>(kk)[1][1] != c3.getGrid().LinId(kk)+571) passed = false;
if (c3.template get<P::t>(kk)[1][2] != c3.getGrid().LinId(kk)+572) passed = false;
if (c3.template get<P::t>(kk)[2][0] != c3.getGrid().LinId(kk)+573) passed = false;
if (c3.template get<P::t>(kk)[2][1] != c3.getGrid().LinId(kk)+574) passed = false;
if (c3.template get<P::t>(kk)[2][2] != c3.getGrid().LinId(kk)+575) passed = false;
++key_it;
}
BOOST_REQUIRE_EQUAL(passed,true);
// Check sub iterator
/*
* Basically we first fill the interior part of the grid than the borders
* creating sub iterator always of smaller dimension
*
* Example:
*
* 2D
*
* if we have a square grid 16x16 we first will with 1 the interior 14x14 grid
*
* than the 4 line borders 14x1 with one
* than the 4 point borders 1x1
*
* We check that
*
* 1) The number of points for each sub-grid correspond
* 2) No point is filled more than one time
* 3) All point are filled
*
* we use the property x of c3
*
*/
// Erase the property x
key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
c3.template get<P::x>(kk) = 0.0;
++key_it;
}
for(size_t i = 0 ; i <= dim ; i++)
{
// get the combination of dimension dim-i
std::vector<comb<dim>> combs = HyperCube<dim>::getCombinations_R(dim-i);
// For each combination create a sub iterator
for (size_t j = 0 ; j < combs.size() ; j++)
{
// Grid key of the sub-iterator
grid_key_dx<dim> start;
grid_key_dx<dim> stop;
// sub iterator
for (size_t k = 0 ; k < dim ; k++)
{
// if combination is 0 the hyper-cube
if (combs[j].c[k] == -1)
{
start.set_d(k,0);
stop.set_d(k,0);
}
else if (combs[j].c[k] == 1)
{
start.set_d(k,c3.getGrid().size(k)-1);
stop.set_d(k,c3.getGrid().size(k)-1);
}
else
{
start.set_d(k,1);
stop.set_d(k,c3.getGrid().size(k)-2);
}
}
bool make_test = true;
#ifdef SE_CLASS1
if (c3.size() == 0)
{make_test = false;}
#endif
if (make_test == true)
{
auto key_it = c3.getSubIterator(start,stop);
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
BOOST_REQUIRE_EQUAL(c3.template get<P::x>(kk),0.0);
c3.template get<P::x>(kk) = 1.0;
++key_it;
}
}
}
}
// Check that everything is 1.0
key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
BOOST_REQUIRE_EQUAL(c3.template get<P::x>(kk),1.0);
++key_it;
}
}
BOOST_AUTO_TEST_SUITE( grid_test )
......@@ -753,278 +526,6 @@ BOOST_AUTO_TEST_CASE( grid_use)
std::cout << "Grid unit test end" << "\n";
}
BOOST_AUTO_TEST_CASE (gpu_computation)
{
#ifdef CUDA_GPU
{
size_t sz[3] = {64,64,64};
grid_gpu<3, Point_test<float> > c3(sz);
c3.setMemory();
test_layout_gridNd<3>(c3,sz[0]);
gpu_grid_3D_compute(c3);
c3.deviceToHost<0>();
auto it = c3.getIterator();
bool good = true;
while(it.isNext())
{
auto key = it.get();
good &= c3.getGrid().LinId(key) == c3.template get<0>(key);
++it;
}
BOOST_REQUIRE_EQUAL(good,true);
}
#endif
}
BOOST_AUTO_TEST_CASE (gpu_computation_stencil)
{
#ifdef CUDA_GPU
{
size_t sz[3] = {64,64,64};
grid_gpu<3, Point_test<float> > c3(sz);