1 #ifndef VTESTBED_OPENCL_PIPELINE_HH 2 #define VTESTBED_OPENCL_PIPELINE_HH 6 #include <blitz/array.h> 8 #include <openclx/array_view> 9 #include <openclx/buffer> 10 #include <openclx/command_queue_flags> 11 #include <openclx/command_stack> 12 #include <openclx/kernel> 13 #include <openclx/memory_flags> 21 const clx::context& context,
24 clx::memory_flags flags=clx::memory_flags::read_write
30 const clx::context& context,
33 clx::memory_flags flags=clx::memory_flags::read_write
34 ) { ::vtb::opencl::resize(context, buffer, size*
sizeof(T), flags); }
40 using clx::buffer::buffer;
42 inline void resize(clx::context ctx,
size_t size,
43 clx::memory_flags flags=clx::memory_flags::read_write) {
44 ::vtb::opencl::resize(ctx, *
this, size*
sizeof(T), flags);
52 inline explicit NDRange(): clx::range{} {}
53 inline explicit NDRange(
size_t rhs): clx::range{rhs} {}
56 NDRange(
const blitz::TinyVector<size_t,1>& rhs):
60 NDRange(
const blitz::TinyVector<size_t,2>& rhs):
61 clx::range{rhs(0),rhs(1)} {}
64 NDRange(
const blitz::TinyVector<size_t,3>& rhs):
65 clx::range{rhs(0),rhs(1),rhs(2)} {}
72 clx::context _context;
75 using clx::command_stack::command_stack;
76 using clx::command_stack::copy;
77 using clx::command_stack::kernel;
79 inline void context(clx::context rhs) { this->_context = rhs; }
80 inline const clx::context& context()
const {
return this->_context; }
82 template <
class T,
int N>
83 inline void allocate(
const blitz::Array<T,N>& src,
Buffer<T>& dst) {
84 const auto& tmp = src.isStorageContiguous() ? src : src.copy();
85 if (!tmp.isStorageContiguous()) {
88 dst.resize(context(), src.size());
91 template <
class T,
int N>
92 inline void copy(
const blitz::Array<T,N>& src,
Buffer<T>& dst) {
93 this->allocate<T,N>(src, dst);
94 this->copy(src.data(), dst.slice(0, src.size()*
sizeof(T)));
97 template <
class T,
int N>
98 inline void copy(
const Buffer<T>& src, blitz::Array<T,N>& dst) {
99 if (!dst.isStorageContiguous()) {
102 this->copy(src.slice(0,dst.size()*
sizeof(T)), dst.data());
107 dst.resize(context(), src.size());
112 const auto size = src.size();
113 dst.resize(context(), size);
114 this->copy(src.data(), dst.slice(0, size*
sizeof(T)));
119 this->copy(src.slice(0,dst.size()*
sizeof(T)), dst.data());
122 inline void copy(
const void* src,
size_t size, clx::buffer& dst) {
123 ::vtb::opencl::resize(context(), dst, size);
124 this->copy(src, dst.slice(0, size));
128 inline void allocate(
size_t size,
Buffer<T>& dst) {
129 dst.resize(context(), size);
132 template <
class T,
int N>
133 inline void allocate(
const blitz::TinyVector<int,N>& shape,
Buffer<T>& dst) {
134 dst.resize(context(), product(shape));
139 kernel(
const clx::kernel& k,
const blitz::TinyVector<int,N>& global) {
140 this->kernel(k,
NDRange{global});
146 const clx::kernel& k,
147 const blitz::TinyVector<int,N>& global,
148 const blitz::TinyVector<int,N>& local
156 const clx::kernel& k,
157 const blitz::TinyVector<int,N>& offset,
158 const blitz::TinyVector<int,N>& global,
159 const blitz::TinyVector<int,N>& local
170 #endif // vim:filetype=cpp