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 3.1 kB

5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_LITE_INCLUDE_MS_TENSOR_H_
  17. #define MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_
  18. #include <functional>
  19. #include <memory>
  20. #include <string>
  21. #include <utility>
  22. #include <vector>
  23. #include "ir/dtype/type_id.h"
  24. namespace mindspore {
  25. #define MS_API __attribute__((visibility("default")))
  26. namespace tensor {
  27. /// \brief MSTensor defined tensor in MindSpore Lite.
  28. class MS_API MSTensor {
  29. public:
  30. /// \brief Constructor of MindSpore Lite MSTensor.
  31. ///
  32. /// \return Instance of MindSpore Lite MSTensor.
  33. MSTensor() = default;
  34. /// \brief Destructor of MindSpore Lite Model.
  35. virtual ~MSTensor() = default;
  36. /// \brief Get data type of the MindSpore Lite MSTensor.
  37. ///
  38. /// \note TypeId is defined in mindspore/mindspore/core/ir/dtype/type_id.h. Only number types in TypeId enum are
  39. /// suitable for MSTensor.
  40. ///
  41. /// \return MindSpore Lite TypeId of the MindSpore Lite MSTensor.
  42. virtual TypeId data_type() const = 0;
  43. /// \brief Get shape of the MindSpore Lite MSTensor.
  44. ///
  45. /// \return A vector of int as the shape of the MindSpore Lite MSTensor.
  46. virtual std::vector<int> shape() const = 0;
  47. /// \brief Get size of the dimension of the MindSpore Lite MSTensor index by the parameter index.
  48. ///
  49. /// \param[in] index Define index of dimension returned.
  50. ///
  51. /// \return Size of dimension of the MindSpore Lite MSTensor.
  52. virtual int DimensionSize(size_t index) const = 0;
  53. /// \brief Get number of element in MSTensor.
  54. ///
  55. /// \return Number of element in MSTensor.
  56. virtual int ElementsNum() const = 0;
  57. /// \brief Get byte size of data in MSTensor.
  58. ///
  59. /// \return Byte size of data in MSTensor.
  60. virtual size_t Size() const = 0;
  61. /// \brief Get the pointer of data in MSTensor.
  62. ///
  63. /// \note The data pointer can be used to both write and read data in MSTensor.
  64. ///
  65. /// \return the pointer points to data in MSTensor.
  66. virtual void *MutableData() = 0;
  67. };
  68. } // namespace tensor
  69. /// \brief CallBackParam defined input arguments for callBack function.
  70. struct CallBackParam {
  71. std::string node_name; /**< node name argument */
  72. std::string node_type; /**< node type argument */
  73. };
  74. /// \brief KernelCallBack defined the function pointer for callBack.
  75. using KernelCallBack = std::function<bool(std::vector<tensor::MSTensor *> inputs,
  76. std::vector<tensor::MSTensor *> outputs, const CallBackParam &opInfo)>;
  77. } // namespace mindspore
  78. #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_