Skip to content

Commit

Permalink
benchdnn: supply info about prim_ref in case of failure
Browse files Browse the repository at this point in the history
  • Loading branch information
dzarukin committed Dec 15, 2023
1 parent aa62c55 commit 4dd01f7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions tests/benchdnn/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ struct res_t {
size_t errors, total;
timer::timer_map_t timer_map;
std::string impl_name;
std::string prim_ref_repro;
skip_reason_t reason;
size_t ibytes, obytes;
bool mem_check_done;
Expand Down
9 changes: 6 additions & 3 deletions tests/benchdnn/conv/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ dnnl_status_t init_pd(init_pd_args_t<prb_t> &init_pd_args) {
return dnnl_success;
}

int init_prim_ref(
benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref, const prb_t *prb) {
int init_prim_ref(benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref,
const prb_t *prb, res_t *res) {
if (!(has_bench_mode_bit(mode_bit_t::corr) && fast_ref)) return OK;
// Create prim_ref if only original prim was successfully created.
if (res->state != INITIALIZED) return OK;

// f32 cases should go through reference no matter what.
if (is_cpu() && (prb->src_dt() == dnnl_f32 && prb->wei_dt() == dnnl_f32))
Expand Down Expand Up @@ -328,6 +330,7 @@ int init_prim_ref(

BENCHDNN_PRINT(5, "CPU reference oneDNN implementation: %s\n",
query_impl_info(pdw).c_str());
res->prim_ref_repro = prb_cpu.str();
break;
}
}
Expand Down Expand Up @@ -534,7 +537,7 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
v_prim.resize(2); // regular + cpu_ref
SAFE(init_prim(prb->ctx_init, v_prim[0], init_pd, prb, res), WARN);
// Use CPU prim as the reference in GPU testing to reduce testing time.
SAFE(init_prim_ref(v_prim[1], prb), WARN);
SAFE(init_prim_ref(v_prim[1], prb, res), WARN);
return OK;
}

Expand Down
9 changes: 6 additions & 3 deletions tests/benchdnn/deconv/deconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ dnnl_status_t init_pd(init_pd_args_t<prb_t> &init_pd_args) {
return dnnl_success;
}

int init_prim_ref(
benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref, const prb_t *prb) {
int init_prim_ref(benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref,
const prb_t *prb, res_t *res) {
if (!(has_bench_mode_bit(mode_bit_t::corr) && fast_ref)) return OK;
// Create prim_ref if only original prim was successfully created.
if (res->state != INITIALIZED) return OK;

// f32 cases should go through reference no matter what.
if (is_cpu() && (prb->src_dt() == dnnl_f32 && prb->wei_dt() == dnnl_f32))
Expand Down Expand Up @@ -326,6 +328,7 @@ int init_prim_ref(

BENCHDNN_PRINT(5, "CPU reference oneDNN implementation: %s\n",
query_impl_info(pdw).c_str());
res->prim_ref_repro = prb_cpu.str();
break;
}
}
Expand Down Expand Up @@ -527,7 +530,7 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
v_prim.resize(2); // regular + cpu_ref
SAFE(init_prim(prb->ctx_init, v_prim[0], init_pd, prb, res), WARN);
// Use CPU prim as the reference in GPU testing to reduce testing time.
SAFE(init_prim_ref(v_prim[1], prb), WARN);
SAFE(init_prim_ref(v_prim[1], prb, res), WARN);
return OK;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/benchdnn/dnnl_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "utils/dims.hpp"
#include "utils/dnnl_query.hpp"
#include "utils/numeric.hpp"
#include "utils/parallel.hpp"

#include "tests/test_thread.hpp"

Expand Down Expand Up @@ -580,6 +581,25 @@ void check_correctness(const prb_t *prb, const std::vector<data_kind_t> &kinds,

TIME_COMPARE(cmp.compare(mem_fp, mem_dt, prb->attr, res));
}

if (prim_ref && res->state == FAILED) {
static cpu_cache_args_t cpu_cache_args {};
SAFE_V(get_cpu_cache_size(cpu_cache_args));

BENCHDNN_PRINT(0,
"[PRIM_REF][INFO]: L2_size:%zu bytes; per_core_L3_size:%zu "
"bytes; nthr:%d; impl_name:%s\n",
cpu_cache_args.L2_size, cpu_cache_args.L3_size,
benchdnn_get_max_threads(),
query_impl_info(query_pd(prim_ref)).c_str());

// Replace engine kind for repro line from GPU to CPU.
const auto eng_pos = res->prim_ref_repro.find("engine=gpu");
res->prim_ref_repro[eng_pos + 7] = 'c'; // Replace `g` in `gpu` with `c`

BENCHDNN_PRINT(
0, "[PRIM_REF][REPRO]: %s\n", res->prim_ref_repro.c_str());
}
}

typedef std::function<dnnl_status_t(
Expand Down
9 changes: 6 additions & 3 deletions tests/benchdnn/ip/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ dnnl_status_t init_pd(init_pd_args_t<prb_t> &init_pd_args) {
return dnnl_success;
}

int init_prim_ref(
benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref, const prb_t *prb) {
int init_prim_ref(benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref,
const prb_t *prb, res_t *res) {
if (!(has_bench_mode_bit(mode_bit_t::corr) && fast_ref)) return OK;
// Create prim_ref if only original prim was successfully created.
if (res->state != INITIALIZED) return OK;

// f32 cases should go through reference no matter what.
if (is_cpu() && (prb->src_dt() == dnnl_f32 && prb->wei_dt() == dnnl_f32))
Expand Down Expand Up @@ -126,6 +128,7 @@ int init_prim_ref(

BENCHDNN_PRINT(5, "CPU reference oneDNN implementation: %s\n",
query_impl_info(pdw).c_str());
res->prim_ref_repro = prb_cpu.str();
break;
}
}
Expand Down Expand Up @@ -375,7 +378,7 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
v_prim.resize(2); // regular + cpu_ref
SAFE(init_prim(prb->ctx_init, v_prim[0], init_pd, prb, res), WARN);
// Use CPU prim as the reference in GPU testing to reduce testing time.
SAFE(init_prim_ref(v_prim[1], prb), WARN);
SAFE(init_prim_ref(v_prim[1], prb, res), WARN);
return OK;
}

Expand Down
9 changes: 6 additions & 3 deletions tests/benchdnn/matmul/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ dnnl_status_t init_pd(init_pd_args_t<prb_t> &init_pd_args) {
return dnnl_success;
}

int init_prim_ref(
benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref, const prb_t *prb) {
int init_prim_ref(benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref,
const prb_t *prb, res_t *res) {
if (!(has_bench_mode_bit(mode_bit_t::corr) && fast_ref)) return OK;
// Create prim_ref if only original prim was successfully created.
if (res->state != INITIALIZED) return OK;

// f32 cases should go through reference no matter what.
if (is_cpu() && (prb->src_dt() == dnnl_f32 && prb->wei_dt() == dnnl_f32))
Expand Down Expand Up @@ -206,6 +208,7 @@ int init_prim_ref(

BENCHDNN_PRINT(5, "CPU reference oneDNN implementation: %s\n",
query_impl_info(pdw).c_str());
res->prim_ref_repro = prb_cpu.str();
break;
}
}
Expand Down Expand Up @@ -690,7 +693,7 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
v_prim.resize(2); // regular + cpu_ref
SAFE(init_prim(prb->ctx_init, v_prim[0], init_pd, prb, res), WARN);
// Use CPU prim as the reference in GPU testing to reduce testing time.
SAFE(init_prim_ref(v_prim[1], prb), WARN);
SAFE(init_prim_ref(v_prim[1], prb, res), WARN);
return OK;
}

Expand Down

0 comments on commit 4dd01f7

Please sign in to comment.