ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
viennacl::backend Namespace Reference

Namespace providing routines for handling the different memory domains. More...

Namespaces

 cpu_ram
 Provides implementations for handling memory buffers in CPU RAM.
 
 cuda
 Provides implementations for handling CUDA memory buffers.
 
 detail
 Implementation details for the generic memory backend interface.
 
 opencl
 Provides implementations for handling OpenCL memory buffers.
 

Classes

class  mem_handle
 Main abstraction class for multiple memory domains. Represents a buffer in either main RAM, an OpenCL context, or a CUDA device. More...
 
class  typesafe_host_array
 Helper class implementing an array on the host. Default case: No conversion necessary. More...
 
class  typesafe_host_array< T, true >
 Special host array type for conversion between OpenCL types and pure CPU types. More...
 

Functions

memory_types default_memory_type ()
 Returns the default memory type for the given configuration. More...
 
memory_types default_memory_type (memory_types new_memory_type)
 Sets the default memory type for the given configuration. More...
 
void finish ()
 Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed. More...
 
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 with data from that pointer. More...
 
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 'dst_buffer + dst_offset'. More...
 
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 buffer just copies the raw handle. More...
 
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'. More...
 
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. More...
 
template<typename DataType >
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 differs from the old one. Memory in the source handle is not free'd. More...
 
template<typename DataType >
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 binary representation of 'DataType' among the memory domains differs. More...
 

Detailed Description

Namespace providing routines for handling the different memory domains.

Function Documentation

memory_types viennacl::backend::default_memory_type ( )
inline

Returns the default memory type for the given configuration.

CUDA has precedence over OpenCL, which has precedence over main memory. Depends on which VIENNACL_WITH_{CUDA/OPENCL/OPENMP} macros are defined.

Definition at line 73 of file mem_handle.hpp.

memory_types viennacl::backend::default_memory_type ( memory_types  new_memory_type)
inline

Sets the default memory type for the given configuration.

Make sure the respective new memory type is enabled. For example, passing CUDA_MEMORY if no CUDA backend is selected will result in exceptions being thrown as soon as you try to allocate buffers.

Definition at line 80 of file mem_handle.hpp.

void viennacl::backend::finish ( )
inline

Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.

Examples:
amg.cpp, and blas3.cpp.

Definition at line 54 of file memory.hpp.

void viennacl::backend::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 
)
inline

Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'dst_buffer + dst_offset'.

This is the generic version for CPU RAM, CUDA, and OpenCL. Copies the memory in the currently active memory domain.

Parameters
src_bufferA smart pointer to the begin of an allocated buffer
dst_bufferA smart pointer to the end of an allocated buffer
src_offsetOffset of the first byte to be written from the address given by 'src_buffer' (in bytes)
dst_offsetOffset of the first byte to be written to the address given by 'dst_buffer' (in bytes)
bytes_to_copyNumber of bytes to be copied

Definition at line 140 of file memory.hpp.

void viennacl::backend::memory_create ( mem_handle handle,
vcl_size_t  size_in_bytes,
viennacl::context const &  ctx,
const void *  host_ptr = NULL 
)
inline

Creates an array of the specified size. If the second argument is provided, the buffer is initialized with data from that pointer.

This is the generic version for CPU RAM, CUDA, and OpenCL. Creates the memory in the currently active memory domain.

Parameters
handleThe generic wrapper handle for multiple memory domains which will hold the new buffer.
size_in_bytesNumber of bytes to allocate
ctxOptional context in which the matrix is created (one out of multiple OpenCL contexts, CUDA, host)
host_ptrPointer to data which will be copied to the new array. Must point to at least 'size_in_bytes' bytes of data.

Definition at line 87 of file memory.hpp.

void viennacl::backend::memory_read ( mem_handle const &  src_buffer,
vcl_size_t  src_offset,
vcl_size_t  bytes_to_read,
void *  ptr,
bool  async = false 
)
inline

Reads data from a buffer back to main RAM.

This is the generic version for CPU RAM, CUDA, and OpenCL. Reads the memory from the currently active memory domain.

Parameters
src_bufferA smart pointer to the beginning of an allocated source buffer
src_offsetOffset of the first byte to be read from the beginning of src_buffer (in bytes_
bytes_to_readNumber of bytes to be read
ptrLocation in main RAM where to read data should be written to
asyncWhether the operation should be asynchronous

Definition at line 261 of file memory.hpp.

void viennacl::backend::memory_shallow_copy ( mem_handle const &  src_buffer,
mem_handle dst_buffer 
)
inline

A 'shallow' copy operation from an initialized buffer to an uninitialized buffer. The uninitialized buffer just copies the raw handle.

Definition at line 177 of file memory.hpp.

void viennacl::backend::memory_write ( mem_handle dst_buffer,
vcl_size_t  dst_offset,
vcl_size_t  bytes_to_write,
const void *  ptr,
bool  async = false 
)
inline

Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.

This is the generic version for CPU RAM, CUDA, and OpenCL. Writes the memory in the currently active memory domain.

Parameters
dst_bufferA smart pointer to the beginning of an allocated buffer
dst_offsetOffset of the first written byte from the beginning of 'dst_buffer' (in bytes)
bytes_to_writeNumber of bytes to be written
ptrPointer to the first byte to be written
asyncWhether the operation should be asynchronous

Definition at line 220 of file memory.hpp.

template<typename DataType >
void viennacl::backend::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 differs from the old one. Memory in the source handle is not free'd.

Definition at line 368 of file memory.hpp.

template<typename DataType >
void viennacl::backend::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 binary representation of 'DataType' among the memory domains differs.

Definition at line 470 of file memory.hpp.