ViennaCL - The Vienna Computing Library: examples/tutorial/wrap-host-buffer.cpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wrap-host-buffer.cpp
Go to the documentation of this file.
1 /* =========================================================================
2 Copyright (c) 2010-2016, 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
main
int main()
Definition: bisect.cpp:91
viennacl::traits::size
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
viennacl::vector< ScalarType >
viennacl::MAIN_MEMORY
Definition: forwards.h:348
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
ScalarType
float ScalarType
Definition: fft_1d.cpp:42