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

graph: backend: passes: verbose log enhancement #2320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions src/graph/backend/dnnl/passes/compile_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

#include "oneapi/dnnl/dnnl.hpp"

#define VCHECK_COMPILE_OPS(cond, status, msg, ...) \
VCONDCHECK(graph, create, check, compile_ops, (cond), status, msg, \
##__VA_ARGS__);

namespace dnnl {
namespace impl {
namespace graph {
Expand All @@ -45,12 +49,15 @@ status_t compile_ops(std::shared_ptr<subgraph_t> &sg) {
= op_schema_registry_t::get_op_schema(op->get_kind());
if (!opm) {
assertm(false, "no schema for current op");
Copy link
Contributor

@wzt1997 wzt1997 Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to keep the assertm after enriching the verbose? If not, maybe we can fuse the if condition check into the macro.

return status::invalid_graph_op;
VCHECK_COMPILE_OPS(false, status::invalid_graph_op,
"no schema for current op %s", op->get_name().c_str());
}

if (!opm->has_additional_item("executable_creator")) {
assertm(false, "no executable creator in this op schema");
return status::invalid_graph_op;
VCHECK_COMPILE_OPS(false, status::invalid_graph_op,
"no executable creator in schema of op %s",
op->get_name().c_str());
}

auto cur_op = op->shared_from_this();
Expand All @@ -61,7 +68,9 @@ status_t compile_ops(std::shared_ptr<subgraph_t> &sg) {

if (!exec) {
assertm(false, "unimplemented op, can't compile it");
return status::unimplemented;
VCHECK_COMPILE_OPS(false, status::invalid_graph_op,
"unimplemented op, can't compile op %s",
op->get_name().c_str());
}

sg->execs_.emplace_back(exec);
Expand Down
39 changes: 26 additions & 13 deletions src/graph/backend/dnnl/passes/insert_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "graph/backend/dnnl/passes/insert_ops.hpp"
#include "graph/backend/dnnl/passes/utils.hpp"

#define VCHECK_INSERT_OPS(cond, status, msg, ...) \
VCONDCHECK(graph, create, check, insert_ops, (cond), status, msg, \
##__VA_ARGS__);

namespace dnnl {
namespace impl {
namespace graph {
Expand Down Expand Up @@ -332,23 +336,30 @@ status_t insert_to_group_for_reorder(std::shared_ptr<subgraph_t> &sg) {
// reorder's input has blocked format with group
// while output has plain format, perhaps for
// backward path. No such case for now, disable
return status::unimplemented;
VCHECK_INSERT_OPS(false, status::unimplemented,
"unsupported i/o dimentions to insert to_group for "
"reorder, input ndims: %d, output ndims: %d",
in_md.get_ndims(), out_md.get_ndims());
} else if (in_md.get_ndims() + 1 == out_md.get_ndims()) {
// reorder's input has plain format while output
// has blocked format with group, typically for
// weight prepacking
auto group = out_md.get_dims()[0];
if (group * out_md.get_dims()[1] != in_md.get_dims()[0])
return status::invalid_shape;

VCHECK_INSERT_OPS(
group * out_md.get_dims()[1] == in_md.get_dims()[0],
status::invalid_shape,
"unmatched shape to insert to_group for reorder, group: %d,"
"output dims[1]: %d, input dims[0], %d",
group, out_md.get_dims()[1], in_md.get_dims()[0]);
// insert to_group op
op_ptr to_group_op = std::make_shared<op_t>(op_kind::dnnl_to_group);
to_group_op->set_attr<int64_t>(op_attr::groups, group);

rewriter.insert_op_before(to_group_op, cur_op, 0);
} else {
// illegal shape
return status::invalid_shape;
VCHECK_INSERT_OPS(false, status::invalid_shape,
"invalid shape to insert to_group for reorder");
}
}

Expand Down Expand Up @@ -833,10 +844,11 @@ status_t insert_unsqueeze_for_prelu(std::shared_ptr<subgraph_t> &sg) {
const bool per_channel_broadcast
= cur_op->get_attr<bool>(op_attr::per_channel_broadcast);

if (!prelu_doable(ltw(src_lt).vdims(), ltw(wei_lt).vdims(), data_format,
per_channel_broadcast)) {
return status::invalid_shape;
}
VCHECK_INSERT_OPS(prelu_doable(ltw(src_lt).vdims(), ltw(wei_lt).vdims(),
data_format, per_channel_broadcast),
status::invalid_shape,
"invalid shape to insert unsqueeze for prelu");

// insert unsqueeze op
int32_t src_ndims = src_lt.ndims;
int32_t wei_ndims = wei_lt.ndims;
Expand Down Expand Up @@ -886,10 +898,11 @@ status_t insert_unsqueeze_and_squeeze_for_prelu_bwd(
const bool per_channel_broadcast
= wei_vdims.size() == 1 && wei_vdims[0] != 1;

if (!prelu_doable(ltw(src_lt).vdims(), wei_vdims, data_format,
per_channel_broadcast)) {
return status::invalid_shape;
}
VCHECK_INSERT_OPS(prelu_doable(ltw(src_lt).vdims(), wei_vdims,
data_format, per_channel_broadcast),
status::invalid_shape,
"invalid shape to insert unsqueeze for prelu_bwd");

// insert unsqueeze op
int32_t src_ndims = src_lt.ndims;
int32_t wei_ndims = wei_lt.ndims;
Expand Down
23 changes: 15 additions & 8 deletions src/graph/backend/dnnl/passes/layout_propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include "graph/backend/dnnl/common.hpp"
#include "graph/backend/dnnl/layout_propagator.hpp"

#define VCHECK_LAYOUT_PROPAGATION(cond, status, msg, ...) \
VCONDCHECK(graph, create, check, layout_propagation, (cond), status, msg, \
##__VA_ARGS__);

namespace dnnl {
namespace impl {
namespace graph {
Expand Down Expand Up @@ -119,12 +123,15 @@ status_t layout_propagation(std::shared_ptr<subgraph_t> &sg) {
= op_schema_registry_t::get_op_schema(op->get_kind());
if (!opm) {
assertm(false, "no schema for current op");
return status::invalid_graph_op;
VCHECK_LAYOUT_PROPAGATION(false, status::invalid_graph_op,
"no schema for current op: %s", op->get_name().c_str());
}

if (!opm->has_additional_item("layout_propagator")) {
assertm(false, "no layout propagator in this op schema");
return status::invalid_graph_op;
VCHECK_LAYOUT_PROPAGATION(false, status::invalid_graph_op,
"no layout propagator in the schema of op: %s",
op->get_name().c_str());
}

auto cur_op = op->shared_from_this();
Expand All @@ -137,13 +144,15 @@ status_t layout_propagation(std::shared_ptr<subgraph_t> &sg) {
return status;
});

if (ret != status::success) return ret;
VCHECK_LAYOUT_PROPAGATION(
ret == status::success, ret, "layout propagation failed");
rewriter.run();
propagation_number++;
if (propagation_number >= LAYOUT_PROPAGATION_NUMBER) {
assertm(false,
"expect layout propagation number to be less than 10");
return status::invalid_arguments;
VCHECK_LAYOUT_PROPAGATION(false, status::invalid_arguments,
"expect layout propagation number to be less than 10");
}
} while (need_prop_once_more(sg));

Expand All @@ -160,8 +169,7 @@ status_t layout_propagation(std::shared_ptr<subgraph_t> &sg) {
auto lt = in_val->get_logical_tensor();
if (lt.id == sg->ins_[i].id) {
auto md = make_dnnl_memory_desc(lt);
auto status = fill_layout_info(&(sg->ins_[i]), md);
if (status != status::success) return status;
CHECK(fill_layout_info(&(sg->ins_[i]), md));
}
}
}
Expand All @@ -172,8 +180,7 @@ status_t layout_propagation(std::shared_ptr<subgraph_t> &sg) {
auto lt = out_val->get_logical_tensor();
if (lt.id == sg->outs_[i].id) {
auto md = make_dnnl_memory_desc(lt);
auto status = fill_layout_info(&(sg->outs_[i]), md);
if (status != status::success) return status;
CHECK(fill_layout_info(&(sg->outs_[i]), md));
}
}
}
Expand Down
53 changes: 27 additions & 26 deletions src/graph/backend/dnnl/passes/memory_planning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

#include "oneapi/dnnl/dnnl.hpp"

#define VCHECK_MEMORY_PLANNING(cond, status, msg, ...) \
VCONDCHECK(graph, create, check, memory_planning, (cond), status, msg, \
##__VA_ARGS__);

namespace dnnl {
namespace impl {
namespace graph {
Expand Down Expand Up @@ -716,7 +720,11 @@ status_t memory_planner_t::book_buffers(std::shared_ptr<subgraph_t> &sg) {
persistent_registrar.book(info.index_,
persistent_buffer_assigner_.query_size(info.index_));
break;
default: return status::unimplemented;
default:
VCHECK_MEMORY_PLANNING(false, status::unimplemented,
"booking memory failed for unimplemented buffer kind "
"%d",
info.kind_);
}
}
return status::success;
Expand Down Expand Up @@ -770,20 +778,24 @@ status_t memory_planner_t::prepare_execution_args_set(
}
return status::success;
});
if (ret != status::success) return ret;
VCHECK_MEMORY_PLANNING(
ret == status::success, ret, "prepare memory failed");

// construct the dnnl execution args for each op
ret = topo_order_visit(sg->get_output_ops(), [&](op_t *op) {
const op_schema_t *opm
= op_schema_registry_t::get_op_schema(op->get_kind());
if (!opm) {
assertm(false, "no schema for current op");
return status::invalid_graph_op;
VCHECK_MEMORY_PLANNING(false, status::invalid_graph_op,
"no schema for current op: %s", op->get_name().c_str());
}

if (!opm->has_additional_item("arg_indices_getter")) {
assertm(false, "no arg indices getter in this op schema");
return status::invalid_graph_op;
VCHECK_MEMORY_PLANNING(false, status::invalid_graph_op,
"no arg indices getter in the schema of op: %s",
op->get_name().c_str());
}

auto getter = opm->get_additional_item<arg_indices_getter_func>(
Expand All @@ -805,7 +817,9 @@ status_t memory_planner_t::prepare_execution_args_set(
// find the corresponding memory object
dnnl::memory mem;
if (!exec_args_set_.find_value_mem_map(val, mem)) {
return status::invalid_arguments;
VCHECK_MEMORY_PLANNING(false, status::invalid_arguments,
"can't find memory for value id: %zu",
val->get_logical_tensor().id);
}

dnnl_exec_args.insert({dnnl_arg, mem});
Expand All @@ -829,8 +843,6 @@ status_t memory_planner_t::prepare_execution_args_set(
// - Assign internal allocated persistent buffer to corresponding edges.
// - Prepare the memory objects which will be used in execution.
status_t memory_planner_t::run(std::shared_ptr<subgraph_t> &sg) {
status_t ret;

auto &mgr = sg->fusion_info_mgr_;
const auto &p_engine = *(sg->p_engine_);
const auto &inputs = sg->ins_;
Expand Down Expand Up @@ -866,21 +878,17 @@ status_t memory_planner_t::run(std::shared_ptr<subgraph_t> &sg) {
}

// Assign external_input buffers to subgraph's inputs and their alias
ret = assign_external_inputs_buffer(sg, inputs);
if (ret != status::success) return ret;
CHECK(assign_external_inputs_buffer(sg, inputs));

// Assign internal temporary buffer for all other edges
ret = assign_internal_temporary_buffer(sg, edge_ref_count, mgr, false);
if (ret != status::success) return ret;
CHECK(assign_internal_temporary_buffer(sg, edge_ref_count, mgr, false));

// Replace some internal temporary buffers to user given external output
// buffer
ret = assign_external_outputs_buffer(sg, outputs, mgr);
if (ret != status::success) return ret;
CHECK(assign_external_outputs_buffer(sg, outputs, mgr));

// Replace some internal temporary buffers to cached persistent buffer
ret = assign_internal_persistent_buffer(sg, mgr);
if (ret != status::success) return ret;
CHECK(assign_internal_persistent_buffer(sg, mgr));

// Reset the unreplaced internal temporary buffer
temporary_buffer_assigner_.clear();
Expand All @@ -895,20 +903,13 @@ status_t memory_planner_t::run(std::shared_ptr<subgraph_t> &sg) {

// Re-assign internal temporary buffer for reset ones (will re-do memory
// sharing between temporary buffers)
ret = assign_internal_temporary_buffer(sg, edge_ref_count, mgr, true);
if (ret != status::success) return ret;

CHECK(assign_internal_temporary_buffer(sg, edge_ref_count, mgr, true));
// Check which input/output pair of the subgraph can be inplaced
ret = prepare_subgraph_inplace_pairs(sg, false);
if (ret != status::success) return ret;

ret = book_buffers(sg);
if (ret != status::success) return ret;
CHECK(prepare_subgraph_inplace_pairs(sg, false));

CHECK(book_buffers(sg));
// Bind memory object to each value
ret = prepare_execution_args_set(sg, p_engine, mgr);
if (ret != status::success) return ret;

CHECK(prepare_execution_args_set(sg, p_engine, mgr));
return status::success;
}

Expand Down
Loading
Loading