vSMC
vSMC: Scalable Monte Carlo
Public Types | Public Member Functions | Static Public Member Functions | List of all members
vsmc::StateCL< StateSize, FPType, ID > Class Template Reference

Particle::value_type subtype using OpenCL. More...

#include <vsmc/internal/forward.hpp>

Public Types

typedef ID cl_id
 
typedef FPType fp_type
 
typedef CLManager< ID > manager_type
 
typedef ::cl_ulong size_type
 
typedef cxx11::conditional< StateSize==Dynamic, std::vector< char >, Array< char, StateSize > >::type state_pack_type
 

Public Member Functions

 StateCL (size_type N)
 
template<typename CharT , typename Traits >
void build (const std::string &source, const std::string &flags, std::basic_ostream< CharT, Traits > &os)
 Build the OpenCL program from source. More...
 
void build (const std::string &source, const std::string &flags=std::string())
 
template<typename CharT , typename Traits >
void build (const ::cl::Program &program, const std::string &flags, std::basic_ostream< CharT, Traits > &os)
 Build from an existing program. More...
 
void build (const ::cl::Program &program, const std::string &flags=std::string())
 
bool build () const
 Whether the last attempted building success. More...
 
int build_id () const
 The build id of the last attempted of building. More...
 
template<typename IntType >
void copy (std::size_t N, const IntType *copy_from)
 
CLConfigurecopy_configure ()
 
const CLConfigurecopy_configure () const
 
::cl::Kernel & copy_kernel ()
 
const ::cl::Kernel & copy_kernel () const
 
void copy_post_processor ()
 
void copy_pre_processor ()
 
::cl::Kernel create_kernel (const std::string &name) const
 Create kernel with the current program. More...
 
const ::cl::Program & program () const
 The OpenCL program associated with this value collection. More...
 
void resize_state (std::size_t state_size)
 Change state size. More...
 
size_type size () const
 
const CLBuffer< char, ID > & state_buffer () const
 The OpenCL buffer that stores the state values. More...
 
state_pack_type state_pack (size_type id) const
 
std::size_t state_size () const
 
void state_unpack (size_type id, const state_pack_type &pack)
 
void update_state (::cl_mem_flags flag)
 Change state buffer flag (cause reallocation) More...
 
void update_state (::cl_mem_flags flag, void *host_ptr)
 Change state buffer flag and host pointer (cause reallocation) More...
 

Static Public Member Functions

static manager_typemanager ()
 The instance of the CLManager signleton associated with this value collcection. More...
 

Detailed Description

template<std::size_t StateSize, typename FPType, typename ID>
class vsmc::StateCL< StateSize, FPType, ID >

Particle::value_type subtype using OpenCL.

Definition at line 76 of file forward.hpp.

Member Typedef Documentation

template<std::size_t StateSize, typename FPType, typename ID>
typedef ID vsmc::StateCL< StateSize, FPType, ID >::cl_id

Definition at line 252 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
typedef FPType vsmc::StateCL< StateSize, FPType, ID >::fp_type

Definition at line 251 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
typedef CLManager<ID> vsmc::StateCL< StateSize, FPType, ID >::manager_type

Definition at line 253 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
typedef ::cl_ulong vsmc::StateCL< StateSize, FPType, ID >::size_type

Definition at line 250 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
typedef cxx11::conditional<StateSize == Dynamic, std::vector<char>, Array<char, StateSize> >::type vsmc::StateCL< StateSize, FPType, ID >::state_pack_type

Definition at line 255 of file backend_cl.hpp.

Constructor & Destructor Documentation

template<std::size_t StateSize, typename FPType, typename ID>
vsmc::StateCL< StateSize, FPType, ID >::StateCL ( size_type  N)
inlineexplicit

Definition at line 257 of file backend_cl.hpp.

Member Function Documentation

template<std::size_t StateSize, typename FPType, typename ID>
template<typename CharT , typename Traits >
void vsmc::StateCL< StateSize, FPType, ID >::build ( const std::string &  source,
const std::string &  flags,
std::basic_ostream< CharT, Traits > &  os 
)
inline

Build the OpenCL program from source.

Parameters
sourceThe source of the program
flagsThe OpenCL compiler flags, e.g., -I
osThe output stream to write the output when error occurs

Note that a few macros are defined before the user supplied source. Say the template parameter StateSize == 4, FPType of this class is set to cl_float, and there are 1000 particles, then the complete source, which acutally get compiled looks like the following

#ifndef FP_TYPE
#define FP_TYPE float
typedef float fp_type;
#endif
#ifndef VSMC_HAS_OPENCL_DOUBLE
#define VSMC_HAS_OPENCL_DOUBLE 0
#endif
#ifndef SIZE
#define SIZE 1000UL;
#endif
#ifndef STATE_SIZE
#define STATE_SIZE 4UL;
#endif
#ifndef SEED
#define SEED 101UL;
#endif
// The actual seed is vsmc::Seed::instance().get()
// ... User source, passed by the source argument

After build, vsmc::Seed::instance().skip(N) is called with N being the nubmer of particles.

Definition at line 345 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::build ( const std::string &  source,
const std::string &  flags = std::string() 
)
inline

Definition at line 357 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
template<typename CharT , typename Traits >
void vsmc::StateCL< StateSize, FPType, ID >::build ( const ::cl::Program &  program,
const std::string &  flags,
std::basic_ostream< CharT, Traits > &  os 
)
inline

Build from an existing program.

Definition at line 363 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::build ( const ::cl::Program &  program,
const std::string &  flags = std::string() 
)
inline

Definition at line 370 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
bool vsmc::StateCL< StateSize, FPType, ID >::build ( ) const
inline

Whether the last attempted building success.

Definition at line 375 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
int vsmc::StateCL< StateSize, FPType, ID >::build_id ( ) const
inline

The build id of the last attempted of building.

This function returns a non-decreasing sequence of integers

Definition at line 381 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
template<typename IntType >
void vsmc::StateCL< StateSize, FPType, ID >::copy ( std::size_t  N,
const IntType *  copy_from 
)
inline

Definition at line 395 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
CLConfigure& vsmc::StateCL< StateSize, FPType, ID >::copy_configure ( )
inline

Definition at line 457 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
const CLConfigure& vsmc::StateCL< StateSize, FPType, ID >::copy_configure ( ) const
inline

Definition at line 459 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
::cl::Kernel& vsmc::StateCL< StateSize, FPType, ID >::copy_kernel ( )
inline

Definition at line 461 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
const ::cl::Kernel& vsmc::StateCL< StateSize, FPType, ID >::copy_kernel ( ) const
inline

Definition at line 463 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::copy_post_processor ( )
inline

Definition at line 430 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::copy_pre_processor ( )
inline

Definition at line 404 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
::cl::Kernel vsmc::StateCL< StateSize, FPType, ID >::create_kernel ( const std::string &  name) const
inline

Create kernel with the current program.

If build() does not return true, then calling this is an error

Definition at line 387 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
static manager_type& vsmc::StateCL< StateSize, FPType, ID >::manager ( )
inlinestatic

The instance of the CLManager signleton associated with this value collcection.

Definition at line 299 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
const ::cl::Program& vsmc::StateCL< StateSize, FPType, ID >::program ( ) const
inline

The OpenCL program associated with this value collection.

Definition at line 305 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::resize_state ( std::size_t  state_size)
inline

Change state size.

Definition at line 279 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
size_type vsmc::StateCL< StateSize, FPType, ID >::size ( ) const
inline

Definition at line 274 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
const CLBuffer<char, ID>& vsmc::StateCL< StateSize, FPType, ID >::state_buffer ( ) const
inline

The OpenCL buffer that stores the state values.

Definition at line 302 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
state_pack_type vsmc::StateCL< StateSize, FPType, ID >::state_pack ( size_type  id) const
inline

Definition at line 440 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
std::size_t vsmc::StateCL< StateSize, FPType, ID >::state_size ( ) const
inline

Definition at line 276 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::state_unpack ( size_type  id,
const state_pack_type pack 
)
inline

Definition at line 448 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::update_state ( ::cl_mem_flags  flag)
inline

Change state buffer flag (cause reallocation)

Definition at line 290 of file backend_cl.hpp.

template<std::size_t StateSize, typename FPType, typename ID>
void vsmc::StateCL< StateSize, FPType, ID >::update_state ( ::cl_mem_flags  flag,
void *  host_ptr 
)
inline

Change state buffer flag and host pointer (cause reallocation)

Definition at line 294 of file backend_cl.hpp.