ViennaCL - The Vienna Computing Library  1.7.1
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fft_operations.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_FFT_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_FFT_OPERATIONS_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2016, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19  ============================================================================= */
20 
25 #include <viennacl/vector.hpp>
26 #include <viennacl/matrix.hpp>
27 
29 
30 #ifdef VIENNACL_WITH_OPENCL
33 #endif
34 
35 #ifdef VIENNACL_WITH_CUDA
37 #endif
38 
39 namespace viennacl
40 {
41 namespace linalg
42 {
43 
50 template<typename NumericT, unsigned int AlignmentV>
53  vcl_size_t batch_num, NumericT sign = NumericT(-1),
55 {
56 
57  switch (viennacl::traits::handle(in).get_active_handle_id())
58  {
60  viennacl::linalg::host_based::direct(in, out, size, stride, batch_num, sign, data_order);
61  break;
62 #ifdef VIENNACL_WITH_OPENCL
64  viennacl::linalg::opencl::direct(viennacl::traits::opencl_handle(in), viennacl::traits::opencl_handle(out), size, stride, batch_num, sign,data_order);
65  break;
66 #endif
67 
68 #ifdef VIENNACL_WITH_CUDA
70  viennacl::linalg::cuda::direct(in, out, size, stride, batch_num,sign,data_order);
71  break;
72 #endif
73 
75  throw memory_exception("not initialised!");
76  default:
77  throw memory_exception("not implemented");
78 
79  }
80 }
81 
88 template<typename NumericT, unsigned int AlignmentV>
91  vcl_size_t stride, vcl_size_t batch_num, NumericT sign = NumericT(-1),
93 {
94 
95  switch (viennacl::traits::handle(in).get_active_handle_id())
96  {
98  viennacl::linalg::host_based::direct(in, out, size, stride, batch_num, sign, data_order);
99  break;
100 #ifdef VIENNACL_WITH_OPENCL
102  viennacl::linalg::opencl::direct(viennacl::traits::opencl_handle(in), viennacl::traits::opencl_handle(out), size, stride, batch_num, sign,data_order);
103  break;
104 #endif
105 
106 #ifdef VIENNACL_WITH_CUDA
108  viennacl::linalg::cuda::direct(in, out, size, stride, batch_num,sign,data_order);
109  break;
110 #endif
111 
113  throw memory_exception("not initialised!");
114  default:
115  throw memory_exception("not implemented");
116 
117  }
118 }
119 
120 /*
121  * This function performs reorder of input data. Indexes are sorted in bit-reversal order.
122  * Such reordering should be done before in-place FFT.
123  */
124 template<typename NumericT, unsigned int AlignmentV>
126  vcl_size_t bits_datasize, vcl_size_t batch_num,
128 {
129  switch (viennacl::traits::handle(in).get_active_handle_id())
130  {
132  viennacl::linalg::host_based::reorder(in, size, stride, bits_datasize, batch_num, data_order);
133  break;
134 #ifdef VIENNACL_WITH_OPENCL
136  viennacl::linalg::opencl::reorder<NumericT>(viennacl::traits::opencl_handle(in), size, stride, bits_datasize, batch_num, data_order);
137  break;
138 #endif
139 
140 #ifdef VIENNACL_WITH_CUDA
142  viennacl::linalg::cuda::reorder(in, size, stride, bits_datasize, batch_num, data_order);
143  break;
144 #endif
145 
147  throw memory_exception("not initialised!");
148  default:
149  throw memory_exception("not implemented");
150 
151  }
152 }
153 
161 template<typename NumericT, unsigned int AlignmentV>
163  vcl_size_t stride, vcl_size_t batch_num, NumericT sign = NumericT(-1),
165 {
166  switch (viennacl::traits::handle(in).get_active_handle_id())
167  {
169  viennacl::linalg::host_based::radix2(in, size, stride, batch_num, sign, data_order);
170  break;
171 #ifdef VIENNACL_WITH_OPENCL
173  viennacl::linalg::opencl::radix2(viennacl::traits::opencl_handle(in), size, stride, batch_num, sign,data_order);
174  break;
175 #endif
176 
177 #ifdef VIENNACL_WITH_CUDA
179  viennacl::linalg::cuda::radix2(in, size, stride, batch_num, sign, data_order);
180  break;
181 #endif
182 
184  throw memory_exception("not initialised!");
185  default:
186  throw memory_exception("not implemented");
187  }
188 }
189 
197 template<typename NumericT, unsigned int AlignmentV>
199  vcl_size_t batch_num, NumericT sign = NumericT(-1),
201 {
202 
203  switch (viennacl::traits::handle(in).get_active_handle_id())
204  {
206  viennacl::linalg::host_based::radix2(in, size, stride, batch_num, sign, data_order);
207  break;
208 #ifdef VIENNACL_WITH_OPENCL
210  viennacl::linalg::opencl::radix2(viennacl::traits::opencl_handle(in), size, stride, batch_num, sign,data_order);
211  break;
212 #endif
213 
214 #ifdef VIENNACL_WITH_CUDA
216  viennacl::linalg::cuda::radix2(in, size, stride, batch_num, sign,data_order);
217  break;
218 #endif
219 
221  throw memory_exception("not initialised!");
222  default:
223  throw memory_exception("not implemented");
224  }
225 }
226 
234 template<typename NumericT, unsigned int AlignmentV>
237 {
238 
239  switch (viennacl::traits::handle(in).get_active_handle_id())
240  {
243  break;
244 #ifdef VIENNACL_WITH_OPENCL
247  break;
248 #endif
249 
250 #ifdef VIENNACL_WITH_CUDA
253  break;
254 #endif
255 
257  throw memory_exception("not initialised!");
258  default:
259  throw memory_exception("not implemented");
260  }
261 }
262 
266 template<typename NumericT, unsigned int AlignmentV>
270 {
271  switch (viennacl::traits::handle(input1).get_active_handle_id())
272  {
274  viennacl::linalg::host_based::multiply_complex(input1, input2, output);
275  break;
276 #ifdef VIENNACL_WITH_OPENCL
278  viennacl::linalg::opencl::multiply_complex(input1, input2, output);
279  break;
280 #endif
281 
282 #ifdef VIENNACL_WITH_CUDA
284  viennacl::linalg::cuda::multiply_complex(input1, input2, output);
285  break;
286 #endif
287 
289  throw memory_exception("not initialised!");
290  default:
291  throw memory_exception("not implemented");
292  }
293 }
294 
298 template<typename NumericT, unsigned int AlignmentV>
300 {
301  switch (viennacl::traits::handle(input).get_active_handle_id())
302  {
305  break;
306 #ifdef VIENNACL_WITH_OPENCL
309  break;
310 #endif
311 
312 #ifdef VIENNACL_WITH_CUDA
315  break;
316 #endif
317 
319  throw memory_exception("not initialised!");
320  default:
321  throw memory_exception("not implemented");
322  }
323 }
324 
328 template<typename NumericT, unsigned int AlignmentV>
330 {
331  switch (viennacl::traits::handle(input).get_active_handle_id())
332  {
335  break;
336 #ifdef VIENNACL_WITH_OPENCL
339  break;
340 #endif
341 
342 #ifdef VIENNACL_WITH_CUDA
345  break;
346 #endif
347 
349  throw memory_exception("not initialised!");
350  default:
351  throw memory_exception("not implemented");
352  }
353 }
354 
358 template<typename NumericT, unsigned int AlignmentV>
361 {
362  switch (viennacl::traits::handle(input).get_active_handle_id())
363  {
366  break;
367 #ifdef VIENNACL_WITH_OPENCL
370  break;
371 #endif
372 
373 #ifdef VIENNACL_WITH_CUDA
375  viennacl::linalg::cuda::transpose(input, output);
376  break;
377 #endif
378 
380  throw memory_exception("not initialised!");
381  default:
382  throw memory_exception("not implemented");
383  }
384 }
385 
389 template<typename NumericT>
392 {
393  switch (viennacl::traits::handle(in).get_active_handle_id())
394  {
397  break;
398 #ifdef VIENNACL_WITH_OPENCL
401  break;
402 #endif
403 
404 #ifdef VIENNACL_WITH_CUDA
407  break;
408 #endif
409 
411  throw memory_exception("not initialised!");
412  default:
413  throw memory_exception("not implemented");
414  }
415 }
416 
420 template<typename NumericT>
423 {
424  switch (viennacl::traits::handle(in).get_active_handle_id())
425  {
428  break;
429 #ifdef VIENNACL_WITH_OPENCL
432  break;
433 #endif
434 
435 #ifdef VIENNACL_WITH_CUDA
438  break;
439 #endif
440 
442  throw memory_exception("not initialised!");
443  default:
444  throw memory_exception("not implemented");
445  }
446 }
447 
451 template<typename NumericT>
453 {
454  switch (viennacl::traits::handle(in).get_active_handle_id())
455  {
458  break;
459 #ifdef VIENNACL_WITH_OPENCL
462  break;
463 #endif
464 
465 #ifdef VIENNACL_WITH_CUDA
468  break;
469 #endif
470 
472  throw memory_exception("not initialised!");
473  default:
474  throw memory_exception("not implemented");
475  }
476 }
477 
478 }
479 }
480 
481 #endif /* FFT_OPERATIONS_HPP_ */
OpenCL kernel file for FFT operations.
Implementations of Fast Furier Transformation using OpenCL.
Exception class in case of memory errors.
Definition: forwards.h:572
void complex_to_real(viennacl::vector_base< NumericT > const &in, viennacl::vector_base< NumericT > &out, vcl_size_t size)
Create real vector from complex vector (even elements(2*k) = real part, odd elements(2*k+1) = imagina...
Implementation of the dense matrix class.
__global__ void real_to_complex(const RealT *in, ComplexT *out, unsigned int size)
void reorder(viennacl::vector< NumericT, AlignmentV > &in, vcl_size_t size, vcl_size_t stride, vcl_size_t bits_datasize, vcl_size_t batch_num, viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
void real_to_complex(viennacl::vector_base< NumericT > const &in, viennacl::vector_base< NumericT > &out, vcl_size_t size)
Create complex vector from real vector (even elements(2*k) = real part, odd elements(2*k+1) = imagina...
void complex_to_real(viennacl::vector_base< NumericT > const &in, viennacl::vector_base< NumericT > &out, vcl_size_t size)
Create real vector from complex vector (even elements(2*k) = real part, odd elements(2*k+1) = imagina...
void reverse(viennacl::vector_base< NumericT > &in)
Reverse vector to oposite order and save it in input vector.
void reverse(viennacl::vector_base< NumericT > &in)
Reverse vector to opposite order and save it in input vector.
void radix2(viennacl::vector< NumericT, AlignmentV > &in, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Radix-2 1D algorithm for computing Fourier transformation.
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
Definition: stride.hpp:45
A dense matrix class.
Definition: forwards.h:375
void transpose(viennacl::matrix< NumericT, viennacl::row_major, AlignmentV > &input)
Inplace_transpose matrix.
void bluestein(viennacl::vector< NumericT, AlignmentV > &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t)
Bluestein's algorithm for computing Fourier transformation.
void normalize(viennacl::vector< NumericT, AlignmentV > &input)
Normalize vector on with his own size.
float NumericT
Definition: bisect.cpp:40
__global__ void transpose(const NumericT *input, NumericT *output, unsigned int row_num, unsigned int col_num)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
void radix2(viennacl::vector< NumericT, AlignmentV > &in, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Radix-2 1D algorithm for computing Fourier transformation.
void real_to_complex(viennacl::vector_base< NumericT > const &in, viennacl::vector_base< NumericT > &out, vcl_size_t size)
Create complex vector from real vector (even elements(2*k) = real part, odd elements(2*k+1) = imagina...
void bluestein(viennacl::vector< NumericT, AlignmentV > &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t)
Bluestein's algorithm for computing Fourier transformation.
void multiply_complex(viennacl::vector< NumericT, AlignmentV > const &input1, viennacl::vector< NumericT, AlignmentV > const &input2, viennacl::vector< NumericT, AlignmentV > &output)
Complex multiplikation of two vectors.
void radix2(viennacl::ocl::handle< cl_mem > const &in, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Radix-2 algorithm for computing Fourier transformation.
void multiply_complex(viennacl::vector< NumericT, AlignmentV > const &input1, viennacl::vector< NumericT, AlignmentV > const &input2, viennacl::vector< NumericT, AlignmentV > &output)
Mutiply two complex vectors and store result in output.
void reverse(viennacl::vector_base< NumericT > &in)
Reverse vector to oposite order and save it in input vector.
void real_to_complex(viennacl::vector_base< NumericT > const &in, viennacl::vector_base< NumericT > &out, vcl_size_t size)
Create complex vector from real vector (even elements(2*k) = real part, odd elements(2*k+1) = imagina...
std::size_t vcl_size_t
Definition: forwards.h:75
void bluestein(viennacl::vector< NumericT, AlignmentV > &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t)
Bluestein's algorithm for computing Fourier transformation.
void direct(viennacl::vector< NumericT, AlignmentV > const &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Direct 1D algorithm for computing Fourier transformation.
void normalize(viennacl::vector< NumericT, AlignmentV > &input)
Normalize vector on with his own size.
void radix2(viennacl::matrix< NumericT, viennacl::row_major, AlignmentV > &in, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Radix-2 1D algorithm for computing Fourier transformation.
void transpose(viennacl::matrix< NumericT, viennacl::row_major, AlignmentV > &input)
Inplace transpose of matrix.
void transpose(viennacl::matrix< NumericT, viennacl::row_major, AlignmentV > &input)
Inplace_transpose matrix.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void multiply_complex(viennacl::vector< NumericT, AlignmentV > const &input1, viennacl::vector< NumericT, AlignmentV > const &input2, viennacl::vector< NumericT, AlignmentV > &output)
Mutiply two complex vectors and store result in output.
Implementations of Fast Furier Transformation using cuda.
void direct(viennacl::ocl::handle< cl_mem > const &in, viennacl::ocl::handle< cl_mem > const &out, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Direct algorithm for computing Fourier transformation.
Implementations of Fast Furier Transformation using a plain single-threaded or OpenMP-enabled executi...
void reverse(viennacl::vector_base< NumericT > &in)
Reverse vector to oposite order and save it in input vector.
void normalize(viennacl::vector< NumericT, AlignmentV > &input)
Normalize vector with his own size.
void multiply_complex(viennacl::vector< NumericT, AlignmentV > const &input1, viennacl::vector< NumericT, AlignmentV > const &input2, viennacl::vector< NumericT, AlignmentV > &output)
Mutiply two complex vectors and store result in output.
__global__ void complex_to_real(const ComplexT *in, RealT *out, unsigned int size)
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
void reorder(viennacl::vector< NumericT, AlignmentV > &in, vcl_size_t size, vcl_size_t stride, vcl_size_t bits_datasize, vcl_size_t batch_num, viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
void direct(viennacl::vector< NumericT, AlignmentV > const &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Direct 1D algorithm for computing Fourier transformation.
void complex_to_real(viennacl::vector_base< NumericT > const &in, viennacl::vector_base< NumericT > &out, vcl_size_t size)
Create real vector from complex vector (even elements(2*k) = real part, odd elements(2*k+1) = imagina...
void direct(viennacl::vector< NumericT, AlignmentV > const &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t size, vcl_size_t stride, vcl_size_t batch_num, NumericT sign=NumericT(-1), viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
Direct 1D algorithm for computing Fourier transformation.
void reorder(viennacl::vector< NumericT, AlignmentV > &in, vcl_size_t size, vcl_size_t stride, vcl_size_t bits_datasize, vcl_size_t batch_num, viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::DATA_ORDER data_order=viennacl::linalg::host_based::detail::fft::FFT_DATA_ORDER::ROW_MAJOR)
void normalize(viennacl::vector< NumericT, AlignmentV > &input)
Normalize vector on with his own size.
void bluestein(viennacl::vector< NumericT, AlignmentV > &in, viennacl::vector< NumericT, AlignmentV > &out, vcl_size_t)
Bluestein's algorithm for computing Fourier transformation.
SCALARTYPE sign(SCALARTYPE val)