com.nativelibs4java.opencl.util.fft.FloatDFTProgram.cl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javacl-jna Show documentation
Show all versions of javacl-jna Show documentation
JavaCL is an Object-Oriented API that makes the C OpenCL API available to Java in a very natural way.
It hides away the complexity of cross-platform C bindings, has a clean OO design (with generics, Java enums, NIO buffers, fully typed exceptions...), provides high-level features (OpenGL-interop, array reductions) and comes with samples and demos.
For more info, please visit http://code.google.com/p/nativelibs4java/wiki/OpenCL.
The newest version!
__kernel void dft(
__global const float2 *in, // complex values input
__global float2 *out, // complex values output
int length, // number of input and output values
int sign) // sign modifier in the exponential :
// 1 for forward transform, -1 for backward.
{
// Get the varying parameter of the parallel execution :
int i = get_global_id(0);
// In case we're executed "too much", check bounds :
if (i >= length)
return;
// Initialize sum and inner arguments
float2 tot = 0;
float param = (-2 * sign * i) * 3.141593f / (float)length;
for (int k = 0; k < length; k++) {
float2 value = in[k];
// Compute sin and cos in a single call :
float c;
float s = sincos(k * param, &c);
// This adds (value.x * c - value.y * s, value.x * s + value.y * c) to the sum :
tot += (float2)(
dot(value, (float2)(c, -s)),
dot(value, (float2)(s, c))
);
}
if (sign == 1) {
// forward transform (space -> frequential)
out[i] = tot;
} else {
// backward transform (frequential -> space)
out[i] = tot / (float)length;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy