26 #include <boost/numeric/ublas/io.hpp>
27 #include <boost/numeric/ublas/vector.hpp>
32 #define VIENNACL_WITH_UBLAS 1
41 #include "viennacl/device_specific/code_generator.hpp"
44 #define CHECK_RESULT(cpu,gpu, op) \
45 if ( double delta = fabs ( diff ( cpu, gpu) ) > epsilon ) {\
46 std::cout << "# Error at operation: " #op << std::endl;\
47 std::cout << " diff: " << delta << std::endl;\
48 retval = EXIT_FAILURE;\
52 using namespace boost::numeric;
53 using namespace viennacl;
55 template<
typename ScalarType,
typename VCLMatrixType>
58 ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
64 for (
unsigned int i = 0; i < mat2_cpu.size1(); ++i)
66 for (
unsigned int j = 0; j < mat2_cpu.size2(); ++j)
68 act = std::fabs(mat2_cpu(i,j) - mat1(i,j)) / std::max<ScalarType>( std::fabs(mat2_cpu(i, j)), std::fabs(mat1(i,j)) );
77 template<
typename ScalarType,
unsigned int Alignment>
79 ublas::vector<ScalarType> v2_cpu ( v2.
size() );
81 for (
unsigned int i=0; i<v1.size(); ++i ) {
82 if (
std::max ( std::fabs ( v2_cpu[i] ), std::fabs ( v1[i] ) ) > 0 )
83 v2_cpu[i] = std::fabs ( v2_cpu[i] - v1[i] ) / std::max<ScalarType>( std::fabs ( v2_cpu[i] ), std::fabs ( v1[i] ) );
91 template<
typename NumericT,
class Layout,
typename Epsilon >
92 int test( Epsilon
const& epsilon) {
93 int retval = EXIT_SUCCESS;
95 ublas::vector<NumericT> cx;
96 ublas::vector<NumericT> cy;
98 ublas::matrix<NumericT> cA;
99 ublas::matrix<NumericT> cB;
100 ublas::matrix<NumericT> cC;
101 ublas::matrix<NumericT> cD;
103 unsigned int size1 = 762;
104 unsigned int size2 = 663;
106 cA.resize(size1,size2);
112 for (
unsigned int i=0; i<
size1; ++i){
113 for (
unsigned int j=0; j<
size2; ++j){
118 for (
unsigned int i=0; i<
size2; ++i){
122 for (
unsigned int i=0; i<
size1; ++i){
151 std::cout <<
"y = A*x..." << std::endl;
155 device_specific::generate_enqueue_statement(statement, statement.
array()[0]);
161 std::cout <<
"x = trans(A)*y..." << std::endl;
164 device_specific::generate_enqueue_statement(statement, statement.
array()[0]);
170 std::cout <<
"y = reduce_rows<add>(A)..." << std::endl;
171 for (
unsigned int i = 0; i <
size1; ++i){
172 NumericT acc = cA(i,0);
173 for (
unsigned int j = 1; j <
size2; ++j){
181 device_specific::generate_enqueue_statement(statement, statement.
array()[0]);
187 std::cout <<
"x = reduce_columns<add>(A)..." << std::endl;
188 for (
unsigned int j = 0; j <
size2; ++j){
189 NumericT acc = cA(0,j);
190 for (
unsigned int i = 1; i <
size1; ++i){
196 device_specific::generate_enqueue_statement(statement, statement.
array()[0]);
207 std::cout << std::endl;
208 std::cout <<
"----------------------------------------------" << std::endl;
209 std::cout <<
"----------------------------------------------" << std::endl;
210 std::cout <<
"## Test :: Generated BLAS2" << std::endl;
211 std::cout <<
"----------------------------------------------" << std::endl;
212 std::cout <<
"----------------------------------------------" << std::endl;
213 std::cout << std::endl;
215 int retval = EXIT_SUCCESS;
217 std::cout << std::endl;
218 std::cout <<
"----------------------------------------------" << std::endl;
219 std::cout << std::endl;
221 double epsilon = 1.0E-4;
222 std::cout <<
"# Testing setup:" << std::endl;
223 std::cout <<
" numeric: float" << std::endl;
224 std::cout <<
" --------------" << std::endl;
225 std::cout <<
" Row-Major" << std::endl;
226 std::cout <<
" --------------" << std::endl;
227 retval = test<float, viennacl::row_major> (epsilon);
228 std::cout <<
" --------------" << std::endl;
229 std::cout <<
" Column-Major" << std::endl;
230 std::cout <<
" --------------" << std::endl;
231 retval &= test<float, viennacl::column_major> (epsilon);
233 if ( retval == EXIT_SUCCESS )
234 std::cout <<
"# Test passed" << std::endl;
void trans(matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > const &proxy, matrix_base< NumericT > &temp_trans)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
ScalarType diff(ublas::matrix< ScalarType > &mat1, VCLMatrixType &mat2)
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Some helper routines for reading/writing/printing scheduler expressions.
A tag class representing assignment.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
container_type const & array() const
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
T max(const T &lhs, const T &rhs)
Maximum.
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
viennacl::vector< float > v1
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
int test(Epsilon const &epsilon)
void prod(const MatrixT1 &A, bool transposed_A, const MatrixT2 &B, bool transposed_B, MatrixT3 &C, ScalarT alpha, ScalarT beta)
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
T norm_inf(std::vector< T, A > const &v1)
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
size_type size() const
Returns the length of the vector (cf. std::vector)
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
iterator end()
Returns an iterator pointing to the end of the vector (STL like)
#define CHECK_RESULT(cpu, gpu, op)