@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
See the License for the specific language governing permissions and
13
13
limitations under the License. */
14
14
15
- #include " MathFunctions.h"
15
+ #include " paddle/math/ MathFunctions.h"
16
16
#include " hl_matrix_apply.cuh"
17
17
#include " hl_matrix_ops.cuh"
18
18
#include " paddle/utils/DynamicLoader.h"
@@ -240,6 +240,36 @@ template <>
240
240
void vAdd<double >(const int n, const double * a, const double * b, double * r) {
241
241
vdAdd (n, a, b, r);
242
242
}
243
+
244
+ template <>
245
+ void vTanh<float >(const int n, const float * a, float * r) {
246
+ vsTanh (n, a, r);
247
+ }
248
+
249
+ template <>
250
+ void vTanh<double >(const int n, const double * a, double * r) {
251
+ vdTanh (n, a, r);
252
+ }
253
+
254
+ template <>
255
+ void vInvSqrt<float >(const int n, const float * a, float * r) {
256
+ vsInvSqrt (n, a, r);
257
+ }
258
+
259
+ template <>
260
+ void vInvSqrt<double >(const int n, const double * a, double * r) {
261
+ vdInvSqrt (n, a, r);
262
+ }
263
+
264
+ template <>
265
+ void vLog1p<float >(const int n, const float * a, float * r) {
266
+ vsLog1p (n, a, r);
267
+ }
268
+
269
+ template <>
270
+ void vLog1p<double >(const int n, const double * a, double * r) {
271
+ vdLog1p (n, a, r);
272
+ }
243
273
#else
244
274
245
275
DEFINE_MATRIX_BINARY_OP (vExp, b = std::exp(a));
@@ -287,35 +317,4 @@ template void vAdd(const int n, const float* a, const float* b, float* r);
287
317
template void vAdd (const int n, const double * a, const double * b, double * r);
288
318
289
319
#endif
290
-
291
- DEFINE_MATRIX_BINARY_OP (vInvSqrt, b = 1 .0f / std::sqrt(a));
292
- template <class T >
293
- void vInvSqrt (const int n, const T* a, T* r) {
294
- hl_cpu_apply_binary_op<T, binary::vInvSqrt<T>, 0 , 0 >(
295
- binary::vInvSqrt<T>(), const_cast <T*>(a), r, 1 , n, n, n);
296
- }
297
-
298
- DEFINE_MATRIX_BINARY_OP (vLog1p, b = std::log(1 .0f + a));
299
- template <class T >
300
- void vLog1p (const int n, const T* a, T* r) {
301
- hl_cpu_apply_binary_op<T, binary::vLog1p<T>, 0 , 0 >(
302
- binary::vLog1p<T>(), const_cast <T*>(a), r, 1 , n, n, n);
303
- }
304
-
305
- DEFINE_MATRIX_BINARY_OP (vTanh, T tmp = -2.0 * a;
306
- tmp = (tmp > EXP_MAX_INPUT) ? EXP_MAX_INPUT : tmp;
307
- b = 2.0 / (1.0 + std::exp(tmp)) - 1.0 );
308
- template <class T >
309
- void vTanh (const int n, const T* a, T* r) {
310
- hl_cpu_apply_binary_op<T, binary::vTanh<T>, 0 , 0 >(
311
- binary::vTanh<T>(), const_cast <T*>(a), r, 1 , n, n, n);
312
- }
313
-
314
- template void vInvSqrt (const int n, const double * a, double * r);
315
- template void vInvSqrt (const int n, const float * a, float * r);
316
- template void vLog1p (const int n, const float * a, float * r);
317
- template void vLog1p (const int n, const double * a, double * r);
318
- template void vTanh (const int n, const float * a, float * r);
319
- template void vTanh (const int n, const double * a, double * r);
320
-
321
320
} // namespace paddle
0 commit comments