forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize_tree.cpp
66 lines (52 loc) · 2.15 KB
/
visualize_tree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/pass/visualize_tree.hpp"
#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/test_assertions.hpp"
#include "openvino/core/model.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
namespace ov {
namespace test {
using ov::op::v0::Constant;
using ov::op::v0::Parameter;
using ov::op::v0::Result;
using ov::op::v1::Add;
class VisualizeTreeTest : public testing::Test {
protected:
void TearDown() override {
if (util::file_exists(vt_svg_file_path)) {
std::remove(vt_svg_file_path.c_str());
}
if (util::file_exists(dot_file_path)) {
std::remove(dot_file_path.c_str());
}
}
static std::shared_ptr<Model> make_dummy_add_model(const element::Type& precision) {
const auto c = Constant::create(precision, Shape{3}, {1.0f, -23.21f, std::numeric_limits<float>::infinity()});
const auto input = std::make_shared<Parameter>(precision, Shape{});
const auto add = std::make_shared<Add>(c, input);
const auto output = std::make_shared<Result>(add);
return std::make_shared<Model>(ResultVector{output}, ParameterVector{input});
}
const std::string vt_svg_file_path =
util::path_join({utils::getExecutableDirectory(), utils::generateTestFilePrefix() + "_tree.svg"}).string();
const std::string dot_file_path = vt_svg_file_path + ".dot";
};
TEST_F(VisualizeTreeTest, model_has_constant_with_inf) {
constexpr auto precision = element::f32;
const auto model = make_dummy_add_model(precision);
pass::VisualizeTree vt(vt_svg_file_path);
OV_ASSERT_NO_THROW(vt.run_on_model(model));
ASSERT_TRUE(util::file_exists(dot_file_path)) << dot_file_path;
}
TEST_F(VisualizeTreeTest, model_has_constant_with_no_inf) {
constexpr auto precision = element::f16;
const auto model = make_dummy_add_model(precision);
pass::VisualizeTree vt(vt_svg_file_path);
OV_ASSERT_NO_THROW(vt.run_on_model(model));
ASSERT_TRUE(util::file_exists(dot_file_path)) << dot_file_path;
}
} // namespace test
} // namespace ov