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_matrix.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_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
24 {
25 #ifdef VIENNACL_WITH_CUDA
27  h.cuda_handle().reset(A->cuda_mem);
28  h.cuda_handle().inc();
29  if (A->precision == ViennaCLFloat)
30  h.raw_size(static_cast<viennacl::vcl_size_t>(A->internal_size1) * static_cast<viennacl::vcl_size_t>(A->internal_size2) * sizeof(float)); // not necessary, but still set for conciseness
31  else if (A->precision == ViennaCLDouble)
32  h.raw_size(static_cast<viennacl::vcl_size_t>(A->internal_size1) * static_cast<viennacl::vcl_size_t>(A->internal_size2) * sizeof(double)); // not necessary, but still set for conciseness
33  else
35 
36  return ViennaCLSuccess;
37 #else
38  (void)h;
39  (void)A;
41 #endif
42 }
43 
44 static ViennaCLStatus init_opencl_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
45 {
46 #ifdef VIENNACL_WITH_OPENCL
48  h.opencl_handle() = A->opencl_mem;
49  h.opencl_handle().inc();
50  if (A->precision == ViennaCLFloat)
51  h.raw_size(static_cast<viennacl::vcl_size_t>(A->internal_size1) * static_cast<viennacl::vcl_size_t>(A->internal_size2) * sizeof(float)); // not necessary, but still set for conciseness
52  else if (A->precision == ViennaCLDouble)
53  h.raw_size(static_cast<viennacl::vcl_size_t>(A->internal_size1) * static_cast<viennacl::vcl_size_t>(A->internal_size2) * sizeof(double)); // not necessary, but still set for conciseness
54  else
56 
57  return ViennaCLSuccess;
58 #else
59  (void)h;
60  (void)A;
62 #endif
63 }
64 
65 
66 static ViennaCLStatus init_host_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
67 {
69  h.ram_handle().reset(A->host_mem);
70  h.ram_handle().inc();
71  if (A->precision == ViennaCLFloat)
72  h.raw_size(static_cast<viennacl::vcl_size_t>(A->internal_size1) * static_cast<viennacl::vcl_size_t>(A->internal_size2) * sizeof(float)); // not necessary, but still set for conciseness
73  else if (A->precision == ViennaCLDouble)
74  h.raw_size(static_cast<viennacl::vcl_size_t>(A->internal_size1) * static_cast<viennacl::vcl_size_t>(A->internal_size2) * sizeof(double)); // not necessary, but still set for conciseness
75  else
77 
78  return ViennaCLSuccess;
79 }
80 
81 
83 {
84  switch (A->backend->backend_type)
85  {
86  case ViennaCLCUDA:
87  return init_cuda_matrix(h, A);
88 
89  case ViennaCLOpenCL:
90  return init_opencl_matrix(h, A);
91 
92  case ViennaCLHost:
93  return init_host_matrix(h, A);
94 
95  default:
97  }
98 }
99 
100 
101 
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
ViennaCLPrecision precision
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