2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "NodeExecution.h"
19 #include "locomotiv/NodeData.h"
20 #include "NodeDataImpl.h"
21 #include "NodeDomain.h"
23 #include <nncc/core/ADT/tensor/Shape.h>
24 #include <nncc/core/ADT/tensor/Buffer.h>
25 #include <nncc/core/ADT/tensor/LexicalLayout.h>
27 #include <gtest/gtest.h>
29 using nncc::core::ADT::tensor::Index;
30 using nncc::core::ADT::tensor::Shape;
31 using nncc::core::ADT::tensor::LexicalLayout;
32 using nncc::core::ADT::tensor::make_buffer;
34 TEST(NodeExecution_Push, s32)
36 // Make pull-push graph
37 auto g = loco::make_graph();
38 auto pull = g->nodes()->create<loco::Pull>();
39 pull->dtype(loco::DataType::S32);
41 auto push = g->nodes()->create<loco::Push>();
44 // Make and assign data to pull node
45 auto pull_buf = make_buffer<int32_t, LexicalLayout>(Shape{1});
46 pull_buf.at(Index{0}) = 42;
47 auto pull_data = locomotiv::make_data(pull_buf);
48 locomotiv::annot_data(pull, std::move(pull_data));
49 locomotiv::annot_domain(pull, loco::Domain::Tensor);
51 locomotiv::NodeExecution::get().run(push);
53 auto push_data = locomotiv::annot_data(push);
54 ASSERT_NE(push_data, nullptr);
55 ASSERT_EQ(loco::DataType::S32, push_data->dtype());
56 ASSERT_EQ(Shape{1}, *(push_data->shape()));
57 ASSERT_EQ(pull_buf.at(Index{0}), push_data->as_s32_bufptr()->at(Index{0}));
59 ASSERT_EQ(loco::Domain::Tensor, locomotiv::annot_domain(push));
62 TEST(NodeExecution_Push, f32)
64 // Make pull-push graph
65 auto g = loco::make_graph();
66 auto pull = g->nodes()->create<loco::Pull>();
67 pull->dtype(loco::DataType::FLOAT32);
69 auto push = g->nodes()->create<loco::Push>();
72 // Make and assign data to pull node
73 auto pull_buf = make_buffer<float, LexicalLayout>(Shape{1});
74 pull_buf.at(Index{0}) = 3.14f;
75 auto pull_data = locomotiv::make_data(pull_buf);
76 locomotiv::annot_data(pull, std::move(pull_data));
77 locomotiv::annot_domain(pull, loco::Domain::Tensor);
79 locomotiv::NodeExecution::get().run(push);
81 auto push_data = locomotiv::annot_data(push);
82 ASSERT_NE(push_data, nullptr);
83 ASSERT_EQ(loco::DataType::FLOAT32, push_data->dtype());
84 ASSERT_EQ(Shape{1}, *(push_data->shape()));
85 ASSERT_FLOAT_EQ(pull_buf.at(Index{0}), push_data->as_f32_bufptr()->at(Index{0}));
87 ASSERT_EQ(loco::Domain::Tensor, locomotiv::annot_domain(push));