paddle_analysis_config.h 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once

#include <cassert>
#include <memory>
#include <string>
19
#include <unordered_set>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <vector>

// Here we include some header files with relative paths, for that in deploy,
// the abstract path of this header file will be changed.
#include "paddle_api.h"           // NOLINT
#include "paddle_pass_builder.h"  // NOLINT

namespace paddle {

class AnalysisPredictor;
// ==
//
// -----------------------------------------------------------------------------------
// NOTE: The following APIs are not mature yet, we are still working on them.
namespace contrib {

// NOTE WIP, not stable yet.
struct AnalysisConfig : public NativeConfig {
  explicit AnalysisConfig(bool use_gpu = false);
  explicit AnalysisConfig(const AnalysisConfig& other);
  explicit AnalysisConfig(AnalysisConfig&& other);

  // Determine whether to perform graph optimization.
  bool enable_ir_optim = true;

  // Get a pass builder for customize the passes in IR analysis phase.
  PassStrategy* pass_builder() const;

  // NOT stable yet.
  bool use_feed_fetch_ops{true};

  void EnableTensorRtEngine(int workspace_size = 1 << 20,
                            int max_batch_size = 1);
53 54
  bool use_tensorrt() const { return use_tensorrt_; }

L
luotao1 已提交
55
  void EnableMKLDNN();
56
  bool use_mkldnn() const { return use_mkldnn_; }
57 58 59
  void SetMKLDNNOp(std::unordered_set<std::string> op_list) {
    mkldnn_enabled_op_types_ = op_list;
  }
60

T
Tao Luo 已提交
61
  // Specify the memory buffer of program and parameter
T
Tao Luo 已提交
62 63 64
  void SetModelBuffer(const char* prog_buffer, size_t prog_buffer_size,
                      const char* program_buffer, size_t program_buffer_size);
  bool model_from_memory() const { return model_from_memory_; }
T
Tao Luo 已提交
65

66 67 68 69 70
  friend class ::paddle::AnalysisPredictor;

 protected:
  bool use_tensorrt_{false};
  bool use_mkldnn_{false};
71
  std::unordered_set<std::string> mkldnn_enabled_op_types_;
72 73 74
  int tensorrt_workspace_size_;
  int tensorrt_max_batchsize_;
  std::unique_ptr<PassStrategy> pass_builder_;
T
Tao Luo 已提交
75
  bool model_from_memory_{false};
76 77 78 79 80 81 82 83 84 85 86 87 88
};

// Configurations for Anakin engine.
struct AnakinConfig : public PaddlePredictor::Config {
  enum TargetType { NVGPU = 0, X86 };
  int device;
  std::string model_file;
  int max_batch_size{-1};
  TargetType target_type;
};

}  // namespace contrib
}  // namespace paddle