inference.h 1.9 KB
Newer Older
H
hangangqiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**
 * Copyright 2020 Huawei Technologies Co., Ltd
 *
 * 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.
 */

#ifndef MINDSPORE_INCLUDE_MS_SESSION_H
#define MINDSPORE_INCLUDE_MS_SESSION_H

#include <memory>
#include <vector>
#include <string>
23
#include "include/infer_tensor.h"
H
hangangqiang 已提交
24 25 26

namespace mindspore {
namespace inference {
D
dinghao 已提交
27
enum Status { SUCCESS = 0, FAILED, INVALID_INPUTS };
28 29 30 31
class MS_API InferSession {
 public:
  InferSession() = default;
  virtual ~InferSession() = default;
D
dinghao 已提交
32 33 34 35
  virtual Status InitEnv(const std::string &device_type, uint32_t device_id) = 0;
  virtual Status FinalizeEnv() = 0;
  virtual Status LoadModelFromFile(const std::string &file_name, uint32_t &model_id) = 0;
  virtual Status UnloadModel(uint32_t model_id) = 0;
36
  // override this method to avoid request/reply data copy
D
dinghao 已提交
37
  virtual Status ExecuteModel(uint32_t model_id, const RequestBase &request, ReplyBase &reply) = 0;
38

D
dinghao 已提交
39 40
  virtual Status ExecuteModel(uint32_t model_id, const std::vector<InferTensor> &inputs,
                              std::vector<InferTensor> &outputs) {
41 42 43 44 45 46
    VectorInferTensorWrapRequest request(inputs);
    VectorInferTensorWrapReply reply(outputs);
    return ExecuteModel(model_id, request, reply);
  }

  static std::shared_ptr<InferSession> CreateSession(const std::string &device, uint32_t device_id);
H
hangangqiang 已提交
47 48 49 50 51
};

}  // namespace inference
}  // namespace mindspore
#endif  // MINDSPORE_INCLUDE_MS_SESSION_H