| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | #if __SSE2__ |
| 16 | #if __AVX__ |
| 17 | #if __AVX512F__ |
| 18 | static void gridsample_nearest_apply_interpolation_p16(const Mat& src, Mat& dst, const Mat& offset_value, const Option& opt) |
| 19 | { |
| 20 | const int channels = dst.c; |
| 21 | const int outw = dst.w; |
| 22 | const int outh = dst.h; |
| 23 | const int outd = dst.d; |
| 24 | const int grid_size = outw * outh * outd; |
| 25 | |
| 26 | #pragma omp parallel for num_threads(opt.num_threads) |
| 27 | for (int q = 0; q < channels; q++) |
| 28 | { |
| 29 | const float* srcptr = src.channel(q); |
| 30 | float* dstptr = dst.channel(q); |
| 31 | |
| 32 | const int* offset_ptr = offset_value.channel(0); |
| 33 | |
| 34 | for (int i = 0; i < grid_size; i++) |
| 35 | { |
| 36 | __m512 _v = offset_ptr[0] >= 0 ? _mm512_loadu_ps(srcptr + offset_ptr[0]) : _mm512_set1_ps(0); |
| 37 | offset_ptr++; |
| 38 | |
| 39 | _mm512_storeu_ps(dstptr, _v); |
| 40 | dstptr += 16; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | #endif // __AVX512F__ |
| 45 | |
| 46 | static void gridsample_nearest_apply_interpolation_p8(const Mat& src, Mat& dst, const Mat& offset_value, const Option& opt) |
| 47 | { |
| 48 | const int channels = dst.c; |
| 49 | const int outw = dst.w; |
| 50 | const int outh = dst.h; |
| 51 | const int outd = dst.d; |
| 52 | const int grid_size = outw * outh * outd; |
| 53 | |
| 54 | #pragma omp parallel for num_threads(opt.num_threads) |
| 55 | for (int q = 0; q < channels; q++) |
| 56 | { |
| 57 | const float* srcptr = src.channel(q); |
| 58 | float* dstptr = dst.channel(q); |
| 59 | |
| 60 | const int* offset_ptr = offset_value.channel(0); |
| 61 | |
| 62 | for (int i = 0; i < grid_size; i++) |
| 63 | { |
| 64 | __m256 _v = offset_ptr[0] >= 0 ? _mm256_loadu_ps(srcptr + offset_ptr[0]) : _mm256_set1_ps(0); |
| 65 | offset_ptr++; |
| 66 | |
| 67 | _mm256_storeu_ps(dstptr, _v); |
| 68 | dstptr += 8; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | #endif // __AVX__ |
| 73 | static void gridsample_nearest_apply_interpolation_p4(const Mat& src, Mat& dst, const Mat& offset_value, const Option& opt) |
| 74 | { |
| 75 | const int channels = dst.c; |
| 76 | const int outw = dst.w; |
| 77 | const int outh = dst.h; |
| 78 | const int outd = dst.d; |
| 79 | const int grid_size = outw * outh * outd; |
| 80 | |
| 81 | #pragma omp parallel for num_threads(opt.num_threads) |
| 82 | for (int q = 0; q < channels; q++) |
| 83 | { |
| 84 | const float* srcptr = src.channel(q); |
| 85 | float* dstptr = dst.channel(q); |
| 86 | |
| 87 | const int* offset_ptr = offset_value.channel(0); |
| 88 | |
| 89 | for (int i = 0; i < grid_size; i++) |
| 90 | { |
| 91 | __m128 _v = offset_ptr[0] >= 0 ? _mm_loadu_ps(srcptr + offset_ptr[0]) : _mm_set1_ps(0); |
| 92 | offset_ptr++; |
| 93 | |
| 94 | _mm_storeu_ps(dstptr, _v); |
| 95 | dstptr += 4; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #endif // __SSE2__ |
| 101 | |
| 102 | static void gridsample_nearest_apply_interpolation_p1(const Mat& src, Mat& dst, const Mat& offset_value, const Option& opt) |
| 103 | { |
| 104 | const int channels = dst.c; |
| 105 | const int outw = dst.w; |
| 106 | const int outh = dst.h; |
| 107 | const int outd = dst.d; |
| 108 | const int grid_size = outw * outh * outd; |
| 109 | |
| 110 | #pragma omp parallel for num_threads(opt.num_threads) |
| 111 | for (int q = 0; q < channels; q++) |
| 112 | { |
| 113 | const float* srcptr = src.channel(q); |
| 114 | float* dstptr = dst.channel(q); |
| 115 | |
| 116 | const int* offset_ptr = offset_value.channel(0); |
| 117 | |
| 118 | for (int x = 0; x < grid_size; x++) |
| 119 | { |
| 120 | *dstptr = offset_ptr[0] >= 0 ? *(srcptr + offset_ptr[0]) : 0; |
| 121 | |
| 122 | offset_ptr++; |
| 123 | dstptr++; |
| 124 | } |
| 125 | } |
| 126 | } |