Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
4 : *
5 : * @file interpreter.h
6 : * @date 01 April 2021
7 : * @brief NNTrainer interpreter that reads and generates a graphRepresentation
8 : from a file
9 : * @see https://github.com/nnstreamer/nntrainer
10 : * @author Jihoon Lee <jhoon.it.lee@samsung.com>
11 : * @bug No known bugs except for NYI items
12 : * @note The boundary of graph interpreter is restricted to graph only.
13 : * @details
14 : * Graph is convertible either from a file, representation by a appropriate
15 : interpreter
16 : * For example, if istream would be from a a.tflite file,
17 : *
18 : * GraphRepresentation g;
19 : * GraphInterpreter * interpreter = new TfliteInterpreter;
20 : *
21 : * std::ifstream f = std::open("a.tflite");
22 : * g = interpreter->serialize(f);
23 : *
24 : * +--------+
25 : * |iostream|
26 : * +--+--+--+
27 : * ^ |
28 : * serialize()| |
29 : * | |
30 : * (Interpreter)
31 : * | |
32 : * | | deserialize()
33 : * | v
34 : * +-------+--+--------+
35 : * |GraphRepresentation|
36 : * +-------+-----------+
37 : *
38 : */
39 : #ifndef __INTERPRETER_H__
40 : #define __INTERPRETER_H__
41 :
42 : #include <memory>
43 : #include <string>
44 : #include <vector>
45 :
46 : #include <compiler_fwd.h>
47 :
48 : namespace nntrainer {
49 :
50 : /**
51 : * @brief Pure virtual class for the Graph Interpreter
52 : *
53 : */
54 : class GraphInterpreter {
55 : public:
56 : virtual ~GraphInterpreter() {}
57 : /**
58 : * @brief serialize graph to a stream
59 : *
60 : * @param representation graph representation
61 : * @param out output file name
62 : */
63 : virtual void serialize(const GraphRepresentation &representation,
64 : const std::string &out) = 0;
65 :
66 : /**
67 : * @brief serialize graph to a stream
68 : *
69 : * @param representation graph representation
70 : * @param out output file name
71 : */
72 0 : virtual void serialize_v1(const NetworkGraph &representation,
73 0 : const std::string &out){};
74 :
75 : /**
76 : * @brief graph representation
77 : *
78 : * @param in input file name
79 : * @return std::shared_ptr<NetworkGraph>
80 : */
81 0 : virtual std::shared_ptr<NetworkGraph> deserialize_v1(const std::string &in) {
82 0 : return nullptr;
83 : }
84 :
85 : /**
86 : * @brief deserialize graph from a stream
87 : *
88 : * @param in input file name
89 : * @return GraphRepresentation graph representation
90 : */
91 : virtual GraphRepresentation deserialize(const std::string &in) = 0;
92 : };
93 :
94 : } // namespace nntrainer
95 :
96 : #endif /** __INTERPRETER_H__ */
|