static std::vector<VT, Allocator> call(T const & t) { std::vector<VT, Allocator> res; std::size_t n = 0; cl_int err = CL_SUCCESS; err = Info::get(t, 0, NULL, &n); OCLM_THROW_IF_EXCEPTION(err, "get_info"); res.resize(n/sizeof(VT)); err = Info::get(t, n, &res[0], NULL); OCLM_THROW_IF_EXCEPTION(err, "get_info"); return res; }
void get() const { if(e_.empty()) return; cl_int err = CL_SUCCESS; err = clWaitForEvents(static_cast<cl_uint>(e_.size()), &e_[0]); OCLM_THROW_IF_EXCEPTION(err, "clWaitForEvents"); }
static void set_kernel_arg(cl_kernel k, std::size_t idx, Buffer & b) { cl_int err = CL_SUCCESS; err = clSetKernelArg(k, static_cast<cl_uint>(idx) , static_cast<cl_uint>(sizeof(cl_mem)), &b.mem); OCLM_THROW_IF_EXCEPTION(err, "clSetKernelArg"); }
static Result call(T const & t) { Result r; cl_int err = CL_SUCCESS; err = Info::get(t, sizeof(Result), &r, NULL); OCLM_THROW_IF_EXCEPTION(err, "get_info"); return r; }
platform_manager::platform_manager() { cl_uint n = 0; cl_int err = ::clGetPlatformIDs(0, NULL, &n); OCLM_THROW_IF_EXCEPTION(err, "clGetPlatformIDs"); std::vector<cl_platform_id> platform_ids(n); err = ::clGetPlatformIDs(n, &platform_ids[0], NULL); OCLM_THROW_IF_EXCEPTION(err, "clGetPlatformIDs"); platforms.resize(n); std::copy(platform_ids.begin(), platform_ids.end(), platforms.begin()); default_platform = platforms[0]; default_device = default_platform.devices[0]; }
static void read(command_queue const & queue, Buffer & b, std::vector<cl_event> & wait_list, std::vector<cl_event> &events) { cl_int err = CL_SUCCESS; cl_event e(0); err = clEnqueueReadBuffer(queue, b.mem, false, 0 , b.size* sizeof(typename Buffer::value_type) , b.data, static_cast<cl_uint>(wait_list.size()) , wait_list.empty() ? 0 : &wait_list[0], &e); OCLM_THROW_IF_EXCEPTION(err, "clEnqueueReadBuffer"); events.push_back(e); }
static void create(command_queue const & queue, Buffer & b) { cl_int err = CL_SUCCESS; b.mem = clCreateBuffer(queue.ctx_, CL_MEM_WRITE_ONLY, b.size* sizeof(typename Buffer::value_type), NULL, &err); OCLM_THROW_IF_EXCEPTION(err, "clCreateBuffer"); }