1 /** 2 * Copyright 2020-2022 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 17 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_DETENSOR_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_DETENSOR_H_ 19 #include <string> 20 #include <vector> 21 #include <memory> 22 #include <functional> 23 #include "include/api/status.h" 24 #include "include/api/types.h" 25 #include "mindspore/core/ir/api_tensor_impl.h" 26 27 namespace mindspore { 28 namespace dataset { 29 class Tensor; 30 class DeviceTensor; 31 32 class DETensor : public mindspore::MSTensor::Impl { 33 public: 34 DETensor() = default; 35 ~DETensor() = default; 36 explicit DETensor(std::shared_ptr<dataset::Tensor> tensor_impl); 37 #ifndef ENABLE_ANDROID 38 DETensor(std::shared_ptr<dataset::DeviceTensor> device_tensor_impl, bool is_device); 39 #endif 40 const std::string &Name() const override; 41 42 enum mindspore::DataType DataType() const override; 43 44 size_t DataSize() const override; 45 46 const std::vector<int64_t> &Shape() const override; SetShape(const std::vector<int64_t> & shape)47 void SetShape(const std::vector<int64_t> &shape) override { shape_ = shape; }; 48 49 int64_t ElementNum() const; 50 51 std::shared_ptr<const void> Data() const override; 52 53 void *MutableData() override; 54 55 bool IsDevice() const override; 56 57 std::shared_ptr<mindspore::MSTensor::Impl> Clone() const override; 58 59 private: 60 std::shared_ptr<dataset::Tensor> tensor_impl_; 61 #ifndef ENABLE_ANDROID 62 std::shared_ptr<dataset::DeviceTensor> device_tensor_impl_; 63 #endif 64 bool is_device_; 65 std::string name_; 66 enum mindspore::DataType type_; 67 std::vector<int64_t> shape_; 68 }; 69 } // namespace dataset 70 } // namespace mindspore 71 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_DETENSOR_H_ 72