|
|
|
@ -40,14 +40,23 @@ struct PaddleBuf {
|
|
|
|
|
struct PaddleTensor {
|
|
|
|
|
std::string name; // variable name.
|
|
|
|
|
std::vector<int> shape;
|
|
|
|
|
// TODO(Superjomn) for LoD support, add a vector<vector<int>> field if needed.
|
|
|
|
|
PaddleBuf data; // blob of data.
|
|
|
|
|
PaddleDType dtype;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class PaddleEngineKind {
|
|
|
|
|
kNative = 0, // Use the native Fluid facility.
|
|
|
|
|
// TODO(Superjomn) support following engines latter.
|
|
|
|
|
// kAnakin, // Use Anakin for inference.
|
|
|
|
|
// kTensorRT, // Use TensorRT for inference.
|
|
|
|
|
// kAutoMixedAnakin, // Automatically mix Fluid with Anakin.
|
|
|
|
|
// kAutoMixedTensorRT, // Automatically mix Fluid with TensorRT.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A simple Inference API for Paddle. Currently this API can be used by
|
|
|
|
|
* non-sequence scenerios.
|
|
|
|
|
* TODO(Superjomn) Support another API for NLP-related usages.
|
|
|
|
|
*/
|
|
|
|
|
class PaddlePredictor {
|
|
|
|
|
public:
|
|
|
|
@ -69,15 +78,6 @@ class PaddlePredictor {
|
|
|
|
|
// Destroy the Predictor.
|
|
|
|
|
virtual ~PaddlePredictor() {}
|
|
|
|
|
|
|
|
|
|
enum class EngineKind {
|
|
|
|
|
kNative = -1, // Use the native Fluid facility.
|
|
|
|
|
// TODO(Superjomn) support latter.
|
|
|
|
|
// kAnakin, // Use Anakin for inference.
|
|
|
|
|
// kTensorRT, // Use TensorRT for inference.
|
|
|
|
|
// kAutoMixedAnakin, // Automatically mix Fluid with Anakin.
|
|
|
|
|
// kAutoMixedTensorRT, // Automatically mix Fluid with TensorRT.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The common configs for all the predictors.
|
|
|
|
|
struct Config {
|
|
|
|
|
std::string model_dir; // path to the model directory.
|
|
|
|
@ -86,18 +86,24 @@ class PaddlePredictor {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NativeConfig : public PaddlePredictor::Config {
|
|
|
|
|
// GPU related fields.
|
|
|
|
|
bool use_gpu{false};
|
|
|
|
|
int device;
|
|
|
|
|
float fraction_of_gpu_memory;
|
|
|
|
|
int device{0};
|
|
|
|
|
float fraction_of_gpu_memory{-1.f}; // Negative to notify initialization.
|
|
|
|
|
|
|
|
|
|
std::string prog_file;
|
|
|
|
|
std::string param_file;
|
|
|
|
|
bool share_variables;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A factory to help create difference predictor.
|
|
|
|
|
template <
|
|
|
|
|
typename ConfigT,
|
|
|
|
|
PaddlePredictor::EngineKind engine = PaddlePredictor::EngineKind::kNative>
|
|
|
|
|
// A factory to help create different predictors.
|
|
|
|
|
//
|
|
|
|
|
// FOR EXTENSION DEVELOPER:
|
|
|
|
|
// Different predictors are designated by config type and engine kind. Similar
|
|
|
|
|
// configs can be merged, but there shouldn't be a huge config containing
|
|
|
|
|
// different fields for more than one kind of predictors.
|
|
|
|
|
//
|
|
|
|
|
// Similarly, each engine kind should map to a unique predictor implementation.
|
|
|
|
|
template <typename ConfigT, PaddleEngineKind engine = PaddleEngineKind::kNative>
|
|
|
|
|
std::unique_ptr<PaddlePredictor> CreatePaddlePredictor(const ConfigT& config);
|
|
|
|
|
|
|
|
|
|
} // namespace paddle
|
|
|
|
|