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.

tensor.h 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <vector>
  19. #include "common/tensor_base.h"
  20. namespace mindspore::serving {
  21. class MS_API Tensor : public TensorBase {
  22. public:
  23. Tensor();
  24. Tensor(DataType type, std::vector<int64_t> shape, const void *data, size_t data_len);
  25. ~Tensor() = default;
  26. void set_data_type(DataType type) override { type_ = type; }
  27. DataType data_type() const override { return type_; }
  28. void set_shape(const std::vector<int64_t> &shape) override { shape_ = shape; }
  29. std::vector<int64_t> shape() const override { return shape_; }
  30. const uint8_t *data() const override;
  31. size_t data_size() const override;
  32. bool resize_data(size_t data_len) override;
  33. uint8_t *mutable_data() override;
  34. // For kMSI_String and kMSI_Bytes
  35. void clear_bytes_data() override;
  36. void add_bytes_data(const uint8_t *data, size_t bytes_len) override;
  37. size_t bytes_data_size() const override;
  38. void get_bytes_data(size_t index, const uint8_t **data, size_t *bytes_len) const override;
  39. private:
  40. DataType type_;
  41. std::vector<int64_t> shape_;
  42. std::vector<uint8_t> data_;
  43. // For kMSI_String and kMSI_Bytes
  44. std::vector<std::vector<uint8_t>> bytes_;
  45. };
  46. class MS_API VectorTensorWrapReply : public ReplyBase {
  47. public:
  48. explicit VectorTensorWrapReply(std::vector<Tensor> *tensor_list);
  49. ~VectorTensorWrapReply();
  50. size_t size() const override;
  51. TensorBase *operator[](size_t index) override;
  52. const TensorBase *operator[](size_t index) const override;
  53. TensorBase *add() override;
  54. void clear() override;
  55. private:
  56. std::vector<Tensor> *tensor_list_;
  57. };
  58. class MS_API VectorTensorWrapRequest : public RequestBase {
  59. public:
  60. explicit VectorTensorWrapRequest(const std::vector<Tensor> &tensor_list) : tensor_list_(tensor_list) {}
  61. ~VectorTensorWrapRequest() = default;
  62. size_t size() const override { return tensor_list_.size(); }
  63. const TensorBase *operator[](size_t index) const override;
  64. private:
  65. const std::vector<Tensor> &tensor_list_;
  66. };
  67. class MS_API VectorTensorPtrWrapReply : public ReplyBase {
  68. public:
  69. explicit VectorTensorPtrWrapReply(std::vector<TensorBasePtr> *tensor_list, std::function<TensorBasePtr()> create_fun);
  70. ~VectorTensorPtrWrapReply();
  71. size_t size() const override;
  72. TensorBase *operator[](size_t index) override;
  73. const TensorBase *operator[](size_t index) const override;
  74. TensorBase *add() override;
  75. void clear() override;
  76. private:
  77. std::vector<TensorBasePtr> *tensor_list_;
  78. std::function<TensorBasePtr()> tensor_create_fun_;
  79. };
  80. class MS_API VectorTensorPtrWrapRequest : public RequestBase {
  81. public:
  82. explicit VectorTensorPtrWrapRequest(const std::vector<TensorBasePtr> &tensor_list) : tensor_list_(tensor_list) {}
  83. ~VectorTensorPtrWrapRequest() = default;
  84. size_t size() const override { return tensor_list_.size(); }
  85. const TensorBase *operator[](size_t index) const override;
  86. private:
  87. std::vector<TensorBasePtr> tensor_list_;
  88. };
  89. } // namespace mindspore::serving
  90. #endif // MINDSPORE_SERVING_TENSOR_H

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.