Commit 355bff8f authored by Sang Ik Lee's avatar Sang Ik Lee Committed by Robert Kimball

Add aliased Constants to aliased_output test. (#555)

* Add aliased Constants to aliased_output test.

* add support for const as outputs
parent d991861d
......@@ -1036,6 +1036,18 @@ namespace ngraph
template <>
void CPU_Emitter::EMITTER_DECL(ngraph::op::Constant)
{
// If an output is a constant then copy it
size_t output_index = 0;
for (shared_ptr<Node> result : external_function->get_function()->get_results())
{
if (result.get() == node)
{
const descriptor::Tensor& tensor = node->get_output_tensor(0);
writer << "memcpy(outputs[" << output_index << "], " << tensor.get_name()
<< ", " << tensor.size() << ");\n";
}
output_index++;
}
}
template <>
......
......@@ -125,7 +125,8 @@ TEST(${BACKEND_NAME}, aliased_output)
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = A + B;
auto D = A * B;
auto f = make_shared<Function>(NodeVector{C, C, D, D, C}, op::ParameterVector{A, B});
auto E = op::Constant::create(element::f32, shape, {1, 2, 3, 4});
auto f = make_shared<Function>(NodeVector{C, C, D, D, C, E, E}, op::ParameterVector{A, B});
auto manager = runtime::Manager::get("${BACKEND_NAME}");
auto external = manager->compile(f);
......@@ -140,18 +141,23 @@ TEST(${BACKEND_NAME}, aliased_output)
shared_ptr<runtime::TensorView> out3 = backend->make_primary_tensor_view(element::f32, shape);
shared_ptr<runtime::TensorView> out4 = backend->make_primary_tensor_view(element::f32, shape);
shared_ptr<runtime::TensorView> out5 = backend->make_primary_tensor_view(element::f32, shape);
shared_ptr<runtime::TensorView> out6 = backend->make_primary_tensor_view(element::f32, shape);
shared_ptr<runtime::TensorView> out7 = backend->make_primary_tensor_view(element::f32, shape);
copy_data(a, vector<float>{0, 1, 2, 3});
copy_data(b, vector<float>{1, 2, 3, 4});
vector<float> expectedC{1, 3, 5, 7};
vector<float> expectedD{0, 2, 6, 12};
vector<float> expectedE{1, 2, 3, 4};
cf->call({a, b}, {out1, out2, out3, out4, out5});
cf->call({a, b}, {out1, out2, out3, out4, out5, out6, out7});
EXPECT_EQ(expectedC, read_vector<float>(out1));
EXPECT_EQ(expectedC, read_vector<float>(out2));
EXPECT_EQ(expectedD, read_vector<float>(out3));
EXPECT_EQ(expectedD, read_vector<float>(out4));
EXPECT_EQ(expectedC, read_vector<float>(out5));
EXPECT_EQ(expectedE, read_vector<float>(out6));
EXPECT_EQ(expectedE, read_vector<float>(out7));
}
TEST(${BACKEND_NAME}, parameter_as_output)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment