Skip to content

Commit f7c41dc

Browse files
committed
fixup: fixup: benchdnn: eltwise: improve input data coverage
* 1) With fp16 argument, exp() is dispatched to fp16 version as well, * overflows and produces inf instead of an fp32 value, resulting in * 0 in the final answer, while it should be a non-zero value exceeding trh. * 2) MSVC math functions are invariant to compiler options leaving the * answer same no matter what. Current threshold is low for it. Slightly * increasing it...
1 parent 407e3ee commit f7c41dc

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/cpu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
4545
file(GLOB FILES_REQUIRED_PREC_DIV
4646
${CMAKE_CURRENT_SOURCE_DIR}/*resampling*.cpp
4747
${CMAKE_CURRENT_SOURCE_DIR}/*normalization*.cpp
48-
${CMAKE_CURRENT_SOURCE_DIR}/ref_eltwise.cpp
48+
${CMAKE_CURRENT_SOURCE_DIR}/eltwise/ref_eltwise.cpp
4949
${CMAKE_CURRENT_SOURCE_DIR}/ref_rnn.cpp)
5050
if(WIN32)
5151
set_source_files_properties(${FILES_REQUIRED_PREC_SQRT}

src/gpu/ocl/ocl_post_ops.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ POST_OP_DATA_T soft_relu_bwd(POST_OP_DATA_T dd, POST_OP_DATA_T s) {
7878
}
7979

8080
POST_OP_DATA_T logistic_fwd(POST_OP_DATA_T s) {
81-
return 1 / (1 + exp(-s));
81+
return 1.0f / (1.0f + exp(-s));
8282
}
8383
POST_OP_DATA_T logistic_bwd(POST_OP_DATA_T dd, POST_OP_DATA_T s) {
8484
POST_OP_DATA_T v = logistic_fwd(s);
@@ -162,7 +162,8 @@ POST_OP_DATA_T gelu_tanh_bwd(POST_OP_DATA_T dd, POST_OP_DATA_T s) {
162162
}
163163

164164
POST_OP_DATA_T swish_fwd(POST_OP_DATA_T s, POST_OP_DATA_T alpha) {
165-
return s / (1.0f + exp(-alpha * s));
165+
float w = -alpha * s;
166+
return s / (1.0f + exp(w));
166167
}
167168
POST_OP_DATA_T swish_bwd(
168169
POST_OP_DATA_T dd, POST_OP_DATA_T s, POST_OP_DATA_T alpha) {

tests/benchdnn/eltwise/eltwise.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int compare(const prb_t *p, const dnn_mem_t &mem_arg_fp,
174174
|| p->alg == alg_t::SRELU || p->alg == alg_t::LOG
175175
|| (is_fwd && p->alg == alg_t::ELU_DST)
176176
|| (is_fwd && p->alg == alg_t::TANH_DST))
177-
trh = 3e-5;
177+
trh = 4e-5;
178178
else
179179
trh = 4e-6;
180180
}
@@ -187,7 +187,7 @@ static int compare(const prb_t *p, const dnn_mem_t &mem_arg_fp,
187187
const float dt = mem_dt.get_elem(i);
188188
const float src = mem_arg_fp.get_elem(i);
189189
const float fp0 = mem_fp.get_elem(i);
190-
const float fp = maybe_saturate(p->dt, fp0);
190+
const float fp = round_to_nearest_representable(p->dt, fp0);
191191

192192
const float diff = fabsf(fp - dt);
193193
const float rel_diff = diff / (fabsf(fp) > FLT_MIN ? fabsf(fp) : 1);

0 commit comments

Comments
 (0)