blob: 1f415c9a2802b914c50343978730614c8b7adf75 [file] [log] [blame]
R"(
/*
* Copyright (c) 2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Copyright (c) 2016-2020 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ARM_COMPUTE_HELPER_H
#define ARM_COMPUTE_HELPER_H
#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16)
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
#endif // defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16)
#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8)
#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable
#endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8)
#if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8)
#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : enable
#endif // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8)
#if defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf)
#pragma OPENCL EXTENSION cl_arm_printf : enable
#endif // defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf)
#define GPU_ARCH_MIDGARD 0x100
#define GPU_ARCH_BIFROST 0x200
/** Concatenate two inputs.
*
* @param[in] a The first input to be concatenated
* @param[in] b The second input to be concatenated
*
* @return The concatenated output
*/
#define CONCAT(a, b) a##b
/** Expand the given vector
*
* @param[in] x The vector to be expanded
*
* @return The expanded output
*/
#define EXPAND(x) x
/** Clamp the given value between an upper and lower bound.
*
* @param[in] x The value to be clamped
* @param[in] min_val The lower bound
* @param[in] max_val The upper bound
*
* @return The clamped value.
*/
#define CLAMP(x, min_val, max_val) min(max(x, min_val), max_val)
/** REVn reverses the given vector whose size is n.
* @name REVn
*
* @param[in] x The vector to be reversed
*
* @return The reversed vector
* @{
*/
#define REV1(x) ((x))
#define REV2(x) ((x).s10)
#define REV3(x) ((x).s210)
#define REV4(x) ((x).s3210)
#define REV8(x) ((x).s76543210)
#define REV16(x) ((x).sFEDCBA9876543210)
/** @} */ // end of group REVn
/** Reverse the given vector.
* @name REVERSE
*
* @param[in] x The vector to be reversed
* @param[in] s The size of the vector
*
* @return The reversed vector
* @{
*/
#define REVERSE_STR(x, s) REV##s((x))
#define REVERSE(x, s) REVERSE_STR(x, s)
/** @} */ // end of group REVERSE
/** Circular-right-shift (rotate-right) the vector of size s by the amount of n.
* @name ROTs_n
*
* @param[in] x The vector to be shifted
*
* @return The shifted vector
* @{
*/
#define ROT1_0(x) ((x))
#define ROT2_0(x) ((x))
#define ROT2_1(x) ((x).s10)
#define ROT3_0(x) ((x))
#define ROT3_1(x) ((x).s201)
#define ROT3_2(x) ((x).s120)
#define ROT4_0(x) ((x))
#define ROT4_1(x) ((x).s3012)
#define ROT4_2(x) ((x).s2301)
#define ROT4_3(x) ((x).s1230)
#define ROT8_0(x) ((x))
#define ROT8_1(x) ((x).s70123456)
#define ROT8_2(x) ((x).s67012345)
#define ROT8_3(x) ((x).s56701234)
#define ROT8_4(x) ((x).s45670123)
#define ROT8_5(x) ((x).s34567012)
#define ROT8_6(x) ((x).s23456701)
#define ROT8_7(x) ((x).s12345670)
#define ROT16_0(x) ((x))
#define ROT16_1(x) ((x).sF0123456789ABCDE)
#define ROT16_2(x) ((x).sEF0123456789ABCD)
#define ROT16_3(x) ((x).sDEF0123456789ABC)
#define ROT16_4(x) ((x).sCDEF0123456789AB)
#define ROT16_5(x) ((x).sBCDEF0123456789A)
#define ROT16_6(x) ((x).sABCDEF0123456789)
#define ROT16_7(x) ((x).s9ABCDEF012345678)
#define ROT16_8(x) ((x).s89ABCDEF01234567)
#define ROT16_9(x) ((x).s789ABCDEF0123456)
#define ROT16_10(x) ((x).s6789ABCDEF012345)
#define ROT16_11(x) ((x).s56789ABCDEF01234)
#define ROT16_12(x) ((x).s456789ABCDEF0123)
#define ROT16_13(x) ((x).s3456789ABCDEF012)
#define ROT16_14(x) ((x).s23456789ABCDEF01)
#define ROT16_15(x) ((x).s123456789ABCDEF0)
/** @} */ // end of group ROTs_n
/** Circular-right-shift (rotate-right) the given vector by the given amount.
* @name ROTATE
*
* @param[in] x The vector to be shifted
* @param[in] s The size of the vector
* @param[in] n The amount to be shifted
*
* @return The shifted vector
* @{
*/
#define ROTATE_STR(x, s, n) ROT##s##_##n(x)
#define ROTATE(x, s, n) ROTATE_STR(x, s, n)
/** @} */ // end of group ROTATE
/** Creates a vector of size n filled with offset values corresponding to the location of each element.
* @name V_OFFSn
*
* @param[in] dt The data type of the output vector
*
* @return The vector filled with offset values
* @{
*/
#define V_OFFS1(dt) (dt)(0)
#define V_OFFS2(dt) (dt)(0, 1)
#define V_OFFS3(dt) (dt)(0, 1, 3)
#define V_OFFS4(dt) (dt)(0, 1, 2, 3)
#define V_OFFS8(dt) (dt)(0, 1, 2, 3, 4, 5, 6, 7)
#define V_OFFS16(dt) (dt)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
/** @} */ // end of group V_OFFSn
/** Create a vector filled with offset values corresponding to the location of each element.
* @name VEC_OFFS
*
* @param[in] dt The data type of the output vector
* @param[in] s The size of the output vector
*
* @return The vector filled with offset values
* @{
*/
#define VEC_OFFS_STR(dt, s) V_OFFS##s(dt)
#define VEC_OFFS(dt, s) VEC_OFFS_STR(dt, s)
/** @} */ // end of group VEC_OFFS
#define VLOAD_STR(size) vload##size
#define VLOAD(size) VLOAD_STR(size)
#define VSTORE_STR(size) vstore##size
#define VSTORE(size) VSTORE_STR(size)
#define float1 float
#define half1 half
#define char1 char
#define uchar1 uchar
#define short1 short
#define ushort1 ushort
#define int1 int
#define uint1 uint
#define long1 long
#define ulong1 ulong
#define double1 double
#define vload1(OFFSET, PTR) *(OFFSET + PTR)
#define vstore1(DATA, OFFSET, PTR) *(OFFSET + PTR) = DATA
// Convert built-in functions with _sat modifier are not supported in floating point so we create defines
// without _sat to overcome this issue
#define convert_float_sat convert_float
#define convert_float1_sat convert_float
#define convert_float2_sat convert_float2
#define convert_float3_sat convert_float3
#define convert_float4_sat convert_float4
#define convert_float8_sat convert_float8
#define convert_float16_sat convert_float16
#define convert_half_sat convert_float
#define convert_half1_sat convert_half
#define convert_half2_sat convert_half2
#define convert_half3_sat convert_half3
#define convert_half4_sat convert_half4
#define convert_half8_sat convert_half8
#define convert_half16_sat convert_half16
#define convert_float1 convert_float
#define convert_half1 convert_half
#define convert_char1 convert_char
#define convert_uchar1 convert_uchar
#define convert_short1 convert_short
#define convert_ushort1 convert_ushort
#define convert_int1 convert_int
#define convert_uint1 convert_uint
#define convert_long1 convert_long
#define convert_ulong1 convert_ulong
#define convert_double1 convert_double
#define convert_char1_sat convert_char_sat
#define convert_uchar1_sat convert_uchar_sat
#define convert_short1_sat convert_short_sat
#define convert_ushort1_sat convert_ushort_sat
#define convert_int1_sat convert_int_sat
#define convert_uint1_sat convert_uint_sat
#define convert_long1_sat convert_long_sat
#define convert_ulong1_sat convert_ulong_sat
#define convert_double1_sat convert_double_sat
#define VEC_DATA_TYPE_STR(type, size) type##size
#define VEC_DATA_TYPE(type, size) VEC_DATA_TYPE_STR(type, size)
#define CL_VEC_DATA_TYPE_STR(type, size) type##size
#define CL_VEC_DATA_TYPE(type, size) CL_VEC_DATA_TYPE_STR(type, size)
#define CONVERT_STR(x, type) (convert_##type((x)))
#define CONVERT(x, type) CONVERT_STR(x, type)
#define CONVERT_SAT_STR(x, type) (convert_##type##_sat((x)))
#define CONVERT_SAT(x, type) CONVERT_SAT_STR(x, type)
#define CONVERT_SAT_ROUND_STR(x, type, round) (convert_##type##_sat_##round((x)))
#define CONVERT_SAT_ROUND(x, type, round) CONVERT_SAT_ROUND_STR(x, type, round)
#define VECTOR_DECLARATION(name) \
__global uchar *name##_ptr, \
uint name##_stride_x, \
uint name##_step_x, \
uint name##_offset_first_element_in_bytes
#define IMAGE_DECLARATION(name) \
__global uchar *name##_ptr, \
uint name##_stride_x, \
uint name##_step_x, \
uint name##_stride_y, \
uint name##_step_y, \
uint name##_offset_first_element_in_bytes
#define TENSOR3D_DECLARATION(name) \
__global uchar *name##_ptr, \
uint name##_stride_x, \
uint name##_step_x, \
uint name##_stride_y, \
uint name##_step_y, \
uint name##_stride_z, \
uint name##_step_z, \
uint name##_offset_first_element_in_bytes
#define TENSOR4D_DECLARATION(name) \
__global uchar *name##_ptr, \
uint name##_stride_x, \
uint name##_step_x, \
uint name##_stride_y, \
uint name##_step_y, \
uint name##_stride_z, \
uint name##_step_z, \
uint name##_stride_w, \
uint name##_step_w, \
uint name##_offset_first_element_in_bytes
#define CONVERT_TO_VECTOR_STRUCT(name) \
update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x)
#define CONVERT_TO_VECTOR_STRUCT_NO_STEP(name) \
update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0)
#define CONVERT_TO_IMAGE_STRUCT(name) \
update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y)
#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name) \
update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0)
#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \
update_image_from_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, name##_stride_z, name##_step_z)
#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(name) \
update_image_from_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, name##_step_z)
#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \
update_image_from_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, name##_stride_z, name##_step_z)
#define CONVERT_TO_TENSOR3D_STRUCT(name) \
update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \
name##_stride_z, name##_step_z)
#define CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(name) \
update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, 0)
#define CONVERT_TO_TENSOR4D_STRUCT(name, mod_size) \
update_tensor4D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \
name##_stride_z, name##_step_z, name##_stride_w, name##_step_w, mod_size)
#define CONVERT_TO_TENSOR4D_STRUCT_NO_STEP(name, mod_size) \
update_tensor4D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, 0, name##_stride_w, 0, mod_size)
/** Structure to hold Vector information */
typedef struct Vector
{
__global uchar *ptr; /**< Pointer to the starting postion of the buffer */
int offset_first_element_in_bytes; /**< The offset of the first element in the source image */
int stride_x; /**< Stride of the image in X dimension (in bytes) */
} Vector;
/** Structure to hold Image information */
typedef struct Image
{
__global uchar *ptr; /**< Pointer to the starting postion of the buffer */
int offset_first_element_in_bytes; /**< The offset of the first element in the source image */
int stride_x; /**< Stride of the image in X dimension (in bytes) */
int stride_y; /**< Stride of the image in Y dimension (in bytes) */
} Image;
/** Structure to hold 3D tensor information */
typedef struct Tensor3D
{
__global uchar *ptr; /**< Pointer to the starting postion of the buffer */
int offset_first_element_in_bytes; /**< The offset of the first element in the source image */
int stride_x; /**< Stride of the image in X dimension (in bytes) */
int stride_y; /**< Stride of the image in Y dimension (in bytes) */
int stride_z; /**< Stride of the image in Z dimension (in bytes) */
} Tensor3D;
/** Structure to hold 4D tensor information */
typedef struct Tensor4D
{
__global uchar *ptr; /**< Pointer to the starting postion of the buffer */
int offset_first_element_in_bytes; /**< The offset of the first element in the source image */
int stride_x; /**< Stride of the image in X dimension (in bytes) */
int stride_y; /**< Stride of the image in Y dimension (in bytes) */
int stride_z; /**< Stride of the image in Z dimension (in bytes) */
int stride_w; /**< Stride of the image in W dimension (in bytes) */
} Tensor4D;
/** Wrap vector information into an Vector structure, and make the pointer point at this workitem's data.
*
* @param[in] ptr Pointer to the starting postion of the buffer
* @param[in] offset_first_element_in_bytes The offset of the first element in the source vector
* @param[in] stride_x Stride of the vector in X dimension (in bytes)
* @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes)
*
* @return An image object
*/
inline Vector update_vector_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x)
{
Vector vector =
{
.ptr = ptr,
.offset_first_element_in_bytes = offset_first_element_in_bytes,
.stride_x = stride_x,
};
vector.ptr += vector.offset_first_element_in_bytes + get_global_id(0) * step_x;
return vector;
}
/** Wrap image information into an Image structure, and make the pointer point at this workitem's data.
*
* @param[in] ptr Pointer to the starting postion of the buffer
* @param[in] offset_first_element_in_bytes The offset of the first element in the source image
* @param[in] stride_x Stride of the image in X dimension (in bytes)
* @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] stride_y Stride of the image in Y dimension (in bytes)
* @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes)
*
* @return An image object
*/
inline Image update_image_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y)
{
Image img =
{
.ptr = ptr,
.offset_first_element_in_bytes = offset_first_element_in_bytes,
.stride_x = stride_x,
.stride_y = stride_y
};
img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y;
return img;
}
/** Wrap 3D tensor information into an image structure, and make the pointer point at this workitem's data.
*
* @param[in] ptr Pointer to the starting postion of the buffer
* @param[in] offset_first_element_in_bytes The offset of the first element in the source image
* @param[in] stride_x Stride of the image in X dimension (in bytes)
* @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] stride_y Stride of the image in Y dimension (in bytes)
* @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] stride_z Stride of the image in Z dimension (in bytes)
* @param[in] step_z stride_z * number of elements along Z processed per workitem(in bytes)
*
* @return A 3D tensor object
*/
inline Image update_image_from_tensor3D_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z)
{
Image img =
{
.ptr = ptr,
.offset_first_element_in_bytes = offset_first_element_in_bytes,
.stride_x = stride_x,
.stride_y = stride_y
};
img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y + get_global_id(2) * step_z;
return img;
}
/** Wrap 3D tensor information into an tensor structure, and make the pointer point at this workitem's data.
*
* @param[in] ptr Pointer to the starting postion of the buffer
* @param[in] offset_first_element_in_bytes The offset of the first element in the source image
* @param[in] stride_x Stride of the image in X dimension (in bytes)
* @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] stride_y Stride of the image in Y dimension (in bytes)
* @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] stride_z Stride of the image in Z dimension (in bytes)
* @param[in] step_z stride_z * number of elements along Z processed per workitem(in bytes)
*
* @return A 3D tensor object
*/
inline Tensor3D update_tensor3D_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z)
{
Tensor3D tensor =
{
.ptr = ptr,
.offset_first_element_in_bytes = offset_first_element_in_bytes,
.stride_x = stride_x,
.stride_y = stride_y,
.stride_z = stride_z
};
tensor.ptr += tensor.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y + get_global_id(2) * step_z;
return tensor;
}
inline Tensor4D update_tensor4D_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z, uint stride_w,
uint step_w,
uint mod_size)
{
Tensor4D tensor =
{
.ptr = ptr,
.offset_first_element_in_bytes = offset_first_element_in_bytes,
.stride_x = stride_x,
.stride_y = stride_y,
.stride_z = stride_z,
.stride_w = stride_w
};
tensor.ptr += tensor.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y + (get_global_id(2) % mod_size) * step_z + (get_global_id(2) / mod_size) * step_w;
return tensor;
}
/** Get the pointer position of a Vector
*
* @param[in] vec Pointer to the starting position of the buffer
* @param[in] x Relative X position
*/
inline __global const uchar *vector_offset(const Vector *vec, int x)
{
return vec->ptr + x * vec->stride_x;
}
/** Get the pointer position of a Image
*
* @param[in] img Pointer to the starting position of the buffer
* @param[in] x Relative X position
* @param[in] y Relative Y position
*/
inline __global uchar *offset(const Image *img, int x, int y)
{
return img->ptr + x * img->stride_x + y * img->stride_y;
}
/** Get the pointer position of a Tensor3D
*
* @param[in] tensor Pointer to the starting position of the buffer
* @param[in] x Relative X position
* @param[in] y Relative Y position
* @param[in] z Relative Z position
*/
inline __global const uchar *tensor3D_offset(const Tensor3D *tensor, int x, int y, int z)
{
return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z;
}
/** Get the pointer position of a Tensor4D
*
* @param[in] tensor Pointer to the starting position of the buffer
* @param[in] x Relative X position
* @param[in] y Relative Y position
* @param[in] z Relative Z position
* @param[in] w Relative W position
*/
inline __global const uchar *tensor4D_offset(const Tensor4D *tensor, int x, int y, int z, int w)
{
return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + w * tensor->stride_w;
}
#endif // _HELPER_H
/** Calculates and applies the twiddle factor to a given input.
*
* @param[in] phi The angle.
* @param[in,out] input The input on which the factor should be applied.
*/
#define TWIDDLE_FACTOR_MULTIPLICATION(phi, input) \
{ \
float2 w, tmp; \
w.x = native_cos(phi); \
w.y = native_sin(phi); \
tmp.x = (w.x * input.x) - (w.y * input.y); \
tmp.y = (w.x * input.y) + (w.y * input.x); \
input = tmp; \
}
/** Computes radix-2 butterfly unit.
*
* @param[in,out] c0 Complex input 0.
* @param[in,out] c1 Complex input 1.
*/
#define DFT_2(c0, c1) \
{ \
float2 v0; \
v0 = c0; \
c0 = v0 + c1; \
c1 = v0 - c1; \
}
// radix-3 butterfly unit factors
#define SQRT3DIV2 0.86602540378443f
/** Computes radix-3 butterfly unit.
*
* @param[in,out] c0 Complex input 0.
* @param[in,out] c1 Complex input 1.
* @param[in,out] c2 Complex input 2.
*/
#define DFT_3(c0, c1, c2) \
{ \
float2 v0 = c1 + c2; \
float2 v1 = c1 - c2; \
c1.x = c0.x - 0.5f * v0.x + v1.y * SQRT3DIV2; \
c1.y = c0.y - 0.5f * v0.y - v1.x * SQRT3DIV2; \
c2.x = c0.x - 0.5f * v0.x - v1.y * SQRT3DIV2; \
c2.y = c0.y - 0.5f * v0.y + v1.x * SQRT3DIV2; \
c0 = c0 + v0; \
}
/**Computes radix-4 butterfly unit.
*
* @param[in,out] c0 Complex input 0.
* @param[in,out] c1 Complex input 1.
* @param[in,out] c2 Complex input 2.
* @param[in,out] c3 Complex input 3.
*/
#define DFT_4(c0, c1, c2, c3) \
{ \
float2 v0, v1, v2, v3; \
v0 = c0 + c2; \
v1 = c1 + c3; \
v2 = c0 - c2; \
v3.x = c1.y - c3.y; \
v3.y = c3.x - c1.x; \
c0 = v0 + v1; \
c2 = v0 - v1; \
c1 = v2 + v3; \
c3 = v2 - v3; \
}
// radix-5 butterfly unit factors
#define W5_A 0.30901699437494f
#define W5_B 0.95105651629515f
#define W5_C 0.80901699437494f
#define W5_D 0.58778525229247f
/** Computes radix-5 butterfly unit.
*
* @param[in,out] c0 Complex input 0.
* @param[in,out] c1 Complex input 1.
* @param[in,out] c2 Complex input 2.
* @param[in,out] c3 Complex input 3.
* @param[in,out] c4 Complex input 4.
*/
#define DFT_5(c0, c1, c2, c3, c4) \
{ \
float2 v0, v1, v2, v3, v4; \
v0 = c0; \
v1 = W5_A * (c1 + c4) - W5_C * (c2 + c3); \
v2 = W5_C * (c1 + c4) - W5_A * (c2 + c3); \
v3 = W5_D * (c1 - c4) - W5_B * (c2 - c3); \
v4 = W5_B * (c1 - c4) + W5_D * (c2 - c3); \
c0 = v0 + c1 + c2 + c3 + c4; \
c1 = v0 + v1 + (float2)(v4.y, -v4.x); \
c2 = v0 - v2 + (float2)(v3.y, -v3.x); \
c3 = v0 - v2 + (float2)(-v3.y, v3.x); \
c4 = v0 + v1 + (float2)(-v4.y, v4.x); \
}
// radix-7 butterfly unit factors
#define W7_A 0.62348980185873f
#define W7_B 0.78183148246802f
#define W7_C 0.22252093395631f
#define W7_D 0.97492791218182f
#define W7_E 0.90096886790241f
#define W7_F 0.43388373911755f
/** Computes radix-7 butterfly unit.
*
* @param[in,out] c0 Complex input 0.
* @param[in,out] c1 Complex input 1.
* @param[in,out] c2 Complex input 2.
* @param[in,out] c3 Complex input 3.
* @param[in,out] c4 Complex input 4.
* @param[in,out] c5 Complex input 5.
* @param[in,out] c6 Complex input 6.
*/
#define DFT_7(c0, c1, c2, c3, c4, c5, c6) \
{ \
float2 v0, v1, v2, v3, v4, v5, v6; \
v0 = c0; \
v1 = W7_A * (c1 + c6) - W7_C * (c2 + c5) - W7_E * (c3 + c4); \
v2 = W7_C * (c1 + c6) + W7_E * (c2 + c5) - W7_A * (c3 + c4); \
v3 = W7_E * (c1 + c6) - W7_A * (c2 + c5) + W7_C * (c3 + c4); \
v4 = W7_B * (c1 - c6) + W7_D * (c2 - c5) + W7_F * (c3 - c4); \
v5 = W7_D * (c1 - c6) - W7_F * (c2 - c5) - W7_B * (c3 - c4); \
v6 = W7_F * (c1 - c6) - W7_B * (c2 - c5) + W7_D * (c3 - c4); \
c0 = v0 + c1 + c2 + c3 + c4 + c5 + c6; \
c1 = v0 + v1 + (float2)(v4.y, -v4.x); \
c2 = v0 - v2 + (float2)(v5.y, -v5.x); \
c3 = v0 - v3 + (float2)(v6.y, -v6.x); \
c4 = v0 - v3 + (float2)(-v6.y, v6.x); \
c5 = v0 - v2 + (float2)(-v5.y, v5.x); \
c6 = v0 + v1 + (float2)(-v4.y, v4.x); \
}
/** Computes radix-8 butterfly unit.
*
* @param[in,out] c0 Complex input 0.
* @param[in,out] c1 Complex input 1.
* @param[in,out] c2 Complex input 2.
* @param[in,out] c3 Complex input 3.
* @param[in,out] c4 Complex input 4.
* @param[in,out] c5 Complex input 5.
* @param[in,out] c6 Complex input 6.
* @param[in,out] c7 Complex input 7.
*/
#define DFT_8(c0, c1, c2, c3, c4, c5, c6, c7) \
{ \
float2 v0, v1, v2, v3, v4, v5, v6, v7; \
float2 s0, s1, s2, s3, s4, s5, s6, s7; \
float2 t0, t1, t2; \
v0 = c0 + c4; \
v1 = c1 + c5; \
v2 = c2 + c6; \
v3 = c3 + c7; \
v4 = c0 - c4; \
v5 = c1 - c5; \
v6 = c2 - c6; \
v7 = c3 - c7; \
s0 = v0 + v2; \
s1 = v1 + v3; \
s2 = v0 - v2; \
s3 = v1 - v3; \
s4.x = v4.x - v6.y; \
s4.y = v4.y + v6.x; \
s5.x = v5.x - v7.y; \
s5.y = v5.y + v7.x; \
s6.x = v4.x + v6.y; \
s6.y = v4.y - v6.x; \
s7.x = v5.x + v7.y; \
s7.y = v5.y - v7.x; \
t0.x = -s3.y; \
t0.y = s3.x; \
t1.x = M_SQRT1_2_F * (s5.x - s5.y); \
t1.y = M_SQRT1_2_F * (s5.x + s5.y); \
t2.x = -M_SQRT1_2_F * (s7.x + s7.y); \
t2.y = M_SQRT1_2_F * (s7.x - s7.y); \
c0 = s0 + s1; \
c1 = s6 - t2; \
c2 = s2 - t0; \
c3 = s4 - t1; \
c4 = s0 - s1; \
c5 = s6 + t2; \
c6 = s2 + t0; \
c7 = s4 + t1; \
}
/** Computes the first stage of a radix-2 DFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_2_first_stage_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load two complex input values
float4 data = vload4(0, (__global float *)input.ptr);
// Compute DFT N = 2
DFT_2(data.s01, data.s23);
// Store two complex output values
vstore4(data, 0, (__global float *)output.ptr);
}
/** Computes the first stage of a radix-2 DFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_2_first_stage_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load two complex input values
float2 data1 = vload2(0, (__global float *)input.ptr);
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 1, 0));
// Compute DFT N = 2
DFT_2(data1, data2);
// Store two complex output values
vstore2(data1, 0, (__global float *)output.ptr);
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 0, 1, 0));
}
/** Computes the first stage of a radix-3 DFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_3_first_stage_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load three complex input values
float4 data0 = vload4(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 2, 0, 0));
// Compute DFT N = 3
DFT_3(data0.s01, data0.s23, data1.s01);
// Store three complex output values
vstore4(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 2, 0, 0));
}
/** Computes the first stage of a radix-3 DFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_3_first_stage_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load three complex input values
float2 data0 = vload2(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 1, 0));
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2, 0));
// Compute DFT N = 3
DFT_3(data0, data1, data2);
// Store three complex output values
vstore2(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 0, 1, 0));
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 0, 2, 0));
}
/** Computes the first stage of a radix-4 DFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_4_first_stage_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load four complex input values
float8 data = vload8(0, (__global float *)input.ptr);
// Compute DFT N = 4
DFT_4(data.s01, data.s23, data.s45, data.s67);
// Store four complex output values
vstore8(data, 0, (__global float *)output.ptr);
}
/** Computes the first stage of a radix-4 DFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_4_first_stage_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load four complex input values
float2 data0 = vload2(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 1, 0));
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2, 0));
float2 data3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3, 0));
// Compute DFT N = 4
DFT_4(data0, data1, data2, data3);
// Store four complex output values
vstore2(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 0, 1, 0));
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 0, 2, 0));
vstore2(data3, 0, (__global float *)tensor3D_offset(&output, 0, 3, 0));
}
/** Computes the first stage of a radix-5 DFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_5_first_stage_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load five complex input values
float8 data0 = vload8(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 4, 0, 0));
// Compute DFT N = 5
DFT_5(data0.s01, data0.s23, data0.s45, data0.s67, data1.s01);
// Store five complex output values
vstore8(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 4, 0, 0));
}
/** Computes the first stage of a radix-5 DFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_5_first_stage_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load five complex input values
float2 data0 = vload2(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 1, 0));
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2, 0));
float2 data3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3, 0));
float2 data4 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 4, 0));
// Compute DFT N = 5
DFT_5(data0, data1, data2, data3, data4);
// Store five complex output values
vstore2(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 0, 1, 0));
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 0, 2, 0));
vstore2(data3, 0, (__global float *)tensor3D_offset(&output, 0, 3, 0));
vstore2(data4, 0, (__global float *)tensor3D_offset(&output, 0, 4, 0));
}
/** Computes the first stage of a radix-7 DFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_7_first_stage_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load seven complex input values
float8 data0 = vload8(0, (__global float *)input.ptr);
float4 data1 = vload4(0, (__global float *)tensor3D_offset(&input, 4, 0, 0));
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 6, 0, 0));
// Compute DFT N = 7
DFT_7(data0.s01, data0.s23, data0.s45, data0.s67, data1.s01, data1.s23, data2.s01);
// Store seven complex output values
vstore8(data0, 0, (__global float *)output.ptr);
vstore4(data1, 0, (__global float *)tensor3D_offset(&output, 4, 0, 0));
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 6, 0, 0));
}
/** Computes the first stage of a radix-7 DFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_7_first_stage_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load seven complex input values
float2 data0 = vload2(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 1, 0));
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2, 0));
float2 data3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3, 0));
float2 data4 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 4, 0));
float2 data5 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 5, 0));
float2 data6 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 6, 0));
// Compute DFT N = 7
DFT_7(data0, data1, data2, data3, data4, data5, data6);
// Store seven complex output values
vstore2(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 0, 1, 0));
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 0, 2, 0));
vstore2(data3, 0, (__global float *)tensor3D_offset(&output, 0, 3, 0));
vstore2(data4, 0, (__global float *)tensor3D_offset(&output, 0, 4, 0));
vstore2(data5, 0, (__global float *)tensor3D_offset(&output, 0, 5, 0));
vstore2(data6, 0, (__global float *)tensor3D_offset(&output, 0, 6, 0));
}
/** Computes the first stage of a radix-8 DFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_8_first_stage_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load eight complex input values
float16 data = vload16(0, (__global float *)input.ptr);
// Compute DFT N = 8
DFT_8(data.s01, data.s23, data.s45, data.s67, data.s89, data.sAB, data.sCD, data.sEF);
// Store eight complex output values
vstore16(data, 0, (__global float *)output.ptr);
}
/** Computes the first stage of a radix-8 DFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
*/
kernel void fft_radix_8_first_stage_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
)
{
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT(input);
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT(output);
#endif /* IN_PLACE */
// Load eight complex input values
float2 data0 = vload2(0, (__global float *)input.ptr);
float2 data1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 1, 0));
float2 data2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2, 0));
float2 data3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3, 0));
float2 data4 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 4, 0));
float2 data5 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 5, 0));
float2 data6 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 6, 0));
float2 data7 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 7, 0));
// Compute DFT N = 8
DFT_8(data0, data1, data2, data3, data4, data5, data6, data7);
// Store eight complex output values
vstore2(data0, 0, (__global float *)output.ptr);
vstore2(data1, 0, (__global float *)tensor3D_offset(&output, 0, 1, 0));
vstore2(data2, 0, (__global float *)tensor3D_offset(&output, 0, 2, 0));
vstore2(data3, 0, (__global float *)tensor3D_offset(&output, 0, 3, 0));
vstore2(data4, 0, (__global float *)tensor3D_offset(&output, 0, 4, 0));
vstore2(data5, 0, (__global float *)tensor3D_offset(&output, 0, 5, 0));
vstore2(data6, 0, (__global float *)tensor3D_offset(&output, 0, 6, 0));
vstore2(data7, 0, (__global float *)tensor3D_offset(&output, 0, 7, 0));
}
/** Computes a stage of a radix-2 FFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_2_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-2
uint kx = get_global_id(0);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += n * input.stride_x + get_global_id(1) * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += n * output.stride_x + get_global_id(1) * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load two complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, Nx, 0, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
// Compute DFT N = 2
DFT_2(c0, c1);
// Store two complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, Nx, 0, 0));
}
/** Computes a stage of a radix-2 FFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_2_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-2
uint kx = get_global_id(1);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += get_global_id(0) * input.stride_x + n * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += get_global_id(0) * output.stride_x + n * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load two complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, Nx, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
// Compute DFT N = 2
DFT_2(c0, c1);
// Store two complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, 0, Nx, 0));
}
/** Computes a stage of a radix-3 FFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_3_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-3
uint kx = get_global_id(0);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += n * input.stride_x + get_global_id(1) * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += n * output.stride_x + get_global_id(1) * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load three complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, Nx, 0, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 2 * Nx, 0, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
// Compute DFT N = 3
DFT_3(c0, c1, c2);
// Store three complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, Nx, 0, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 2 * Nx, 0, 0));
}
/** Computes a stage of a radix-3 FFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_3_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-3
uint kx = get_global_id(1);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += get_global_id(0) * input.stride_x + n * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += get_global_id(0) * output.stride_x + n * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load three complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, Nx, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2 * Nx, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
// Compute DFT N = 3
DFT_3(c0, c1, c2);
// Store three complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, 0, Nx, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 0, 2 * Nx, 0));
}
/** Computes a stage of a radix-4 FFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_4_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-4
uint kx = get_global_id(0);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += n * input.stride_x + get_global_id(1) * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += n * output.stride_x + get_global_id(1) * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load four complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, Nx, 0, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 2 * Nx, 0, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 3 * Nx, 0, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
// Compute DFT N = 4
DFT_4(c0, c1, c2, c3);
// Store four complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, Nx, 0, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 2 * Nx, 0, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 3 * Nx, 0, 0));
}
/** Computes a stage of a radix-4 FFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_4_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-4
uint kx = get_global_id(1);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += get_global_id(0) * input.stride_x + n * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += get_global_id(0) * output.stride_x + n * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load four complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, Nx, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2 * Nx, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3 * Nx, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
// Compute DFT N = 4
DFT_4(c0, c1, c2, c3);
// Store four complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, 0, Nx, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 0, 2 * Nx, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 0, 3 * Nx, 0));
}
/** Computes a stage of a radix-5 FFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_5_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-5
uint kx = get_global_id(0);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += n * input.stride_x + get_global_id(1) * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += n * output.stride_x + get_global_id(1) * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load five complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, Nx, 0, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 2 * Nx, 0, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 3 * Nx, 0, 0));
float2 c4 = vload2(0, (__global float *)tensor3D_offset(&input, 4 * Nx, 0, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
TWIDDLE_FACTOR_MULTIPLICATION(4 * phi, c4);
// Compute DFT N = 5
DFT_5(c0, c1, c2, c3, c4);
// Store five complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, Nx, 0, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 2 * Nx, 0, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 3 * Nx, 0, 0));
vstore2(c4, 0, (__global float *)tensor3D_offset(&output, 4 * Nx, 0, 0));
}
/** Computes a stage of a radix-5 FFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_5_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-5
uint kx = get_global_id(1);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += get_global_id(0) * input.stride_x + n * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += get_global_id(0) * output.stride_x + n * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load five complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, Nx, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2 * Nx, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3 * Nx, 0));
float2 c4 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 4 * Nx, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
TWIDDLE_FACTOR_MULTIPLICATION(4 * phi, c4);
// Compute DFT N = 5
DFT_5(c0, c1, c2, c3, c4);
// Store five complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, 0, Nx, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 0, 2 * Nx, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 0, 3 * Nx, 0));
vstore2(c4, 0, (__global float *)tensor3D_offset(&output, 0, 4 * Nx, 0));
}
/** Computes a stage of a radix-7 FFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_7_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-7
uint kx = get_global_id(0);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += n * input.stride_x + get_global_id(1) * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += n * output.stride_x + get_global_id(1) * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load seven complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, Nx, 0, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 2 * Nx, 0, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 3 * Nx, 0, 0));
float2 c4 = vload2(0, (__global float *)tensor3D_offset(&input, 4 * Nx, 0, 0));
float2 c5 = vload2(0, (__global float *)tensor3D_offset(&input, 5 * Nx, 0, 0));
float2 c6 = vload2(0, (__global float *)tensor3D_offset(&input, 6 * Nx, 0, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
TWIDDLE_FACTOR_MULTIPLICATION(4 * phi, c4);
TWIDDLE_FACTOR_MULTIPLICATION(5 * phi, c5);
TWIDDLE_FACTOR_MULTIPLICATION(6 * phi, c6);
// Compute DFT N = 7
DFT_7(c0, c1, c2, c3, c4, c5, c6);
// Store seven complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, Nx, 0, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 2 * Nx, 0, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 3 * Nx, 0, 0));
vstore2(c4, 0, (__global float *)tensor3D_offset(&output, 4 * Nx, 0, 0));
vstore2(c5, 0, (__global float *)tensor3D_offset(&output, 5 * Nx, 0, 0));
vstore2(c6, 0, (__global float *)tensor3D_offset(&output, 6 * Nx, 0, 0));
}
/** Computes a stage of a radix-7 FFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_7_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-7
uint kx = get_global_id(1);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += get_global_id(0) * input.stride_x + n * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += get_global_id(0) * output.stride_x + n * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load seven complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, Nx, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2 * Nx, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3 * Nx, 0));
float2 c4 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 4 * Nx, 0));
float2 c5 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 5 * Nx, 0));
float2 c6 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 6 * Nx, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
TWIDDLE_FACTOR_MULTIPLICATION(4 * phi, c4);
TWIDDLE_FACTOR_MULTIPLICATION(5 * phi, c5);
TWIDDLE_FACTOR_MULTIPLICATION(6 * phi, c6);
// Compute DFT N = 7
DFT_7(c0, c1, c2, c3, c4, c5, c6);
// Store seven complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, 0, Nx, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 0, 2 * Nx, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 0, 3 * Nx, 0));
vstore2(c4, 0, (__global float *)tensor3D_offset(&output, 0, 4 * Nx, 0));
vstore2(c5, 0, (__global float *)tensor3D_offset(&output, 0, 5 * Nx, 0));
vstore2(c6, 0, (__global float *)tensor3D_offset(&output, 0, 6 * Nx, 0));
}
/** Computes a stage of a radix-8 FFT on axis 0.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_8_axis_0(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-8
uint kx = get_global_id(0);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += n * input.stride_x + get_global_id(1) * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += n * output.stride_x + get_global_id(1) * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load eight complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, Nx, 0, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 2 * Nx, 0, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 3 * Nx, 0, 0));
float2 c4 = vload2(0, (__global float *)tensor3D_offset(&input, 4 * Nx, 0, 0));
float2 c5 = vload2(0, (__global float *)tensor3D_offset(&input, 5 * Nx, 0, 0));
float2 c6 = vload2(0, (__global float *)tensor3D_offset(&input, 6 * Nx, 0, 0));
float2 c7 = vload2(0, (__global float *)tensor3D_offset(&input, 7 * Nx, 0, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
TWIDDLE_FACTOR_MULTIPLICATION(4 * phi, c4);
TWIDDLE_FACTOR_MULTIPLICATION(5 * phi, c5);
TWIDDLE_FACTOR_MULTIPLICATION(6 * phi, c6);
TWIDDLE_FACTOR_MULTIPLICATION(7 * phi, c7);
// Compute DFT N = 8
DFT_8(c0, c1, c2, c3, c4, c5, c6, c7);
// Store eight complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, Nx, 0, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 2 * Nx, 0, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 3 * Nx, 0, 0));
vstore2(c4, 0, (__global float *)tensor3D_offset(&output, 4 * Nx, 0, 0));
vstore2(c5, 0, (__global float *)tensor3D_offset(&output, 5 * Nx, 0, 0));
vstore2(c6, 0, (__global float *)tensor3D_offset(&output, 6 * Nx, 0, 0));
vstore2(c7, 0, (__global float *)tensor3D_offset(&output, 7 * Nx, 0, 0));
}
/** Computes a stage of a radix-8 FFT on axis 1.
*
* @note In order to perform the FFT function "in-place", the pre-processor -DIN_PLACE must be passed at compile time
*
* @param[in,out] input_ptr Pointer to the source tensor. Supported data types: F32
* @param[in,out] input_stride_x Stride of the source tensor in X dimension (in bytes)
* @param[in,out] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in,out] input_stride_y Stride of the source tensor in Y dimension (in bytes)
* @param[in,out] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in,out] input_stride_z Stride of the source tensor in Z dimension (in bytes)
* @param[in,out] input_step_z input_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in,out] input_offset_first_element_in_bytes The offset of the first element in the source tensor
* @param[out] output_ptr (Optional) Pointer to the destination image. Supported data types: same as @p input_ptr
* @param[in] output_stride_x (Optional) Stride of the destination image in X dimension (in bytes)
* @param[in] output_step_x (Optional) output_stride_x * number of elements along X processed per workitem(in bytes)
* @param[in] output_stride_y (Optional) Stride of the destination image in Y dimension (in bytes)
* @param[in] output_step_y (Optional) output_stride_y * number of elements along Y processed per workitem(in bytes)
* @param[in] output_stride_z (Optional) Stride of the source tensor in Z dimension (in bytes)
* @param[in] output_step_z (Optional) output_stride_z * number of elements along Z processed per workitem(in bytes)
* @param[in] output_offset_first_element_in_bytes (Optional) The offset of the first element in the destination image
* @param[in] Nx The butterfly span. Products of radix order of previous radix's stage
* @param[in] Ni Nx * Ny.
* @param[in] exp_const Exponent constant
*/
kernel void fft_radix_8_axis_1(
TENSOR3D_DECLARATION(input)
#ifndef IN_PLACE
,
TENSOR3D_DECLARATION(output)
#endif /* not IN_PLACE */
,
uint Nx, uint Ni, float exp_const)
{
// Each work-item computes a single radix-8
uint kx = get_global_id(1);
// Compute nx
uint nx = kx % Nx;
// Compute n index
uint n = nx + (kx / Nx) * Ni;
// Get tensor pointers
Tensor3D input = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(input);
input.ptr += get_global_id(0) * input.stride_x + n * input.stride_y + get_global_id(2) * input.stride_z;
#ifdef IN_PLACE
Tensor3D output = input;
#else /* IN_PLACE */
Tensor3D output = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(output);
output.ptr += get_global_id(0) * output.stride_x + n * output.stride_y + get_global_id(2) * output.stride_z;
#endif /* IN_PLACE */
// Load eight complex input values
float2 c0 = vload2(0, (__global float *)input.ptr);
float2 c1 = vload2(0, (__global float *)tensor3D_offset(&input, 0, Nx, 0));
float2 c2 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 2 * Nx, 0));
float2 c3 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 3 * Nx, 0));
float2 c4 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 4 * Nx, 0));
float2 c5 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 5 * Nx, 0));
float2 c6 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 6 * Nx, 0));
float2 c7 = vload2(0, (__global float *)tensor3D_offset(&input, 0, 7 * Nx, 0));
// Compute phi
float phi = (float)nx * exp_const;
// Multiply by twiddle factor
TWIDDLE_FACTOR_MULTIPLICATION(phi, c1);
TWIDDLE_FACTOR_MULTIPLICATION(2 * phi, c2);
TWIDDLE_FACTOR_MULTIPLICATION(3 * phi, c3);
TWIDDLE_FACTOR_MULTIPLICATION(4 * phi, c4);
TWIDDLE_FACTOR_MULTIPLICATION(5 * phi, c5);
TWIDDLE_FACTOR_MULTIPLICATION(6 * phi, c6);
TWIDDLE_FACTOR_MULTIPLICATION(7 * phi, c7);
// Compute DFT N = 8
DFT_8(c0, c1, c2, c3, c4, c5, c6, c7);
// Store eight complex output values
vstore2(c0, 0, (__global float *)output.ptr);
vstore2(c1, 0, (__global float *)tensor3D_offset(&output, 0, Nx, 0));
vstore2(c2, 0, (__global float *)tensor3D_offset(&output, 0, 2 * Nx, 0));
vstore2(c3, 0, (__global float *)tensor3D_offset(&output, 0, 3 * Nx, 0));
vstore2(c4, 0, (__global float *)tensor3D_offset(&output, 0, 4 * Nx, 0));
vstore2(c5, 0, (__global float *)tensor3D_offset(&output, 0, 5 * Nx, 0));
vstore2(c6, 0, (__global float *)tensor3D_offset(&output, 0, 6 * Nx, 0));
vstore2(c7, 0, (__global float *)tensor3D_offset(&output, 0, 7 * Nx, 0));
}
)"