ViennaCL - The Vienna Computing Library: libviennacl/src/init_vector.hpp 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
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"
19 #include "viennacl/backend/mem_handle.hpp"
20
21
22
23 static ViennaCLStatus init_cuda_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
24 {
25 #ifdef VIENNACL_WITH_CUDA
26 h.switch_active_handle_id(viennacl::CUDA_MEMORY);
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
34 return ViennaCLGenericFailure;
35
36 return ViennaCLSuccess;
37 #else
38 (void)h;
39 (void)x;
40 return ViennaCLGenericFailure;
41 #endif
42 }
43
44 static ViennaCLStatus init_opencl_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
45 {
46 #ifdef VIENNACL_WITH_OPENCL
47 h.switch_active_handle_id(viennacl::OPENCL_MEMORY);
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
55 return ViennaCLGenericFailure;
56
57 return ViennaCLSuccess;
58 #else
59 (void)h;
60 (void)x;
61 return ViennaCLGenericFailure;
62 #endif
63 }
64
65
66 static ViennaCLStatus init_host_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
67 {
68 h.switch_active_handle_id(viennacl::MAIN_MEMORY);
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
76 return ViennaCLGenericFailure;
77
78 return ViennaCLSuccess;
79 }
80
81
82 static ViennaCLStatus init_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
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:
96 return ViennaCLGenericFailure;
97 }
98 }
99
100
101
ViennaCLHost
Definition: viennacl.hpp:58
ViennaCLVector_impl::precision
ViennaCLPrecision precision
Definition: viennacl_private.hpp:97
viennacl::tools::shared_ptr::inc
void inc()
Definition: shared_ptr.hpp:154
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
ViennaCLBackend_impl::backend_type
ViennaCLBackendTypes backend_type
Definition: viennacl_private.hpp:56
ViennaCLDouble
Definition: viennacl.hpp:93
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
ViennaCLVector_impl::backend
ViennaCLBackend backend
Definition: viennacl_private.hpp:96
ViennaCLVector_impl::size
ViennaCLInt size
Definition: viennacl_private.hpp:110
ViennaCLVector_impl::inc
ViennaCLInt inc
Definition: viennacl_private.hpp:109
ViennaCLVector_impl
Definition: viennacl_private.hpp:94
viennacl::CUDA_MEMORY
Definition: forwards.h:350
ViennaCLCUDA
Definition: viennacl.hpp:56
mem_handle.hpp
Implements the multi-memory-domain handle.
ViennaCLVector_impl::host_mem
char * host_mem
Definition: viennacl_private.hpp:106
ViennaCLGenericFailure
Definition: viennacl.hpp:100
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::backend::mem_handle::switch_active_handle_id
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
viennacl::tools::shared_ptr::reset
void reset()
Definition: shared_ptr.hpp:123
viennacl::backend::mem_handle
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
viennacl::backend::mem_handle::raw_size
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:230
ViennaCLOpenCL
Definition: viennacl.hpp:57
viennacl.hpp
ViennaCLFloat
Definition: viennacl.hpp:92
viennacl::backend::mem_handle::ram_handle
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
ViennaCLSuccess
Definition: viennacl.hpp:99