Skip to content

Commit

Permalink
fixup: fixup: benchdnn: eltwise: improve input data coverage
Browse files Browse the repository at this point in the history
* 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...
  • Loading branch information
dzarukin committed Apr 15, 2020
1 parent 407e3ee commit f7c41dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
file(GLOB FILES_REQUIRED_PREC_DIV
${CMAKE_CURRENT_SOURCE_DIR}/*resampling*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*normalization*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ref_eltwise.cpp
${CMAKE_CURRENT_SOURCE_DIR}/eltwise/ref_eltwise.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ref_rnn.cpp)
if(WIN32)
set_source_files_properties(${FILES_REQUIRED_PREC_SQRT}
Expand Down
5 changes: 3 additions & 2 deletions src/gpu/ocl/ocl_post_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ POST_OP_DATA_T soft_relu_bwd(POST_OP_DATA_T dd, POST_OP_DATA_T s) {
}

POST_OP_DATA_T logistic_fwd(POST_OP_DATA_T s) {
return 1 / (1 + exp(-s));
return 1.0f / (1.0f + exp(-s));
}
POST_OP_DATA_T logistic_bwd(POST_OP_DATA_T dd, POST_OP_DATA_T s) {
POST_OP_DATA_T v = logistic_fwd(s);
Expand Down Expand Up @@ -162,7 +162,8 @@ POST_OP_DATA_T gelu_tanh_bwd(POST_OP_DATA_T dd, POST_OP_DATA_T s) {
}

POST_OP_DATA_T swish_fwd(POST_OP_DATA_T s, POST_OP_DATA_T alpha) {
return s / (1.0f + exp(-alpha * s));
float w = -alpha * s;
return s / (1.0f + exp(w));
}
POST_OP_DATA_T swish_bwd(
POST_OP_DATA_T dd, POST_OP_DATA_T s, POST_OP_DATA_T alpha) {
Expand Down
4 changes: 2 additions & 2 deletions tests/benchdnn/eltwise/eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static int compare(const prb_t *p, const dnn_mem_t &mem_arg_fp,
|| p->alg == alg_t::SRELU || p->alg == alg_t::LOG
|| (is_fwd && p->alg == alg_t::ELU_DST)
|| (is_fwd && p->alg == alg_t::TANH_DST))
trh = 3e-5;
trh = 4e-5;
else
trh = 4e-6;
}
Expand All @@ -187,7 +187,7 @@ static int compare(const prb_t *p, const dnn_mem_t &mem_arg_fp,
const float dt = mem_dt.get_elem(i);
const float src = mem_arg_fp.get_elem(i);
const float fp0 = mem_fp.get_elem(i);
const float fp = maybe_saturate(p->dt, fp0);
const float fp = round_to_nearest_representable(p->dt, fp0);

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

0 comments on commit f7c41dc

Please sign in to comment.