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

Manages an OpenCL context and provides the respective convenience functions for creating buffers, etc. More...

#include <context.hpp>

Public Member Functions

 context ()
 
std::string cache_path () const
 Returns the compiled kernel cache path. More...
 
void cache_path (std::string new_path)
 Sets the compiled kernel cache path. More...
 
vcl_size_t default_device_num () const
 Returns the maximum number of devices to be set up for the context. More...
 
void default_device_num (vcl_size_t new_num)
 Sets the maximum number of devices to be set up for the context. More...
 
cl_device_type default_device_type ()
 Returns the default device type for the context. More...
 
void default_device_type (cl_device_type dtype)
 Sets the device type for this context. More...
 
std::vector< viennacl::ocl::device > const & devices () const
 Returns a vector with all devices in this context. More...
 
viennacl::ocl::device const & current_device () const
 Returns the current device. More...
 
void switch_device (vcl_size_t i)
 Switches the current device to the i-th device in this context. More...
 
void switch_device (viennacl::ocl::device const &d)
 If the supplied device is used within the context, it becomes the current active device. More...
 
void add_device (viennacl::ocl::device const &d)
 Add a device to the context. Must be done before the context is initialized. More...
 
void add_device (cl_device_id d)
 Add a device to the context. Must be done before the context is initialized. More...
 
void init ()
 Initializes a new context. More...
 
void init (cl_context c)
 Initializes the context from an existing, user-supplied context. More...
 
cl_mem create_memory_without_smart_handle (cl_mem_flags flags, unsigned int size, void *ptr=NULL) const
 Creates a memory buffer within the context. Does not wrap the OpenCL handle into the smart-pointer-like viennacl::ocl::handle, which saves an OpenCL backend call, yet the user has to ensure that the OpenCL memory handle is free'd or passed to a viennacl::ocl::handle later on. More...
 
viennacl::ocl::handle< cl_mem > create_memory (cl_mem_flags flags, unsigned int size, void *ptr=NULL) const
 Creates a memory buffer within the context. More...
 
template<typename NumericT , typename A , template< typename, typename > class VectorType>
viennacl::ocl::handle< cl_mem > create_memory (cl_mem_flags flags, const VectorType< NumericT, A > &buffer) const
 Creates a memory buffer within the context initialized from the supplied data. More...
 
void add_queue (cl_device_id dev, cl_command_queue q)
 Adds an existing queue for the given device to the context. More...
 
void add_queue (cl_device_id dev)
 Adds a queue for the given device to the context. More...
 
void add_queue (viennacl::ocl::device d)
 Adds a queue for the given device to the context. More...
 
viennacl::ocl::command_queueget_queue ()
 
viennacl::ocl::command_queue const & get_queue () const
 
viennacl::ocl::command_queueget_queue (cl_device_id dev, vcl_size_t i=0)
 Returns the queue with the provided index for the given device. More...
 
viennacl::ocl::command_queue const & current_queue ()
 Returns the current device. More...
 
void switch_queue (vcl_size_t i)
 Switches the current device to the i-th device in this context. More...
 
void switch_queue (viennacl::ocl::command_queue const &q)
 If the supplied command_queue is used within the context, it becomes the current active command_queue, the command_queue's device becomes current active device. More...
 
viennacl::ocl::programadd_program (cl_program p, std::string const &prog_name)
 Adds a program to the context. More...
 
viennacl::ocl::programadd_program (std::string const &source, std::string const &prog_name)
 Adds a new program with the provided source to the context. Compiles the program and extracts all kernels from it. More...
 
void delete_program (std::string const &name)
 Delete the program with the provided name. More...
 
viennacl::ocl::programget_program (std::string const &name)
 Returns the program with the provided name. More...
 
viennacl::ocl::program const & get_program (std::string const &name) const
 
bool has_program (std::string const &name)
 Returns whether the program with the provided name exists or not. More...
 
viennacl::ocl::programget_program (vcl_size_t id)
 Returns the program with the provided id. More...
 
program_container_type get_programs ()
 
vcl_size_t program_num ()
 Returns the number of programs within this context. More...
 
viennacl::ocl::kernelget_kernel (std::string const &program_name, std::string const &kernel_name)
 Convenience function for retrieving the kernel of a program directly from the context. More...
 
vcl_size_t device_num ()
 Returns the number of devices within this context. More...
 
const viennacl::ocl::handle< cl_context > & handle () const
 Returns the context handle. More...
 
std::string build_options () const
 Returns the current build option string. More...
 
void build_options (std::string op)
 Sets the build option string, which is passed to the OpenCL compiler in subsequent compilations. Does not effect programs already compiled previously. More...
 
vcl_size_t platform_index () const
 Returns the platform ID of the platform to be used for the context. More...
 
void platform_index (vcl_size_t new_index)
 Sets the platform ID of the platform to be used for the context. More...
 
bool operator< (context const &other) const
 Less-than comparable for compatibility with std:map. More...
 
bool operator== (context const &other) const
 

Detailed Description

Manages an OpenCL context and provides the respective convenience functions for creating buffers, etc.

This class was originally written before the OpenCL C++ bindings were standardized. Regardless, it provides a couple of convience functionality which is not covered by the OpenCL C++ bindings.

Examples:
matrix-free.cpp.

Definition at line 55 of file context.hpp.

Constructor & Destructor Documentation

viennacl::ocl::context::context ( )
inline

Definition at line 60 of file context.hpp.

Member Function Documentation

void viennacl::ocl::context::add_device ( viennacl::ocl::device const &  d)
inline

Add a device to the context. Must be done before the context is initialized.

Definition at line 146 of file context.hpp.

void viennacl::ocl::context::add_device ( cl_device_id  d)
inline

Add a device to the context. Must be done before the context is initialized.

Definition at line 157 of file context.hpp.

viennacl::ocl::program& viennacl::ocl::context::add_program ( cl_program  p,
std::string const &  prog_name 
)
inline

Adds a program to the context.

Examples:
custom-context.cpp, custom-kernels.cpp, and matrix-free.cpp.

Definition at line 368 of file context.hpp.

viennacl::ocl::program& viennacl::ocl::context::add_program ( std::string const &  source,
std::string const &  prog_name 
)
inline

Adds a new program with the provided source to the context. Compiles the program and extracts all kernels from it.

Definition at line 379 of file context.hpp.

void viennacl::ocl::context::add_queue ( cl_device_id  dev,
cl_command_queue  q 
)
inline

Adds an existing queue for the given device to the context.

Definition at line 235 of file context.hpp.

void viennacl::ocl::context::add_queue ( cl_device_id  dev)
inline

Adds a queue for the given device to the context.

Definition at line 246 of file context.hpp.

void viennacl::ocl::context::add_queue ( viennacl::ocl::device  d)
inline

Adds a queue for the given device to the context.

Definition at line 263 of file context.hpp.

std::string viennacl::ocl::context::build_options ( ) const
inline

Returns the current build option string.

Definition at line 614 of file context.hpp.

void viennacl::ocl::context::build_options ( std::string  op)
inline

Sets the build option string, which is passed to the OpenCL compiler in subsequent compilations. Does not effect programs already compiled previously.

Definition at line 617 of file context.hpp.

std::string viennacl::ocl::context::cache_path ( ) const
inline

Returns the compiled kernel cache path.

Definition at line 75 of file context.hpp.

void viennacl::ocl::context::cache_path ( std::string  new_path)
inline

Sets the compiled kernel cache path.

Definition at line 78 of file context.hpp.

viennacl::ocl::handle<cl_mem> viennacl::ocl::context::create_memory ( cl_mem_flags  flags,
unsigned int  size,
void *  ptr = NULL 
) const
inline

Creates a memory buffer within the context.

Parameters
flagsOpenCL flags for the buffer creation
sizeSize of the memory buffer in bytes
ptrOptional pointer to CPU memory, with which the OpenCL memory should be initialized

Definition at line 216 of file context.hpp.

template<typename NumericT , typename A , template< typename, typename > class VectorType>
viennacl::ocl::handle<cl_mem> viennacl::ocl::context::create_memory ( cl_mem_flags  flags,
const VectorType< NumericT, A > &  buffer 
) const
inline

Creates a memory buffer within the context initialized from the supplied data.

Parameters
flagsOpenCL flags for the buffer creation
bufferA vector (STL vector, ublas vector, etc.)

Definition at line 227 of file context.hpp.

cl_mem viennacl::ocl::context::create_memory_without_smart_handle ( cl_mem_flags  flags,
unsigned int  size,
void *  ptr = NULL 
) const
inline

Creates a memory buffer within the context. Does not wrap the OpenCL handle into the smart-pointer-like viennacl::ocl::handle, which saves an OpenCL backend call, yet the user has to ensure that the OpenCL memory handle is free'd or passed to a viennacl::ocl::handle later on.

Parameters
flagsOpenCL flags for the buffer creation
sizeSize of the memory buffer in bytes
ptrOptional pointer to CPU memory, with which the OpenCL memory should be initialized
Returns
A plain OpenCL handle. Either assign it to a viennacl::ocl::handle<cl_mem> directly, or make sure that you free to memory manually if you no longer need the allocated memory.

Definition at line 196 of file context.hpp.

viennacl::ocl::device const& viennacl::ocl::context::current_device ( ) const
inline

Returns the current device.

Definition at line 112 of file context.hpp.

viennacl::ocl::command_queue const& viennacl::ocl::context::current_queue ( )
inline

Returns the current device.

Definition at line 323 of file context.hpp.

vcl_size_t viennacl::ocl::context::default_device_num ( ) const
inline

Returns the maximum number of devices to be set up for the context.

Definition at line 82 of file context.hpp.

void viennacl::ocl::context::default_device_num ( vcl_size_t  new_num)
inline

Sets the maximum number of devices to be set up for the context.

Definition at line 85 of file context.hpp.

cl_device_type viennacl::ocl::context::default_device_type ( )
inline

Returns the default device type for the context.

Definition at line 89 of file context.hpp.

void viennacl::ocl::context::default_device_type ( cl_device_type  dtype)
inline

Sets the device type for this context.

Definition at line 95 of file context.hpp.

void viennacl::ocl::context::delete_program ( std::string const &  name)
inline

Delete the program with the provided name.

Definition at line 514 of file context.hpp.

vcl_size_t viennacl::ocl::context::device_num ( )
inline

Returns the number of devices within this context.

Definition at line 608 of file context.hpp.

std::vector<viennacl::ocl::device> const& viennacl::ocl::context::devices ( ) const
inline

Returns a vector with all devices in this context.

Examples:
blas3.cpp, multithreaded.cpp, and multithreaded_cg.cpp.

Definition at line 106 of file context.hpp.

viennacl::ocl::kernel& viennacl::ocl::context::get_kernel ( std::string const &  program_name,
std::string const &  kernel_name 
)
inline

Convenience function for retrieving the kernel of a program directly from the context.

Examples:
matrix-free.cpp.

Definition at line 605 of file context.hpp.

viennacl::ocl::program& viennacl::ocl::context::get_program ( std::string const &  name)
inline

Returns the program with the provided name.

Definition at line 532 of file context.hpp.

viennacl::ocl::program const& viennacl::ocl::context::get_program ( std::string const &  name) const
inline

Definition at line 551 of file context.hpp.

viennacl::ocl::program& viennacl::ocl::context::get_program ( vcl_size_t  id)
inline

Returns the program with the provided id.

Definition at line 583 of file context.hpp.

program_container_type viennacl::ocl::context::get_programs ( )
inline

Definition at line 596 of file context.hpp.

viennacl::ocl::command_queue& viennacl::ocl::context::get_queue ( )
inline

Definition at line 266 of file context.hpp.

viennacl::ocl::command_queue const& viennacl::ocl::context::get_queue ( ) const
inline

Definition at line 276 of file context.hpp.

viennacl::ocl::command_queue& viennacl::ocl::context::get_queue ( cl_device_id  dev,
vcl_size_t  i = 0 
)
inline

Returns the queue with the provided index for the given device.

Definition at line 301 of file context.hpp.

const viennacl::ocl::handle<cl_context>& viennacl::ocl::context::handle ( ) const
inline

Returns the context handle.

Examples:
custom-context.cpp.

Definition at line 611 of file context.hpp.

bool viennacl::ocl::context::has_program ( std::string const &  name)
inline

Returns whether the program with the provided name exists or not.

Definition at line 571 of file context.hpp.

void viennacl::ocl::context::init ( )
inline

Initializes a new context.

Definition at line 167 of file context.hpp.

void viennacl::ocl::context::init ( cl_context  c)
inline

Initializes the context from an existing, user-supplied context.

Definition at line 173 of file context.hpp.

bool viennacl::ocl::context::operator< ( context const &  other) const
inline

Less-than comparable for compatibility with std:map.

Definition at line 630 of file context.hpp.

bool viennacl::ocl::context::operator== ( context const &  other) const
inline

Definition at line 635 of file context.hpp.

vcl_size_t viennacl::ocl::context::platform_index ( ) const
inline

Returns the platform ID of the platform to be used for the context.

Definition at line 620 of file context.hpp.

void viennacl::ocl::context::platform_index ( vcl_size_t  new_index)
inline

Sets the platform ID of the platform to be used for the context.

Definition at line 623 of file context.hpp.

vcl_size_t viennacl::ocl::context::program_num ( )
inline

Returns the number of programs within this context.

Definition at line 602 of file context.hpp.

void viennacl::ocl::context::switch_device ( vcl_size_t  i)
inline

Switches the current device to the i-th device in this context.

Examples:
blas3.cpp.

Definition at line 119 of file context.hpp.

void viennacl::ocl::context::switch_device ( viennacl::ocl::device const &  d)
inline

If the supplied device is used within the context, it becomes the current active device.

Definition at line 126 of file context.hpp.

void viennacl::ocl::context::switch_queue ( vcl_size_t  i)
inline

Switches the current device to the i-th device in this context.

Definition at line 329 of file context.hpp.

void viennacl::ocl::context::switch_queue ( viennacl::ocl::command_queue const &  q)
inline

If the supplied command_queue is used within the context, it becomes the current active command_queue, the command_queue's device becomes current active device.

Definition at line 336 of file context.hpp.


The documentation for this class was generated from the following file: