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

Variadic Split #91

Merged
merged 6 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 19 additions & 3 deletions inference-engine/src/plaidml_plugin/ops/variadic_split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
#include "plaidml/op/op.h"

using namespace plaidml; // NOLINT[build/namespaces]
using namespace InferenceEngine; // NOLINT[build/namespaces]

namespace {

template <typename T>
std::vector<T> cast_constant_operand(size_t operand_idx, ngraph::Node* layer) {
auto* ngraph_const = ngraph::as_type<ngraph::op::Constant>(layer->get_input_node_ptr(operand_idx));
if (ngraph_const) {
return ngraph_const->cast_vector<T>();
} else {
THROW_IE_EXCEPTION << "Dynamic padding not currently supported by PlaidML plugin; all of pads_begin, pads_end, "
"and pads_value must be Constants";
mwyi marked this conversation as resolved.
Show resolved Hide resolved
}
}

} // namespace

namespace PlaidMLPlugin {

Expand All @@ -20,7 +36,7 @@ static OpRegistration reg("variadicsplit", [](const Context& ctx) {
auto axes = get_axis_vector_from_constant_operand(1, ctx.layer);
IE_ASSERT(axes.size() == 1);
auto axis = axes[0];
auto split_lengths = get_shape_from_constant_operand(2, ctx.layer);
auto split_lengths = cast_constant_operand<int32_t>(2, ctx.layer);

auto ndims = I.rank();
std::vector<edsl::TensorDim> I_dims(ndims);
Expand All @@ -45,10 +61,10 @@ static OpRegistration reg("variadicsplit", [](const Context& ctx) {
O_dims[axis] = placeholder;
offset = offset + placeholder;
} else {
O_dims[axis] = static_cast<edsl::TensorDim>(split);
O_dims[axis] = edsl::TensorDim(split);
offset = offset + split;
}
Os.push_back(plaidml::edsl::Contraction().outShape(O_dims).outAccess(O_idxs).assign(I(I_idxs)));
Os.push_back(edsl::Contraction().outShape(O_dims).outAccess(O_idxs).assign(I(I_idxs)));
}
return edsl::make_tuple(Os);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace {
};

// Sum of elements numSplits = inputShapes[Axis]
const std::vector<std::vector<size_t>> numSplits = {
const std::vector<std::vector<int32_t>> numSplits = {
{1, 16, 5, 8},
{2, 19, 5, 4},
{7, 13, 2, 8},
{5, 8, 12, 5},
{4, 11, 6, 9}
{4, 11, -1, 9}
};

INSTANTIATE_TEST_CASE_P(NumSplitsCheck, VariadicSplitLayerTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace {
};

// Sum of elements numSplits = inputShapes[Axis]
const std::vector<std::vector<size_t>> numSplits = {
const std::vector<std::vector<int32_t>> numSplits = {
{1, 16, 5, 8},
{2, 19, 5, 4},
{7, 13, 2, 8},
{5, 8, 12, 5},
{4, 11, 6, 9}
{4, 11, -1, 9}
};

INSTANTIATE_TEST_CASE_P(NumSplitsCheck, VariadicSplitLayerTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace LayerTestsDefinitions {

typedef std::tuple<
std::vector<size_t>, // Num splits
std::vector<int32_t>, // Num splits
size_t, // Axis
InferenceEngine::Precision, // Net precision
std::vector<size_t>, // Input shapes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace LayerTestsDefinitions {

std::string VariadicSplitLayerTest::getTestCaseName(testing::TestParamInfo<VariadicSplitParams> obj) {
size_t axis;
std::vector<size_t> numSplits;
std::vector<int32_t> numSplits;
InferenceEngine::Precision netPrecision;
InferenceEngine::SizeVector inputShapes;
std::string targetDevice;
Expand All @@ -41,7 +41,8 @@ namespace LayerTestsDefinitions {
void VariadicSplitLayerTest::SetUp() {
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
size_t axis;
std::vector<size_t> inputShape, numSplits;
std::vector<size_t> inputShape;
std::vector<int32_t> numSplits;
InferenceEngine::Precision netPrecision;
std::tie(numSplits, axis, netPrecision, inputShape, targetDevice) = this->GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ std::shared_ptr<ngraph::Node> makeSplit(const ngraph::Output<Node> &in,
size_t axis);

std::shared_ptr<ngraph::Node> makeVariadicSplit(const ngraph::Output<Node> &in,
const std::vector<size_t> numSplits,
const std::vector<int32_t> numSplits,
size_t axis);

std::shared_ptr<ngraph::Node> makeActivation(const ngraph::Output<Node> &in,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
namespace ngraph {
namespace builder {
std::shared_ptr<ngraph::Node> makeVariadicSplit(const ngraph::Output<Node> &in,
const std::vector<size_t> numSplits,
const std::vector<int32_t> numSplits,
size_t axis) {
auto splitAxisOp = std::make_shared<ngraph::opset3::Constant>(element::u64, ngraph::Shape{},
std::vector<size_t>{axis});
auto numSplit = std::make_shared<ngraph::opset3::Constant>(element::u64, ngraph::Shape{numSplits.size()},
auto numSplit = std::make_shared<ngraph::opset3::Constant>(element::i64, ngraph::Shape{numSplits.size()},
numSplits);
auto VariadicSplitNode = std::make_shared<ngraph::opset3::VariadicSplit>(in, splitAxisOp, numSplit);
return VariadicSplitNode;
Expand Down