32 #ifndef VSMC_OPENCL_INTERNAL_COPY_HPP
33 #define VSMC_OPENCL_INTERNAL_COPY_HPP
39 namespace vsmc {
namespace internal {
41 template <
typename ID>
50 std::size_t
size () {
return size_;}
54 void operator() (const ::cl::Buffer ©_from, const ::cl::Buffer &state)
60 void operator () (const ::cl::Buffer &idx, const ::cl::Buffer &tmp,
61 const ::cl::Buffer &state)
67 void build (std::size_t
size, std::size_t state_size)
73 ss <<
"#define Size " << size <<
"UL\n";
74 ss <<
"typedef struct {char c[" << state_size <<
"];} state_type;";
76 ss <<
"__kernel void copy (__global const ulong *copy_from,\n";
77 ss <<
" __global state_type *state)\n";
79 ss <<
" ulong to = get_global_id(0);\n";
80 ss <<
" if (to >= Size) return;\n";
81 ss <<
" ulong from = copy_from[to];\n";
82 ss <<
" if (to == from) return;\n";
83 ss <<
" state[to] = state[from];\n";
86 ss <<
"__kernel void copy_post (__global const char *idx,\n";
87 ss <<
" __global const state_type *tmp,\n";
88 ss <<
" __global state_type *state)\n";
90 ss <<
" ulong id = get_global_id(0);\n";
91 ss <<
" if (id >= Size) return;\n";
92 ss <<
" if (idx[id] != 0) state[id] = tmp[id];\n";
96 program_.build(
manager().device_vec());
97 kernel_ = ::cl::Kernel(program_,
"copy");
98 kernel_post_ = ::cl::Kernel(program_,
"copy_post");
104 const ::cl::Program &
program ()
const {
return program_;}
106 ::cl::Kernel &
kernel () {
return kernel_;}
107 const ::cl::Kernel &
kernel ()
const {
return kernel_;}
116 ::cl::Program program_;
117 ::cl::Kernel kernel_;
118 ::cl::Kernel kernel_post_;
125 #endif // VSMC_OPENCL_INTERNAL_COPY_HPP
CLConfigure & configure()
void build(std::size_t size, std::size_t state_size)
const ::cl::Program & program() const
CLManager< ID > manager_type
::cl::Program & program()
static manager_type & manager()
void cl_set_kernel_args(::cl::Kernel &,::cl_uint)
void operator()(const ::cl::Buffer ©_from, const ::cl::Buffer &state)
const CLConfigure & configure() const
void run_kernel(const ::cl::Kernel &kern, std::size_t N, std::size_t local_size=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Run a given kernel with one dimensional global size and local size on the current command queue...
::cl::Program create_program(const std::string &source) const
Create a program given the source within the current context.
static CLManager< ID > & instance()
Get an instance of the manager singleton.
const ::cl::Kernel & kernel() const