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_array.cc 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2021 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. #include "runtime/device/tensor_array.h"
  17. namespace mindspore {
  18. namespace device {
  19. bool TensorArray::CheckValue(const TypeId &dtype, const std::vector<size_t> &shape) {
  20. MS_LOG(DEBUG) << "Check the data shape and type for " << name_;
  21. if (dtype != dtype_->type_id()) {
  22. MS_LOG(ERROR) << "Invalid data type " << TypeIdLabel(dtype) << " for " << name_ << ", the origin type is "
  23. << TypeIdLabel(dtype_->type_id());
  24. return false;
  25. }
  26. if (shape != shapes_) {
  27. MS_LOG(ERROR) << "Invalid data shape " << shape << " for " << name_ << ", the origin shape is " << shapes_;
  28. return false;
  29. }
  30. return true;
  31. }
  32. bool TensorArray::CheckReadIndexLogical(const int64_t index) {
  33. if (LongToSize(index) >= valid_size_) {
  34. MS_LOG(ERROR) << "Index " << index << " out of range " << valid_size_ << ", " << name_;
  35. return false;
  36. }
  37. return true;
  38. }
  39. // Function Read() can get the tensors in the scope of tensors_.
  40. mindspore::kernel::AddressPtr TensorArray::Read(const int64_t index) {
  41. if (LongToSize(index) >= tensors_.size()) {
  42. MS_LOG(EXCEPTION) << "Index " << index << " out of range " << tensors_.size() << ", " << name_;
  43. }
  44. MS_LOG(DEBUG) << "Read tensor index = " << index << ", addr = " << tensors_[LongToSize(index)]->addr;
  45. return tensors_[LongToSize(index)];
  46. }
  47. void TensorArray::Clear() {
  48. valid_size_ = 0;
  49. return;
  50. }
  51. size_t TensorArray::GetRealSize() const { return valid_size_; }
  52. void TensorArray::SetMaxSize(const int64_t size, const bool is_dynamic) {
  53. MS_LOG(DEBUG) << name_ << " use default SetTensorArrayMaxSize, and keep it empty";
  54. return;
  55. }
  56. } // namespace device
  57. } // namespace mindspore