ncnn

Форк
0
/
mish_mips.cpp 
68 строк · 1.9 Кб
1
// Tencent is pleased to support the open source community by making ncnn available.
2
//
3
// Copyright (C) 2021 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
#include "mish_mips.h"
16

17
#if __mips_msa
18
#include <msa.h>
19
#include "msa_mathfun.h"
20
#endif // __mips_msa
21

22
namespace ncnn {
23

24
Mish_mips::Mish_mips()
25
{
26
#if __mips_msa
27
    support_packing = true;
28
#endif
29
}
30

31
int Mish_mips::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
32
{
33
    int w = bottom_top_blob.w;
34
    int h = bottom_top_blob.h;
35
    int d = bottom_top_blob.d;
36
    int channels = bottom_top_blob.c;
37
    int elempack = bottom_top_blob.elempack;
38
    int size = w * h * d * elempack;
39

40
    #pragma omp parallel for num_threads(opt.num_threads)
41
    for (int q = 0; q < channels; q++)
42
    {
43
        float* ptr = bottom_top_blob.channel(q);
44

45
        int i = 0;
46
#if __mips_msa
47
        v4f32 _one = (v4f32)__msa_fill_w_f32(1.f);
48
        for (; i + 3 < size; i += 4)
49
        {
50
            __builtin_prefetch(ptr + 16);
51
            v4f32 _p = (v4f32)__msa_ld_w(ptr, 0);
52
            _p = __msa_fmul_w(_p, tanh_ps(log_ps(__msa_fadd_w(exp_ps(_p), _one))));
53
            __msa_st_w((v4i32)_p, ptr, 0);
54

55
            ptr += 4;
56
        }
57
#endif // __mips_msa
58
        for (; i < size; i++)
59
        {
60
            *ptr = *ptr * tanh(log(exp(*ptr) + 1.f));
61
            ptr++;
62
        }
63
    }
64

65
    return 0;
66
}
67

68
} // namespace ncnn
69

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.