29 #include <boost/numeric/ublas/io.hpp>
30 #include <boost/numeric/ublas/vector.hpp>
31 #include <boost/foreach.hpp>
37 #define VIENNACL_WITH_UBLAS
51 #define CHECK_RESULT(cpu,gpu, op) \
52 if ( float delta = fabs ( diff ( cpu, gpu) ) > epsilon ) {\
53 std::cout << "# Error at operation: " #op << std::endl;\
54 std::cout << " diff: " << delta << std::endl;\
55 retval = EXIT_FAILURE;\
59 using namespace boost::numeric;
60 using namespace viennacl;
62 template<
typename ScalarType,
typename VCLMatrixType>
65 ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
70 for (
unsigned int i = 0; i < mat2_cpu.size1(); ++i)
72 for (
unsigned int j = 0; j < mat2_cpu.size2(); ++j)
74 act = fabs(mat2_cpu(i,j) - mat1(i,j)) /
std::max( fabs(mat2_cpu(i, j)), fabs(mat1(i,j)) );
83 template<
typename ScalarType,
unsigned int Alignment>
85 ublas::vector<ScalarType> v2_cpu ( v2.
size() );
87 for (
unsigned int i=0; i<v1.size(); ++i ) {
88 if (
std::max ( fabs ( v2_cpu[i] ), fabs ( v1[i] ) ) > 0 )
89 v2_cpu[i] = fabs ( v2_cpu[i] - v1[i] ) /
std::max ( fabs ( v2_cpu[i] ), fabs ( v1[i] ) );
96 template<
typename ScalarType>
99 return (s - other) /
std::max(s, other);
103 template<
typename NumericT,
typename Epsilon >
105 using namespace viennacl::device_specific;
106 int retval = EXIT_SUCCESS;
108 unsigned int size = 1024*32;
109 ublas::vector<NumericT> cw(
size);
110 ublas::vector<NumericT> cx(
size);
111 ublas::vector<NumericT> cy(
size);
112 ublas::vector<NumericT> cz(
size);
118 for (
unsigned int i=0; i<cw.size(); ++i){
119 cw[i]=std::rand()/(
NumericT)RAND_MAX;
122 std::cout <<
"Running tests for vector of size " << cw.size() << std::endl;
350 std::cout <<
"s = reduce<argmax>(x)..." << std::endl;
353 for (
unsigned int i=1; i<
size; ++i)
372 template<
typename NumericT,
class Layout,
typename Epsilon >
374 int retval = EXIT_SUCCESS;
376 unsigned int size1 = 1024;
377 unsigned int size2 = 1024;
379 unsigned int pattern_size1 = 256;
380 unsigned int pattern_size2 = 128;
385 ublas::matrix<NumericT> cA(size1,size2);
386 ublas::matrix<NumericT> cB(size1,size2);
387 ublas::matrix<NumericT> cC(size1,size2);
389 ublas::matrix<NumericT> cPattern(pattern_size1,pattern_size2);
391 ublas::vector<NumericT> cx(size1);
392 ublas::vector<NumericT> cy(size2);
395 for (
unsigned int i=0; i<
size1; ++i)
396 for (
unsigned int j=0; j<
size2; ++j)
397 cA(i,j)=(
NumericT)std::rand()/RAND_MAX;
399 for (
unsigned int i = 0; i < pattern_size1; ++i)
400 for (
unsigned int j = 0; j < pattern_size2; ++j)
401 cPattern(i,j) = (
NumericT)std::rand()/RAND_MAX;
404 for (
unsigned int i=0; i<
size2; ++i){
405 cx(i) = (
NumericT)std::rand()/RAND_MAX;
406 cy(i) = (
NumericT)std::rand()/RAND_MAX;
441 std::cout <<
"C = diag(x) ..." << std::endl;
442 for (
unsigned int i = 0; i <
size1; ++i)
443 for (
unsigned int j = 0; j <
size2; ++j)
444 cC(i,j) = (i==j)?cx[i]:0;
446 device_specific::execute<device_specific::matrix_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::matrix_axpy), statement);
452 std::cout <<
"x = diag(C) ..." << std::endl;
453 for (
unsigned int i = 0; i <
std::min(size1, size2); ++i)
456 device_specific::execute<device_specific::vector_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::vector_axpy), statement);
462 std::cout <<
"y = row(C, 7) ..." << std::endl;
463 for (
unsigned int j = 0; j <
size2; ++j)
466 device_specific::execute<device_specific::vector_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::vector_axpy), statement);
575 int main(
int argc,
char* argv[]){
576 std::vector<std::string> args(argv,argv+argc);
577 unsigned int requested_device;
582 requested_device = atoi(args[1].c_str());
584 int retval = EXIT_SUCCESS;
586 typedef std::vector< viennacl::ocl::platform > platforms_type;
587 typedef std::vector<viennacl::ocl::device> devices_type;
590 size_t num_platforms = platforms.size();
594 for (
unsigned int k=0; k < num_platforms; ++k)
601 for (devices_type::iterator it = dev.begin(); it != dev.end(); ++it){
603 if (current_device++ == requested_device ){
605 std::cout << std::endl;
606 std::cout <<
"----------------------------------------------" << std::endl;
607 std::cout <<
" Device Info" << std::endl;
608 std::cout <<
"----------------------------------------------" << std::endl;
638 std::cout << std::endl;
639 std::cout <<
"----------------------------------------------" << std::endl;
640 std::cout <<
"----------------------------------------------" << std::endl;
641 std::cout <<
"## Test :: Matrix" << std::endl;
642 std::cout <<
"----------------------------------------------" << std::endl;
645 double epsilon = 1.0E-4;
646 std::cout <<
"# Testing setup:" << std::endl;
648 std::cout <<
" numeric: float" << std::endl;
649 std::cout <<
" --------------" << std::endl;
650 std::cout <<
" Row-Major" << std::endl;
651 std::cout <<
" --------------" << std::endl;
652 retval = test_matrix<float, viennacl::row_major> (epsilon);
654 std::cout <<
" --------------" << std::endl;
655 std::cout <<
" Column-Major" << std::endl;
656 std::cout <<
" --------------" << std::endl;
657 retval &= test_matrix<float, viennacl::column_major> (epsilon);
659 std::cout <<
" numeric: double" << std::endl;
660 std::cout <<
" --------------" << std::endl;
661 std::cout <<
" Row-Major" << std::endl;
662 std::cout <<
" --------------" << std::endl;
663 retval = test_matrix<double, viennacl::row_major> (epsilon);
665 std::cout <<
" --------------" << std::endl;
666 std::cout <<
" Column-Major" << std::endl;
667 std::cout <<
" --------------" << std::endl;
668 retval &= test_matrix<double, viennacl::column_major> (epsilon);
670 if ( retval == EXIT_SUCCESS )
671 std::cout <<
"# Test passed" << std::endl;
std::vector< platform > get_platforms()
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
**********************************ViennaCL Change Logs *************************************Version x ***Version While the work for the upcoming release is in full this maintenance release fixes a couple of bugs and performance regressions reported to x and this increases the performance of matrix matrix multiplications to GFLOPs in single precision on a GeForce GTX Thanks to Paul Dufort for bringing this to our attention Added support for the operation A
Implementations of vector operations.
int test_matrix(Epsilon const &epsilon)
Implementation of the dense matrix class.
viennacl::vector< int > v2
#define CHECK_RESULT(cpu, gpu, op)
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.
viennacl::ocl::context & current_context()
Convenience function for returning the current context.
A tag class representing assignment.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
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.
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
ScalarType diff(ublas::matrix< ScalarType > &mat1, VCLMatrixType &mat2)
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
int main(int argc, char *argv[])
std::string info(vcl_size_t indent=0, char indent_char= ' ') const
Returns an info string with a few properties of the device. Use full_info() to get all details...
void switch_device(viennacl::ocl::device &d)
Convenience function for switching the active device in the current context.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
ocl::device const & current_device(SomeT const &obj)
size_type size() const
Returns the length of the vector (cf. std::vector)
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
void execute(template_base const &T, statements_container const &statements, viennacl::ocl::context &ctx=viennacl::ocl::current_context(), bool force_compilation=false)
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
void switch_context(long i)
Convenience function for switching the current context.
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) ...
int test_vector(Epsilon const &epsilon)
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
T min(const T &lhs, const T &rhs)
Minimum.
iterator end()
Returns an iterator pointing to the end of the vector (STL like)
void set_context_platform_index(long i, vcl_size_t pf_index)
Convenience function for setting the platform index.
**********************************ViennaCL Change Logs *************************************Version x ***Version While the work for the upcoming release is in full this maintenance release fixes a couple of bugs and performance regressions reported to x and y
std::vector< viennacl::ocl::device > const & devices() const
Returns a vector with all devices in this context.
void set_context_device_type(long i, cl_device_type dev_type)
Convenience function for setting the default device type for a context.
viennacl::vector< float > v1