Skip to content

Commit

Permalink
PluginShapesOverride rt_info field is now mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanNovoselov committed Nov 8, 2022
1 parent 95ee941 commit 60c65e6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 59 deletions.
6 changes: 1 addition & 5 deletions src/common/snippets/src/pass/insert_loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ bool ngraph::snippets::pass::InsertLoops::run_on_model(const std::shared_ptr<ov:
const auto& body_rt_info = model->get_rt_info();
const auto& plugin_shapes = body_rt_info.find("PluginShapesOverride");
if (plugin_shapes == body_rt_info.end()) {
ioShapes.reserve(commonParams.size() + commonResults.size());
std::transform(commonParams.begin(), commonParams.end(), std::back_inserter(ioShapes),
[](const std::shared_ptr<Node>& n) { return n->get_output_partial_shape(0); });
std::transform(commonResults.begin(), commonResults.end(), std::back_inserter(ioShapes),
[](const std::shared_ptr<Node>& n) { return n->get_input_partial_shape(0); });
throw ngraph_error("InsertLoops requires PluginShapesOverride rt_info field");
} else {
const auto& new_shapes = plugin_shapes->second.as<std::vector<std::vector<size_t>>>();
if (new_shapes.size() != commonResults.size() + commonParams.size())
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/intel_cpu/src/emitters/jit_snippets_emitters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ KernelEmitter::KernelEmitter(dnnl::impl::cpu::x64::jit_generator* h, dnnl::impl:
const auto& model_rt_info = model->get_rt_info();
const auto& plugin_shapes = model_rt_info.find("PluginShapesOverride");
if (plugin_shapes == model_rt_info.end()) {
for (const auto& op : io_nodes)
io_shapes.push_back(get_static_shape(op));
IE_THROW() << "JIT KernelEmitter requires plugin-overriden shapes in model rt_info";
} else {
const auto& new_shapes = plugin_shapes->second.as<std::vector<std::vector<size_t>>>();
if (new_shapes.size() != num_inputs + num_outputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct jit_snippets_call_args {
struct jit_snippets_compile_args {
std::vector<size_t> master_shape{};
size_t tile_rank = 0;
// int64_t data_offsets[SNIPPETS_MAX_SNIPPETS_DIMS * SNIPPETS_MAX_HARNESS_DIMS] = {};
};
///
/// \brief jit_container_emitter designed to wrap Emitters that contain other Emitters (for example, KernelEmitter)
Expand Down
54 changes: 5 additions & 49 deletions src/plugins/intel_cpu/src/nodes/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,29 +212,6 @@ InferenceEngine::Precision Snippet::getRuntimePrecision() const {
return getMaxPrecision(inputPrecisions);
}

void Snippet::calcJITParams(std::vector<int64_t>& offsets) const {
const size_t numInputs = normInputShapes.size();
const size_t numParams = numInputs + normOutputShapes.size();

// Note that we don't need offset for the last dim, since it's handled directly by Tile emitter
const size_t offset_rank = masterShape.size() - 1;
offsets.resize(numParams * (offset_rank), 1);
auto offset_calculation = [offset_rank, this](int64_t *off, const std::vector<size_t>& dims, const size_t data_size) {
size_t k = dims.back();
for (int i = offset_rank - 1; i >= 0; i--) {
// auto tmp = (dims[i] == masterShape[i] && masterShape[i] != 1) ? k : 0;
// dims could be either master_shape[i] or 1
auto tmp = (dims[i] != 1) ? k : 0;
off[i] = tmp * data_size;
k *= dims[i];
}
};
for (size_t i = 0; i < numParams; i++) {
offset_calculation(&offsets[i * offset_rank],
i < numInputs ? normInputShapes[i] : normOutputShapes[i - numInputs],
dataSize[i]);
}
}
bool Snippet::optimizeExecDomain(std::vector<VectorDims>& inputShapes, std::vector<VectorDims>& outputShapes,
VectorDims &domain, size_t& TileRank) const {
const size_t minimalConcurrency = parallel_get_max_threads();
Expand Down Expand Up @@ -367,7 +344,6 @@ void Snippet::createPrimitive() {
prepareParams();
jcp.master_shape = masterShape;
jcp.tile_rank = tileRank;
// std::copy(data_offsets.begin(), data_offsets.end(), jcp.data_offsets);
generate(&jcp);
}

Expand Down Expand Up @@ -453,8 +429,6 @@ void Snippet::prepareParams() {
}
exec_domain = masterShape;

// todo: probably better to pass a call_args instance
calcJITParams(data_offsets);
auto initStartMemoryOffsets = [this]() {
const auto config = getSelectedPrimitiveDescriptor()->getConfig();
const size_t numInputs = inputShapes.size();
Expand Down Expand Up @@ -488,30 +462,12 @@ void Snippet::prepareParams() {
dim = 1;
}

// Note: if exec domain is updated (dimensions are collapsed) then we need to communicate updated shapes
if (execDomainIsUpdated) {
auto& body_rt_info = snippet->get_body()->get_rt_info();
std::vector<std::vector<size_t>> new_shapes;
std::copy(normInputShapes.begin(), normInputShapes.end(), std::back_inserter(new_shapes));
std::copy(normOutputShapes.begin(), normOutputShapes.end(), std::back_inserter(new_shapes));
body_rt_info["PluginShapesOverride"] = new_shapes;
snippet->set_master_shape(ov::PartialShape(masterShape));
}
// snippet->set_overriden_shapes(new_shapes);
// todo: tileRank should be determined by snippets based on body shapes and operation semantics, not by plugin
auto& body_rt_info = snippet->get_body()->get_rt_info();
std::vector<std::vector<size_t>> new_shapes(normInputShapes);
std::copy(normOutputShapes.begin(), normOutputShapes.end(), std::back_inserter(new_shapes));
body_rt_info["PluginShapesOverride"] = new_shapes;
snippet->set_master_shape(ov::PartialShape(masterShape));
snippet->tileRank = tileRank;
/*
snippet->set_master_shape(PartialShape(scheduler_work_amounts));
// If the snippets has domain sensitive ops (e.g. Transpose) then domain optimizations are not performed
// so need only update Parameter and Result shapes so Loops will be appropriately inserted in the snippets::pass::InsertLoops
if (snippet->has_domain_sensitive_ops()) {
for (const auto& s : get_shapes_for_snippet(normOutputShapes, tileRank))
new_shapes.push_back(s);
snippet->set_overriden_shapes(new_shapes);
} else {
snippet->reshape_body(new_shapes);
}
*/
}

bool Snippet::needPrepareParams() const {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/subgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class Snippet : public Node {
ov::PartialShape canonicalizeBody();
// returns true if exec domain was modified
bool optimizeExecDomain(std::vector<VectorDims>&, std::vector<VectorDims>&, VectorDims&, size_t&) const;
void calcJITParams(std::vector<int64_t>& offsets) const;

void generate(const jit_snippets_compile_args*);
void updateSrcDstPtrs(jit_snippets_call_args&) const;
Expand Down Expand Up @@ -96,7 +95,6 @@ class Snippet : public Node {
std::vector<MemoryPtr> dstMemPtrs = {};
std::vector<size_t> dataSize = {};

std::vector<int64_t> data_offsets;
// this is needed for fast shape inference of blocking-invariant prepended shapes
std::vector<bool> inputShapeIsBlocked = {}; // we need this info to shape-infer mixed layouts
std::vector<bool> outputShapeIsBlocked = {}; // we need this info to shape-infer mixed layouts
Expand Down

0 comments on commit 60c65e6

Please sign in to comment.