17 #include "Kokkos_Core.hpp"
20 #ifdef KOKKOS_ENABLE_THREADS
25 #if defined(KOKKOS_ENABLE_OPENMP) && defined(HAVE_STOKHOS_MKL)
30 #include "Stokhos_KokkosArrayKernelsUnitTestNew.hpp"
32 using namespace KokkosKernelsUnitTest;
37 #include "Stokhos_KokkosArrayKernelsUnitTestNewDecl.hpp"
45 typedef int size_type;
49 Stokhos::create_product_tensor<Device>( *
setup.basis, *
setup.Cijk );
51 for (
int i=0; i<
setup.stoch_length; ++i) {
53 const int iEntryEnd = tensor.entry_end(i);
54 for (
int iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
55 const int kj = tensor.coord( iEntry );
56 const int j = kj & 0x0ffff;
57 const int k = kj >> 16;
60 value_type c2 = tensor.value(iEntry);
61 if (j == k) c2 *= 2.0;
63 int ii =
setup.inv_perm[i];
64 int jj =
setup.inv_perm[
j];
65 int kk =
setup.inv_perm[k];
66 value_type c =
setup.Cijk->getValue(ii,jj,kk);
69 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
70 <<
" == " << c2 <<
" failed!" << std::endl;
84 params.
set(
"Tile Size",10);
85 params.
set(
"Max Tiles",10000);
88 Stokhos::create_tiled_product_tensor<Device>( *
setup.basis, *
setup.Cijk,
95 const size_t n_tile = tensor.num_tiles();
96 for (
size_t tile = 0 ; tile < n_tile ; ++tile ) {
97 const size_t i_offset = tensor.offset(tile, 0);
98 const size_t j_offset = tensor.offset(tile, 1);
99 const size_t k_offset = tensor.offset(tile, 2);
100 const size_t n_row = tensor.num_rows(tile);
102 for (
size_t i=0; i<n_row; ++i) {
103 const size_t iEntryBeg = tensor.entry_begin(tile,i);
104 const size_t iEntryEnd = tensor.entry_end(tile,i);
105 for (
size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
106 const size_t j = tensor.coord(iEntry,0);
107 const size_t k = tensor.coord(iEntry,1);
108 value_type c2 = tensor.value(iEntry);
109 int ii = i + i_offset;
110 int jj = j + j_offset;
111 int kk = k + k_offset;
114 value_type c =
setup.Cijk->getValue(ii,jj,kk);
117 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
118 <<
" == " << c2 <<
" failed!" << std::endl;
133 params.
set(
"Tile Size",10);
136 Stokhos::create_simple_tiled_product_tensor<Device>(
140 const size_t n_i_tile = tensor.num_i_tiles();
141 for (
size_t i_tile = 0; i_tile<n_i_tile; ++i_tile) {
142 const size_t i_begin = tensor.i_begin(i_tile);
143 const size_t i_size = tensor.i_size(i_tile);
145 const size_t n_j_tile = tensor.num_j_tiles(i_tile);
146 for (
size_t j_tile = 0; j_tile<n_j_tile; ++j_tile) {
147 const size_t j_begin = tensor.j_begin(i_tile, j_tile);
150 const size_t n_k_tile = tensor.num_k_tiles(i_tile, j_tile);
151 for (
size_t k_tile = 0; k_tile<n_k_tile; ++k_tile) {
152 const size_t k_begin = tensor.k_begin(i_tile, j_tile, k_tile);
155 for (
size_t i=0; i<i_size; ++i) {
156 const size_t iEntryBeg = tensor.entry_begin(i_tile,j_tile,k_tile,i);
157 const size_t iEntryEnd = tensor.entry_end(i_tile,j_tile,k_tile,i);
158 for (
size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
159 const size_t j = tensor.coord(iEntry,0);
160 const size_t k = tensor.coord(iEntry,1);
161 value_type c2 = tensor.value(iEntry);
162 int ii = i + i_begin;
163 int jj = j + j_begin;
164 int kk = k + k_begin;
170 value_type c =
setup.Cijk->getValue(ii,jj,kk);
173 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
174 <<
" == " << c2 <<
" failed!" << std::endl;
185 template <
typename Scalar,
typename Device,
bool Pack>
194 Stokhos::create_coo_product_tensor<Device, Pack>(
197 const size_t nEntry = tensor.entry_count();
199 for (
size_t entry = 0 ; entry < nEntry ; ++entry ) {
200 tensor.coord(entry, i, j, k);
201 value_type c2 = tensor.value(entry);
202 if (j == k) c2 *= 2.0;
203 value_type c = setup.
Cijk->getValue(i,j,k);
206 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
207 <<
" == " << c2 <<
" failed!" << std::endl;
216 success = test_coo_product_tensor_cijk<Scalar,Device,true>(
setup, out);
220 success = test_coo_product_tensor_cijk<Scalar,Device,false>(
setup, out);
228 typedef size_t size_type;
231 Stokhos::create_flat_sparse_3_tensor<Device>( *
setup.basis, *
setup.Cijk );
233 for (
int i=0; i<
setup.stoch_length; ++i) {
234 const size_type nk = tensor.
num_k(i);
235 const size_type kBeg = tensor.k_begin(i);
236 const size_type kEnd = kBeg + nk;
237 for (size_type kEntry = kBeg; kEntry < kEnd; ++kEntry) {
238 const size_type k = tensor.k_coord(kEntry);
239 const size_type nj = tensor.num_j(kEntry);
240 const size_type jBeg = tensor.j_begin(kEntry);
241 const size_type jEnd = jBeg + nj;
242 for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
243 const size_type
j = tensor.j_coord(jEntry);
244 value_type c2 = tensor.value(jEntry);
245 if (j == k) c2 *= 2.0;
246 value_type c =
setup.Cijk->getValue(i,j,k);
248 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
249 <<
" == " << c2 <<
" failed!" << std::endl;
262 typedef size_t size_type;
265 Stokhos::create_flat_sparse_3_tensor_kji<Device>(*
setup.basis, *
setup.Cijk);
266 const size_type nk = tensor.
num_k();
268 for ( size_type k = 0; k < nk; ++k) {
269 const size_type nj = tensor.num_j(k);
270 const size_type jBeg = tensor.j_begin(k);
271 const size_type jEnd = jBeg + nj;
272 for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
273 const size_type
j = tensor.j_coord(jEntry);
274 const size_type ni = tensor.num_i(jEntry);
275 const size_type iBeg = tensor.i_begin(jEntry);
276 const size_type iEnd = iBeg + ni;
277 for (size_type iEntry = iBeg; iEntry < iEnd; ++iEntry) {
278 const size_type i = tensor.i_coord(iEntry);
279 value_type c2 = tensor.value(iEntry);
280 if (j == k) c2 *= 2.0;
281 value_type c =
setup.Cijk->getValue(i,j,k);
283 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
284 <<
" == " << c2 <<
" failed!" << std::endl;
292 #define UNIT_TEST_GROUP_SCALAR_HOST_DEVICE( SCALAR, DEVICE ) \
293 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CrsProductTensorCijk, SCALAR, DEVICE ) \
294 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, TiledCrsProductTensorCijk, SCALAR, DEVICE ) \
295 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, SimpleTiledCrsProductTensorCijk, SCALAR, DEVICE ) \
296 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CooProductTensorCijk_Packed, SCALAR, DEVICE ) \
297 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CooProductTensorCijk_Unpacked, SCALAR, DEVICE ) \
298 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, FlatSparseCijk, SCALAR, DEVICE ) \
299 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, FlatSparseCijk_kji, SCALAR, DEVICE )
301 #ifdef KOKKOS_ENABLE_THREADS
302 using Kokkos::Threads;
307 #ifdef KOKKOS_ENABLE_OPENMP
308 using Kokkos::OpenMP;
312 #ifdef HAVE_STOKHOS_MKL
315 typedef Kokkos::OpenMP Device;
316 typedef Stokhos::MKLMultiply SparseMatOps;
317 success = test_crs_matrix_free<Scalar,Device,SparseMatOps>(
324 using Kokkos::Serial;
331 const size_t team_count =
332 Kokkos::hwloc::get_available_numa_count() *
333 Kokkos::hwloc::get_available_cores_per_numa();
334 const size_t threads_per_team =
335 Kokkos::hwloc::get_available_threads_per_core();
339 Kokkos::InitializationSettings init_args;
340 init_args.set_num_threads(team_count*threads_per_team);
341 init_args.set_device_id(0);
342 Kokkos::initialize( init_args );
343 Kokkos::print_configuration( std::cout );
bool test_coo_product_tensor_cijk(const KokkosKernelsUnitTest::UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
#define UNIT_TEST_GROUP_SCALAR_HOST_DEVICE(SCALAR, DEVICE)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
KOKKOS_INLINE_FUNCTION size_type num_k() const
Number of k entries.
KOKKOS_INLINE_FUNCTION size_type entry_begin(size_type i) const
Begin entries with a coordinate 'i'.
UnitTestSetup< int, double > setup
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION size_type num_k(size_type i) const
Number of k entries with a coordinate 'i'.
RCP< product_basis_type > basis
int main(int argc, char **argv)
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
#define UNIT_TEST_GROUP_SCALAR_DEVICE(SCALAR, DEVICE)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
Sparse product tensor using 'COO'-like storage format.