ViennaCL - The Vienna Computing Library
1.5.1
|
Manages an OpenCL context and provides the respective convenience functions for creating buffers, etc. More...
#include <context.hpp>
Public Member Functions | |
context () | |
vcl_size_t | default_device_num () const |
Returns the maximum number of devices to be set up for the context. | |
void | default_device_num (vcl_size_t new_num) |
Sets the maximum number of devices to be set up for the context. | |
cl_device_type | default_device_type () |
Returns the default device type for the context. | |
void | default_device_type (cl_device_type dtype) |
Sets the device type for this context. | |
std::vector < viennacl::ocl::device > const & | devices () const |
Returns a vector with all devices in this context. | |
viennacl::ocl::device const & | current_device () const |
Returns the current device. | |
void | switch_device (vcl_size_t i) |
Switches the current device to the i-th device in this context. | |
void | switch_device (viennacl::ocl::device const &d) |
If the supplied device is used within the context, it becomes the current active device. | |
void | add_device (viennacl::ocl::device const &d) |
Add a device to the context. Must be done before the context is initialized. | |
void | add_device (cl_device_id d) |
Add a device to the context. Must be done before the context is initialized. | |
void | init () |
Initializes a new context. | |
void | init (cl_context c) |
Initializes the context from an existing, user-supplied context. | |
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. | |
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. | |
template<typename SCALARTYPE , typename A , template< typename, typename > class VectorType> | |
viennacl::ocl::handle< cl_mem > | create_memory (cl_mem_flags flags, const VectorType< SCALARTYPE, A > &buffer) const |
Creates a memory buffer within the context initialized from the supplied data. | |
void | add_queue (cl_device_id dev, cl_command_queue q) |
Adds an existing queue for the given device to the context. | |
void | add_queue (cl_device_id dev) |
Adds a queue for the given device to the context. | |
void | add_queue (viennacl::ocl::device d) |
Adds a queue for the given device to the context. | |
viennacl::ocl::command_queue & | get_queue () |
viennacl::ocl::command_queue const & | get_queue () const |
viennacl::ocl::command_queue & | get_queue (cl_device_id dev, vcl_size_t i=0) |
Returns the queue with the provided index for the given device. | |
viennacl::ocl::command_queue const & | current_queue () |
Returns the current device. | |
void | switch_queue (vcl_size_t i) |
Switches the current device to the i-th device in this context. | |
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. | |
viennacl::ocl::program & | add_program (cl_program p, std::string const &prog_name) |
Adds a program to the context. | |
viennacl::ocl::program & | add_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. | |
void | delete_program (std::string const &name) |
Delete the program with the provided name. | |
viennacl::ocl::program & | get_program (std::string const &name) |
Returns the program with the provided name. | |
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. | |
viennacl::ocl::program & | get_program (vcl_size_t id) |
Returns the program with the provided id. | |
vcl_size_t | program_num () |
Returns the number of programs within this context. | |
viennacl::ocl::kernel & | get_kernel (std::string const &program_name, std::string const &kernel_name) |
Convenience function for retrieving the kernel of a program directly from the context. | |
vcl_size_t | device_num () |
Returns the number of devices within this context. | |
const viennacl::ocl::handle < cl_context > & | handle () const |
Returns the context handle. | |
std::string | build_options () const |
Returns the current build option string. | |
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. | |
vcl_size_t | platform_index () const |
Returns the platform ID of the platform to be used for the context. | |
void | platform_index (vcl_size_t new_index) |
Sets the platform ID of the platform to be used for the context. | |
bool | operator< (context const &other) const |
Less-than comparable for compatibility with std:map. | |
bool | operator== (context const &other) const |
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.
context | ( | ) | [inline] |
void add_device | ( | viennacl::ocl::device const & | d | ) | [inline] |
Add a device to the context. Must be done before the context is initialized.
void add_device | ( | cl_device_id | d | ) | [inline] |
Add a device to the context. Must be done before the context is initialized.
viennacl::ocl::program& add_program | ( | cl_program | p, |
std::string const & | prog_name | ||
) | [inline] |
Adds a program to the context.
viennacl::ocl::program& 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.
void add_queue | ( | cl_device_id | dev, |
cl_command_queue | q | ||
) | [inline] |
Adds an existing queue for the given device to the context.
void add_queue | ( | cl_device_id | dev | ) | [inline] |
Adds a queue for the given device to the context.
void add_queue | ( | viennacl::ocl::device | d | ) | [inline] |
Adds a queue for the given device to the context.
std::string build_options | ( | ) | const [inline] |
Returns the current build option string.
void 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.
viennacl::ocl::handle<cl_mem> create_memory | ( | cl_mem_flags | flags, |
unsigned int | size, | ||
void * | ptr = NULL |
||
) | const [inline] |
Creates a memory buffer within the context.
flags | OpenCL flags for the buffer creation |
size | Size of the memory buffer in bytes |
ptr | Optional pointer to CPU memory, with which the OpenCL memory should be initialized |
viennacl::ocl::handle<cl_mem> create_memory | ( | cl_mem_flags | flags, |
const VectorType< SCALARTYPE, A > & | buffer | ||
) | const [inline] |
Creates a memory buffer within the context initialized from the supplied data.
flags | OpenCL flags for the buffer creation |
buffer | A vector (STL vector, ublas vector, etc.) |
cl_mem 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.
flags | OpenCL flags for the buffer creation |
size | Size of the memory buffer in bytes |
ptr | Optional pointer to CPU memory, with which the OpenCL memory should be initialized |
viennacl::ocl::device const& current_device | ( | ) | const [inline] |
Returns the current device.
viennacl::ocl::command_queue const& current_queue | ( | ) | [inline] |
Returns the current device.
vcl_size_t default_device_num | ( | ) | const [inline] |
Returns the maximum number of devices to be set up for the context.
void default_device_num | ( | vcl_size_t | new_num | ) | [inline] |
Sets the maximum number of devices to be set up for the context.
cl_device_type default_device_type | ( | ) | [inline] |
Returns the default device type for the context.
void default_device_type | ( | cl_device_type | dtype | ) | [inline] |
Sets the device type for this context.
void delete_program | ( | std::string const & | name | ) | [inline] |
Delete the program with the provided name.
vcl_size_t device_num | ( | ) | [inline] |
Returns the number of devices within this context.
std::vector<viennacl::ocl::device> const& devices | ( | ) | const [inline] |
Returns a vector with all devices in this context.
viennacl::ocl::kernel& 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.
viennacl::ocl::program& get_program | ( | std::string const & | name | ) | [inline] |
Returns the program with the provided name.
viennacl::ocl::program const& get_program | ( | std::string const & | name | ) | const [inline] |
viennacl::ocl::program& get_program | ( | vcl_size_t | id | ) | [inline] |
Returns the program with the provided id.
viennacl::ocl::command_queue& get_queue | ( | ) | [inline] |
viennacl::ocl::command_queue const& get_queue | ( | ) | const [inline] |
viennacl::ocl::command_queue& get_queue | ( | cl_device_id | dev, |
vcl_size_t | i = 0 |
||
) | [inline] |
Returns the queue with the provided index for the given device.
const viennacl::ocl::handle<cl_context>& handle | ( | ) | const [inline] |
Returns the context handle.
bool has_program | ( | std::string const & | name | ) | [inline] |
Returns whether the program with the provided name exists or not.
void init | ( | ) | [inline] |
Initializes a new context.
void init | ( | cl_context | c | ) | [inline] |
Initializes the context from an existing, user-supplied context.
bool operator< | ( | context const & | other | ) | const [inline] |
Less-than comparable for compatibility with std:map.
bool operator== | ( | context const & | other | ) | const [inline] |
vcl_size_t platform_index | ( | ) | const [inline] |
Returns the platform ID of the platform to be used for the context.
void platform_index | ( | vcl_size_t | new_index | ) | [inline] |
Sets the platform ID of the platform to be used for the context.
vcl_size_t program_num | ( | ) | [inline] |
Returns the number of programs within this context.
void switch_device | ( | vcl_size_t | i | ) | [inline] |
Switches the current device to the i-th device in this context.
void switch_device | ( | viennacl::ocl::device const & | d | ) | [inline] |
If the supplied device is used within the context, it becomes the current active device.
void switch_queue | ( | vcl_size_t | i | ) | [inline] |
Switches the current device to the i-th device in this context.
void 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.