ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
generator_blas1.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2012, Institute for Microelectronics,
3  Institute for Analysis and Scientific Computing,
4  TU Wien.
5  Portions of this software are copyright by UChicago Argonne, LLC.
6 
7  -----------------
8  ViennaCL - The Vienna Computing Library
9  -----------------
10 
11  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12 
13  (A list of authors and contributors can be found in the PDF manual)
14 
15  License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17 
18 //#define VIENNACL_DEBUG_ALL
19 //#define VIENNACL_DEBUG_BUILD
20 //#define VIENNACL_DEBUG_BUILD
21 //
22 // *** System
23 //
24 #include <iostream>
25 
26 //
27 // *** Boost
28 //
29 #include <boost/numeric/ublas/io.hpp>
30 #include <boost/numeric/ublas/vector.hpp>
31 #include <boost/foreach.hpp>
32 
33 //
34 // *** ViennaCL
35 //
36 //#define VIENNACL_DEBUG_BUILD
37 #define VIENNACL_WITH_UBLAS
38 //#define VIENNACL_DEBUG_ALL
39 
40 #include "viennacl/matrix.hpp"
41 #include "viennacl/vector.hpp"
45 //#include "viennacl/linalg/norm_1.hpp"
46 //#include "viennacl/linalg/norm_2.hpp"
47 //#include "viennacl/linalg/norm_inf.hpp"
49 
50 
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;\
56  }\
57 
58 
59 using namespace boost::numeric;
60 using namespace viennacl;
61 
62 template<typename ScalarType, typename VCLMatrixType>
63 ScalarType diff(ublas::matrix<ScalarType> & mat1, VCLMatrixType & mat2)
64 {
65  ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
67  viennacl::copy(mat2, mat2_cpu);
68  double ret = 0;
69  double act = 0;
70  for (unsigned int i = 0; i < mat2_cpu.size1(); ++i)
71  {
72  for (unsigned int j = 0; j < mat2_cpu.size2(); ++j)
73  {
74  act = fabs(mat2_cpu(i,j) - mat1(i,j)) / std::max( fabs(mat2_cpu(i, j)), fabs(mat1(i,j)) );
75  if (act > ret)
76  ret = act;
77  }
78  }
79  //std::cout << ret << std::endl;
80  return ret;
81 }
82 
83 template<typename ScalarType, unsigned int Alignment>
84 ScalarType diff ( ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType,Alignment> & v2 ) {
85  ublas::vector<ScalarType> v2_cpu ( v2.size() );
86  viennacl::copy( v2.begin(), v2.end(), v2_cpu.begin() );
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] ) );
90  else
91  v2_cpu[i] = 0.0;
92  }
93  return norm_inf ( v2_cpu );
94 }
95 
96 template<typename ScalarType>
98  ScalarType other = gs;
99  return (s - other) / std::max(s, other);
100 }
101 
102 
103 template< typename NumericT, typename Epsilon >
104 int test_vector ( Epsilon const& epsilon) {
105  using namespace viennacl::device_specific;
106  int retval = EXIT_SUCCESS;
107 
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);
113 
114 // NumericT s;
115 
116 
117 
118  for (unsigned int i=0; i<cw.size(); ++i){
119  cw[i]=std::rand()/(NumericT)RAND_MAX;
120  }
121 
122  std::cout << "Running tests for vector of size " << cw.size() << std::endl;
127  NumericT s = 0;
129 
130  cx = 2.0f*cw;
131  cy = 3.0f*cw;
132  cz = 4.0f*cw;
133  viennacl::copy (cw, w);
134  viennacl::copy (cx, x);
135  viennacl::copy (cy, y);
136  viennacl::copy (cz, z);
137 
138  NumericT alpha = 3.14;
139  NumericT beta = 1;
140 
141  // --------------------------------------------------------------------------
142 
143 // {
144 // std::cout << "w = scalar_vector(alpha) ..." << std::endl;
145 // for (unsigned int i = 0; i < size; ++i)
146 // cw[i] = alpha;
147 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::scalar_vector<NumericT>(size,alpha));
148 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
149 // viennacl::backend::finish();
150 // CHECK_RESULT(cw, w, w = scalar_vector(alpha));
151 // }
152 
153 // {
154 // std::cout << "w = x ..." << std::endl;
155 // cw = cx;
156 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), x);
157 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
158 // viennacl::backend::finish();
159 // CHECK_RESULT(cw, w, w = x);
160 // }
161 
162 
163 // {
164 // std::cout << "w = -x ..." << std::endl;
165 // viennacl::scalar<NumericT> s0(1);
166 // cw = -cx;
167 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), -s0*x);
168 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
169 // viennacl::backend::finish();
170 // CHECK_RESULT(cw, w, w = -x);
171 // }
172 
173 // {
174 // std::cout << "w = alpha*x + beta*y ..." << std::endl;
175 // cw = alpha*cx + beta*cy;
176 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), alpha*x + beta*y);
177 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
178 // viennacl::backend::finish();
179 // CHECK_RESULT(cw, w, w = alpha*x + beta*y);
180 // }
181 
182 // {
183 // std::cout << "x = alpha*w + beta*y ..." << std::endl;
184 // cx = alpha*cw + beta*cy;
185 // viennacl::scheduler::statement statement(x, viennacl::op_assign(), alpha*w + beta*y);
186 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
187 // viennacl::backend::finish();
188 // CHECK_RESULT(cw, w, w = alpha*x + beta*y);
189 // }
190 
191 // {
192 // std::cout << "[Independent] x = alpha*w + beta*y, y = alpha*x + beta*w ..." << std::endl;
193 // for (std::size_t i = 0; i < size; ++i)
194 // {
195 // NumericT tmpcx = cx[i];
196 // NumericT tmpcy = cy[i];
197 
198 // cx[i] = alpha*cw[i] + beta*tmpcy;
199 // cy[i] = alpha*tmpcx + beta*cw[i];
200 // }
201 // viennacl::scheduler::statement s1(x, viennacl::op_assign(), alpha*w + beta*y);
202 // viennacl::scheduler::statement s2(y, viennacl::op_assign(), alpha*x + beta*w);
203 // device_specific::execute(database::get<NumericT>(database::axpy), statements_container(s1, s2, statements_container::INDEPENDENT));
204 // viennacl::backend::finish();
205 // CHECK_RESULT(cx, x, (x = alpha*w + beta*y, y = alpha*x + beta*w));
206 // CHECK_RESULT(cy, y, (x = alpha*w + beta*y, y = alpha*x + beta*w));
207 // }
208 
209 // {
210 // std::cout << "[Sequential] x = alpha*w + beta*y, y = alpha*x + beta*w ..." << std::endl;
211 // cx = alpha*cw + beta*cy;
212 // cy = alpha*cx + beta*cw;
213 // viennacl::scheduler::statement s1(x, viennacl::op_assign(), alpha*w + beta*y);
214 // viennacl::scheduler::statement s2(y, viennacl::op_assign(), alpha*x + beta*w);
215 // device_specific::execute(database::get<NumericT>(database::axpy), statements_container(s1, s2, statements_container::SEQUENTIAL));
216 // viennacl::backend::finish();
217 // CHECK_RESULT(cx, x, (x = alpha*w + beta*y, y = alpha*x + beta*w));
218 // CHECK_RESULT(cy, y, (x = alpha*w + beta*y, y = alpha*x + beta*w));
219 // }
220 
221 // {
222 // std::cout << "w = exp(y) ..." << std::endl;
223 // for (std::size_t i = 0; i < size; ++i)
224 // cw[i] = std::exp(y[i]);
225 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_exp(y));
226 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
227 // viennacl::backend::finish();
228 // CHECK_RESULT(cw, w, w = alpha*x + beta*y);
229 // }
230 
231 // {
232 // std::cout << "w = element_prod(x,y) ..." << std::endl;
233 // for (std::size_t i = 0; i < size; ++i)
234 // cw[i] = x[i]*y[i];
235 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_prod(x,y));
236 // device_specific::execute(database::get<NumericT>(database::axpy), statement);
237 // viennacl::backend::finish();
238 // CHECK_RESULT(cw, w, w = element_prod(x,y));
239 // }
240 
241 // {
242 // std::cout << "w = x == x" << std::endl;
243 // for (unsigned int i=0; i < size; ++i){
244 // cw(i) = (cx(i) == cx(i));
245 // }
246 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_eq(x,x));
247 // generator::execute(statement, statement.array()[0]);
248 // viennacl::backend::finish();
249 // CHECK_RESULT(cw, w, w = (x == x))
250 // }
251 
252 // {
253 // std::cout << "w = x != x" << std::endl;
254 // for (unsigned int i=0; i < size; ++i){
255 // cw(i) = cx(i) != cx(i);
256 // }
257 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_neq(x,x));
258 // generator::execute(statement, statement.array()[0]);
259 // viennacl::backend::finish();
260 // CHECK_RESULT(cw, w, w = x != x)
261 // }
262 
263 // {
264 // std::cout << "w = x > y" << std::endl;
265 // for (unsigned int i=0; i < size; ++i){
266 // cw(i) = cx(i) > cy(i);
267 // }
268 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_greater(x,y));
269 // generator::execute(statement, statement.array()[0]);
270 // viennacl::backend::finish();
271 // CHECK_RESULT(cw, w, w = x > y)
272 // }
273 
274 // {
275 // std::cout << "w = x >= y" << std::endl;
276 // for (unsigned int i=0; i < size; ++i){
277 // cw(i) = cx(i) >= cy(i);
278 // }
279 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_geq(x,y));
280 // generator::execute(statement, statement.array()[0]);
281 // viennacl::backend::finish();
282 // CHECK_RESULT(cw, w, w = x > y)
283 // }
284 
285 // {
286 // std::cout << "w = x < y" << std::endl;
287 // for (unsigned int i=0; i < size; ++i){
288 // cw(i) = cx(i) < cy(i);
289 // }
290 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_less(x,y));
291 // generator::execute(statement, statement.array()[0]);
292 // viennacl::backend::finish();
293 // CHECK_RESULT(cw, w, w = x > y)
294 // }
295 
296 // {
297 // std::cout << "w = x <= y" << std::endl;
298 // for (unsigned int i=0; i < size; ++i){
299 // cw(i) = cx(i) <= cy(i);
300 // }
301 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_leq(x,y));
302 // generator::execute(statement, statement.array()[0]);
303 // viennacl::backend::finish();
304 // CHECK_RESULT(cw, w, w = x > y)
305 // }
306 
307 
308 // {
309 // std::cout << "w = x.^y" << std::endl;
310 // for (unsigned int i=0; i < size; ++i){
311 // cw(i) = std::pow(cx(i),cy(i));
312 // }
313 // viennacl::scheduler::statement statement(w, viennacl::op_assign(), viennacl::linalg::element_pow(x,y));
314 // generator::execute(statement, statement.array()[0]);
315 // viennacl::backend::finish();
316 // CHECK_RESULT(cw, w, w = x.^y)
317 // }
318 
319 // {
320 // std::cout << "s = inner_prod(x,y)..." << std::endl;
321 // s = 0;
322 // for (unsigned int i=0; i<size; ++i) s+=cx[i]*cy[i];
323 // viennacl::scheduler::statement statement(gs, viennacl::op_assign(), viennacl::linalg::inner_prod(x,y));
324 // device_specific::execute(database::get<NumericT>(database::reduction), statement);
325 // viennacl::backend::finish();
326 // CHECK_RESULT(s, gs, s = inner_prod(x,y));
327 // }
328 
329 // {
330 // std::cout << "s = reduce<add>(x)..." << std::endl;
331 // s = 0;
332 // for (unsigned int i=0; i<size; ++i) s+=cx[i];
333 // viennacl::scheduler::statement statement(gs, viennacl::op_assign(), viennacl::linalg::reduce<viennacl::op_add>(x));
334 // device_specific::execute(profiles::get(REDUCTION_TYPE, NUMERIC_TYPE), statement);
335 // viennacl::backend::finish();
336 // CHECK_RESULT(s, gs, s = reduce<add>(x));
337 // }
338 
339 // {
340 // std::cout << "s = reduce<fmax>(x)..." << std::endl;
341 // s = cx[0];
342 // for (unsigned int i=1; i<size; ++i) s=std::max(s,cx[i]);
343 // viennacl::scheduler::statement statement(gs, viennacl::op_assign(), viennacl::linalg::reduce<iennacl::op_fmax>(x));
344 // device_specific::execute(database::get<NumericT>(database::reduction), statement);
345 // viennacl::backend::finish();
346 // CHECK_RESULT(s, gs, s = reduce<mult>(x));
347 // }
348 
349  {
350  std::cout << "s = reduce<argmax>(x)..." << std::endl;
351  NumericT s = 0;
352  NumericT val = cx[0];
353  for (unsigned int i=1; i<size; ++i)
354  {
355  if (cx[i] > val)
356  {
357  s = i;
358  val = cx[i];
359  }
360  }
361  viennacl::scheduler::statement statement(gs, viennacl::op_assign(), viennacl::linalg::reduce<viennacl::op_argmax>(x));
362  device_specific::execute(database::get<NumericT>(database::reduction), statement);
364  CHECK_RESULT(s, gs, s = reduce<argmax>(x));
365  }
366 
367  return retval;
368 }
369 
370 
371 
372 template< typename NumericT, class Layout, typename Epsilon >
373 int test_matrix ( Epsilon const& epsilon) {
374  int retval = EXIT_SUCCESS;
375 
376  unsigned int size1 = 1024;
377  unsigned int size2 = 1024;
378 
379  unsigned int pattern_size1 = 256;
380  unsigned int pattern_size2 = 128;
381 
382 // unsigned int n_rep1 = size1/pattern_size1;
383 // unsigned int n_rep2 = size2/pattern_size2;
384 
385  ublas::matrix<NumericT> cA(size1,size2);
386  ublas::matrix<NumericT> cB(size1,size2);
387  ublas::matrix<NumericT> cC(size1,size2);
388 
389  ublas::matrix<NumericT> cPattern(pattern_size1,pattern_size2);
390 
391  ublas::vector<NumericT> cx(size1);
392  ublas::vector<NumericT> cy(size2);
393 
394 
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;
398 
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;
402 
403 
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;
407  }
408 
409 // std::cout << "Running tests for matrix of size " << cA.size1() << "," << cA.size2() << std::endl;
410 
411  viennacl::matrix<NumericT,Layout> A (size1, size2);
412  viennacl::matrix<NumericT,Layout> B (size1, size2);
413  viennacl::matrix<NumericT,Layout> C (size1, size2);
414 
415  viennacl::matrix<NumericT, Layout> pattern(pattern_size1, pattern_size2);
416 
419 
420 
421  cB = cA;
422  cC = cA;
423  viennacl::copy(cA,A);
424  viennacl::copy(cB,B);
425  viennacl::copy(cC,C);
426 
427  viennacl::copy(cx,x);
428  viennacl::copy(cy,y);
429  viennacl::copy(cPattern,pattern);
430 
431 // {
432 // std::cout << "C = A + B ..." << std::endl;
433 // cC = ( cA + cB );
434 // viennacl::scheduler::statement statement(C, viennacl::op_assign(), A + B);
435 // device_specific::execute<device_specific::matrix_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::matrix_axpy), statement);
436 // viennacl::backend::finish();
437 // CHECK_RESULT(cC, C, C=A+B)
438 // }
439 
440  {
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);
448  CHECK_RESULT(cC, C, C=diag(x))
449  }
450 
451  {
452  std::cout << "x = diag(C) ..." << std::endl;
453  for (unsigned int i = 0; i < std::min(size1, size2); ++i)
454  cx[i] = cC(i,i);
456  device_specific::execute<device_specific::vector_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::vector_axpy), statement);
458  CHECK_RESULT(cx, x, x=diag(C))
459  }
460 
461  {
462  std::cout << "y = row(C, 7) ..." << std::endl;
463  for (unsigned int j = 0; j < size2; ++j)
464  cy[j] = cC(7,j);
466  device_specific::execute<device_specific::vector_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::vector_axpy), statement);
468  CHECK_RESULT(cy, y, y=row(C, 7))
469  }
470 
471 // {
472 // std::cout << "x = diag(C) ..." << std::endl;
473 // for (unsigned int i = 0; i < std::min(size1, size2); ++i)
474 // cx[i] = cC(i,i);
475 // viennacl::scheduler::statement statement(x, viennacl::op_assign(), viennacl::diag(C));
476 // device_specific::execute<device_specific::vector_axpy_template>(device_specific::database::get<NumericT>(device_specific::database::vector_axpy), statement);
477 // viennacl::backend::finish();
478 // CHECK_RESULT(cx, x, x=diag(C))
479 // }
480 
481 
482 // {
483 // std::cout << "C = diag(x) ..." << std::endl;
484 // for (unsigned int i = 0; i < size1; ++i){
485 // for (unsigned int j = 0; j < size2; ++j){
486 // cC(i,j) = (i==j)?cx[i]:0;
487 // }
488 // }
489 // generator::custom_operation op;
490 // op.add(mat(C) = generator::diag(vec(x)));
491 // op.execute();
492 // viennacl::backend::finish();
493 // CHECK_RESULT(cC, C, C = diag(x))
494 // }
495 
496 // {
497 // std::cout << "x = diag(C) ..." << std::endl;
498 // for (unsigned int i = 0; i < size1; ++i){
499 // cx(i) = cA(i,i);
500 // }
501 // generator::custom_operation op;
502 // op.add(vec(x) = generator::diag(mat(A)));
503 // op.execute();
504 // viennacl::backend::finish();
505 // CHECK_RESULT(cx,x, x = diag(A));
506 // }
507 
508 // {
509 // std::cout << "C = repmat(P, M, N) ..." << std::endl;
510 // for (unsigned int i = 0; i < size1; ++i)
511 // for (unsigned int j = 0; j < size2; ++j)
512 // cC(i,j) = cPattern(i%pattern_size1, j%pattern_size2);
513 // generator::custom_operation op;
514 // op.add(mat(C) = generator::repmat(mat(pattern),n_rep1,n_rep2));
515 // op.execute();
516 // viennacl::backend::finish();
517 // CHECK_RESULT(cC, C, C = repmat(P, M, N))
518 // }
519 
520 // {
521 // std::cout << "C = repmat(x, 1, N) ..." << std::endl;
522 // for (unsigned int i = 0; i < size1; ++i)
523 // for (unsigned int j = 0; j < size2; ++j)
524 // cC(i,j) = cx(i);
525 // generator::custom_operation op;
526 // op.add(mat(C) = generator::repmat(vec(x),1, C.size2()));
527 // op.execute();
528 // viennacl::backend::finish();
529 // CHECK_RESULT(cC, C, C = repmat(x, 1, N))
530 // }
531 
532 // {
533 // std::cout << "C = trans(repmat(x, 1, N)) ..." << std::endl;
534 // for (unsigned int i = 0; i < size1; ++i)
535 // for (unsigned int j = 0; j < size2; ++j)
536 // cC(i,j) = cx(j);
537 // generator::custom_operation op;
538 // op.add(mat(C) = generator::trans(generator::repmat(vec(x),1,C.size2())));
539 // op.execute();
540 // viennacl::backend::finish();
541 // CHECK_RESULT(cC, C, C = repmat(x, 1, N))
542 // }
543 
544 
545 // {
546 // std::cout << "C = -A ..." << std::endl;
547 // for (unsigned int i = 0; i < size1; ++i)
548 // for (unsigned int j = 0; j < size2; ++j)
549 // cC(i,j) = -cA(i,j);
550 // generator::custom_operation op;
551 // op.add(mat(C) = -mat(A));
552 // op.execute();
553 // viennacl::backend::finish();
554 
555 // CHECK_RESULT(cC, C, C = -A)
556 // }
557 
558 // {
559 // std::cout << "C = 1/(1+EXP(-A)) ..." << std::endl;
560 // for (unsigned int i = 0; i < size1; ++i)
561 // for (unsigned int j = 0; j < size2; ++j)
562 // cC(i,j) = 1.0f/(1.0f+std::exp(-cA(i,j)));
563 // generator::custom_operation op;
564 // op.add(mat(C) = 1.0f/(1.0f+generator::exp(-mat(A))));
565 // op.execute();
566 // viennacl::backend::finish();
567 // CHECK_RESULT(cC, C, C = 1/(1+EXP(-A)))
568 // }
569 
570 
571  return retval;
572 }
573 
574 
575 int main(int argc, char* argv[]){
576  std::vector<std::string> args(argv,argv+argc);
577  unsigned int requested_device;
578  if (argc!=2){
579  requested_device=0;
580  }
581  else{
582  requested_device = atoi(args[1].c_str());
583  }
584  int retval = EXIT_SUCCESS;
585 
586  typedef std::vector< viennacl::ocl::platform > platforms_type;
587  typedef std::vector<viennacl::ocl::device> devices_type;
588 
589  platforms_type platforms = viennacl::ocl::get_platforms();
590  size_t num_platforms = platforms.size();
591 
592  unsigned int current_device = 0;
593 
594  for (unsigned int k=0; k < num_platforms; ++k)
595  {
597  viennacl::ocl::set_context_device_type(k,CL_DEVICE_TYPE_ALL);
600  devices_type dev = viennacl::ocl::current_context().devices();
601  for (devices_type::iterator it = dev.begin(); it != dev.end(); ++it){
602 
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;
609  std::cout << viennacl::ocl::current_device().info() << std::endl;
610 
611 // std::cout << std::endl;
612 // std::cout << "----------------------------------------------" << std::endl;
613 // std::cout << "----------------------------------------------" << std::endl;
614 // std::cout << "## Test :: Vector" << std::endl;
615 // std::cout << "----------------------------------------------" << std::endl;
616 
617 // {
618 // double epsilon = 1.0E-4;
619 
620 // std::cout << "# Testing setup:" << std::endl;
621 // std::cout << " numeric: float" << std::endl;
622 // retval = test_vector<float> (epsilon);
623 
624 
625 // std::cout << std::endl;
626 
627 // std::cout << "# Testing setup:" << std::endl;
628 // std::cout << " numeric: double" << std::endl;
629 // retval = test_vector<double> (epsilon);
630 
631 // if ( retval == EXIT_SUCCESS )
632 // std::cout << "# Test passed" << std::endl;
633 // else
634 // return retval;
635 // }
636 
637 
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;
643 
644  {
645  double epsilon = 1.0E-4;
646  std::cout << "# Testing setup:" << std::endl;
647 
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);
653 
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);
658 
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);
664 
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);
669 
670  if ( retval == EXIT_SUCCESS )
671  std::cout << "# Test passed" << std::endl;
672  else
673  return retval;
674  }
675 
676  }
677  }
678  }
679 }
std::vector< platform > get_platforms()
Definition: platform.hpp:124
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:226
Wrapper class for an OpenCL platform.
Definition: platform.hpp:45
Implementations of vector operations.
int test_matrix(Epsilon const &epsilon)
Implementation of the dense matrix class.
#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.)
Definition: size.hpp:216
Some helper routines for reading/writing/printing scheduler expressions.
viennacl::ocl::context & current_context()
Convenience function for returning the current context.
Definition: backend.hpp:213
A tag class representing assignment.
Definition: forwards.h:80
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
Definition: memory.hpp:54
A dense matrix class.
Definition: forwards.h:374
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.
Definition: util.hpp:59
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
Definition: backend.hpp:351
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...
Definition: size.hpp:245
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...
Definition: device.hpp:995
viennacl::vector< float > v1
void switch_device(viennacl::ocl::device &d)
Convenience function for switching the active device in the current context.
Definition: backend.hpp:345
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
ocl::device const & current_device(SomeT const &obj)
Definition: common.hpp:97
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
Definition: matrix.hpp:838
void execute(template_base const &T, statements_container const &statements, viennacl::ocl::context &ctx=viennacl::ocl::current_context(), bool force_compilation=false)
Definition: execute.hpp:44
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
Definition: matrix.hpp:853
void switch_context(long i)
Convenience function for switching the current context.
Definition: backend.hpp:219
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)
Definition: norm_inf.hpp:60
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)
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
float ScalarType
Definition: fft_1d.cpp:42
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:504
T min(const T &lhs, const T &rhs)
Minimum.
Definition: util.hpp:45
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.
Definition: backend.hpp:313
std::vector< viennacl::ocl::device > const & devices() const
Returns a vector with all devices in this context.
Definition: context.hpp:105
void set_context_device_type(long i, cl_device_type dev_type)
Convenience function for setting the default device type for a context.
Definition: backend.hpp:272