forked from PaddlePaddle/Anakin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower.cpp
140 lines (119 loc) · 4.38 KB
/
power.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Copyright (c) 2018 Anakin Authors, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "framework/operators/power.h"
namespace anakin {
namespace ops {
#define INSTANCE_POWER(Ttype, Ptype) \
template<> \
void Power<Ttype, Ptype>::operator()(OpContext<Ttype>& ctx, \
const std::vector<Tensor4dPtr<Ttype> >& ins, \
std::vector<Tensor4dPtr<Ttype> >& outs) { \
auto* impl = static_cast<PowerHelper<Ttype, Ptype>*>(this->_helper); \
auto& param = static_cast<PowerHelper<Ttype, Ptype>*> \
(this->_helper)->_param_power; \
impl->_funcs_power(ins, outs, param, ctx); \
}
/// set helper
template<typename Ttype, Precision Ptype>
PowerHelper<Ttype, Ptype>::~PowerHelper() {
}
template<typename Ttype, Precision Ptype>
Status PowerHelper<Ttype, Ptype>::InitParam() {
DLOG(WARNING) << "Parsing Power op parameter.";
auto scale = GET_PARAMETER(float, scale);
auto shift = GET_PARAMETER(float, shift);
auto power = GET_PARAMETER(float, power);
saber::PowerParam<Ttype> power_param(power, scale, shift);
_param_power = power_param;
return Status::OK();
}
template<typename Ttype, Precision Ptype>
Status PowerHelper<Ttype, Ptype>::Init(OpContext<Ttype>& ctx,
const std::vector<Tensor4dPtr<Ttype> >& ins,
std::vector<Tensor4dPtr<Ttype> >& outs) {
SABER_CHECK(_funcs_power.init(ins, outs, _param_power, SPECIFY, SABER_IMPL, ctx));
return Status::OK();
}
template<typename Ttype, Precision Ptype>
Status PowerHelper<Ttype, Ptype>::InferShape(const std::vector<Tensor4dPtr<Ttype> >&
ins,
std::vector<Tensor4dPtr<Ttype> >& outs) {
SABER_CHECK(_funcs_power.compute_output_shape(ins, outs, _param_power));
return Status::OK();
}
#ifdef USE_CUDA
INSTANCE_POWER(NV, Precision::FP32);
template class PowerHelper<NV, Precision::FP32>;
template class PowerHelper<NV, Precision::FP16>;
template class PowerHelper<NV, Precision::INT8>;
#endif
#ifdef USE_ARM_PLACE
INSTANCE_POWER(ARM, Precision::FP32);
template class PowerHelper<ARM, Precision::FP32>;
template class PowerHelper<ARM, Precision::FP16>;
template class PowerHelper<ARM, Precision::INT8>;
#endif
#if defined USE_X86_PLACE || defined BUILD_LITE
INSTANCE_POWER(X86, Precision::FP32);
template class PowerHelper<X86, Precision::FP32>;
template class PowerHelper<X86, Precision::FP16>;
template class PowerHelper<X86, Precision::INT8>;
#endif
#ifdef AMD_GPU
INSTANCE_POWER(AMD, Precision::FP32);
template class PowerHelper<AMD, Precision::FP32>;
ANAKIN_REGISTER_OP_HELPER(Power, PowerHelper, AMD, Precision::FP32);
#endif
#ifdef USE_MLU
INSTANCE_POWER(MLU, Precision::FP32)
INSTANCE_POWER(MLU, Precision::FP16)
template class PowerHelper<MLU, Precision::FP32>;
template class PowerHelper<MLU, Precision::FP16>;
template class PowerHelper<MLU, Precision::INT8>;
ANAKIN_REGISTER_OP_HELPER(Power, PowerHelper, MLU, Precision::FP32);
ANAKIN_REGISTER_OP_HELPER(Power, PowerHelper, MLU, Precision::FP16);
#endif
// register helper
#ifdef USE_CUDA
ANAKIN_REGISTER_OP_HELPER(Power, PowerHelper, NV, Precision::FP32);
#endif
#ifdef USE_ARM_PLACE
ANAKIN_REGISTER_OP_HELPER(Power, PowerHelper, ARM, Precision::FP32);
#endif
#if defined USE_X86_PLACE || defined BUILD_LITE
ANAKIN_REGISTER_OP_HELPER(Power, PowerHelper, X86, Precision::FP32);
#endif
//! register op
ANAKIN_REGISTER_OP(Power)
.Doc("Power operator")
#ifdef USE_CUDA
.__alias__<NV, Precision::FP32>("power")
#endif
#ifdef USE_ARM_PLACE
.__alias__<ARM, Precision::FP32>("power")
#endif
#if defined USE_X86_PLACE || defined BUILD_LITE
.__alias__<X86, Precision::FP32>("power")
#endif
#ifdef AMD_GPU
.__alias__<AMD, Precision::FP32>("power")
#endif
#ifdef USE_MLU
.__alias__<MLU, Precision::FP32>("power")
#endif
.num_in(1)
.num_out(1)
.Args<float>("scale", " scale of param for pawer")
.Args<float>("shift", " shift of param for power")
.Args<float>("power", " power of param for power");
} /* namespace ops */
} /* namespace anakin */