text
stringlengths
0
2.2M
float rel_diff_aX = diff_aX
/ (fabsf(fp - beta) > FLT_MIN ? fabsf(fp - beta)
: 1);
ok = rel_diff_aX <= eps;
}
}
res->errors += !ok;
}
bool dump = (!ok && (res->errors < 10 || verbose >= 10))
|| (verbose >= 99);
if (dump) {
std::stringstream ss;
if (kind == DATA) {
int64_t mb, c, d, h, w;
inv_data_off(prb, i, mb, c, d, h, w);
ss << mb << "," << c << "," << d << "," << h << "," << w;
} else if (kind == SS) {
ss << i / prb->ic << "," << i % prb->ic;
} else {
ss << i;
}
std::string ind_str = ss.str();
BENCHDNN_PRINT(0,
"[%4ld][%s%s][%s] fp:%8g dt:%8g diff:%8g rdiff:%8g\n",
(long)i, prb->dir & FLAG_BWD ? "D_" : "", skind,
ind_str.c_str(), fp, dt, diff, rel_diff);
}
}
if (rely_on_norm) {
diff_norm.done();
const bool ok = diff_norm.rel_diff(norm_t::L1) <= eps
&& diff_norm.rel_diff(norm_t::L2) <= eps
&& diff_norm.rel_diff(norm_t::L8) <= eps;
res->errors += !ok;
if (res->errors || verbose >= 5) {
const int vl = res->errors ? 0 : 2;
BENCHDNN_PRINT(vl,
"@@@ [%s%s] diff: l0(``%g``) "
"l1:(%g,%g,%g,``%g``) "
"l2:(%g,%g,%g,``%g``) "
"l8:(%g,%g,%g,``%g``)\n",
prb->dir & FLAG_BWD ? "D_" : "", skind,
diff_norm.rel_diff(norm_t::L0), diff_norm.a_[norm_t::L1],
diff_norm.b_[norm_t::L1], diff_norm.diff_[norm_t::L1],
diff_norm.rel_diff(norm_t::L1), diff_norm.a_[norm_t::L2],
diff_norm.b_[norm_t::L2], diff_norm.diff_[norm_t::L2],
diff_norm.rel_diff(norm_t::L2), diff_norm.a_[norm_t::L8],
diff_norm.b_[norm_t::L8], diff_norm.diff_[norm_t::L8],
diff_norm.rel_diff(norm_t::L8));
}
}
if (res->errors) res->state = FAILED;
if (res->state == UNTESTED) res->state = PASSED; /* optimism */
return res->state == FAILED ? FAIL : OK;
}
int check_fwd_ws(const dnn_mem_t &dst_dt, const dnn_mem_t &ws_dt, res_t *res) {
if (ws_dt.ndims() == 0) return OK;
/* so far we know ws is just bit-mask of whether value was negative or
* positive */
const auto nelems = dst_dt.nelems(true);
const uint8_t *ws = (const uint8_t *)ws_dt;
/* some internal knowledge: flags in ws are either stored as bytes (e.g.
* for the ref implementation) or as bits (e.g. for the jitted one); in
* the latter case the ws memory has fewer elements than the data memory */
enum { ws_byte, ws_bit } ws_type;
ws_type = ws_dt.nelems(true) < nelems ? ws_bit : ws_byte;
/* more internal knowledge: dst_dt and ws_dt are expected to have exactly
* the same data layout, and dst_dt padded regions are expected to be
* zero, and the respective ws_dt elements should be set accordingly */
for (int64_t i = 0; i < nelems; i += 8) {
for (int64_t j = 0; j < MIN2(8, nelems - i); ++j) {
const float data = dst_dt.get_elem(i + j);
const bool want = data > 0.f;
const bool bit_set = ws_type == ws_byte ? *ws : !!(*ws & (1 << j));
const bool ok = bit_set == want;
res->errors += !ok;
bool dump = false || (!ok && (res->errors < 10 || verbose >= 10))
|| (verbose >= 50 && i < 30);
if (dump) {
BENCHDNN_PRINT(0, "[%4ld] ws exp:%d got:%d (data:%g:%a)\n",
(long)(i + j), want, bit_set, data, data);
}
if (ws_type == ws_byte) ++ws;
}
if (ws_type == ws_bit) ++ws;