ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
init_vector.hpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2014, 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 #include "viennacl.hpp"
20 
21 
22 
23 static ViennaCLStatus init_cuda_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
24 {
25 #ifdef VIENNACL_WITH_CUDA
27  h.cuda_handle().reset(x->cuda_mem);
28  h.cuda_handle().inc();
29  if (x->precision == ViennaCLFloat)
30  h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * x->size * sizeof(float)); // not necessary, but still set for conciseness
31  else if (x->precision == ViennaCLDouble)
32  h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * x->size * sizeof(double)); // not necessary, but still set for conciseness
33  else
35 
36  return ViennaCLSuccess;
37 #else
38  (void)h;
39  (void)x;
41 #endif
42 }
43 
44 static ViennaCLStatus init_opencl_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
45 {
46 #ifdef VIENNACL_WITH_OPENCL
48  h.opencl_handle() = x->opencl_mem;
49  h.opencl_handle().inc();
50  if (x->precision == ViennaCLFloat)
51  h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(float)); // not necessary, but still set for conciseness
52  else if (x->precision == ViennaCLDouble)
53  h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(double)); // not necessary, but still set for conciseness
54  else
56 
57  return ViennaCLSuccess;
58 #else
59  (void)h;
60  (void)x;
62 #endif
63 }
64 
65 
66 static ViennaCLStatus init_host_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
67 {
69  h.ram_handle().reset(x->host_mem);
70  h.ram_handle().inc();
71  if (x->precision == ViennaCLFloat)
72  h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(float)); // not necessary, but still set for conciseness
73  else if (x->precision == ViennaCLDouble)
74  h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(double)); // not necessary, but still set for conciseness
75  else
77 
78  return ViennaCLSuccess;
79 }
80 
81 
83 {
84  switch (x->backend->backend_type)
85  {
86  case ViennaCLCUDA:
87  return init_cuda_vector(h, x);
88 
89  case ViennaCLOpenCL:
90  return init_opencl_vector(h, x);
91 
92  case ViennaCLHost:
93  return init_host_vector(h, x);
94 
95  default:
97  }
98 }
99 
100 
101 
ViennaCLPrecision precision
ViennaCLBackendTypes backend_type
ViennaCLStatus
Definition: viennacl.hpp:97
ViennaCLBackend backend
Implements the multi-memory-domain handle.
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
Definition: mem_handle.hpp:121
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:230
ram_handle_type & ram_handle()
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
Definition: mem_handle.hpp:99