-
Notifications
You must be signed in to change notification settings - Fork 0
/
clip.patch
126 lines (123 loc) · 5.55 KB
/
clip.patch
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
diff --git a/include/mkldnn.hpp b/include/mkldnn.hpp
index d1e4761..0c053b3 100644
--- a/include/mkldnn.hpp
+++ b/include/mkldnn.hpp
@@ -250,6 +250,7 @@ enum algorithm {
convolution_direct = mkldnn_convolution_direct,
convolution_winograd = mkldnn_convolution_winograd,
eltwise_relu = mkldnn_eltwise_relu,
+ eltwise_clip = mkldnn_eltwise_clip,
eltwise_tanh = mkldnn_eltwise_tanh,
eltwise_elu = mkldnn_eltwise_elu,
eltwise_square = mkldnn_eltwise_square,
diff --git a/include/mkldnn_types.h b/include/mkldnn_types.h
index 8d3c1b3..c4a4eb6 100644
--- a/include/mkldnn_types.h
+++ b/include/mkldnn_types.h
@@ -334,6 +334,8 @@ typedef enum {
mkldnn_eltwise_soft_relu = 16,
/** Eltwise: logistic */
mkldnn_eltwise_logistic = 17,
+ /** Eltwise: Clip */
+ mkldnn_eltwise_clip = 30,
/** Max pooling */
mkldnn_pooling_max = 34,
/** Average pooling include padding */
@@ -835,6 +837,7 @@ typedef enum {
mkldnn_query_convolution_d, /**< convolution descriptor */
mkldnn_query_eltwise_d, /**< eltwise descriptor */
mkldnn_query_relu_d = mkldnn_query_eltwise_d, /**< @deprecated */
+ mkldnn_query_clip_d = mkldnn_query_eltwise_d, /**< @deprecated */
mkldnn_query_softmax_d, /**< softmax descriptor */
mkldnn_query_pooling_d, /**< pooling descriptor */
mkldnn_query_lrn_d, /**< lrn descriptor */
diff --git a/scripts/prepare_mkl.sh b/scripts/prepare_mkl.sh
index 353694b..f91e642 100755
--- a/scripts/prepare_mkl.sh
+++ b/scripts/prepare_mkl.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#===============================================================================
# Copyright 2016-2017 Intel Corporation
#
diff --git a/src/common/c_types_map.hpp b/src/common/c_types_map.hpp
index 716aadd..f4b738b 100644
--- a/src/common/c_types_map.hpp
+++ b/src/common/c_types_map.hpp
@@ -61,6 +61,7 @@ namespace alg_kind {
const alg_kind_t convolution_direct = mkldnn_convolution_direct;
const alg_kind_t convolution_winograd = mkldnn_convolution_winograd;
const alg_kind_t eltwise_relu = mkldnn_eltwise_relu;
+ const alg_kind_t eltwise_clip = mkldnn_eltwise_clip;
const alg_kind_t eltwise_tanh = mkldnn_eltwise_tanh;
const alg_kind_t eltwise_elu = mkldnn_eltwise_elu;
const alg_kind_t eltwise_square = mkldnn_eltwise_square;
diff --git a/src/common/eltwise.cpp b/src/common/eltwise.cpp
index b97f986..6f62717 100644
--- a/src/common/eltwise.cpp
+++ b/src/common/eltwise.cpp
@@ -36,7 +36,7 @@ status_t eltwise_desc_init(eltwise_desc_t *eltwise_desc, prop_kind_t prop_kind,
&& !any_null(eltwise_desc, data_desc)
&& one_of(prop_kind, forward_training, forward_inference,
backward_data)
- && one_of(alg_kind, eltwise_relu, eltwise_tanh, eltwise_elu,
+ && one_of(alg_kind, eltwise_relu, eltwise_clip, eltwise_tanh, eltwise_elu,
eltwise_square, eltwise_abs, eltwise_sqrt, eltwise_linear,
eltwise_bounded_relu, eltwise_soft_relu, eltwise_logistic)
&& implication(prop_kind == backward_data, diff_data_desc != nullptr);
diff --git a/src/cpu/jit_uni_eltwise.cpp b/src/cpu/jit_uni_eltwise.cpp
index 623d104..6b07b01 100644
--- a/src/cpu/jit_uni_eltwise.cpp
+++ b/src/cpu/jit_uni_eltwise.cpp
@@ -949,9 +949,9 @@ status_t jit_uni_eltwise_fwd_t<isa>::pd_t::init() {
&& utils::one_of(desc()->prop_kind, prop_kind::forward_training,
prop_kind::forward_inference)
&& utils::implication(isa > avx2, utils::one_of(desc()->alg_kind,
- eltwise_relu, eltwise_elu))
+ eltwise_relu, eltwise_clip, eltwise_elu))
&& utils::implication(isa == sse42 || isa == avx2, utils::one_of(
- desc()->alg_kind, eltwise_relu, eltwise_tanh, eltwise_elu,
+ desc()->alg_kind, eltwise_relu, eltwise_clip, eltwise_tanh, eltwise_elu,
eltwise_square, eltwise_abs, eltwise_sqrt, eltwise_linear,
eltwise_bounded_relu, eltwise_soft_relu, eltwise_logistic))
&& utils::everyone_is(data_type::f32, desc()->data_desc.data_type)
@@ -968,6 +968,7 @@ jit_uni_eltwise_fwd_t<isa>::jit_uni_eltwise_fwd_t(const pd_t *pd,
switch (desc.alg_kind) {
case alg_kind::eltwise_relu:
kernel_ = new jit_uni_relu_kernel_f32<isa>(desc); break;
+ case alg_kind::eltwise_clip: break;
default:
kernel_ = new jit_uni_kernel_fwd_f32<isa>(desc);
}
@@ -982,6 +983,15 @@ void jit_uni_eltwise_fwd_t<isa>::execute_forward() {
auto src = reinterpret_cast<const data_t *>(this->input_memory(0));
auto dst = reinterpret_cast<data_t *>(this->memory(0));
+ const auto &desc = conf_.desc();
+ bool is_clip = false;
+ switch (desc->alg_kind) {
+ case alg_kind::eltwise_clip:
+ is_clip = true;
+ break;
+ default: break;
+ }
+
const memory_desc_wrapper data_d(conf_.src_pd());
const size_t nelems = data_d.nelems();
@@ -1003,8 +1013,15 @@ void jit_uni_eltwise_fwd_t<isa>::execute_forward() {
arg.for_comparison = &src[start];
arg.to = &dst[start];
arg.work_amount = end - start;
- if (arg.work_amount)
- (*kernel_)(&arg);
+ if(arg.work_amount) {
+ if ( is_clip ) {
+ for( int i = int(start); i < int(end); i++ ) {
+ if ( src[i] > desc->beta ) dst[i] = desc->beta;
+ else if ( src[i] < desc->alpha ) dst[i] = desc->alpha;
+ else dst[i] = src[i];
+ }
+ } else (*kernel_)(&arg);
+ }
};
# pragma omp parallel