Skip to content

Commit

Permalink
AUGRU op ov core shell and reference implementation (openvinotoolkit#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mitruska authored Aug 26, 2022
1 parent 371e393 commit 67f4b8e
Show file tree
Hide file tree
Showing 19 changed files with 2,268 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/Doxyfile.config
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ RECURSIVE = YES
EXCLUDE = "@OpenVINO_SOURCE_DIR@/thirdparty" \
"@OpenVINO_SOURCE_DIR@/temp" \
"@OpenVINO_SOURCE_DIR@/bin" \
"@OpenVINO_SOURCE_DIR@/src/core/dev_api/ops/docs"
"@OpenVINO_SOURCE_DIR@/docs/ops/internal"

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/template_plugin/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target_compile_definitions(interpreter_backend
SHARED_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}"
SHARED_LIB_SUFFIX="${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
target_link_libraries(interpreter_backend PRIVATE ngraph::builder ngraph::reference openvino::util)
target_link_libraries(interpreter_backend PRIVATE ngraph::builder ngraph::reference openvino::util openvino::runtime::dev)

target_include_directories(interpreter_backend PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

Expand Down
76 changes: 76 additions & 0 deletions docs/template_plugin/backend/evaluates_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
#include "backend.hpp"
#include "ngraph/ops.hpp"
#include "ngraph/runtime/reference/convert_color_nv12.hpp"
#include "ngraph_ops/augru_cell.hpp"
#include "ngraph_ops/augru_sequence.hpp"

using namespace ngraph;
using namespace std;
Expand Down Expand Up @@ -3102,6 +3104,30 @@ bool evaluate(const shared_ptr<op::v3::GRUCell>& op, const HostTensorVector& out
return true;
}

template <element::Type_t ET>
bool evaluate(const shared_ptr<ov::op::internal::AUGRUCell>& op,
const HostTensorVector& outputs,
const HostTensorVector& inputs) {
using T = typename element_type_traits<ET>::value_type;
runtime::reference::gru_cell<T>(inputs[0]->get_data_ptr<ET>(),
inputs[0]->get_shape(),
inputs[1]->get_data_ptr<ET>(),
inputs[1]->get_shape(),
inputs[2]->get_data_ptr<ET>(),
inputs[2]->get_shape(),
inputs[3]->get_data_ptr<ET>(),
inputs[3]->get_shape(),
inputs[4]->get_data_ptr<ET>(),
inputs[4]->get_shape(),
outputs[0]->get_data_ptr<ET>(),
op->get_activations()[0],
op->get_activations()[1],
op->get_clip(),
op->get_linear_before_reset(),
inputs[5]->get_data_ptr<ET>());
return true;
}

namespace rnn_seq_v5 {
template <element::Type_t t1, element::Type_t t2>
inline void evaluate(const shared_ptr<op::v5::RNNSequence>& op,
Expand Down Expand Up @@ -3374,6 +3400,56 @@ bool evaluate(const shared_ptr<op::v5::GRUSequence>& op,
}
return true;
}

namespace augru_seq {
template <element::Type_t t1, element::Type_t t2>
inline void evaluate(const shared_ptr<ov::op::internal::AUGRUSequence>& op,
const HostTensorVector& outputs,
const HostTensorVector& inputs) {
using T1 = typename element_type_traits<t1>::value_type;
using T2 = typename element_type_traits<t2>::value_type;
runtime::reference::gru_sequence<T1, T2>(inputs[0]->get_data_ptr<char>(),
inputs[0]->get_shape(),
inputs[1]->get_data_ptr<char>(),
inputs[1]->get_shape(),
inputs[2]->get_data_ptr<char>(),
inputs[2]->get_shape(),
inputs[3]->get_data_ptr<char>(),
inputs[3]->get_shape(),
inputs[4]->get_data_ptr<char>(),
inputs[4]->get_shape(),
inputs[5]->get_data_ptr<char>(),
inputs[5]->get_shape(),
outputs[0]->get_data_ptr<char>(),
outputs[1]->get_data_ptr<char>(),
op->get_activations()[0],
op->get_activations()[1],
op->get_clip(),
op->get_direction(),
op->get_linear_before_reset(),
inputs[6]->get_data_ptr<char>());
}
} // namespace augru_seq

template <element::Type_t ET>
bool evaluate(const shared_ptr<ov::op::internal::AUGRUSequence>& op,
const HostTensorVector& outputs,
const HostTensorVector& inputs) {
switch (inputs[2]->get_element_type()) {
case element::Type_t::i64:
case element::Type_t::u64:
augru_seq::evaluate<ET, element::Type_t::i64>(op, outputs, inputs);
break;
case element::Type_t::i32:
case element::Type_t::u32:
augru_seq::evaluate<ET, element::Type_t::i32>(op, outputs, inputs);
break;
default:
return false;
}
return true;
}

template <element::Type_t ET>
bool evaluate(const shared_ptr<op::v9::ROIAlign>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
using T = typename element_type_traits<ET>::value_type;
Expand Down
3 changes: 3 additions & 0 deletions docs/template_plugin/backend/opset_int_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ NGRAPH_OP(IRDFT, op::v9)
NGRAPH_OP(ROIAlign, op::v9)
NGRAPH_OP(SoftSign, op::v9)
NGRAPH_OP(MulticlassNms, op::v9)

NGRAPH_OP(AUGRUCell, ov::op::internal)
NGRAPH_OP(AUGRUSequence, ov::op::internal)
1 change: 1 addition & 0 deletions docs/template_plugin/tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ov_add_test_target(
openvino_template_plugin
LINK_LIBRARIES
openvino::funcSharedTests
openvino::runtime::dev
INCLUDES
"${TEMPLATE_PLUGIN_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/op_reference"
Expand Down
216 changes: 216 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/augru_cell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <gtest/gtest.h>

#include "ngraph_ops/augru_cell.hpp"
#include "base_reference_test.hpp"

using namespace reference_tests;
using namespace ov;

namespace {
struct AUGRUCellParams {
AUGRUCellParams(
const int32_t batchSize, const int32_t inputSize, const int32_t hiddenSize, const int32_t gatesCount,
const reference_tests::Tensor& X, const reference_tests::Tensor& H_t, const reference_tests::Tensor& W, const reference_tests::Tensor& R, const reference_tests::Tensor& B, const reference_tests::Tensor& A,
const reference_tests::Tensor& Ho, const std::string& testcaseName = "") :
batchSize(batchSize), inputSize(inputSize), hiddenSize(hiddenSize), gatesCount(gatesCount),
X(X), H_t(H_t), W(W), R(R), B(B), A(A), Ho(Ho), testcaseName(testcaseName) {}

int32_t batchSize;
int32_t inputSize;
int32_t hiddenSize;
int32_t gatesCount;
reference_tests::Tensor X;
reference_tests::Tensor H_t;
reference_tests::Tensor W;
reference_tests::Tensor R;
reference_tests::Tensor B;
reference_tests::Tensor A;
reference_tests::Tensor Ho;
std::string testcaseName;
};

class ReferenceAUGRUCellTest : public testing::TestWithParam<AUGRUCellParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.X.data, params.H_t.data, params.W.data, params.R.data, params.B.data, params.A.data};
refOutData = {params.Ho.data};
}

static std::string getTestCaseName(const testing::TestParamInfo<AUGRUCellParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "bSize=" << param.batchSize;
result << "_iSize=" << param.inputSize;
result << "_hSize=" << param.hiddenSize;
result << "_gCount=" << param.gatesCount;
result << "_xType=" << param.X.type;
result << "_xShape=" << param.X.shape;
result << "_htType=" << param.H_t.type;
result << "_htShape=" << param.H_t.shape;
result << "_wType=" << param.W.type;
result << "_wShape=" << param.W.shape;
result << "_rType=" << param.R.type;
result << "_rShape=" << param.R.shape;
result << "_hoType=" << param.Ho.type;
if (param.testcaseName != "") {
result << "_hoShape=" << param.Ho.shape;
result << "_=" << param.testcaseName;
} else {
result << "_hoShape=" << param.Ho.shape;
}
return result.str();
}

private:
static std::shared_ptr<Model> CreateFunction(const AUGRUCellParams& params) {
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
const auto A = std::make_shared<op::v0::Parameter>(params.A.type, params.A.shape);

const auto augru_cell = std::make_shared<ov::op::internal::AUGRUCell>(X,
H_t,
W,
R,
B,
A,
params.hiddenSize);

auto function = std::make_shared<Model>(NodeVector{augru_cell}, ParameterVector{X, H_t, W, R, B, A});
return function;
}
};

TEST_P(ReferenceAUGRUCellTest, CompareWithRefs) {
Exec();
}

template <element::Type_t ET>
std::vector<AUGRUCellParams> generateParams() {
using T = typename element_type_traits<ET>::value_type;
std::vector<AUGRUCellParams> params {
AUGRUCellParams(
2, 3, 3, 3,
reference_tests::Tensor(ET, {2, 3}, std::vector<T>{
0.52421564f, 0.78845507f, 0.9372873f, 0.59783894f, 0.18278378f, 0.2084126f}),
reference_tests::Tensor(ET, {2, 3}, std::vector<T>{
0.45738035f, 0.996877f, 0.82882977f, 0.47492632f, 0.88471466f, 0.57833236f}),
reference_tests::Tensor(ET, {3 * 3, 3}, std::vector<T>{
0.5815369f, 0.16559383f, 0.08464007f, 0.843122f, 0.73968244f, 0.11359601f,
0.8295078f, 0.9240567f, 0.10007995f, 0.20573162f, 0.09002485f, 0.2839569f,
0.3096991f, 0.5638341f, 0.5787327f, 0.84552664f, 0.16263747f, 0.7243242f,
0.8049057f, 0.43966424f, 0.46294412f, 0.9833361f, 0.31369713f, 0.1719934f,
0.4937093f, 0.6353004f, 0.77982515f}),
reference_tests::Tensor(ET, {3 * 3, 3}, std::vector<T>{
0.16510165f, 0.52435565f, 0.2788478f, 0.99427545f, 0.1623331f, 0.01389796f,
0.99669236f, 0.53901845f, 0.8737506f, 0.9254788f, 0.21172932f, 0.11634306f,
0.40111724f, 0.37497616f, 0.2903471f, 0.6796794f, 0.65131867f, 0.78163475f,
0.12058706f, 0.45591718f, 0.791677f, 0.76497287f, 0.9895242f, 0.7845312f,
0.51267904f, 0.49030215f, 0.08498167f}),
reference_tests::Tensor(ET, {3 * 3}, std::vector<T>{
0.8286678f + 0.9175602f,
0.9153158f + 0.14958014f,
0.9581612f + 0.49230585f,
0.6639213f + 0.63162816f,
0.84239805f + 0.4161903f,
0.5282445f + 0.22148274f,
0.14153397f + 0.50496656f,
0.22404431f + 0.34798595f,
0.6549655f + 0.6699164f}),
reference_tests::Tensor(ET, {2, 1}, std::vector<T>(2, 0)),
reference_tests::Tensor(ET, {2, 3}, std::vector<T>{
0.480763f, 0.996927f, 0.830836f, 0.50231f, 0.894105f, 0.58932f}),
"augru_zero_attentional_gate"),
AUGRUCellParams(
2, 3, 3, 3,
reference_tests::Tensor(ET, {2, 3}, std::vector<T>{
0.52421564f, 0.78845507f, 0.9372873f, 0.59783894f, 0.18278378f, 0.2084126f}),
reference_tests::Tensor(ET, {2, 3}, std::vector<T>{
0.45738035f, 0.996877f, 0.82882977f, 0.47492632f, 0.88471466f, 0.57833236f}),
reference_tests::Tensor(ET, {3 * 3, 3}, std::vector<T>{
0.5815369f, 0.16559383f, 0.08464007f, 0.843122f, 0.73968244f, 0.11359601f,
0.8295078f, 0.9240567f, 0.10007995f, 0.20573162f, 0.09002485f, 0.2839569f,
0.3096991f, 0.5638341f, 0.5787327f, 0.84552664f, 0.16263747f, 0.7243242f,
0.8049057f, 0.43966424f, 0.46294412f, 0.9833361f, 0.31369713f, 0.1719934f,
0.4937093f, 0.6353004f, 0.77982515f}),
reference_tests::Tensor(ET, {3 * 3, 3}, std::vector<T>{
0.16510165f, 0.52435565f, 0.2788478f, 0.99427545f, 0.1623331f, 0.01389796f,
0.99669236f, 0.53901845f, 0.8737506f, 0.9254788f, 0.21172932f, 0.11634306f,
0.40111724f, 0.37497616f, 0.2903471f, 0.6796794f, 0.65131867f, 0.78163475f,
0.12058706f, 0.45591718f, 0.791677f, 0.76497287f, 0.9895242f, 0.7845312f,
0.51267904f, 0.49030215f, 0.08498167f}),
reference_tests::Tensor(ET, {3 * 3}, std::vector<T>{
0.8286678f + 0.9175602f,
0.9153158f + 0.14958014f,
0.9581612f + 0.49230585f,
0.6639213f + 0.63162816f,
0.84239805f + 0.4161903f,
0.5282445f + 0.22148274f,
0.14153397f + 0.50496656f,
0.22404431f + 0.34798595f,
0.6549655f + 0.6699164f}),
reference_tests::Tensor(ET, {2, 1}, std::vector<T>{0.4f, 0.7f}),
reference_tests::Tensor(ET, {2, 3}, std::vector<T>{
0.686381f, 0.997266f, 0.897868f, 0.832165f, 0.963144f, 0.868483f}),
"augru_attentional_gate_provided"),
AUGRUCellParams(
2, 3, 4, 3,
reference_tests::Tensor(ET, {1, 3}, std::vector<T>{
0.64053001f, 0.84805253f, 0.84544252f}),
reference_tests::Tensor(ET, {1, 4}, std::vector<T>{
0.43200249f, 0.08097203f, 0.68151259f, 0.09095205f}),
reference_tests::Tensor(ET, {3 * 4, 3}, std::vector<T>{
0.23187583f, 0.66675389f, 0.01945467f, 0.60630121f, 0.18400699f, 0.16003634f,
0.04636866f, 0.75745989f, 0.96562912f, 0.56330529f, 0.20863093f, 0.93179716f,
0.99211225f, 0.73087621f, 0.21175275f, 0.03808638f, 0.63130526f, 0.76965886f,
0.67656870f, 0.57886251f, 0.94375534f, 0.88943972f, 0.96256618f, 0.38204562f,
0.76424904f, 0.30076485f, 0.60250044f, 0.40778284f, 0.70017757f, 0.00410288f,
0.97978094f, 0.73106175f, 0.22250106f, 0.44011834f, 0.11434720f, 0.62128995}),
reference_tests::Tensor(ET, {3 * 4, 4}, std::vector<T>{
0.60702709f, 0.47515485f, 0.26202747f, 0.53851601f, 0.73423241f, 0.11627945f,
0.04631785f, 0.43604361f, 0.12472080f, 0.47546322f, 0.23103632f, 0.36108585f,
0.45139418f, 0.79838954f, 0.28194170f, 0.76877929f, 0.28428253f, 0.13822001f,
0.51670576f, 0.80312243f, 0.11050813f, 0.19925340f, 0.29769184f, 0.78933459f,
0.79981487f, 0.55313454f, 0.04135296f, 0.50578146f, 0.76553680f, 0.44311704f,
0.30525652f, 0.26301583f, 0.41771479f, 0.18182059f, 0.11106816f, 0.67427757f,
0.59174944f, 0.13339960f, 0.33362533f, 0.78938375f, 0.99260256f, 0.86955733f,
0.24899024f, 0.87134874f, 0.02803802f, 0.61244129f, 0.40803782f, 0.90735816f,
0.51267904f, 0.49030215f, 0.08498167f}),
reference_tests::Tensor(ET, {3 * 4}, std::vector<T>{
0.61387895f, 0.56121052f, 0.89328753f, 0.15302506f, 0.90491122f, 0.78289335f,
0.97930211f, 0.75002178f, 0.92500923f, 0.18957983f, 0.07849785f, 0.76568159f}),
reference_tests::Tensor(ET, {1, 1}, std::vector<T>{0.3333f}),
reference_tests::Tensor(ET, {2, 2}, std::vector<T>{
0.666063f, 0.451451f, 0.792762f, 0.453281f}),
"augru_different_input_and_hidden_size"),
};
return params;
}

std::vector<AUGRUCellParams> generateCombinedParams() {
const std::vector<std::vector<AUGRUCellParams>> generatedParams {
generateParams<element::Type_t::bf16>(),
generateParams<element::Type_t::f16>(),
generateParams<element::Type_t::f32>(),
generateParams<element::Type_t::f64>(),
};
std::vector<AUGRUCellParams> combinedParams;

for (const auto& params : generatedParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}

INSTANTIATE_TEST_SUITE_P(smoke_AUGRUCell_With_Hardcoded_Refs, ReferenceAUGRUCellTest,
testing::ValuesIn(generateCombinedParams()), ReferenceAUGRUCellTest::getTestCaseName);

} // namespace
Loading

0 comments on commit 67f4b8e

Please sign in to comment.