GuidedFilter  1.2.0
 Hosted by GitHub
math.hpp
Go to the documentation of this file.
1 
32 #ifndef GF_MATH_HPP
33 #define GF_MATH_HPP
34 
35 #include <CLUtils.hpp>
36 #include <GuidedFilter/common.hpp>
37 
38 
42 namespace cl_algo
43 {
44 namespace GF
45 {
48 namespace Math
49 {
50 
73  class Mult
74  {
75  public:
80  enum class Memory : uint8_t
81  {
82  H_IN_A,
83  H_IN_B,
84  H_OUT,
85  D_IN_A,
86  D_IN_B,
87  D_OUT
88  };
89 
91  Mult (clutils::CLEnv &_env, clutils::CLEnvInfo<1> _info);
93  cl::Memory& get (Mult::Memory mem);
95  void init (unsigned int _width, unsigned int _height, Staging _staging = Staging::IO);
97  void write (Mult::Memory mem = Mult::Memory::D_IN_A, void *ptr = nullptr, bool block = CL_FALSE,
98  const std::vector<cl::Event> *events = nullptr, cl::Event *event = nullptr);
100  void* read (Mult::Memory mem = Mult::Memory::H_OUT, bool block = CL_TRUE,
101  const std::vector<cl::Event> *events = nullptr, cl::Event *event = nullptr);
103  void run (const std::vector<cl::Event> *events = nullptr, cl::Event *event = nullptr);
104 
105  cl_float *hPtrInA;
106  cl_float *hPtrInB;
107  cl_float *hPtrOut;
109  private:
110  clutils::CLEnv &env;
111  clutils::CLEnvInfo<1> &info;
112  cl::Context context;
113  cl::CommandQueue queue;
114  cl::Kernel kernel;
115  cl::NDRange global;
116  Staging staging;
117  unsigned int length, bufferSize;
118  cl::Buffer hBufferInA, hBufferInB, hBufferOut;
119  cl::Buffer dBufferInA, dBufferInB, dBufferOut;
120 
121  public:
129  template <typename period>
130  double run (clutils::GPUTimer<period> &timer, const std::vector<cl::Event> *events = nullptr)
131  {
132  queue.enqueueNDRangeKernel (kernel, cl::NullRange, global, cl::NullRange, events, &timer.event ());
133  queue.flush (); timer.wait ();
134  return timer.duration ();
135  }
136 
137  };
138 
139 
160  class Pown
161  {
162  public:
167  enum class Memory : uint8_t
168  {
169  H_IN,
170  H_OUT,
171  D_IN,
172  D_OUT
173  };
174 
176  Pown (clutils::CLEnv &_env, clutils::CLEnvInfo<1> _info);
178  cl::Memory& get (Pown::Memory mem);
180  void init (unsigned int _width, unsigned int _height, int _n, Staging _staging = Staging::IO);
182  void write (Pown::Memory mem = Pown::Memory::D_IN, void *ptr = nullptr, bool block = CL_FALSE,
183  const std::vector<cl::Event> *events = nullptr, cl::Event *event = nullptr);
185  void* read (Pown::Memory mem = Pown::Memory::H_OUT, bool block = CL_TRUE,
186  const std::vector<cl::Event> *events = nullptr, cl::Event *event = nullptr);
188  void run (const std::vector<cl::Event> *events = nullptr, cl::Event *event = nullptr);
190  int getPower ();
192  void setPower (int _n);
193 
194  cl_float *hPtrIn;
195  cl_float *hPtrOut;
197  private:
198  clutils::CLEnv &env;
199  clutils::CLEnvInfo<1> &info;
200  cl::Context context;
201  cl::CommandQueue queue;
202  cl::Kernel kernel;
203  cl::NDRange global;
204  Staging staging;
205  unsigned int length, bufferSize;
206  int n;
207  cl::Buffer hBufferIn, hBufferOut;
208  cl::Buffer dBufferIn, dBufferOut;
209 
210  public:
218  template <typename period>
219  double run (clutils::GPUTimer<period> &timer, const std::vector<cl::Event> *events = nullptr)
220  {
221  queue.enqueueNDRangeKernel (kernel, cl::NullRange, global, cl::NullRange, events, &timer.event ());
222  queue.flush (); timer.wait ();
223  return timer.duration ();
224  }
225 
226  };
227 
228 }
229 }
230 }
231 
232 #endif // GF_MATH_HPP
int getPower()
Gets the power.
Definition: math.cpp:450
void write(Mult::Memory mem=Mult::Memory::D_IN_A, void *ptr=nullptr, bool block=CL_FALSE, const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
Performs a data transfer to a device buffer.
Definition: math.cpp:197
Mult(clutils::CLEnv &_env, clutils::CLEnvInfo< 1 > _info)
Configures an OpenCL environment as specified by _info.
Definition: math.cpp:56
Memory
Enumerates the memory objects handled by the class.
Definition: math.hpp:167
void * read(Mult::Memory mem=Mult::Memory::H_OUT, bool block=CL_TRUE, const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
Performs a data transfer to a staging buffer.
Definition: math.cpp:230
Interface class for the mult kernel.
Definition: math.hpp:73
Interface class for the pown_ kernel.
Definition: math.hpp:160
Staging
Enumerates staging buffer configurations.
Definition: common.hpp:43
double run(clutils::GPUTimer< period > &timer, const std::vector< cl::Event > *events=nullptr)
Executes the necessary kernels.
Definition: math.hpp:219
Offers classes which set up kernel execution parameters and provide interfaces for the handling of me...
Definition: algorithms.hpp:43
cl_float * hPtrInB
Definition: math.hpp:106
Declares classes used by the OpenCL interface classes in cl_algo.
void run(const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
Executes the necessary kernels.
Definition: math.cpp:442
void * read(Pown::Memory mem=Pown::Memory::H_OUT, bool block=CL_TRUE, const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
Performs a data transfer to a staging buffer.
Definition: math.cpp:419
void init(unsigned int _width, unsigned int _height, int _n, Staging _staging=Staging::IO)
Configures kernel execution parameters.
Definition: math.cpp:302
void write(Pown::Memory mem=Pown::Memory::D_IN, void *ptr=nullptr, bool block=CL_FALSE, const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
Performs a data transfer to a device buffer.
Definition: math.cpp:391
cl_float * hPtrInA
Definition: math.hpp:105
Memory
Enumerates the memory objects handled by the class.
Definition: math.hpp:80
void init(unsigned int _width, unsigned int _height, Staging _staging=Staging::IO)
Configures kernel execution parameters.
Definition: math.cpp:99
cl_float * hPtrOut
Definition: math.hpp:107
double run(clutils::GPUTimer< period > &timer, const std::vector< cl::Event > *events=nullptr)
Executes the necessary kernels.
Definition: math.hpp:130
cl_float * hPtrIn
Definition: math.hpp:194
Pown(clutils::CLEnv &_env, clutils::CLEnvInfo< 1 > _info)
Configures an OpenCL environment as specified by _info.
Definition: math.cpp:262
Definition: helper_funcs.hpp:41
cl_float * hPtrOut
Definition: math.hpp:195
void run(const std::vector< cl::Event > *events=nullptr, cl::Event *event=nullptr)
Executes the necessary kernels.
Definition: math.cpp:253
void setPower(int _n)
Sets the power.
Definition: math.cpp:460