JayBeams  0.1
Another project to have fun coding.
conjugate_and_multiply_kernel.cl
Go to the documentation of this file.
1 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
2 
3 /// Compile with -DTYPENAME_MACRO=float2 or -DTYPENAME_MACRO=double2
4 typedef TYPENAME_MACRO T;
5 
6 /// Complex number conjugate
7 inline T cconj(T a) {
8  return (T)(a.x, -a.y);
9 }
10 
11 /// Complex number multiplication
12 inline T cmul(T a, T b) {
13  return (T)(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
14 }
15 
16 /**
17  * Interpret @a a, @a b, and @a dst as vectors of @a N complex numbers
18  * and compute:
19  *
20  * dst(i) = conj(a(i)) * b(i)
21  *
22  * This is used when computing a cross correlation via FFTs, as this
23  * expression is the frequency space version of cross-correlation.
24  */
25 __kernel void conjugate_and_multiply(
26  __global T* dst, __global T const* a, __global T const* b,
27  unsigned int const N) {
28  // Get our global thread ID
29  int col = get_global_id(0);
30 
31  if (col < N) {
32  dst[col] = cmul(cconj(a[col]), b[col]);
33  }
34 }