Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
dragon.h
Go to the documentation of this file.
1 
13 #ifndef DRAGON_CXX_DRAGON_H_
14 #define DRAGON_CXX_DRAGON_H_
15 
16 #include <string>
17 #include <cstdint>
18 #include <vector>
19 
20 #ifdef _MSC_VER
21  #ifdef DRAGON_CXX_EXPORTS
22  #define DRAGON_API __declspec(dllexport)
23  #else
24  #define DRAGON_API __declspec(dllimport)
25  #endif
26 #else
27  #define DRAGON_API
28 #endif
29 
30 /* * * * * * * * * * * * * * * * * * * * *
31  * *
32  * Internal Headers *
33  * *
34  * * * * * * * * * * * * * * * * * * * * */
35 
36 #ifdef DRAGON_CXX_EXPORTS
37 #else
38 namespace dragon {
39 
40 typedef struct float16* float16_t;
41 
42 }
43 #endif // DRAGON_CXX_EXPORTS
44 
45 namespace dragon {
46 
47 typedef struct GraphDef* GraphDef_t;
48 typedef struct Workspace* Workspace_t;
49 
51  public:
52  Device();
53  explicit Device(std::string device_type);
54  Device(std::string device_type, int device_id);
55 
56  const int& device_type() const { return device_type_; }
57  const int device_id() const { return device_id_; }
58 
59  private:
60  int device_type_, device_id_;
61 };
62 
63 /* * * * * * * * * * * * * * * * * * * * *
64  * *
65  * Workspace *
66  * *
67  * * * * * * * * * * * * * * * * * * * * */
68 
69 DRAGON_API Workspace_t CreateWorkspace(const std::string& name);
70 
72 
73 DRAGON_API Workspace_t ResetWorkspace(const std::string& name);
74 
76 
78 
79 DRAGON_API void DestroyWorkspace(const std::string& name);
80 
81 /* * * * * * * * * * * * * * * * * * * * *
82  * *
83  * Graph *
84  * *
85  * * * * * * * * * * * * * * * * * * * * */
86 
87 DRAGON_API std::string CreateGraph(
88  const GraphDef_t graph_def,
89  const Device& device,
90  Workspace_t ws);
91 
92 DRAGON_API std::string CreateGraph(
93  const std::string& graph_file,
94  const Device& device,
95  Workspace_t ws);
96 
97 DRAGON_API void RunGraph(
98  const std::string& graph_name,
99  Workspace_t ws,
100  int stream_id = 0);
101 
102 /* * * * * * * * * * * * * * * * * * * * *
103  * *
104  * Tensor *
105  * *
106  * * * * * * * * * * * * * * * * * * * * */
107 
109  const std::string& name,
110  Workspace_t ws);
111 
112 template <typename T>
114  const std::string& name,
115  std::vector<int64_t>& shape,
116  Workspace_t ws,
117  const bool copy = false);
118 
119 template <typename T>
121  const std::string& name,
122  const std::vector<int64_t>& shape,
123  const T* data,
124  const Device& device,
125  Workspace_t ws);
126 
127 /* * * * * * * * * * * * * * * * * * * * *
128 * *
129 * Proto *
130 * *
131 * * * * * * * * * * * * * * * * * * * * */
132 
133 DRAGON_API void CreateGraphDef(GraphDef_t* graph_def);
134 DRAGON_API void DestroyGraphDef(GraphDef_t graph_def);
135 
136 /* * * * * * * * * * * * * * * * * * * * *
137  * *
138  * I / O *
139  * *
140  * * * * * * * * * * * * * * * * * * * * */
141 
143  const std::string& model_file,
144  Workspace_t ws);
145 
147  const std::string& model_file,
148  GraphDef_t init_graph,
149  GraphDef_t pred_graph,
150  std::vector<std::string>& inputs,
151  std::vector<std::string>& outputs);
152 
153 /* * * * * * * * * * * * * * * * * * * * *
154  * *
155  * Config *
156  * *
157  * * * * * * * * * * * * * * * * * * * * */
158 
159 DRAGON_API void SetLoggingLevel(const std::string& level);
160 
161 } // namespace dragon
162 
163 #endif // DRAGON_CXX_DRAGON_H_
Definition: workspace.h:20
void DestroyWorkspace(const std::string &name)
Definition: dragon.cc:64
DRAGON_API void CreateGraphDef(GraphDef_t *graph_def)
Definition: dragon.cc:193
Workspace * ResetWorkspace(const std::string &name)
Definition: dragon.cc:32
void LoadONNXModel(const std::string &model_file, GraphDef_t init_graph, GraphDef_t pred_graph, std::vector< std::string > &inputs, std::vector< std::string > &outputs)
Definition: dragon.cc:250
void SetLoggingLevel(const std::string &level)
Definition: dragon.cc:271
void LoadCaffeModel(string file, Workspace *ws)
Definition: caffemodel.h:21
struct float16 * float16_t
Definition: dragon.h:40
DRAGON_API void DestroyGraphDef(GraphDef_t graph_def)
Definition: dragon.cc:197
struct GraphDef * GraphDef_t
Definition: dragon.h:47
T * FetchTensor(const std::string &name, vector< int64_t > &shape, Workspace_t ws, const bool copy)
Definition: dragon.cc:127
void RunGraph(const std::string &graph_name, Workspace_t ws, const int stream_id)
Definition: dragon.cc:107
struct Workspace * Workspace_t
Definition: dragon.h:48
const int device_id() const
Definition: dragon.h:57
Workspace * CreateWorkspace(const std::string &name)
Definition: dragon.cc:22
void CreateTensor(const std::string &name, Workspace_t ws)
Definition: dragon.cc:120
Definition: dragon.h:50
Definition: common.h:41
#define DRAGON_API
Definition: dragon.h:27
void FeedTensor(const std::string &name, const vector< int64_t > &shape, const T *data, const Device &device, Workspace_t ws)
Definition: dragon.cc:161
void MoveWorkspace(Workspace_t dst, Workspace_t src)
Definition: dragon.cc:52
std::string CreateGraph(const GraphDef_t graph_def, const Device &device, Workspace_t ws)
Definition: dragon.cc:84
const int & device_type() const
Definition: dragon.h:56