All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
memory.hpp
Go to the documentation of this file.
#ifndef VIENNACL_BACKEND_MEMORY_HPP
#define VIENNACL_BACKEND_MEMORY_HPP
/* =========================================================================
Copyright (c) 2010-2016, 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 manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <vector>
#include <cassert>
#include "viennacl/forwards.h"
#include "viennacl/backend/mem_handle.hpp"
#include "viennacl/context.hpp"
#include "viennacl/traits/handle.hpp"
#include "viennacl/traits/context.hpp"
#include "viennacl/backend/util.hpp"
#include "viennacl/backend/cpu_ram.hpp"
#ifdef VIENNACL_WITH_OPENCL
#include "viennacl/backend/opencl.hpp"
#include "viennacl/ocl/backend.hpp"
#endif
#ifdef VIENNACL_WITH_CUDA
#include "viennacl/backend/cuda.hpp"
#endif
namespace viennacl
{
namespace backend
{
// if a user compiles with CUDA, it is reasonable to expect that CUDA should be the default
inline void finish()
{
#ifdef VIENNACL_WITH_CUDA
cudaDeviceSynchronize();
#endif
#ifdef VIENNACL_WITH_OPENCL
viennacl::ocl::get_queue().finish();
#endif
}
// Requirements for backend:
// ---- Memory ----
//
// * memory_create(size, host_ptr)
// * memory_copy(src, dest, offset_src, offset_dest, size)
// * memory_write(src, offset, size, ptr)
// * memory_read(src, offset, size, ptr)
//
inline void memory_create(mem_handle & handle, vcl_size_t size_in_bytes, viennacl::context const & ctx, const void * host_ptr = NULL)
{
if (size_in_bytes > 0)
{
if (handle.get_active_handle_id() == MEMORY_NOT_INITIALIZED)
handle.switch_active_handle_id(ctx.memory_type());
switch (handle.get_active_handle_id())
{
case MAIN_MEMORY:
handle.ram_handle() = cpu_ram::memory_create(size_in_bytes, host_ptr);
handle.raw_size(size_in_bytes);
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
handle.opencl_handle().context(ctx.opencl_context());
handle.opencl_handle() = opencl::memory_create(handle.opencl_handle().context(), size_in_bytes, host_ptr);
handle.raw_size(size_in_bytes);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
handle.cuda_handle() = cuda::memory_create(size_in_bytes, host_ptr);
handle.raw_size(size_in_bytes);
break;
#endif
case MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("unknown memory handle!");
}
}
}
/*
inline void memory_create(mem_handle & handle, vcl_size_t size_in_bytes, const void * host_ptr = NULL)
{
viennacl::context ctx(default_memory_type());
memory_create(handle, size_in_bytes, ctx, host_ptr);
}*/
inline void memory_copy(mem_handle const & src_buffer,
mem_handle & dst_buffer,
vcl_size_t src_offset,
vcl_size_t dst_offset,
vcl_size_t bytes_to_copy)
{
assert( src_buffer.get_active_handle_id() == dst_buffer.get_active_handle_id() && bool("memory_copy() must be called on buffers from the same domain") );
if (bytes_to_copy > 0)
{
switch (src_buffer.get_active_handle_id())
{
case MAIN_MEMORY:
cpu_ram::memory_copy(src_buffer.ram_handle(), dst_buffer.ram_handle(), src_offset, dst_offset, bytes_to_copy);
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
opencl::memory_copy(src_buffer.opencl_handle(), dst_buffer.opencl_handle(), src_offset, dst_offset, bytes_to_copy);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
cuda::memory_copy(src_buffer.cuda_handle(), dst_buffer.cuda_handle(), src_offset, dst_offset, bytes_to_copy);
break;
#endif
case MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("unknown memory handle!");
}
}
}
// TODO: Refine this concept. Maybe move to constructor?
inline void memory_shallow_copy(mem_handle const & src_buffer,
mem_handle & dst_buffer)
{
assert( (dst_buffer.get_active_handle_id() == MEMORY_NOT_INITIALIZED) && bool("Shallow copy on already initialized memory not supported!"));
switch (src_buffer.get_active_handle_id())
{
case MAIN_MEMORY:
dst_buffer.switch_active_handle_id(src_buffer.get_active_handle_id());
dst_buffer.ram_handle() = src_buffer.ram_handle();
dst_buffer.raw_size(src_buffer.raw_size());
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
dst_buffer.switch_active_handle_id(src_buffer.get_active_handle_id());
dst_buffer.opencl_handle() = src_buffer.opencl_handle();
dst_buffer.raw_size(src_buffer.raw_size());
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
dst_buffer.switch_active_handle_id(src_buffer.get_active_handle_id());
dst_buffer.cuda_handle() = src_buffer.cuda_handle();
dst_buffer.raw_size(src_buffer.raw_size());
break;
#endif
case MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("unknown memory handle!");
}
}
inline void memory_write(mem_handle & dst_buffer,
vcl_size_t dst_offset,
vcl_size_t bytes_to_write,
const void * ptr,
bool async = false)
{
if (bytes_to_write > 0)
{
switch (dst_buffer.get_active_handle_id())
{
case MAIN_MEMORY:
cpu_ram::memory_write(dst_buffer.ram_handle(), dst_offset, bytes_to_write, ptr, async);
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
opencl::memory_write(dst_buffer.opencl_handle(), dst_offset, bytes_to_write, ptr, async);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
cuda::memory_write(dst_buffer.cuda_handle(), dst_offset, bytes_to_write, ptr, async);
break;
#endif
case MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("unknown memory handle!");
}
}
}
inline void memory_read(mem_handle const & src_buffer,
vcl_size_t src_offset,
vcl_size_t bytes_to_read,
void * ptr,
bool async = false)
{
//finish(); //Fixes some issues with AMD APP SDK. However, might sacrifice a few percents of performance in some cases.
if (bytes_to_read > 0)
{
switch (src_buffer.get_active_handle_id())
{
case MAIN_MEMORY:
cpu_ram::memory_read(src_buffer.ram_handle(), src_offset, bytes_to_read, ptr, async);
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
opencl::memory_read(src_buffer.opencl_handle(), src_offset, bytes_to_read, ptr, async);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
cuda::memory_read(src_buffer.cuda_handle(), src_offset, bytes_to_read, ptr, async);
break;
#endif
case MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("unknown memory handle!");
}
}
}
namespace detail
{
template<typename T>
vcl_size_t element_size(memory_types /* mem_type */)
{
return sizeof(T);
}
template<>
inline vcl_size_t element_size<unsigned long>(memory_types
#ifdef VIENNACL_WITH_OPENCL
mem_type //in order to compile cleanly at -Wextra in GCC
#endif
)
{
#ifdef VIENNACL_WITH_OPENCL
if (mem_type == OPENCL_MEMORY)
return sizeof(cl_ulong);
#endif
return sizeof(unsigned long);
}
template<>
inline vcl_size_t element_size<long>(memory_types
#ifdef VIENNACL_WITH_OPENCL
mem_type //in order to compile cleanly at -Wextra in GCC
#endif
)
{
#ifdef VIENNACL_WITH_OPENCL
if (mem_type == OPENCL_MEMORY)
return sizeof(cl_long);
#endif
return sizeof(long);
}
template<>
inline vcl_size_t element_size<unsigned int>(memory_types
#ifdef VIENNACL_WITH_OPENCL
mem_type //in order to compile cleanly at -Wextra in GCC
#endif
)
{
#ifdef VIENNACL_WITH_OPENCL
if (mem_type == OPENCL_MEMORY)
return sizeof(cl_uint);
#endif
return sizeof(unsigned int);
}
template<>
inline vcl_size_t element_size<int>(memory_types
#ifdef VIENNACL_WITH_OPENCL
mem_type //in order to compile cleanly at -Wextra in GCC
#endif
)
{
#ifdef VIENNACL_WITH_OPENCL
if (mem_type == OPENCL_MEMORY)
return sizeof(cl_int);
#endif
return sizeof(int);
}
}
template<typename DataType>
void switch_memory_context(mem_handle & handle, viennacl::context new_ctx)
{
if (handle.get_active_handle_id() == new_ctx.memory_type())
return;
if (handle.get_active_handle_id() == viennacl::MEMORY_NOT_INITIALIZED || handle.raw_size() == 0)
{
handle.switch_active_handle_id(new_ctx.memory_type());
#ifdef VIENNACL_WITH_OPENCL
if (new_ctx.memory_type() == OPENCL_MEMORY)
handle.opencl_handle().context(new_ctx.opencl_context());
#endif
return;
}
vcl_size_t size_dst = detail::element_size<DataType>(handle.get_active_handle_id());
vcl_size_t size_src = detail::element_size<DataType>(new_ctx.memory_type());
if (size_dst != size_src) // OpenCL data element size not the same as host data element size
{
throw memory_exception("Heterogeneous data element sizes not yet supported!");
}
else //no data conversion required
{
if (handle.get_active_handle_id() == MAIN_MEMORY) //we can access the existing data directly
{
switch (new_ctx.memory_type())
{
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
handle.opencl_handle().context(new_ctx.opencl_context());
handle.opencl_handle() = opencl::memory_create(handle.opencl_handle().context(), handle.raw_size(), handle.ram_handle().get());
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
handle.cuda_handle() = cuda::memory_create(handle.raw_size(), handle.ram_handle().get());
break;
#endif
case MAIN_MEMORY:
default:
throw memory_exception("Invalid destination domain");
}
}
#ifdef VIENNACL_WITH_OPENCL
else if (handle.get_active_handle_id() == OPENCL_MEMORY) // data can be dumped into destination directly
{
std::vector<DataType> buffer;
switch (new_ctx.memory_type())
{
case MAIN_MEMORY:
handle.ram_handle() = cpu_ram::memory_create(handle.raw_size());
opencl::memory_read(handle.opencl_handle(), 0, handle.raw_size(), handle.ram_handle().get());
break;
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
buffer.resize(handle.raw_size() / sizeof(DataType));
opencl::memory_read(handle.opencl_handle(), 0, handle.raw_size(), &(buffer[0]));
cuda::memory_create(handle.cuda_handle(), handle.raw_size(), &(buffer[0]));
break;
#endif
default:
throw memory_exception("Invalid destination domain");
}
}
#endif
#ifdef VIENNACL_WITH_CUDA
else //CUDA_MEMORY
{
std::vector<DataType> buffer;
// write
switch (new_ctx.memory_type())
{
case MAIN_MEMORY:
handle.ram_handle() = cpu_ram::memory_create(handle.raw_size());
cuda::memory_read(handle.cuda_handle(), 0, handle.raw_size(), handle.ram_handle().get());
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
buffer.resize(handle.raw_size() / sizeof(DataType));
cuda::memory_read(handle.cuda_handle(), 0, handle.raw_size(), &(buffer[0]));
handle.opencl_handle() = opencl::memory_create(handle.raw_size(), &(buffer[0]));
break;
#endif
default:
throw memory_exception("Unsupported source memory domain");
}
}
#endif
// everything succeeded so far, now switch to new domain:
handle.switch_active_handle_id(new_ctx.memory_type());
} // no data conversion
}
template<typename DataType>
void typesafe_memory_copy(mem_handle const & handle_src, mem_handle & handle_dst)
{
if (handle_dst.get_active_handle_id() == MEMORY_NOT_INITIALIZED)
handle_dst.switch_active_handle_id(default_memory_type());
vcl_size_t element_size_src = detail::element_size<DataType>(handle_src.get_active_handle_id());
vcl_size_t element_size_dst = detail::element_size<DataType>(handle_dst.get_active_handle_id());
if (element_size_src != element_size_dst)
{
// Data needs to be converted.
typesafe_host_array<DataType> buffer_src(handle_src);
typesafe_host_array<DataType> buffer_dst(handle_dst, handle_src.raw_size() / element_size_src);
//
// Step 1: Fill buffer_dst depending on where the data resides:
//
DataType const * src_data;
switch (handle_src.get_active_handle_id())
{
case MAIN_MEMORY:
src_data = reinterpret_cast<DataType const *>(handle_src.ram_handle().get());
for (vcl_size_t i=0; i<buffer_dst.size(); ++i)
buffer_dst.set(i, src_data[i]);
break;
#ifdef VIENNACL_WITH_OPENCL
case OPENCL_MEMORY:
buffer_src.resize(handle_src, handle_src.raw_size() / element_size_src);
opencl::memory_read(handle_src.opencl_handle(), 0, buffer_src.raw_size(), buffer_src.get());
for (vcl_size_t i=0; i<buffer_dst.size(); ++i)
buffer_dst.set(i, buffer_src[i]);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case CUDA_MEMORY:
buffer_src.resize(handle_src, handle_src.raw_size() / element_size_src);
cuda::memory_read(handle_src.cuda_handle(), 0, buffer_src.raw_size(), buffer_src.get());
for (vcl_size_t i=0; i<buffer_dst.size(); ++i)
buffer_dst.set(i, buffer_src[i]);
break;
#endif
default:
throw memory_exception("unsupported memory domain");
}
//
// Step 2: Write to destination
//
if (handle_dst.raw_size() == buffer_dst.raw_size())
viennacl::backend::memory_write(handle_dst, 0, buffer_dst.raw_size(), buffer_dst.get());
else
viennacl::backend::memory_create(handle_dst, buffer_dst.raw_size(), viennacl::traits::context(handle_dst), buffer_dst.get());
}
else
{
// No data conversion required.
typesafe_host_array<DataType> buffer(handle_src);
switch (handle_src.get_active_handle_id())
{
case MAIN_MEMORY:
switch (handle_dst.get_active_handle_id())
{
case MAIN_MEMORY:
case OPENCL_MEMORY:
case CUDA_MEMORY:
if (handle_dst.raw_size() == handle_src.raw_size())
viennacl::backend::memory_write(handle_dst, 0, handle_src.raw_size(), handle_src.ram_handle().get());
else
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst), handle_src.ram_handle().get());
break;
default:
throw memory_exception("unsupported destination memory domain");
}
break;
case OPENCL_MEMORY:
switch (handle_dst.get_active_handle_id())
{
case MAIN_MEMORY:
if (handle_dst.raw_size() != handle_src.raw_size())
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst));
viennacl::backend::memory_read(handle_src, 0, handle_src.raw_size(), handle_dst.ram_handle().get());
break;
case OPENCL_MEMORY:
if (handle_dst.raw_size() != handle_src.raw_size())
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst));
viennacl::backend::memory_copy(handle_src, handle_dst, 0, 0, handle_src.raw_size());
break;
case CUDA_MEMORY:
if (handle_dst.raw_size() != handle_src.raw_size())
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst));
buffer.resize(handle_src, handle_src.raw_size() / element_size_src);
viennacl::backend::memory_read(handle_src, 0, handle_src.raw_size(), buffer.get());
viennacl::backend::memory_write(handle_dst, 0, handle_src.raw_size(), buffer.get());
break;
default:
throw memory_exception("unsupported destination memory domain");
}
break;
case CUDA_MEMORY:
switch (handle_dst.get_active_handle_id())
{
case MAIN_MEMORY:
if (handle_dst.raw_size() != handle_src.raw_size())
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst));
viennacl::backend::memory_read(handle_src, 0, handle_src.raw_size(), handle_dst.ram_handle().get());
break;
case OPENCL_MEMORY:
if (handle_dst.raw_size() != handle_src.raw_size())
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst));
buffer.resize(handle_src, handle_src.raw_size() / element_size_src);
viennacl::backend::memory_read(handle_src, 0, handle_src.raw_size(), buffer.get());
viennacl::backend::memory_write(handle_dst, 0, handle_src.raw_size(), buffer.get());
break;
case CUDA_MEMORY:
if (handle_dst.raw_size() != handle_src.raw_size())
viennacl::backend::memory_create(handle_dst, handle_src.raw_size(), viennacl::traits::context(handle_dst));
viennacl::backend::memory_copy(handle_src, handle_dst, 0, 0, handle_src.raw_size());
break;
default:
throw memory_exception("unsupported destination memory domain");
}
break;
default:
throw memory_exception("unsupported source memory domain");
}
}
}
} //backend
//
// Convenience layer:
//
template<typename T>
void switch_memory_context(T & obj, viennacl::context new_ctx)
{
obj.switch_memory_context(new_ctx);
}
} //viennacl
#endif
viennacl::backend::typesafe_memory_copy
void typesafe_memory_copy(mem_handle const &handle_src, mem_handle &handle_dst)
Copies data of the provided 'DataType' from 'handle_src' to 'handle_dst' and converts the data if the...
Definition: memory.hpp:470
viennacl::backend::typesafe_host_array
Helper class implementing an array on the host. Default case: No conversion necessary.
Definition: util.hpp:92
viennacl::backend::cpu_ram::memory_read
void memory_read(handle_type const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_copy, void *ptr, bool)
Reads data from a buffer back to main RAM.
Definition: cpu_ram.hpp:153
viennacl::backend::opencl::memory_create
cl_mem memory_create(viennacl::ocl::context const &ctx, vcl_size_t size_in_bytes, const void *host_ptr=NULL)
Creates an array of the specified size in the current OpenCL context. If the second argument is provi...
Definition: opencl.hpp:55
viennacl::backend::memory_write
void memory_write(mem_handle &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_write, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
Definition: memory.hpp:220
viennacl::backend::cpu_ram::memory_create
handle_type memory_create(vcl_size_t size_in_bytes, const void *host_ptr=NULL)
Creates an array of the specified size in main RAM. If the second argument is provided, the buffer is initialized with data from that pointer.
Definition: cpu_ram.hpp:73
viennacl::ocl::command_queue::finish
void finish() const
Waits until all kernels in the queue have finished their execution.
Definition: command_queue.hpp:70
viennacl::memory_exception
Exception class in case of memory errors.
Definition: forwards.h:572
viennacl::backend::opencl::memory_write
void memory_write(viennacl::ocl::handle< cl_mem > &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_copy, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the OpenCL buffer identified by 'dst_buffer'.
Definition: opencl.hpp:97
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
viennacl::backend::cuda::memory_write
void memory_write(handle_type &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_copy, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the CUDA buffer identified by 'dst_buffer'.
Definition: cuda.hpp:154
viennacl::backend::finish
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
Definition: memory.hpp:54
viennacl::backend::detail::element_size< unsigned long >
vcl_size_t element_size< unsigned long >(memory_types)
Definition: memory.hpp:306
viennacl::backend::cuda::memory_copy
void memory_copy(handle_type const &src_buffer, handle_type &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' on the CUDA device to memory star...
Definition: cuda.hpp:130
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::backend::typesafe_host_array::get
void * get()
Definition: util.hpp:110
viennacl::backend::memory_read
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
Definition: memory.hpp:261
viennacl::backend::opencl::memory_read
void memory_read(viennacl::ocl::handle< cl_mem > const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_copy, void *ptr, bool async=false)
Reads data from an OpenCL buffer back to main RAM.
Definition: opencl.hpp:129
viennacl::backend::typesafe_host_array::resize
void resize(mem_handle const &handle, vcl_size_t num)
Resize including initialization of new memory (cf. std::vector<>)
Definition: util.hpp:138
viennacl::backend::cpu_ram::memory_write
void memory_write(handle_type &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_copy, const void *ptr, bool)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
Definition: cpu_ram.hpp:131
context.hpp
Implementation of a OpenCL-like context, which serves as a unification of {OpenMP, CUDA, OpenCL} at the user API.
viennacl::backend::detail::element_size
vcl_size_t element_size(memory_types)
Definition: memory.hpp:299
viennacl::context
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
viennacl::backend::detail::element_size< unsigned int >
vcl_size_t element_size< unsigned int >(memory_types)
Definition: memory.hpp:335
viennacl::backend::detail::element_size< long >
vcl_size_t element_size< long >(memory_types)
Definition: memory.hpp:320
viennacl::backend::detail::element_size< int >
vcl_size_t element_size< int >(memory_types)
Definition: memory.hpp:349
viennacl::backend::opencl::memory_copy
void memory_copy(viennacl::ocl::handle< cl_mem > const &src_buffer, viennacl::ocl::handle< cl_mem > &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' in the OpenCL context to memory s...
Definition: opencl.hpp:69
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
viennacl::CUDA_MEMORY
Definition: forwards.h:350
viennacl::ocl::get_queue
viennacl::ocl::command_queue & get_queue()
Convenience function for getting the default queue for the currently active device in the active cont...
Definition: backend.hpp:320
cpu_ram.hpp
Implementations for the OpenCL backend functionality.
context.hpp
Extracts the underlying context from objects.
mem_handle.hpp
Implements the multi-memory-domain handle.
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::backend::switch_memory_context
void switch_memory_context(mem_handle &handle, viennacl::context new_ctx)
Switches the active memory domain within a memory handle. Data is copied if the new active domain dif...
Definition: memory.hpp:368
cuda.hpp
Implementations for the CUDA backend functionality.
viennacl::backend::cpu_ram::memory_copy
void memory_copy(handle_type const &src_buffer, handle_type &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'ds...
Definition: cpu_ram.hpp:108
backend.hpp
Implementations of the OpenCL backend, where all contexts are stored in.
viennacl::backend::default_memory_type
memory_types default_memory_type()
Returns the default memory type for the given configuration.
Definition: mem_handle.hpp:73
viennacl::context::memory_type
viennacl::memory_types memory_type() const
Definition: context.hpp:76
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::backend::cuda::memory_create
handle_type memory_create(vcl_size_t size_in_bytes, const void *host_ptr=NULL)
Creates an array of the specified size on the CUDA device. If the second argument is provided...
Definition: cuda.hpp:103
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::backend::memory_copy
void memory_copy(mem_handle const &src_buffer, mem_handle &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'ds...
Definition: memory.hpp:140
viennacl::traits::context
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
viennacl::backend::cuda::memory_read
void memory_read(handle_type const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_copy, void *ptr, bool async=false)
Reads data from a CUDA buffer back to main RAM.
Definition: cuda.hpp:183
viennacl::backend::typesafe_host_array::set
void set(vcl_size_t index, U value)
Definition: util.hpp:115
viennacl::tools::shared_ptr::get
T * get() const
Definition: shared_ptr.hpp:101
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
viennacl::backend::memory_create
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
Definition: memory.hpp:87
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
opencl.hpp
Implementations for the OpenCL backend functionality.
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
viennacl::memory_types
memory_types
Definition: forwards.h:345
viennacl::backend::typesafe_host_array::raw_size
vcl_size_t raw_size() const
Definition: util.hpp:111
viennacl::backend::memory_shallow_copy
void memory_shallow_copy(mem_handle const &src_buffer, mem_handle &dst_buffer)
A 'shallow' copy operation from an initialized buffer to an uninitialized buffer. The uninitialized b...
Definition: memory.hpp:177
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
viennacl::backend::mem_handle::get_active_handle_id
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
Definition: mem_handle.hpp:118
util.hpp
Helper functionality for working with different memory domains.
viennacl::switch_memory_context
void switch_memory_context(T &obj, viennacl::context new_ctx)
Generic convenience routine for migrating data of an object to a new memory domain.
Definition: memory.hpp:622