Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchdnn: improve memory estimation #2658

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions tests/benchdnn/binary/bench_binary.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,17 +25,7 @@

namespace binary {

using create_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using check_cache_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using do_func_t = std::function<int(
const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &,
const prb_t *, res_t *)>;
using driver_task_executor_t = task_executor_t<prb_t, perf_report_t,
create_func_t, check_cache_func_t, do_func_t>;
TASK_EXECUTOR_DECL_TYPES;

void check_correctness(
const settings_t &s, driver_task_executor_t &task_executor) {
Expand All @@ -52,8 +42,7 @@ void check_correctness(
i_inplace, i_attr, i_ctx_init, i_ctx_exe, s.impl_filter);
if (s.pattern && !match_regex(prb.str(), s.pattern)) return;

task_executor.submit(
prb, s.perf_template, createit, check_cacheit, doit);
task_executor.submit(prb, s.perf_template, createit, checkit, doit);
}
}

Expand Down
11 changes: 8 additions & 3 deletions tests/benchdnn/binary/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,15 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
return OK;
}

int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res) {
return check_caches(v_prim[0], prb, res);
if (has_bench_mode_bit(mode_bit_t::exec)) {
SAFE(check_total_size(res), WARN);
}
if (has_bench_mode_bit(mode_bit_t::corr)) {
SAFE(check_caches(v_prim[0], prb, res), WARN);
}
return OK;
}

int doit(const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
Expand Down
5 changes: 2 additions & 3 deletions tests/benchdnn/binary/binary.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -167,8 +167,7 @@ void compute_ref(const prb_t *prb, const args_t &args,

int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int doit(const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
Expand Down
17 changes: 3 additions & 14 deletions tests/benchdnn/bnorm/bench_bnorm.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2017-2024 Intel Corporation
* Copyright 2017-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,17 +26,7 @@

namespace bnorm {

using create_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using check_cache_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using do_func_t = std::function<int(
const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &,
const prb_t *, res_t *)>;
using driver_task_executor_t = task_executor_t<prb_t, perf_report_t,
create_func_t, check_cache_func_t, do_func_t>;
TASK_EXECUTOR_DECL_TYPES;

void check_correctness(
const settings_t &s, driver_task_executor_t &task_executor) {
Expand All @@ -55,8 +45,7 @@ void check_correctness(
i_ctx_init, i_ctx_exe, s.impl_filter);
if (s.pattern && !match_regex(prb.str(), s.pattern)) return;

task_executor.submit(
prb, s.perf_template, createit, check_cacheit, doit);
task_executor.submit(prb, s.perf_template, createit, checkit, doit);
}
}

Expand Down
15 changes: 10 additions & 5 deletions tests/benchdnn/bnorm/bnorm.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2017-2024 Intel Corporation
* Copyright 2017-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -718,11 +718,16 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
return OK;
}

int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res) {
SAFE(check_caches(v_prim[0], prb, res), WARN);
if (v_prim[1]) { SAFE(check_caches(v_prim[1], prb, res), WARN); }
if (has_bench_mode_bit(mode_bit_t::exec)) {
SAFE(check_total_size(res), WARN);
if (v_prim[1]) SAFE(check_total_size(res), WARN);
}
if (has_bench_mode_bit(mode_bit_t::corr)) {
SAFE(check_caches(v_prim[0], prb, res), WARN);
if (v_prim[1]) { SAFE(check_caches(v_prim[1], prb, res), WARN); }
}
return OK;
}

Expand Down
5 changes: 2 additions & 3 deletions tests/benchdnn/bnorm/bnorm.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2017-2024 Intel Corporation
* Copyright 2017-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -278,8 +278,7 @@ void compute_ref(const prb_t *prb, const args_t &args,

int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int doit(const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
Expand Down
4 changes: 2 additions & 2 deletions tests/benchdnn/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static void zfree_protect(void *ptr) {

void *zmalloc(size_t size, size_t align) {
#ifdef BENCHDNN_MEMORY_CHECK
if (has_bench_mode_bit(mode_bit_t::corr)) { return zmalloc_protect(size); }
if (has_bench_mode_bit(mode_bit_t::exec)) { return zmalloc_protect(size); }
#endif

void *ptr;
Expand All @@ -264,7 +264,7 @@ void *zmalloc(size_t size, size_t align) {
void zfree(void *ptr) {
if (!ptr) return;
#ifdef BENCHDNN_MEMORY_CHECK
if (has_bench_mode_bit(mode_bit_t::corr)) {
if (has_bench_mode_bit(mode_bit_t::exec)) {
zfree_protect(ptr);
return;
}
Expand Down
17 changes: 3 additions & 14 deletions tests/benchdnn/concat/bench_concat.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,17 +25,7 @@

namespace concat {

using create_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using check_cache_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using do_func_t = std::function<int(
const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &,
const prb_t *, res_t *)>;
using driver_task_executor_t = task_executor_t<prb_t, perf_report_t,
create_func_t, check_cache_func_t, do_func_t>;
TASK_EXECUTOR_DECL_TYPES;

void check_correctness(
const settings_t &s, driver_task_executor_t &task_executor) {
Expand All @@ -51,8 +41,7 @@ void check_correctness(
i_attr, i_ctx_init, i_ctx_exe, s.impl_filter);
if (s.pattern && !match_regex(prb.str(), s.pattern)) return;

task_executor.submit(
prb, s.perf_template, createit, check_cacheit, doit);
task_executor.submit(prb, s.perf_template, createit, checkit, doit);
}
}

Expand Down
35 changes: 21 additions & 14 deletions tests/benchdnn/concat/concat.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -196,21 +196,28 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
return OK;
}

int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res) {
// Assume it doesn't change through the execution.
static int capacity = 0;
static auto st = dnnl_get_primitive_cache_capacity(&capacity);
if (st != dnnl_success) return FAIL;
if (capacity > 0 && prb->n_inputs() + 1 > capacity) {
BENCHDNN_PRINT(2, "%s\n",
"[INFO] The number of potential internal reorder pds plus "
"concat itself exceeds the cache capacity which will lead to a "
"test case false-positive failure.");
return OK;
if (has_bench_mode_bit(mode_bit_t::exec)) {
SAFE(check_total_size(res), WARN);
}
return check_caches(v_prim[0], prb, res);
if (has_bench_mode_bit(mode_bit_t::corr)) {
// The assumtion is the capacity doesn't change through the execution.
static int capacity = 0;
static auto st = dnnl_get_primitive_cache_capacity(&capacity);
if (st != dnnl_success) return FAIL;

if (capacity > 0 && prb->n_inputs() + 1 > capacity) {
BENCHDNN_PRINT(2, "%s\n",
"[INFO] The number of potential internal reorder pds plus "
"concat itself exceeds the cache capacity which will lead "
"to a test case false-positive failure.");
return OK;
}

SAFE(check_caches(v_prim[0], prb, res), WARN);
}
return OK;
}

int doit(const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
Expand Down
5 changes: 2 additions & 3 deletions tests/benchdnn/concat/concat.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -176,8 +176,7 @@ void compute_ref(const prb_t *prb, const args_t &args,

int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int doit(const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
Expand Down
20 changes: 5 additions & 15 deletions tests/benchdnn/conv/bench_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@

namespace conv {

using create_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using check_cache_func_t = std::function<int(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &, const prb_t *,
res_t *)>;
using do_func_t = std::function<int(
const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &,
const prb_t *, res_t *)>;
using driver_task_executor_t = task_executor_t<prb_t, perf_report_t,
create_func_t, check_cache_func_t, do_func_t>;
TASK_EXECUTOR_DECL_TYPES;

void check_correctness(
const settings_t &s, driver_task_executor_t &task_executor) {
Expand Down Expand Up @@ -76,11 +66,11 @@ void check_correctness(
bool has_dw_po = i_attr.post_ops.convolution_index() >= 0;
auto &conv_createit
= has_dw_po ? conv_dw_fusion::createit : conv::createit;
auto &conv_check_cacheit = has_dw_po ? conv_dw_fusion::check_cacheit
: conv::check_cacheit;
auto &conv_checkit
= has_dw_po ? conv_dw_fusion::checkit : conv::checkit;
auto &conv_doit = has_dw_po ? conv_dw_fusion::doit : conv::doit;
task_executor.submit(prb, s.perf_template, conv_createit,
conv_check_cacheit, conv_doit);
task_executor.submit(
prb, s.perf_template, conv_createit, conv_checkit, conv_doit);
}
}

Expand Down
54 changes: 22 additions & 32 deletions tests/benchdnn/conv/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ int init_prim_ref(benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref,
prim_ref_dt.erase(prim_ref_dt.begin());
prim_ref_bia_dt.erase(prim_ref_bia_dt.begin());
}
dnnl_primitive_t prim_ref_ {};

for_(const auto &prim_ref_dt_i : prim_ref_dt)
for (const auto &prim_ref_bia_dt_i : prim_ref_bia_dt) {
Expand All @@ -342,35 +341,11 @@ int init_prim_ref(benchdnn_dnnl_wrapper_t<dnnl_primitive_t> &prim_ref,
prb->mb, cpu_attr, prb->ctx_init, prb->ctx_exe,
prb->impl_filter};

init_pd_args_t<prb_t> init_pd_args(
/* res = */ nullptr, get_cpu_engine(), &prb_cpu, prb->dir,
/* hint = */ nullptr, /* src_md = */ nullptr);
init_pd(init_pd_args);

benchdnn_dnnl_wrapper_t<dnnl_primitive_desc_t> pdw;
// `is_service_prim=true` prevents from filtering the implementation
// by name which is intended through a `get_prim_ref_impl_filter()`.
// As `fetch_impl` doesn't have any further logic related to it, it's
// safe to set it to `false`.
fetch_impl(pdw, init_pd_args, get_prim_ref_impl_filter(),
/* res = */ nullptr,
/* is_service_prim = */ false);

// Prim desc wasn't created - try the next set...
if (!pdw) continue;

auto st = dnnl_primitive_create(&prim_ref_, pdw);
// Primitive wasn't created - try the next set...
if (st != dnnl_success) continue;

BENCHDNN_PRINT(5, "CPU reference oneDNN implementation: %s\n",
query_impl_info(pdw).c_str());
res->prim_ref_repro = prb_cpu.str();
prim_ref.reset(prim_ref_);
return OK;
auto st = init_prim_ref_common(prim_ref, &prb_cpu, res);
if (st == OK) return OK;
}

prim_ref.reset(prim_ref_);
prim_ref.reset(nullptr);
return OK;
}

Expand Down Expand Up @@ -577,11 +552,26 @@ int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
return OK;
}

int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res) {
SAFE(check_caches(v_prim[0], prb, res), WARN);
// Don't check caches for CPU prim as the reference.
if (has_bench_mode_bit(mode_bit_t::exec)) {
const auto &prim_ref = v_prim[1];
if (prim_ref) {
// Copy res to avoid save/restore state and reason.
res_t res_copy = *res;
SAFE(check_total_size(&res_copy, prim_ref), WARN);
if (res_copy.state == SKIPPED) {
v_prim[1].reset(nullptr);
SAFE(check_total_size(res), WARN);
}
} else {
SAFE(check_total_size(res), WARN);
}
}
if (has_bench_mode_bit(mode_bit_t::corr)) {
SAFE(check_caches(v_prim[0], prb, res), WARN);
// Don't check caches for CPU prim as the reference.
}
return OK;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/benchdnn/conv/conv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ void compute_ref(const prb_t *prb, const args_t &args,

int createit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int check_cacheit(
std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
int checkit(std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
int doit(const std::vector<benchdnn_dnnl_wrapper_t<dnnl_primitive_t>> &v_prim,
const prb_t *prb, res_t *res);
Expand Down
Loading