ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
wrap-host-buffer.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2015, 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 
26 // System headers
27 #include <iostream>
28 #include <cstdlib>
29 #include <string>
30 
31 // ViennaCL headers
32 #include "viennacl/vector.hpp"
33 
38 int main()
39 {
40  typedef float ScalarType;
41 
45  std::size_t size = 10;
46 
47  std::vector<ScalarType> host_x(size, 1.0);
48  std::vector<ScalarType> host_y(size, 2.0);
49 
50  std::cout << "Result on host: ";
51  for (std::size_t i=0; i<size; ++i)
52  std::cout << host_x[i] + host_y[i] << " ";
53  std::cout << std::endl;
54 
59  // wrap host buffer within ViennaCL vectors:
60  viennacl::vector<ScalarType> vcl_vec1(&(host_x[0]), viennacl::MAIN_MEMORY, size); // Second parameter specifies that this is host memory rather than CUDA memory
61  viennacl::vector<ScalarType> vcl_vec2(&(host_y[0]), viennacl::MAIN_MEMORY, size); // Second parameter specifies that this is host memory rather than CUDA memory
62 
63  vcl_vec1 += vcl_vec2;
64 
65  std::cout << "Result with ViennaCL: " << vcl_vec1 << std::endl;
66 
67  std::cout << "Data in STL-vector: ";
68  for (std::size_t i=0; i<size; ++i)
69  std::cout << host_x[i] << " ";
70  std::cout << std::endl;
71 
75  std::cout << "!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
76 
77  return EXIT_SUCCESS;
78 }
79 
int main()
Definition: bisect.cpp:91
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:235
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
float ScalarType
Definition: fft_1d.cpp:42