blasutil.cpp File Reference
#include "main.h"

Classes

struct  PacketBlockSet< Scalar, StorageOrder, n >
 

Macros

#define GET(i, j)   (StorageOrder == RowMajor ? (i) * stride + (j) : (i) + (j) * stride)
 
#define SCATTER(i, j, k)   (StorageOrder == RowMajor ? ((i) + (k)) * stride + (j) : (i) + ((j) + (k)) * stride)
 

Functions

template<typename Scalar , typename Packet >
void compare (const Packet &a, const Packet &b)
 
template<typename Scalar , int StorageOrder, int BlockSize>
void run_bdmp_spec_1 ()
 
template<typename Scalar >
void run_test ()
 
 EIGEN_DECLARE_TEST (blasutil)
 

Macro Definition Documentation

◆ GET

#define GET (   i,
  j 
)    (StorageOrder == RowMajor ? (i) * stride + (j) : (i) + (j) * stride)

◆ SCATTER

#define SCATTER (   i,
  j,
  k 
)    (StorageOrder == RowMajor ? ((i) + (k)) * stride + (j) : (i) + ((j) + (k)) * stride)

Function Documentation

◆ compare()

template<typename Scalar , typename Packet >
void compare ( const Packet a,
const Packet b 
)
24  {
26  Scalar* buffA = new Scalar[pktsz];
27  Scalar* buffB = new Scalar[pktsz];
28 
29  internal::pstoreu<Scalar, Packet>(buffA, a);
30  internal::pstoreu<Scalar, Packet>(buffB, b);
31 
32  for (int i = 0; i < pktsz; i++) {
33  VERIFY_IS_EQUAL(buffA[i], buffB[i]);
34  }
35 
36  delete[] buffA;
37  delete[] buffB;
38 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
const Scalar * a
Definition: level2_cplx_impl.h:32
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367

References a, b, i, size, and VERIFY_IS_EQUAL.

Referenced by Eigen::getMarketHeader(), File::write(), and DPMBase::write().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( blasutil  )
164  {
165  for (int i = 0; i < g_repeat; i++) {
166  CALL_SUBTEST_1(run_test<numext::int8_t>());
167  CALL_SUBTEST_2(run_test<numext::int16_t>());
168  CALL_SUBTEST_3(run_test<numext::int32_t>());
169 
170  // TODO: Replace this by a call to numext::int64_t as soon as we have a way to
171  // detect the typedef for int64_t on all platforms
172  CALL_SUBTEST_4(run_test<signed long long>());
173  CALL_SUBTEST_5(run_test<float_t>());
174  CALL_SUBTEST_6(run_test<double_t>());
175  CALL_SUBTEST_7(run_test<std::complex<float> >());
176  CALL_SUBTEST_8(run_test<std::complex<double> >());
177  }
178 }
void run_test()
Definition: blasutil.cpp:151
static int g_repeat
Definition: main.h:191
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, Eigen::g_repeat, i, and run_test().

◆ run_bdmp_spec_1()

template<typename Scalar , int StorageOrder, int BlockSize>
void run_bdmp_spec_1 ( )
59  {
60  typedef internal::blas_data_mapper<Scalar, int, StorageOrder> BlasDataMapper;
62  int minSize = std::max<int>(packetSize, BlockSize);
64 
65  int szm = internal::random<int>(minSize, 500), szn = internal::random<int>(minSize, 500);
66  int stride = StorageOrder == RowMajor ? szn : szm;
67  Scalar* d = new Scalar[szn * szm];
68 
69  // Initializing with random entries
70  for (int i = 0; i < szm * szn; i++) {
71  d[i] = internal::random<Scalar>(static_cast<Scalar>(3), static_cast<Scalar>(10));
72  }
73 
74  BlasDataMapper bdm(d, stride);
75 
76  // Testing operator()
77  for (int i = 0; i < szm; i++) {
78  for (int j = 0; j < szn; j++) {
79  VERIFY_IS_EQUAL(d[GET(i, j)], bdm(i, j));
80  }
81  }
82 
83  // Testing getSubMapper and getLinearMapper
84  int i0 = internal::random<int>(0, szm - 2);
85  int j0 = internal::random<int>(0, szn - 2);
86  for (int i = i0; i < szm; i++) {
87  for (int j = j0; j < szn; j++) {
88  const BlasDataMapper& bdmSM = bdm.getSubMapper(i0, j0);
89  const internal::BlasLinearMapper<Scalar, int, 0>& bdmLM = bdm.getLinearMapper(i0, j0);
90 
91  Scalar v = bdmSM(i - i0, j - j0);
92  Scalar vd = d[GET(i, j)];
93  VERIFY_IS_EQUAL(vd, v);
94  VERIFY_IS_EQUAL(vd, bdmLM(GET(i - i0, j - j0)));
95  }
96  }
97 
98  // Testing loadPacket
99  for (int i = 0; i < szm - minSize; i++) {
100  for (int j = 0; j < szn - minSize; j++) {
101  Packet pktBDM = bdm.template loadPacket<Packet>(i, j);
102  Packet pktD = internal::ploadu<Packet>(d + GET(i, j));
103 
104  compare<Scalar, Packet>(pktBDM, pktD);
105  }
106  }
107 
108  // Testing gatherPacket
109  Scalar* buff = new Scalar[packetSize];
110  for (int i = 0; i < szm - minSize; i++) {
111  for (int j = 0; j < szn - minSize; j++) {
112  Packet p = bdm.template gatherPacket<Packet>(i, j);
113  internal::pstoreu<Scalar, Packet>(buff, p);
114 
115  for (int k = 0; k < packetSize; k++) {
116  VERIFY_IS_EQUAL(d[SCATTER(i, j, k)], buff[k]);
117  }
118  }
119  }
120  delete[] buff;
121 
122  // Testing scatterPacket
123  for (int i = 0; i < szm - minSize; i++) {
124  for (int j = 0; j < szn - minSize; j++) {
125  Packet p = internal::pset1<Packet>(static_cast<Scalar>(1));
126  bdm.template scatterPacket<Packet>(i, j, p);
127  for (int k = 0; k < packetSize; k++) {
128  VERIFY_IS_EQUAL(d[SCATTER(i, j, k)], static_cast<Scalar>(1));
129  }
130  }
131  }
132 
133  // Testing storePacketBlock
134  internal::PacketBlock<Packet, BlockSize> block;
135 
137  pbs.setPacketBlock(block, static_cast<Scalar>(2));
138 
139  for (int i = 0; i < szm - minSize; i++) {
140  for (int j = 0; j < szn - minSize; j++) {
141  bdm.template storePacketBlock<Packet, BlockSize>(i, j, block);
142 
143  pbs.comparePacketBlock(d, i, j, stride, block);
144  }
145  }
146 
147  delete[] d;
148 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
float * p
Definition: Tutorial_Map_using.cpp:9
m m block(1, 0, 2, 2)<< 4
internal::packet_traits< Scalar >::type Packet
Definition: benchmark-blocking-sizes.cpp:54
#define GET(i, j)
Definition: blasutil.cpp:20
#define SCATTER(i, j, k)
Definition: blasutil.cpp:21
@ RowMajor
Definition: Constants.h:320
char char char int int * k
Definition: level2_impl.h:374
Definition: blasutil.cpp:41
void setPacketBlock(internal::PacketBlock< Packet, n > &block, Scalar value)
Definition: blasutil.cpp:44
void comparePacketBlock(Scalar *data, int i, int j, int stride, internal::PacketBlock< Packet, n > &block)
Definition: blasutil.cpp:50
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References block(), PacketBlockSet< Scalar, StorageOrder, n >::comparePacketBlock(), GET, i, j, k, p, Eigen::RowMajor, SCATTER, PacketBlockSet< Scalar, StorageOrder, n >::setPacketBlock(), size, v, and VERIFY_IS_EQUAL.

◆ run_test()

template<typename Scalar >
void run_test ( )
151  {
152  run_bdmp_spec_1<Scalar, RowMajor, 1>();
153  run_bdmp_spec_1<Scalar, ColMajor, 1>();
154  run_bdmp_spec_1<Scalar, RowMajor, 2>();
155  run_bdmp_spec_1<Scalar, ColMajor, 2>();
156  run_bdmp_spec_1<Scalar, RowMajor, 4>();
157  run_bdmp_spec_1<Scalar, ColMajor, 4>();
158  run_bdmp_spec_1<Scalar, RowMajor, 8>();
159  run_bdmp_spec_1<Scalar, ColMajor, 8>();
160  run_bdmp_spec_1<Scalar, RowMajor, 16>();
161  run_bdmp_spec_1<Scalar, ColMajor, 16>();
162 }

Referenced by EIGEN_DECLARE_TEST().