Treelite
compiler.h
Go to the documentation of this file.
1 
7 #ifndef TREELITE_COMPILER_H_
8 #define TREELITE_COMPILER_H_
9 
10 #include <unordered_map>
11 #include <functional>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 #include <utility>
16 
17 namespace treelite {
18 
19 class Model; // forward declaration
20 
21 namespace compiler {
22 
23 struct CompilerParam; // forward declaration
24 
25 struct CompiledModel {
26  struct FileEntry {
27  std::string content;
28  std::vector<char> content_binary;
29  bool is_binary;
30  FileEntry() : is_binary(false) {}
31  // Passing std::vector<char> indicates binary data
32  // Passing std::string indicates text data
33  // Use move constructor and assignment exclusively to save memory
34  explicit FileEntry(const std::string& content) = delete;
35  explicit FileEntry(std::string&& content)
36  : content(std::move(content)), is_binary(false) {}
37  explicit FileEntry(const std::vector<char>&) = delete;
38  explicit FileEntry(std::vector<char>&& content)
39  : content_binary(std::move(content)), is_binary(true) {}
40  FileEntry(const FileEntry& other) = delete;
41  FileEntry(FileEntry&& other) = default;
42  FileEntry& operator=(const FileEntry& other) = delete;
43  FileEntry& operator=(FileEntry&& other) = default;
44  };
45  std::string backend;
46  std::unordered_map<std::string, FileEntry> files;
47  std::string file_prefix;
48 };
49 
50 } // namespace compiler
51 
53 class Compiler {
54  public:
56  virtual ~Compiler() = default;
61  virtual compiler::CompiledModel Compile(const Model& model) = 0;
66  virtual compiler::CompilerParam QueryParam() const = 0;
73  static Compiler* Create(const std::string& name,
74  const char* param_json_str);
75 };
76 
77 } // namespace treelite
78 
79 #endif // TREELITE_COMPILER_H_
parameters for tree compiler
interface of compiler
Definition: compiler.h:53
Definition: compiler.h:26
thin wrapper for tree ensemble model
Definition: tree.h:667