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.

ms_tensor.h 2.2 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_INCLUDE_MS_TENSOR_H_
  17. #define MINDSPORE_INCLUDE_MS_TENSOR_H_
  18. #include <utility>
  19. #include <vector>
  20. #include <memory>
  21. #include "mindspore/core/ir/dtype/type_id.h"
  22. namespace mindspore {
  23. #define MS_API __attribute__((visibility("default")))
  24. namespace inference {
  25. class MS_API MSTensor {
  26. public:
  27. MSTensor() = default;
  28. // brief Create a MSTensor pointer.
  29. //
  30. // param data_type DataTypeId of tensor to be created.
  31. // param shape Shape of tensor to be created.
  32. // return MSTensor pointer.
  33. static MSTensor *CreateTensor(TypeId data_type, const std::vector<int> &shape);
  34. ~MSTensor() = default;
  35. virtual TypeId data_type() const = 0;
  36. virtual TypeId set_data_type(const TypeId data_type) = 0;
  37. virtual std::vector<int> shape() const = 0;
  38. virtual size_t set_shape(const std::vector<int> &shape) = 0;
  39. virtual int DimensionSize(size_t index) const = 0;
  40. // brief Get number of element in MSTensor.
  41. //
  42. // return Number of element in MSTensor.
  43. virtual int ElementsNum() const = 0;
  44. virtual std::size_t hash() const = 0;
  45. // brief Get byte size of data in MSTensor.
  46. //
  47. // return Byte size of data in MSTensor.
  48. virtual size_t Size() const = 0;
  49. // brief Get pointer of data in MSTensor.
  50. //
  51. // The data pointer can be used to both write or read data in MSTensor.
  52. //
  53. // return A pointer points to data in MSTensor.
  54. virtual void *MutableData() const = 0;
  55. };
  56. using MultiTensor = std::vector<std::shared_ptr<inference::MSTensor>>;
  57. } // namespace inference
  58. } // namespace mindspore
  59. #endif // MINDSPORE_INCLUDE_MS_TENSOR_H_