1 #ifndef jb_clfft_plan_hpp 2 #define jb_clfft_plan_hpp 9 #include <boost/compute/command_queue.hpp> 10 #include <boost/compute/container/vector.hpp> 11 #include <boost/compute/context.hpp> 12 #include <boost/compute/event.hpp> 13 #include <boost/compute/utility/wait_list.hpp> 34 template <
typename in_timeseries_type,
typename out_timeseries_type>
69 plan tmp(std::move(rhs));
70 std::swap(
p_, tmp.
p_);
71 std::swap(
d_, tmp.
d_);
78 if (
d_ == ENDDIRECTION) {
81 cl_int err = clfftDestroyPlan(&
p_);
108 out_timeseries_type& out, in_timeseries_type
const& in,
109 boost::compute::command_queue& queue,
110 boost::compute::wait_list
const& wait = boost::compute::wait_list()) {
111 boost::compute::event event;
112 cl_int err = clfftEnqueueTransform(
113 p_,
d_, 1, &queue.get(), wait.size(), wait.get_event_ptr(),
114 &
event.get(), &in.get_buffer().get(), &out.get_buffer().get(),
nullptr);
124 template <
typename itype,
typename otype>
126 otype
const&, itype
const&, boost::compute::context&,
127 boost::compute::command_queue&,
int);
128 template <
typename itype,
typename otype>
130 otype
const&, itype
const&, boost::compute::context&,
131 boost::compute::command_queue&,
int);
152 out_timeseries_type
const& out, in_timeseries_type
const& in,
153 boost::compute::context& context, boost::compute::command_queue& queue,
154 clfftDirection direction, std::size_t batch_size) {
155 if (out.size() != in.size()) {
156 throw std::invalid_argument(
"clfft::plan - size mismatch");
158 if (batch_size == 0) {
159 throw std::invalid_argument(
"clfft::plan - 0 is not a valid batch size");
161 if (in.size() % batch_size != 0) {
162 throw std::invalid_argument(
"clfft::plan - the input / output sizes must" 163 " be multiples of the batch size");
167 clfftDim dim = CLFFT_1D;
171 std::size_t lengths[] = {in.size()};
174 clfftPlanHandle
plan;
175 cl_int err = clfftCreateDefaultPlan(&plan, context.get(), dim, lengths);
182 err = clfftSetPlanPrecision(plan, in_value_traits::precision);
187 clfftSetLayout(plan, in_value_traits::layout, out_value_traits::layout);
192 err = clfftSetResultLocation(plan, CLFFT_OUTOFPLACE);
196 err = clfftSetPlanBatchSize(plan, batch_size);
201 err = clfftBakePlan(plan, 1, &queue.get(),
nullptr,
nullptr);
222 explicit plan(clfftPlanHandle p, clfftDirection d)
254 template <
typename invector,
typename outvector>
256 outvector
const& out, invector
const& in, boost::compute::context& ct,
257 boost::compute::command_queue& q,
int batch_size = 1) {
259 out, in, ct, q, CLFFT_FORWARD, batch_size);
283 template <
typename invector,
typename outvector>
285 outvector
const& out, invector
const& in, boost::compute::context& ct,
286 boost::compute::command_queue& q,
int batch_size = 1) {
288 out, in, ct, q, CLFFT_BACKWARD, batch_size);
294 template <
typename in_timeseries_type,
typename out_timeseries_type>
297 using in_value_type =
typename in_timeseries_type::value_type;
299 using in_precision_type =
301 using out_precision_type =
304 std::is_same<in_precision_type, out_precision_type>::value,
305 "Mismatched precision_type, both timeseries must have the same" 308 std::is_same<in_precision_type, float>::value or
309 std::is_same<in_precision_type, double>::value,
310 "Unsupported precision type, clFFT only supports double or float");
317 #endif // jb_plan_hpp plan(clfftPlanHandle p, clfftDirection d)
Constructor from a clfftPlanHandle.
void check_error_code(cl_int err, char const *msg)
Check in an OpenCL error code is really an error and raise an exception if so.
typename jb::extract_value_type< in_value_type >::precision precision_type
friend plan< itype, otype > create_forward_plan_1d(otype const &, itype const &, boost::compute::context &, boost::compute::command_queue &, int)
~plan() noexcept(false)
Destructor, cleanup the plan.
boost::compute::event enqueue(out_timeseries_type &out, in_timeseries_type const &in, boost::compute::command_queue &queue, boost::compute::wait_list const &wait=boost::compute::wait_list())
Enqueue the transform to be executed.
Check the compile-time constraints for a jb::fftw::plan<>
static plan create_plan_1d_impl(out_timeseries_type const &out, in_timeseries_type const &in, boost::compute::context &context, boost::compute::command_queue &queue, clfftDirection direction, std::size_t batch_size)
Refactor code to create plans.
friend plan< itype, otype > create_inverse_plan_1d(otype const &, itype const &, boost::compute::context &, boost::compute::command_queue &, int)
plan(plan &&rhs)
Basic move constructor.
Wrap clfftPlanHandle objects.
typename in_timeseries_type::value_type in_value_type
type straits
plan()
Default constructor.
typename out_timeseries_type::value_type out_value_type
plan & operator=(plan &&rhs)
Move assigment operator.
Generic version, not implemented.
The top-level namespace for the JayBeams library.