blob: 200ab91f491441b3c94eece37dfd4269fbccc0a6 [file] [log] [blame]
Georgios Pinitas8be91482019-03-26 17:23:28 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019 Arm Limited.
Georgios Pinitas8be91482019-03-26 17:23:28 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "helpers.h"
25
26#if defined(VEC_SIZE)
27/** Computes the digit reverse stage on axis X
28 *
29 * @param[in] src_ptr Pointer to the source tensor. Supported data types: F32
30 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
31 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
32 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
33 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
34 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
35 * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
36 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
37 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
38 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
39 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
40 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
41 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
42 * @param[in] dst_stride_z Stride of the source tensor in Z dimension (in bytes)
43 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
44 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
45 * @param[in] idx_ptr Pointer to the index tensor. Supported data types: U32
46 * @param[in] idx_stride_x Stride of the index tensor in X dimension (in bytes)
47 * @param[in] idx_step_x idx_stride_x * number of elements along X processed per workitem(in bytes)
48 * @param[in] idx_offset_first_element_in_bytes The offset of the first element in the index tensor
49 */
50__kernel void fft_digit_reverse_axis_0(
51 TENSOR3D_DECLARATION(src),
52 TENSOR3D_DECLARATION(dst),
53 VECTOR_DECLARATION(idx))
54{
55 // Get tensor pointers
56 Tensor3D src = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(src);
57 Tensor3D dst = CONVERT_TO_TENSOR3D_STRUCT(dst);
58 Vector idx = CONVERT_TO_VECTOR_STRUCT(idx);
59
60 const unsigned int iidx = *((__global uint *)(idx.ptr));
61
62 // Load data
63#if VEC_SIZE == 1
64 float data = *((__global float *)tensor3D_offset(&src, iidx, get_global_id(1), get_global_id(2)));
65#elif VEC_SIZE == 2
66 float2 data = vload2(0, (__global float *)tensor3D_offset(&src, iidx, get_global_id(1), get_global_id(2)));
67#else // VEC_SIZE == 1
68#error "vec_size of 1 and 2 are supported"
69#endif // VEC_SIZE == 1
70
71 // Create result
72#if VEC_SIZE == 1
73 float2 res = { data, 0 };
74#elif VEC_SIZE == 2
75 float2 res = data;
76#else // VEC_SIZE == 1
77#error "vec_size of 1 and 2 are supported"
78#endif // VEC_SIZE == 1
79
80 // Store result
81#if defined(CONJ)
82 vstore2((float2)(res.s0, -res.s1), 0, (__global float *)dst.ptr);
83#else // defined(CONJ)
84 vstore2(res, 0, (__global float *)dst.ptr);
85#endif // defined(CONJ)
86}
87
88/** Computes the digit reverse stage on axis Y
89 *
90 * @param[in] src_ptr Pointer to the source tensor. Supported data types: F32
91 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
92 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
93 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
94 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
95 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
96 * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
97 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
98 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
99 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
100 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
101 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
102 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
103 * @param[in] dst_stride_z Stride of the source tensor in Z dimension (in bytes)
104 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
105 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
106 * @param[in] idx_ptr Pointer to the index tensor. Supported data types: U32
107 * @param[in] idx_stride_x Stride of the index tensor in X dimension (in bytes)
108 * @param[in] idx_step_x idx_stride_x * number of elements along X processed per workitem(in bytes)
109 * @param[in] idx_offset_first_element_in_bytes The offset of the first element in the index tensor
110 */
111__kernel void fft_digit_reverse_axis_1(
112 TENSOR3D_DECLARATION(src),
113 TENSOR3D_DECLARATION(dst),
114 VECTOR_DECLARATION(idx))
115{
116 // Get tensor pointers
117 Tensor3D src = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(src);
118 Tensor3D dst = CONVERT_TO_TENSOR3D_STRUCT(dst);
119 Vector idx = CONVERT_TO_VECTOR_STRUCT_NO_STEP(idx);
120
121 const unsigned int iidx = *((__global uint *)vector_offset(&idx, (int)(get_global_id(1))));
122
123 // Load data
124#if VEC_SIZE == 1
125 float data = *((__global float *)tensor3D_offset(&src, get_global_id(0), iidx, get_global_id(2)));
126#elif VEC_SIZE == 2
127 float2 data = vload2(0, (__global float *)tensor3D_offset(&src, get_global_id(0), iidx, get_global_id(2)));
128#else // VEC_SIZE == 1
129#error "vec_size of 1 and 2 are supported"
130#endif // VEC_SIZE == 1
131
132 // Create result
133#if VEC_SIZE == 1
134 float2 res = { data, 0 };
135#elif VEC_SIZE == 2
136 float2 res = data;
137#else // VEC_SIZE == 1
138#error "vec_size of 1 and 2 are supported"
139#endif // VEC_SIZE == 1
140
141 // Store result
142#if defined(CONJ)
143 vstore2((float2)(res.s0, -res.s1), 0, (__global float *)dst.ptr);
144#else // defined(CONJ)
145 vstore2(res, 0, (__global float *)dst.ptr);
146#endif // defined(CONJ)
147}
148#endif // defined(VEC_SIZE)