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_ReLU, f32)
36 // Make pull-relu graph
37 auto g = loco::make_graph();
38 auto pull = g->nodes()->create<loco::Pull>();
39 pull->dtype(loco::DataType::FLOAT32);
41 auto relu = g->nodes()->create<loco::ReLU>();
44 // Make and assign data to pull node
45 auto pull_buf = make_buffer<float, LexicalLayout>(Shape{2});
46 pull_buf.at(Index{0}) = -10.0f;
47 pull_buf.at(Index{1}) = 10.0f;
48 auto pull_data = locomotiv::make_data(pull_buf);
49 locomotiv::annot_data(pull, std::move(pull_data));
50 locomotiv::annot_domain(pull, loco::Domain::Tensor);
52 locomotiv::NodeExecution::get().run(relu);
54 auto relu_data = locomotiv::annot_data(relu);
55 ASSERT_NE(relu_data, nullptr);
56 ASSERT_EQ(loco::DataType::FLOAT32, relu_data->dtype());
57 ASSERT_EQ(Shape{2}, *(relu_data->shape()));
58 ASSERT_FLOAT_EQ(0.0f, relu_data->as_f32_bufptr()->at(Index{0}));
59 ASSERT_FLOAT_EQ(10.0f, relu_data->as_f32_bufptr()->at(Index{1}));
61 ASSERT_EQ(loco::Domain::Tensor, locomotiv::annot_domain(relu));