RandomBallCover  1.2.1
 Hosted by GitHub
Public Types | Public Member Functions | Public Attributes | List of all members
cl_algo::RBC::Reduce< C, T > Class Template Reference

Interface class for the reduce kernels. More...

#include <algorithms.hpp>

Collaboration diagram for cl_algo::RBC::Reduce< C, T >:
Collaboration graph
[legend]

Public Types

enum  Memory : uint8_t {
  Memory::H_IN, Memory::H_OUT, Memory::D_IN, Memory::D_RED,
  Memory::D_OUT
}
 Enumerates the memory objects handled by the class. More...
 

Public Member Functions

 Reduce (clutils::CLEnv &_env, clutils::CLEnvInfo< 1 > _info)
 Configures an OpenCL environment as specified by _info. More...
 
cl::Memory & get (Reduce::Memory mem)
 Returns a reference to an internal memory object. More...
 
void init (unsigned int _cols, unsigned int _rows, Staging _staging=Staging::IO)
 Configures kernel execution parameters. More...
 
void write (Reduce::Memory mem=Reduce::Memory::D_IN, void *ptr=nullptr, bool block=CL_FALSE, const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
 Performs a data transfer to a device buffer. More...
 
void * read (Reduce::Memory mem=Reduce::Memory::H_OUT, bool block=CL_TRUE, const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
 Performs a data transfer to a staging buffer. More...
 
void run (const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
 Executes the necessary kernels. More...
 
template<typename period >
double run (clutils::GPUTimer< period > &timer, const std::vector< cl::Event > *events=nullptr)
 Executes the necessary kernels. More...
 
template<>
 Reduce (clutils::CLEnv &_env, clutils::CLEnvInfo< 1 > _info)
 
template<>
 Reduce (clutils::CLEnv &_env, clutils::CLEnvInfo< 1 > _info)
 

Public Attributes

T * hPtrIn
 
T * hPtrOut
 

Detailed Description

template<ReduceConfig C, typename T = cl_float>
class cl_algo::RBC::Reduce< C, T >

Interface class for the reduce kernels.

The reduce kernels reduce each row of an array to a single element. For more details, look at the kernels' documentation.

Note
The reduce kernels are available in kernels/reduce_kernels.cl.
The class creates its own buffers. If you would like to provide your own buffers, call get to get references to the placeholders within the class and assign them to your buffers. You will have to do this strictly before the call to init. You can also call get (after the call to init) to get a reference to a buffer within the class and assign it to another kernel class instance further down in your task pipeline.

The following input/output OpenCL memory objects are created by a Reduce instance:

Name Type Placement I/O Use Properties Size
H_IN Buffer Host I Staging CL_MEM_READ_WRITE \(columns*rows*sizeof\ (T)\)
H_OUT Buffer Host O Staging CL_MEM_READ_WRITE \( rows*sizeof\ (T)\)
D_IN Buffer Device I Processing CL_MEM_READ_ONLY \(columns*rows*sizeof\ (T)\)
D_OUT Buffer Device O Processing CL_MEM_WRITE_ONLY \( rows*sizeof\ (T)\)
Template Parameters
Cconfigures the class for different types of reduction.
Tconfigures the class to work with different types of data.

Member Enumeration Documentation

template<ReduceConfig C, typename T = cl_float>
enum cl_algo::RBC::Reduce::Memory : uint8_t
strong

Enumerates the memory objects handled by the class.

Note
H_* names refer to staging buffers on the host.
D_* names refer to buffers on the device.
Enumerator
H_IN 

Input staging buffer.

H_OUT 

Output staging buffer.

D_IN 

Input buffer.

D_RED 

Buffer of reduced elements per work-group.

D_OUT 

Output buffer.

Constructor & Destructor Documentation

template<ReduceConfig C, typename T = cl_float>
cl_algo::RBC::Reduce< C, T >::Reduce ( clutils::CLEnv &  _env,
clutils::CLEnvInfo< 1 >  _info 
)

Configures an OpenCL environment as specified by _info.

template<>
cl_algo::RBC::Reduce< ReduceConfig::MIN, cl_float >::Reduce ( clutils::CLEnv &  _env,
clutils::CLEnvInfo< 1 >  _info 
)
Parameters
[in]_envopencl environment.
[in]_infoopencl configuration. Specifies the context, queue, etc, to be used.
template<>
cl_algo::RBC::Reduce< ReduceConfig::MAX, cl_uint >::Reduce ( clutils::CLEnv &  _env,
clutils::CLEnvInfo< 1 >  _info 
)
Parameters
[in]_envopencl environment.
[in]_infoopencl configuration. Specifies the context, queue, etc, to be used.

Member Function Documentation

template<ReduceConfig C, typename T >
cl::Memory & cl_algo::RBC::Reduce< C, T >::get ( Reduce< C, T >::Memory  mem)

Returns a reference to an internal memory object.

This interface exists to allow CL memory sharing between different kernels.

Parameters
[in]memenumeration value specifying the requested memory object.
Returns
A reference to the requested memory object.
template<ReduceConfig C, typename T >
void cl_algo::RBC::Reduce< C, T >::init ( unsigned int  _cols,
unsigned int  _rows,
Staging  _staging = Staging::IO 
)

Configures kernel execution parameters.

Sets up memory objects as necessary, and defines the kernel workspaces.

Note
If you have assigned a memory object to one member variable of the class before the call to init, then that memory will be maintained. Otherwise, a new memory object will be created.
Parameters
[in]_colsnumber of columns in the input array.
[in]_rowsnumber of rows in the input array.
[in]_stagingflag to indicate whether or not to instantiate the staging buffers.
template<ReduceConfig C, typename T >
void * cl_algo::RBC::Reduce< C, T >::read ( Reduce< C, T >::Memory  mem = Reduce< C, T >::Memory::H_OUT,
bool  block = CL_TRUE,
const std::vector< cl::Event > *  events = nullptr,
cl::Event *  event = nullptr 
)

Performs a data transfer to a staging buffer.

The transfer happens from a device buffer to the associated (specified) staging buffer on the host.

Parameters
[in]memenumeration value specifying an output staging buffer.
[in]blocka flag to indicate whether to perform a blocking or a non-blocking operation.
[in]eventsa wait-list of events.
[out]eventevent associated with the read operation to the staging buffer.
template<ReduceConfig C, typename T >
void cl_algo::RBC::Reduce< C, T >::run ( const std::vector< cl::Event > *  events = nullptr,
cl::Event *  event = nullptr 
)

Executes the necessary kernels.

The function call is non-blocking.

Parameters
[in]eventsa wait-list of events.
[out]eventevent associated with the kernel execution.
template<ReduceConfig C, typename T = cl_float>
template<typename period >
double cl_algo::RBC::Reduce< C, T >::run ( clutils::GPUTimer< period > &  timer,
const std::vector< cl::Event > *  events = nullptr 
)
inline

Executes the necessary kernels.

This run instance is used for profiling.

Parameters
[in]timerGPUTimer that does the profiling of the kernel executions.
[in]eventsa wait-list of events.
Returns
Τhe total execution time measured by the timer.
template<ReduceConfig C, typename T >
void cl_algo::RBC::Reduce< C, T >::write ( Reduce< C, T >::Memory  mem = Reduce< C, T >::Memory::D_IN,
void *  ptr = nullptr,
bool  block = CL_FALSE,
const std::vector< cl::Event > *  events = nullptr,
cl::Event *  event = nullptr 
)

Performs a data transfer to a device buffer.

The transfer happens from a staging buffer on the host to the associated (specified) device buffer.

Parameters
[in]memenumeration value specifying an input device buffer.
[in]ptra pointer to an array holding input data. If not NULL, the data from ptr will be copied to the associated staging buffer.
[in]blocka flag to indicate whether to perform a blocking or a non-blocking operation.
[in]eventsa wait-list of events.
[out]eventevent associated with the write operation to the device buffer.

Member Data Documentation

template<ReduceConfig C, typename T = cl_float>
T* cl_algo::RBC::Reduce< C, T >::hPtrIn

Mapping of the input staging buffer.

template<ReduceConfig C, typename T = cl_float>
T* cl_algo::RBC::Reduce< C, T >::hPtrOut

Mapping of the output staging buffer.


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