You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

serving_tensor.h 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_SERVING_TENSOR_H_
  17. #define MINDSPORE_SERVING_TENSOR_H_
  18. #include <utility>
  19. #include <vector>
  20. #include <memory>
  21. #include "include/infer_tensor.h"
  22. #include "serving/ms_service.pb.h"
  23. namespace mindspore {
  24. namespace serving {
  25. class MS_API ServingTensor : public inference::InferTensorBase {
  26. public:
  27. // the other's lifetime must longer than this object
  28. explicit ServingTensor(ms_serving::Tensor &other);
  29. ~ServingTensor();
  30. inference::DataType data_type() const override;
  31. void set_data_type(inference::DataType type) override;
  32. std::vector<int64_t> shape() const override;
  33. void set_shape(const std::vector<int64_t> &shape) override;
  34. const void *data() const override;
  35. size_t data_size() const override;
  36. bool resize_data(size_t data_len) override;
  37. void *mutable_data() override;
  38. private:
  39. // if tensor_ is reference from other ms_serving::Tensor, the other's lifetime must
  40. // longer than this object
  41. ms_serving::Tensor &tensor_;
  42. };
  43. class ServingRequest : public inference::RequestBase {
  44. public:
  45. explicit ServingRequest(const ms_serving::PredictRequest &request);
  46. size_t size() const override;
  47. const inference::InferTensorBase *operator[](size_t index) const override;
  48. private:
  49. const ms_serving::PredictRequest &request_;
  50. std::vector<ServingTensor> cache_;
  51. };
  52. class ServingReply : public inference::ReplyBase {
  53. public:
  54. explicit ServingReply(ms_serving::PredictReply &reply) : reply_(reply) {}
  55. size_t size() const override;
  56. inference::InferTensorBase *operator[](size_t index) override;
  57. const inference::InferTensorBase *operator[](size_t index) const override;
  58. inference::InferTensorBase *add() override;
  59. void clear() override;
  60. private:
  61. ms_serving::PredictReply &reply_;
  62. std::vector<ServingTensor> cache_;
  63. };
  64. } // namespace serving
  65. } // namespace mindspore
  66. #endif // MINDSPORE_SERVING_TENSOR_H_