All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
init_matrix.hpp
Go to the documentation of this file.
/* =========================================================================
Copyright (c) 2010-2014, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the PDF manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include "viennacl.hpp"
#include "viennacl/backend/mem_handle.hpp"
static ViennaCLStatus init_cuda_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
{
#ifdef VIENNACL_WITH_CUDA
h.switch_active_handle_id(viennacl::CUDA_MEMORY);
h.cuda_handle().reset(A->cuda_mem);
h.cuda_handle().inc();
if (A->precision == ViennaCLFloat)
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
else if (A->precision == ViennaCLDouble)
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
else
return ViennaCLGenericFailure;
return ViennaCLSuccess;
#else
(void)h;
(void)A;
return ViennaCLGenericFailure;
#endif
}
static ViennaCLStatus init_opencl_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
{
#ifdef VIENNACL_WITH_OPENCL
h.switch_active_handle_id(viennacl::OPENCL_MEMORY);
h.opencl_handle() = A->opencl_mem;
h.opencl_handle().inc();
if (A->precision == ViennaCLFloat)
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
else if (A->precision == ViennaCLDouble)
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
else
return ViennaCLGenericFailure;
return ViennaCLSuccess;
#else
(void)h;
(void)A;
return ViennaCLGenericFailure;
#endif
}
static ViennaCLStatus init_host_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
{
h.switch_active_handle_id(viennacl::MAIN_MEMORY);
h.ram_handle().reset(A->host_mem);
h.ram_handle().inc();
if (A->precision == ViennaCLFloat)
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
else if (A->precision == ViennaCLDouble)
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
else
return ViennaCLGenericFailure;
return ViennaCLSuccess;
}
static ViennaCLStatus init_matrix(viennacl::backend::mem_handle & h, ViennaCLMatrix A)
{
switch (A->backend->backend_type)
{
case ViennaCLCUDA:
return init_cuda_matrix(h, A);
case ViennaCLOpenCL:
return init_opencl_matrix(h, A);
case ViennaCLHost:
return init_host_matrix(h, A);
default:
return ViennaCLGenericFailure;
}
}
ViennaCLHost
Definition: viennacl.hpp:58
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
ViennaCLMatrix_impl::internal_size2
ViennaCLInt internal_size2
Definition: viennacl_private.hpp:137
ViennaCLMatrix_impl
Definition: viennacl_private.hpp:113
viennacl::CUDA_MEMORY
Definition: forwards.h:350
ViennaCLMatrix_impl::backend
ViennaCLBackend backend
Definition: viennacl_private.hpp:115
ViennaCLMatrix_impl::internal_size1
ViennaCLInt internal_size1
Definition: viennacl_private.hpp:132
ViennaCLCUDA
Definition: viennacl.hpp:56
mem_handle.hpp
Implements the multi-memory-domain handle.
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
ViennaCLMatrix_impl::precision
ViennaCLPrecision precision
Definition: viennacl_private.hpp:116
ViennaCLOpenCL
Definition: viennacl.hpp:57
viennacl.hpp
ViennaCLMatrix_impl::host_mem
char * host_mem
Definition: viennacl_private.hpp:127
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