@@ -40,14 +40,23 @@ struct PaddleBuf {
40
40
struct PaddleTensor {
41
41
std::string name; // variable name.
42
42
std::vector<int > shape;
43
+ // TODO(Superjomn) for LoD support, add a vector<vector<int>> field if needed.
43
44
PaddleBuf data; // blob of data.
44
45
PaddleDType dtype;
45
46
};
46
47
48
+ enum class PaddleEngineKind {
49
+ kNative = 0 , // Use the native Fluid facility.
50
+ // TODO(Superjomn) support following engines latter.
51
+ // kAnakin, // Use Anakin for inference.
52
+ // kTensorRT, // Use TensorRT for inference.
53
+ // kAutoMixedAnakin, // Automatically mix Fluid with Anakin.
54
+ // kAutoMixedTensorRT, // Automatically mix Fluid with TensorRT.
55
+ };
56
+
47
57
/*
48
58
* A simple Inference API for Paddle. Currently this API can be used by
49
59
* non-sequence scenerios.
50
- * TODO(Superjomn) Support another API for NLP-related usages.
51
60
*/
52
61
class PaddlePredictor {
53
62
public:
@@ -69,15 +78,6 @@ class PaddlePredictor {
69
78
// Destroy the Predictor.
70
79
virtual ~PaddlePredictor () {}
71
80
72
- enum class EngineKind {
73
- kNative = -1 , // Use the native Fluid facility.
74
- // TODO(Superjomn) support latter.
75
- // kAnakin, // Use Anakin for inference.
76
- // kTensorRT, // Use TensorRT for inference.
77
- // kAutoMixedAnakin, // Automatically mix Fluid with Anakin.
78
- // kAutoMixedTensorRT, // Automatically mix Fluid with TensorRT.
79
- };
80
-
81
81
// The common configs for all the predictors.
82
82
struct Config {
83
83
std::string model_dir; // path to the model directory.
@@ -86,18 +86,24 @@ class PaddlePredictor {
86
86
};
87
87
88
88
struct NativeConfig : public PaddlePredictor ::Config {
89
+ // GPU related fields.
89
90
bool use_gpu{false };
90
- int device;
91
- float fraction_of_gpu_memory;
91
+ int device{0 };
92
+ float fraction_of_gpu_memory{-1 .f }; // Negative to notify initialization.
93
+
92
94
std::string prog_file;
93
95
std::string param_file;
94
- bool share_variables;
95
96
};
96
97
97
- // A factory to help create difference predictor.
98
- template <
99
- typename ConfigT,
100
- PaddlePredictor::EngineKind engine = PaddlePredictor::EngineKind::kNative >
98
+ // A factory to help create different predictors.
99
+ //
100
+ // FOR EXTENSION DEVELOPER:
101
+ // Different predictors are designated by config type and engine kind. Similar
102
+ // configs can be merged, but there shouldn't be a huge config containing
103
+ // different fields for more than one kind of predictors.
104
+ //
105
+ // Similarly, each engine kind should map to a unique predictor implementation.
106
+ template <typename ConfigT, PaddleEngineKind engine = PaddleEngineKind::kNative >
101
107
std::unique_ptr<PaddlePredictor> CreatePaddlePredictor (const ConfigT& config);
102
108
103
109
} // namespace paddle
0 commit comments