35 #include <boost/numeric/ublas/io.hpp>
36 #include <boost/numeric/ublas/triangular.hpp>
37 #include <boost/numeric/ublas/matrix_sparse.hpp>
38 #include <boost/numeric/ublas/matrix.hpp>
39 #include <boost/numeric/ublas/matrix_proxy.hpp>
40 #include <boost/numeric/ublas/lu.hpp>
41 #include <boost/numeric/ublas/io.hpp>
45 #define VIENNACL_WITH_UBLAS 1
56 #define BLAS3_MATRIX_SIZE 400
58 using namespace boost::numeric;
65 #ifndef VIENNACL_WITH_OPENCL
68 std::size_t
size()
const {
return 1; }
92 for (
unsigned int i = 0; i < ublas_A.size1(); ++i)
93 for (
unsigned int j = 0; j < ublas_A.size2(); ++j)
94 ublas_A(i,j) = randomNumber();
96 for (
unsigned int i = 0; i < ublas_B.size1(); ++i)
97 for (
unsigned int j = 0; j < ublas_B.size2(); ++j)
98 ublas_B(i,j) = randomNumber();
113 std::cout <<
"--- Computing matrix-matrix product using ublas ---" << std::endl;
116 exec_time = timer.
get();
117 std::cout <<
" - Execution time: " << exec_time << std::endl;
123 std::cout << std::endl <<
"--- Computing matrix-matrix product on each available compute device using ViennaCL ---" << std::endl;
124 #ifdef VIENNACL_WITH_OPENCL
130 for (std::size_t device_id=0; device_id<devices.size(); ++device_id)
132 #ifdef VIENNACL_WITH_OPENCL
147 exec_time = timer.
get();
148 std::cout <<
" - Execution time on device (no setup time included): " << exec_time << std::endl;
155 std::cout <<
" - Checking result... ";
156 bool check_ok =
true;
157 for (std::size_t i = 0; i < ublas_A.size1(); ++i)
159 for (std::size_t j = 0; j < ublas_A.size2(); ++j)
161 if ( std::fabs(ublas_C1(i,j) - ublas_C(i,j)) / ublas_C(i,j) > 1e-4 )
171 std::cout <<
"[OK]" << std::endl << std::endl;
173 std::cout <<
"[FAILED]" << std::endl << std::endl;
180 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
void switch_device(vcl_size_t i)
Switches the current device to the i-th device in this context.
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
viennacl::ocl::context & current_context()
Convenience function for returning the current context.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
std::string name() const
Device name string.
#define BLAS3_MATRIX_SIZE
A simple, yet (mostly) sufficiently accurate timer for benchmarking and profiling.
void prod(std::vector< std::map< IndexT, NumericT > > const &stl_A, std::vector< std::map< IndexT, NumericT > > const &stl_B, std::vector< std::map< IndexT, NumericT > > &stl_C)
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
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) ...
A small collection of sequential random number generators.
std::vector< viennacl::ocl::device > const & devices() const
Returns a vector with all devices in this context.
Implementation of the ViennaCL scalar class.