Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable infer api with multi-threads #11162

Merged
merged 3 commits into from
Jun 5, 2018

Conversation

tensor-tang
Copy link
Contributor

@tensor-tang tensor-tang commented Jun 4, 2018

According to @Superjomn 's suggestion, the usage should be like this:

  auto main_predictor = CreatePaddlePredictor(config);

  std::vector<std::thread> threads;
  for (size_t i = 0; i < num_threads; ++i) {
    threads.emplace_back([&, i](
      // clone a predictor which is thread-safe
      // and shared the same parameters
      auto predictor = main_predictor->Clone();
      // prepare inputs and output ...
      predictor->Run(inputs, outputs);
    ));
  }
  // join...

So, we should only focus on thread-safe and sharing parameters.

@tensor-tang tensor-tang added the 预测 原名Inference,包含Capi预测问题等 label Jun 4, 2018
@@ -54,17 +54,23 @@ std::string num2str(T a) {
}
} // namespace

bool NativePaddlePredictor::Init() {
bool NativePaddlePredictor::Init(std::shared_ptr<framework::Scope> scope) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be unique_ptr? and std::moved around?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there no change in CreatePaddlePredictor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be unique_ptr? and std::moved around?

I am afraid not, this scope should be parent scope and the sub scope should be depend on it

Why is there no change in CreatePaddlePredictor?

Because as default only need change Clone.

@@ -34,14 +34,15 @@ class NativePaddlePredictor : public PaddlePredictor {
explicit NativePaddlePredictor(const NativeConfig &config)
: config_(config) {}

bool Init();
// will only create sub scope if have global scope
bool Init(std::shared_ptr<framework::Scope> scope = nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure~ will update it.

@tensor-tang tensor-tang merged commit a385803 into PaddlePaddle:develop Jun 5, 2018
@tensor-tang tensor-tang deleted the infer/api branch June 5, 2018 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
预测 原名Inference,包含Capi预测问题等
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants