prepare to support int64

pull/5055/head
lirongzhen1 5 years ago
parent e3899c552c
commit 531ad4df70

@ -371,9 +371,9 @@ bool IsNeedPadding(const std::string &format, const size_t shape_size) {
return false;
}
std::vector<int> GetRuntimePaddingShape(const AnfNodePtr &node, size_t index) {
ShapeVector GetRuntimePaddingShape(const AnfNodePtr &node, size_t index) {
MS_EXCEPTION_IF_NULL(node);
std::vector<int> shape;
ShapeVector shape;
std::vector<size_t> host_shape;
if (node->isa<ValueNode>()) {
auto value_node = node->cast<ValueNodePtr>();

@ -26,6 +26,7 @@
#include "ir/dtype.h"
#include "backend/kernel_compiler/kernel.h"
#include "ir/dtype/type.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace trans {
@ -52,7 +53,7 @@ size_t ShapeSize(const std::vector<size_t> &shape);
size_t CubeSizeByType(const TypeId data_type);
std::vector<size_t> PaddingShapeTo4d(const std::vector<size_t> &shape, const std::vector<Axis> &padding_axis = {});
std::vector<int> GetRuntimePaddingShape(const AnfNodePtr &node, size_t index);
ShapeVector GetRuntimePaddingShape(const AnfNodePtr &node, size_t index);
bool IsNeedPadding(const std::string &format, const size_t shape_size);
std::vector<size_t> TransShapeToDevice(const std::vector<size_t> &shape, const std::string &format);
bool TransDataType(const TypeIdArgs &args, void *result);

@ -28,6 +28,7 @@
#include "frontend/parallel/ps/util.h"
#include "frontend/parallel/ps/common.h"
#include "frontend/parallel/ps/worker_proxy.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace parallel {
@ -41,15 +42,15 @@ class Worker {
}
void Run();
void Push(const std::vector<size_t> &keys, std::vector<uintptr_t> addrs, const std::vector<int> &sizes);
void Push(const std::vector<size_t> &keys, std::vector<uintptr_t> addrs, const ShapeVector &sizes);
void Pull(const size_t key, void *dev_addr, const size_t size);
size_t SetParamKey(const std::string &param_name);
void SetParamInitInServer(const std::string &param_name, bool init_in_server);
bool GetParamInitInServer(const std::string &param_name);
void SetKeyOptimId(size_t key, const std::string &optimizer_name);
void SetOptimInputShapes(size_t key, const std::vector<int> &shape);
void SetOptimInputShapes(size_t key, const ShapeVector &shape);
void AddEmbeddingTable(const ::ps::Key &key, const size_t &row_count);
void InitPSEmbeddingTable(const std::vector<size_t> &keys, std::vector<size_t> shapes, const std::vector<int> &sizes);
void InitPSEmbeddingTable(const std::vector<size_t> &keys, std::vector<size_t> shapes, const ShapeVector &sizes);
void InitPSParamAndOptim(const std::string &param_name, tensor::TensorPtr tensor);
void DoPSEmbeddingLookup(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray<int> &lookup_ids,
const ::ps::SArray<int> &lens, ::ps::SArray<T> *lookup_result, int cmd);
@ -75,7 +76,7 @@ class Worker {
std::map<std::string, size_t> param_to_key_;
std::map<size_t, bool> init_keys_;
std::map<size_t, int> key_to_optimId_;
std::map<size_t, std::vector<std::vector<int>>> key_to_optim_shapes_;
std::map<size_t, std::vector<ShapeVector>> key_to_optim_shapes_;
std::map<std::string, bool> param_to_init_in_server_;
};
@ -94,7 +95,7 @@ void Worker<T>::Run() {
}
template <typename T>
void Worker<T>::Push(const std::vector<size_t> &keys, std::vector<uintptr_t> addrs, const std::vector<int> &sizes) {
void Worker<T>::Push(const std::vector<size_t> &keys, std::vector<uintptr_t> addrs, const ShapeVector &sizes) {
size_t total_size = 0;
for (auto size : sizes) {
total_size += size;
@ -154,7 +155,7 @@ void Worker<T>::InitPSParamData(const std::vector<size_t> &keys, void *origin_ad
}
template <typename T>
void Worker<T>::SetOptimInputShapes(size_t key, const std::vector<int> &shape) {
void Worker<T>::SetOptimInputShapes(size_t key, const ShapeVector &shape) {
if (key_to_optim_shapes_.find(key) == key_to_optim_shapes_.end()) {
key_to_optim_shapes_[key] = {shape};
} else {
@ -167,7 +168,7 @@ void Worker<T>::InitPSOptimInputShapes(const size_t key) {
::ps::SArray<::ps::Key> keys;
::ps::SArray<int> shape_len;
::ps::SArray<T> all_shape;
std::vector<std::vector<int>> shapes = key_to_optim_shapes_[key];
std::vector<ShapeVector> shapes = key_to_optim_shapes_[key];
for (auto shape : shapes) {
keys.push_back(key);
if (shape.size() == 0) {
@ -255,7 +256,7 @@ void Worker<T>::InitPSOptimId(const size_t param_key) {
template <typename T>
void Worker<T>::InitPSEmbeddingTable(const std::vector<size_t> &keys, std::vector<size_t> shapes,
const std::vector<int> &sizes) {
const ShapeVector &sizes) {
bool has_init = IsKeyInit(keys[0]);
if (has_init) {
MS_LOG(DEBUG) << "The key embedding table of key " << keys[0] << " is initialized.";
@ -272,7 +273,7 @@ template <typename T>
void Worker<T>::InitPSParamAndOptim(const std::string &param_name, tensor::TensorPtr tensor) {
void *param_data = tensor->data_c();
size_t param_size = LongToSize(tensor->data().nbytes());
std::vector<int> param_shape = tensor->shape_c();
ShapeVector param_shape = tensor->shape_c();
size_t param_key = GetParamKey(param_name);
if (param_key == kInvalidKey) {
@ -280,7 +281,7 @@ void Worker<T>::InitPSParamAndOptim(const std::string &param_name, tensor::Tenso
return;
}
bool init_in_server = false;
std::vector<int> shape_init_in_server = {1};
ShapeVector shape_init_in_server = {1};
if (param_shape == shape_init_in_server) {
init_in_server = true;
}

@ -42,7 +42,7 @@
#include "frontend/optimizer/py_pass_manager.h"
#include "pybind_api/pybind_patch.h"
#include "backend/kernel_compiler/cpu/random_op_cpu_kernel.h"
#include "utils/shape_utils.h"
#if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
#include "frontend/parallel/ps/common.h"
#include "frontend/parallel/ps/util.h"
@ -136,10 +136,10 @@ py::bool_ VerifyInputSignature(const py::list input_signature, const py::tuple i
return false;
}
std::shared_ptr<MetaTensor> sig = input_signature[count].cast<std::shared_ptr<MetaTensor>>();
std::vector<int> sig_shape = sig->shape();
ShapeVector sig_shape = sig->shape();
TypePtr sig_type = sig->Dtype();
std::vector<int> tensor_shape = m_tensor->shape_c();
ShapeVector tensor_shape = m_tensor->shape_c();
if (tensor_shape != sig_shape) {
MS_LOG(ERROR) << "Python input shape is incompatible with input_signature";
return false;
@ -849,13 +849,13 @@ bool InitExecDatasetVm(const std::string &queue_name, int64_t size, int64_t batc
const std::vector<TypePtr> &types, const std::vector<std::vector<int64_t>> &shapes,
const std::vector<int64_t> &input_indexes, bool need_run) {
MS_LOG(INFO) << "Start InitDataSet Entry";
std::vector<int> int_input_indexes;
ShapeVector int_input_indexes;
(void)std::transform(input_indexes.begin(), input_indexes.end(), std::back_inserter(int_input_indexes),
[](int64_t item) { return static_cast<int>(item); });
std::vector<std::vector<int>> int_shapes;
std::vector<ShapeVector> int_shapes;
(void)std::transform(shapes.begin(), shapes.end(), std::back_inserter(int_shapes),
[](const std::vector<int64_t> &item) {
std::vector<int> vector_item;
ShapeVector vector_item;
(void)std::transform(item.begin(), item.end(), std::back_inserter(vector_item),
[](int64_t inner_item) { return static_cast<int>(inner_item); });
return vector_item;

@ -39,6 +39,7 @@
#include "abstract/primitive_infer_map.h"
#include "abstract/param_validator.h"
#include "utils/ms_utils.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace abstract {
@ -309,13 +310,13 @@ py::dict ConvertAbstractToPython(const AbstractBasePtr &abs_base) {
dic["dtype"] = arg->BuildType();
dic["value"] = BuildValue(arg->BuildValue());
} else if (abs_base->isa<AbstractScalar>() || abs_base->isa<AbstractType>() || abs_base->isa<AbstractRefKey>()) {
std::vector<int> shape;
ShapeVector shape;
dic["shape"] = shape;
dic["dtype"] = abs_base->BuildType();
dic["value"] = BuildValue(abs_base->BuildValue());
} else if (abs_base->isa<AbstractSlice>()) {
auto arg_slice = dyn_cast<AbstractSlice>(abs_base);
std::vector<int> shape;
ShapeVector shape;
dic["shape"] = shape;
dic["dtype"] = arg_slice->BuildType();
dic["value"] = BuildValue(arg_slice->BuildValue());

@ -275,7 +275,7 @@ void AscendDeviceAddress::SyncStream() const {
MS_LOG(INFO) << "Finish!";
}
bool AscendDeviceAddress::SyncDeviceToHost(const std::vector<int> &shape, size_t size, mindspore::TypeId type,
bool AscendDeviceAddress::SyncDeviceToHost(const ShapeVector &shape, size_t size, mindspore::TypeId type,
void *host_ptr) const {
MS_LOG(INFO) << "SyncDeviceToHost, Device(format:" << format_ << ", type_id:" << TypeIdLabel(type_id_)
<< ", size:" << size_ << "), Host(type_id:" << TypeIdLabel(type) << ", size:" << size << ")";
@ -462,7 +462,7 @@ std::vector<size_t> AscendDeviceAddress::GetDeviceShape(std::vector<size_t> *hos
return device_shape;
}
bool AscendDeviceAddress::SyncDeviceToHostAndConvertFormat(const std::vector<int> &shape, size_t size,
bool AscendDeviceAddress::SyncDeviceToHostAndConvertFormat(const ShapeVector &shape, size_t size,
mindspore::TypeId type, void *host_ptr) const {
MS_LOG(INFO) << "SyncDeviceToHostAndConvertFormat, Device(format:" << format_ << ", type_id:" << TypeIdLabel(type_id_)
<< ", size:" << size_ << "), Host(type_id:" << TypeIdLabel(type) << ", size:" << size << ")";
@ -513,7 +513,7 @@ bool AscendDeviceAddress::SyncDeviceToHostAndConvertFormat(const std::vector<int
return sync_ok;
}
bool AscendDeviceAddress::SyncHostToDevice(const std::vector<int> &shape, size_t size, mindspore::TypeId type,
bool AscendDeviceAddress::SyncHostToDevice(const ShapeVector &shape, size_t size, mindspore::TypeId type,
const void *host_ptr) const {
MS_LOG(INFO) << "SyncHostToDevice, Device(format:" << format_ << ", type_id:" << TypeIdLabel(type_id_)
<< ", size:" << size_ << "), Host(type_id:" << TypeIdLabel(type) << ", size:" << size << ")";
@ -557,7 +557,7 @@ bool AscendDeviceAddress::SyncHostToDevice(const std::vector<int> &shape, size_t
return sync_ok;
}
bool AscendDeviceAddress::ConvertFormatAndSyncHostToDevice(const std::vector<int> &shape, size_t size,
bool AscendDeviceAddress::ConvertFormatAndSyncHostToDevice(const ShapeVector &shape, size_t size,
mindspore::TypeId type, const void *host_ptr) const {
bool sync_ok = false;
MS_LOG(INFO) << "ConvertFormatAndSyncHostToDevice, Device(format:" << format_ << ", type_id:" << TypeIdLabel(type_id_)
@ -622,7 +622,7 @@ AscendDeviceAddress::~AscendDeviceAddress() {
#ifdef ENABLE_DUMP_E2E
bool AscendDeviceAddress::DumpMemToFile(bool trans_flag, const std::string &filepath, const std::string &host_fmt,
const std::vector<int> &host_shape, TypeId host_type) const {
const ShapeVector &host_shape, TypeId host_type) const {
bool ret = false;
if (filepath.empty()) {
MS_LOG(ERROR) << "Dump file path is null!";
@ -666,8 +666,8 @@ bool AscendDeviceAddress::DumpMemToFile(bool trans_flag, const std::string &file
#ifdef ENABLE_DEBUGGER
bool AscendDeviceAddress::LoadMemToHost(bool trans_flag, const std::string &tensor_name, int execution_order,
const std::string &host_fmt, const std::vector<int> &host_shape,
TypeId host_type, size_t slot, Debugger *debugger, bool keep_prev) const {
const std::string &host_fmt, const ShapeVector &host_shape, TypeId host_type,
size_t slot, Debugger *debugger, bool keep_prev) const {
bool ret = false;
DebugServices *debug_services = debugger->debug_services();
TensorLoader *tensor_loader = debug_services->tensor_loader();

@ -25,6 +25,7 @@
#include "runtime/device/ascend/ascend_memory_pool.h"
#include "ir/dtype.h"
#include "backend/kernel_compiler/kernel.h"
#include "utils/shape_utils.h"
namespace mindspore {
#ifdef ENABLE_DEBUGGER
@ -38,23 +39,22 @@ class AscendDeviceAddress : public DeviceAddress {
explicit AscendDeviceAddress(void *ptr, size_t size, const std::string &format, TypeId type_id)
: DeviceAddress(ptr, size, format, type_id) {}
~AscendDeviceAddress() override;
bool SyncDeviceToHost(const std::vector<int> &shape, size_t size, TypeId type, void *host_ptr) const override;
bool SyncHostToDevice(const std::vector<int> &shape, size_t size, TypeId type, const void *host_ptr) const override;
bool SyncDeviceToHost(const ShapeVector &shape, size_t size, TypeId type, void *host_ptr) const override;
bool SyncHostToDevice(const ShapeVector &shape, size_t size, TypeId type, const void *host_ptr) const override;
DeviceAddressType DeviceType() const override { return DeviceAddressType::kAscend; }
#ifdef ENABLE_DUMP_E2E
bool DumpMemToFile(bool dump_mode, const std::string &filepath, const std::string &host_fmt,
const std::vector<int> &host_shape, TypeId host_type) const;
const ShapeVector &host_shape, TypeId host_type) const;
#endif
#ifdef ENABLE_DEBUGGER
bool LoadMemToHost(bool dump_mode, const std::string &tensor_name, int execution_order, const std::string &host_fmt,
const std::vector<int> &host_shape, TypeId host_type, size_t slot, Debugger *debugger,
const ShapeVector &host_shape, TypeId host_type, size_t slot, Debugger *debugger,
bool keep_prev) const;
#endif
private:
bool SyncDeviceToHostAndConvertFormat(const std::vector<int> &shape, size_t size, TypeId type, void *host_ptr) const;
bool ConvertFormatAndSyncHostToDevice(const std::vector<int> &shape, size_t size, TypeId type,
const void *host_ptr) const;
bool SyncDeviceToHostAndConvertFormat(const ShapeVector &shape, size_t size, TypeId type, void *host_ptr) const;
bool ConvertFormatAndSyncHostToDevice(const ShapeVector &shape, size_t size, TypeId type, const void *host_ptr) const;
bool SyncDeviceToHostAndConvertFormatBasedOnTransData(const std::vector<size_t> &host_shape,
const std::vector<size_t> &device_shape, size_t size,
mindspore::TypeId type, void *host_ptr) const;

@ -39,6 +39,7 @@
#include "backend/kernel_compiler/tbe/tbe_utils.h"
#include "runtime/device/ascend/ascend_memory_manager.h"
#include "debug/tensor_load.h"
#include "utils/shape_utils.h"
#ifdef MEM_REUSE_DEBUG
#include "backend/optimizer/mem_reuse/mem_reuse_checker.h"
#endif
@ -231,7 +232,7 @@ void DumpOutput(mindspore::session::KernelGraph *graph, const string &dump_path,
auto output_size = AnfAlgo::GetOutputTensorNum(node);
for (size_t j = 0; j < output_size; ++j) {
auto addr = AnfAlgo::GetOutputAddr(node, j);
std::vector<int> int_shapes;
ShapeVector int_shapes;
if (trans_flag) {
int_shapes = trans::GetRuntimePaddingShape(node, j);
} else {
@ -266,7 +267,7 @@ void DumpParameters(mindspore::session::KernelGraph *graph, const string &dump_p
continue;
}
auto addr = AnfAlgo::GetOutputAddr(item, PRAMATER_OUTPUT_INDEX);
std::vector<int> int_shapes;
ShapeVector int_shapes;
if (trans_flag) {
int_shapes = trans::GetRuntimePaddingShape(item, PRAMATER_OUTPUT_INDEX);
} else {
@ -351,7 +352,7 @@ void LoadOutput(mindspore::session::KernelGraph *graph, Debugger *debugger) {
auto format = kOpFormat_DEFAULT;
string tensor_name = kernel_name + ':' + std::to_string(j);
auto ascend_addr = dynamic_cast<const mindspore::device::ascend::AscendDeviceAddress *>(addr);
std::vector<int> int_shapes;
ShapeVector int_shapes;
if (trans_flag) {
int_shapes = trans::GetRuntimePaddingShape(node, j);
} else {
@ -387,7 +388,7 @@ void LoadParameters(mindspore::session::KernelGraph *graph, Debugger *debugger)
auto format = kOpFormat_DEFAULT;
string tensor_name = parameter_name + ':' + "0";
auto ascend_addr = dynamic_cast<const mindspore::device::ascend::AscendDeviceAddress *>(addr);
std::vector<int> int_shapes;
ShapeVector int_shapes;
if (trans_flag) {
int_shapes = trans::GetRuntimePaddingShape(item, PRAMATER_OUTPUT_INDEX);
} else {

@ -20,8 +20,7 @@
namespace mindspore {
namespace device {
namespace cpu {
bool CPUDeviceAddress::SyncDeviceToHost(const std::vector<int> & /*shape*/, size_t size, TypeId type,
void *host_ptr) const {
bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector & /*shape*/, size_t size, TypeId type, void *host_ptr) const {
if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The pointer ptr_ is null!";
return false;
@ -50,7 +49,7 @@ bool CPUDeviceAddress::SyncDeviceToHost(const std::vector<int> & /*shape*/, size
return true;
}
bool CPUDeviceAddress::SyncHostToDevice(const std::vector<int> & /*shape*/, size_t size, TypeId type,
bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /*shape*/, size_t size, TypeId type,
const void *host_ptr) const {
if (host_ptr == ptr_) {
MS_LOG(DEBUG) << "host_ptr is equal to ptr_, request ignored.";

@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include "runtime/device/device_address.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace device {
@ -32,8 +33,8 @@ class CPUDeviceAddress : public DeviceAddress {
~CPUDeviceAddress() override = default;
bool SyncDeviceToHost(const std::vector<int> &shape, size_t size, TypeId type, void *host_ptr) const override;
bool SyncHostToDevice(const std::vector<int> &shape, size_t size, TypeId type, const void *host_ptr) const override;
bool SyncDeviceToHost(const ShapeVector &shape, size_t size, TypeId type, void *host_ptr) const override;
bool SyncHostToDevice(const ShapeVector &shape, size_t size, TypeId type, const void *host_ptr) const override;
DeviceAddressType DeviceType() const override { return DeviceAddressType::kCPU; }
};
} // namespace cpu

@ -25,6 +25,7 @@
#include "backend/session/anf_runtime_algorithm.h"
#include "backend/session/session_basic.h"
#include "frontend/operator/ops.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace device {
@ -52,7 +53,7 @@ void CPUKernelRuntime::AssignValueNodeAddress(session::KernelGraph *kernel_graph
}
auto tensor = node_value->cast<TensorPtr>();
MS_EXCEPTION_IF_NULL(tensor);
std::vector<int> data_shape = tensor->shape();
ShapeVector data_shape = tensor->shape();
size_t tensor_size = std::accumulate(data_shape.begin(), data_shape.end(), type_size, std::multiplies<size_t>());
DeviceAddressPtr address = CreateDeviceAddress(nullptr, tensor_size, kOpFormat_DEFAULT, kNumberTypeFloat32);
MS_EXCEPTION_IF_NULL(address);
@ -135,7 +136,7 @@ tensor::TensorPtr CPUKernelRuntime::CreatTensorForOutput(session::KernelGraph *k
tensor::TensorPtr tensor = kernel_graph->GetInternalOutputTensor(node, index);
if (tensor == nullptr) {
auto shape = AnfAlgo::GetOutputInferShape(node, index);
std::vector<int> temp_shape;
ShapeVector temp_shape;
(void)temp_shape.insert(temp_shape.end(), shape.begin(), shape.end());
tensor = std::make_shared<tensor::Tensor>(infer_type_id, temp_shape);
bool is_internal_output = kernel_graph->IsInternalOutput(node, index);
@ -149,7 +150,7 @@ tensor::TensorPtr CPUKernelRuntime::CreatTensorForOutput(session::KernelGraph *k
} else {
if (infer_type_id != device_type_id) {
size_t type_size = GetTypeByte(TypeIdToType(device_type_id));
std::vector<int> data_shape = tensor->shape();
ShapeVector data_shape = tensor->shape();
size_t tensor_size = std::accumulate(data_shape.begin(), data_shape.end(), type_size, std::multiplies<size_t>());
address->ptr_ = resource_manager_.MemMalloc(tensor_size);
need_sync_outputs->emplace_back(tensor);
@ -224,7 +225,7 @@ void CPUKernelRuntime::BindInputOutput(session::KernelGraph *kernel_graph, const
tensor->data_type() == kNumberTypeInt32) {
address->ptr_ = tensor->data_c();
} else {
std::vector<int> data_shape = tensor->shape();
ShapeVector data_shape = tensor->shape();
size_t tensor_size =
std::accumulate(data_shape.begin(), data_shape.end(), sizeof(float), std::multiplies<size_t>());
address->ptr_ = resource_manager_.MemMalloc(tensor_size);

@ -22,6 +22,7 @@
#include <memory>
#include "ir/dtype.h"
#include "ir/device_sync.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace device {
@ -60,7 +61,7 @@ class DeviceAddress : public mindspore::DeviceSync {
size_t GetSize() const { return size_; }
std::string format() const { return format_; }
TypeId type_id() const { return type_id_; }
void set_host_shape(const std::vector<int> &shape) { host_shape_ = shape; }
void set_host_shape(const ShapeVector &shape) { host_shape_ = shape; }
virtual void set_status(DeviceAddressStatus status) {}
virtual DeviceAddressStatus status() const { return DeviceAddressStatus::kInDevice; }
virtual DeviceAddressType DeviceType() const { return DeviceAddressType::kUnknown; }
@ -77,7 +78,7 @@ class DeviceAddress : public mindspore::DeviceSync {
TypeId type_id_{kNumberTypeFloat16};
bool from_mem_pool_{false};
uint8_t *communication_ptr_{nullptr};
std::vector<int> host_shape_{};
ShapeVector host_shape_{};
friend class KernelRuntime;
friend class MemoryManager;
friend class mindspore::device::ascend::tasksink::TaskGenerator;

@ -30,7 +30,7 @@
namespace mindspore {
namespace device {
namespace gpu {
bool GPUDeviceAddress::SyncDeviceToHost(const std::vector<int> &, size_t size, TypeId, void *host_ptr) const {
bool GPUDeviceAddress::SyncDeviceToHost(const ShapeVector &, size_t size, TypeId, void *host_ptr) const {
MS_EXCEPTION_IF_NULL(host_ptr);
bool need_sync = (size != 0) && (size_ != 0);
if (!need_sync) {
@ -50,7 +50,7 @@ bool GPUDeviceAddress::SyncDeviceToHost(const std::vector<int> &, size_t size, T
return GPUDeviceManager::GetInstance().CopyDeviceMemToHost(host_ptr, ptr_, size);
}
bool GPUDeviceAddress::SyncHostToDevice(const std::vector<int> &, size_t size, TypeId, const void *host_ptr) const {
bool GPUDeviceAddress::SyncHostToDevice(const ShapeVector &, size_t size, TypeId, const void *host_ptr) const {
MS_EXCEPTION_IF_NULL(host_ptr);
bool need_sync = (size != 0) && (size_ != 0);
if (!need_sync) {
@ -80,8 +80,8 @@ GPUDeviceAddress::~GPUDeviceAddress() {
}
#ifdef ENABLE_DEBUGGER
bool GPUDeviceAddress::LoadMemToHost(const std::string &tensor_name, int execution_order, const std::string &host_fmt,
const std::vector<int> &host_shape, TypeId host_type, size_t slot,
Debugger *debugger, bool keep_prev) const {
const ShapeVector &host_shape, TypeId host_type, size_t slot, Debugger *debugger,
bool keep_prev) const {
bool ret = false;
if (size_ == 0) {
return true;

@ -21,6 +21,8 @@
#include <vector>
#include "runtime/device/device_address.h"
using ShapeVecotr = std::vector<int>;
namespace mindspore {
#ifdef ENABLE_DEBUGGER
class Debugger;
@ -34,15 +36,15 @@ class GPUDeviceAddress : public DeviceAddress {
: DeviceAddress(ptr, size, format, type_id) {}
~GPUDeviceAddress() override;
bool SyncDeviceToHost(const std::vector<int> &shape, size_t size, TypeId type, void *host_ptr) const override;
bool SyncHostToDevice(const std::vector<int> &shape, size_t size, TypeId type, const void *host_ptr) const override;
bool SyncDeviceToHost(const ShapeVector &shape, size_t size, TypeId type, void *host_ptr) const override;
bool SyncHostToDevice(const ShapeVector &shape, size_t size, TypeId type, const void *host_ptr) const override;
void set_status(DeviceAddressStatus status) { status_ = status; }
DeviceAddressStatus status() const { return status_; }
DeviceAddressType DeviceType() const override { return DeviceAddressType::kGPU; }
#ifdef ENABLE_DEBUGGER
bool LoadMemToHost(const std::string &tensor_name, int execution_order, const std::string &host_fmt,
const std::vector<int> &host_shape, TypeId host_type, size_t slot, Debugger *debugger,
const ShapeVector &host_shape, TypeId host_type, size_t slot, Debugger *debugger,
bool keep_prev) const;
#endif
private:

@ -32,6 +32,7 @@
#include "common/trans.h"
#include "ir/dtype.h"
#include "profiler/device/gpu/gpu_profiling.h"
#include "utils/shape_utils.h"
#ifdef ENABLE_DEBUGGER
#include "debug/debug_services.h"
#endif
@ -107,7 +108,7 @@ void DumpOutput(mindspore::session::KernelGraph *graph, const string &dump_path,
auto addr = AnfAlgo::GetOutputAddr(node, j);
TypeId addr_type_id = addr->type_id();
std::string addr_format = addr->format();
std::vector<int> int_shapes;
ShapeVector int_shapes;
if (trans_flag) {
int_shapes = trans::GetRuntimePaddingShape(node, j);
} else {
@ -153,7 +154,7 @@ void DumpParameters(mindspore::session::KernelGraph *graph, const string &dump_p
auto addr = AnfAlgo::GetOutputAddr(item, PARAMETER_OUTPUT_INDEX);
TypeId addr_type_id = addr->type_id();
std::string addr_format = addr->format();
std::vector<int> int_shapes;
ShapeVector int_shapes;
if (trans_flag) {
int_shapes = trans::GetRuntimePaddingShape(item, PARAMETER_OUTPUT_INDEX);
} else {
@ -251,7 +252,7 @@ void LoadKernelData(Debugger *debugger, const CNodePtr &kernel,
auto format = kOpFormat_DEFAULT;
auto gpu_addr = std::make_unique<GPUDeviceAddress>(addr->addr, addr->size, format, type);
string input_tensor_name = input_kernel_name + ':' + "0";
std::vector<int> int_shapes;
ShapeVector int_shapes;
auto shape = AnfAlgo::GetOutputDeviceShape(input_kernel, PARAMETER_OUTPUT_INDEX);
(void)std::transform(shape.begin(), shape.end(), std::back_inserter(int_shapes),
[](size_t inner_item) { return SizeToInt(inner_item); });
@ -270,7 +271,7 @@ void LoadKernelData(Debugger *debugger, const CNodePtr &kernel,
auto format = kOpFormat_DEFAULT;
auto gpu_addr = std::make_unique<GPUDeviceAddress>(addr->addr, addr->size, format, type);
string tensor_name = kernel_name + ':' + std::to_string(j);
std::vector<int> int_shapes;
ShapeVector int_shapes;
auto shape = AnfAlgo::GetOutputDeviceShape(kernel, j);
(void)std::transform(shape.begin(), shape.end(), std::back_inserter(int_shapes),
[](size_t inner_item) { return SizeToInt(inner_item); });
@ -310,7 +311,7 @@ void LoadParameters(const session::KernelGraph *graph, Debugger *debugger, bool
auto format = kOpFormat_DEFAULT;
string tensor_name = parameter_name + ':' + "0";
auto gpu_addr = dynamic_cast<const mindspore::device::gpu::GPUDeviceAddress *>(addr);
std::vector<int> int_shapes;
ShapeVector int_shapes;
auto shape = AnfAlgo::GetOutputDeviceShape(item, PARAMETER_OUTPUT_INDEX);
(void)std::transform(shape.begin(), shape.end(), std::back_inserter(int_shapes),
[](size_t inner_item) { return SizeToInt(inner_item); });

@ -31,6 +31,7 @@
#include "runtime/device/ascend/profiling/profiling_manager.h"
#include "runtime/base.h"
#include "runtime/device/ascend/ascend_stream_assign.h"
#include "utils/shape_utils.h"
namespace {
constexpr auto kProfilingGraphId = "PROFILING_GRAPH_ID";
@ -320,7 +321,7 @@ void KernelAdjust::CreateSwitchOpParameters(const std::shared_ptr<session::Kerne
std::map<std::string, mindspore::ParameterPtr> *switch_loop_input) {
MS_EXCEPTION_IF_NULL(kernel_graph_ptr);
MS_EXCEPTION_IF_NULL(switch_loop_input);
std::vector<int> shp = {1};
ShapeVector shp = {1};
tensor::TensorPtr tensor_ptr = std::make_shared<tensor::Tensor>(kInt32->type_id(), shp);
MS_EXCEPTION_IF_NULL(tensor_ptr);
mindspore::abstract::AbstractBasePtr paremeter_abstract_ptr = tensor_ptr->ToAbstract();
@ -559,7 +560,7 @@ void KernelAdjust::LoadSwitchInputs(std::vector<tensor::TensorPtr> *inputs) {
MS_LOG(INFO) << "---------------- LoadSwitchInputs---";
MS_EXCEPTION_IF_NULL(inputs);
// current loop count
std::vector<int> shp = {1};
ShapeVector shp = {1};
tensor::TensorPtr cur_loop_count = std::make_shared<tensor::Tensor>(kInt32->type_id(), shp);
MS_EXCEPTION_IF_NULL(cur_loop_count);
int32_t *val = nullptr;

@ -27,6 +27,7 @@
#include "backend/session/anf_runtime_algorithm.h"
#include "backend/optimizer/common/helper.h"
#include "ir/value.h"
#include "utils/shape_utils.h"
using mindspore::kernel::Address;
using mindspore::kernel::AddressPtr;
@ -681,7 +682,7 @@ void KernelRuntime::AssignStaticMemoryValueNode(session::KernelGraph *graph) {
MS_LOG(EXCEPTION) << "Cannot alloc address when flag is: " << kStaticMem << ", tensor size is: " << tensor_size;
}
AnfAlgo::SetOutputAddr(address, 0, value_node.get());
std::vector<int> shape = {1, SizeToInt(tensor_size)};
ShapeVector shape = {1, SizeToInt(tensor_size)};
if (!address->SyncHostToDevice(shape, tensor_size, kNumberTypeUInt8, value.data())) {
MS_LOG(EXCEPTION) << "kValueNode SyncHostToDevice fail!";
}

@ -94,8 +94,8 @@ GeFormat TransformUtil::ConvertFormat(const string &format) {
static int64_t IntegerCastFunc(size_t temp) { return static_cast<int64_t>(temp); }
std::shared_ptr<GeTensorDesc> TransformUtil::GetGeTensorDesc(const std::vector<int> &me_shape,
const MeDataType &me_type, const std::string &format) {
std::shared_ptr<GeTensorDesc> TransformUtil::GetGeTensorDesc(const ShapeVector &me_shape, const MeDataType &me_type,
const std::string &format) {
// convert me shape to ge shape
std::vector<int64_t> ge_shape;
@ -196,7 +196,7 @@ GeTensorPtr TransformUtil::ConvertTensor(const MeTensorPtr &tensor, const std::s
}
std::vector<MeTensorPtr> TransformUtil::ConvertGeTensors(const std::vector<GeTensorPtr> &ge_tensors,
const std::vector<std::vector<int>> &request_dims) {
const std::vector<ShapeVector> &request_dims) {
std::vector<MeTensorPtr> outputs;
for (size_t index = 0; index < ge_tensors.size(); index++) {
@ -204,7 +204,7 @@ std::vector<MeTensorPtr> TransformUtil::ConvertGeTensors(const std::vector<GeTen
if (index < request_dims.size()) {
me_tensor_ptr = ConvertGeTensor(ge_tensors[index], request_dims[index]);
} else {
std::vector<int> empty_shape;
ShapeVector empty_shape;
me_tensor_ptr = ConvertGeTensor(ge_tensors[index], empty_shape);
}
@ -270,7 +270,7 @@ MeDataType TransformUtil::ConvertGeDataType(const GeDataType &type) {
}
namespace {
bool IsGeShapeCompatible(const GeShape &ge_shape, const std::vector<int> &request_dims) {
bool IsGeShapeCompatible(const GeShape &ge_shape, const ShapeVector &request_dims) {
MS_LOG(INFO) << "GeTensor's shape is " << TransformUtil::PrintVector(ge_shape.GetDims());
MS_LOG(INFO) << "Me request shape is " << TransformUtil::PrintVector(request_dims);
@ -307,20 +307,20 @@ bool IsGeShapeCompatible(const GeShape &ge_shape, const std::vector<int> &reques
}
} // namespace
GeShape TransformUtil::ConvertMeShape(const std::vector<int> &me_dims) {
GeShape TransformUtil::ConvertMeShape(const ShapeVector &me_dims) {
std::vector<int64_t> ge_dims;
(void)std::copy(me_dims.begin(), me_dims.end(), std::back_inserter(ge_dims));
return GeShape(ge_dims);
}
std::vector<int> TransformUtil::ConvertGeShape(const GeShape &ge_shape) {
std::vector<int> me_dims;
ShapeVector TransformUtil::ConvertGeShape(const GeShape &ge_shape) {
ShapeVector me_dims;
std::vector<int64_t> ge_dims = ge_shape.GetDims();
(void)std::copy(ge_dims.begin(), ge_dims.end(), std::back_inserter(me_dims));
return me_dims;
}
std::vector<int> TransformUtil::ConvertGeShape(const GeShape &ge_shape, const std::vector<int> &request_dims) {
ShapeVector TransformUtil::ConvertGeShape(const GeShape &ge_shape, const ShapeVector &request_dims) {
vector<int> ret;
if (ge_shape.GetDimNum() == 0) {
MS_LOG(DEBUG) << "GeTensor's shape is scalar";
@ -336,7 +336,7 @@ std::vector<int> TransformUtil::ConvertGeShape(const GeShape &ge_shape, const st
return ret;
}
MeTensorPtr TransformUtil::GenerateMeTensor(const GeTensorPtr &ge_tensor, const std::vector<int> &me_dims,
MeTensorPtr TransformUtil::GenerateMeTensor(const GeTensorPtr &ge_tensor, const ShapeVector &me_dims,
const TypeId &me_type) {
MeTensor me_tensor(me_type, me_dims);
@ -380,7 +380,7 @@ MeTensorPtr TransformUtil::ConvertGeTensor(const GeTensorPtr &ge_tensor) {
}
// if request_dims is empty, use ge tensor's shape,otherwise convert to request shape
MeTensorPtr TransformUtil::ConvertGeTensor(const GeTensorPtr ge_tensor, const std::vector<int> &request_dims) {
MeTensorPtr TransformUtil::ConvertGeTensor(const GeTensorPtr ge_tensor, const ShapeVector &request_dims) {
MS_EXCEPTION_IF_NULL(ge_tensor);
GeShape ge_shape = ge_tensor->GetTensorDesc().GetShape();
vector<int> me_dims = ConvertGeShape(ge_shape, request_dims);

@ -26,8 +26,8 @@
#include "ir/dtype.h"
#include "ir/tensor.h"
#include "transform/graph_ir/types.h"
#include "graph/tensor.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace transform {
@ -73,7 +73,7 @@ class TransformUtil {
* Return
* [shared_ptr<GeTensorDesc>] the shared pointer of ge tensor description
* */
static std::shared_ptr<GeTensorDesc> GetGeTensorDesc(const std::vector<int> &shape, const MeDataType &me_type,
static std::shared_ptr<GeTensorDesc> GetGeTensorDesc(const ShapeVector &shape, const MeDataType &me_type,
const std::string &format);
/*
@ -107,20 +107,20 @@ class TransformUtil {
/*
* Parameters:
* tensor: [GeTensor] the data tensor in GE
* request_dims [std::vector<int>] the output Me tensors must adjust to this shapes
* request_dims [ShapeVector] the output Me tensors must adjust to this shapes
* Return
* [MeTensor] the data tensor in ME
* */
static MeTensorPtr ConvertGeTensor(GeTensorPtr ge_tensor, const std::vector<int> &request_dims);
static MeTensorPtr ConvertGeTensor(GeTensorPtr ge_tensor, const ShapeVector &request_dims);
/*
* Parameters:
* ge_tensors: [std::vector<GeTensorPtr>] the data tensor in GE
* request_dims [std::vector<std::vector<int>>] the output Me tensors must adjust to this shapes
* request_dims [std::vector<ShapeVector>] the output Me tensors must adjust to this shapes
* Return
* [std::vector<MeTensorPtr>] the data tensor in ME
* */
static std::vector<MeTensorPtr> ConvertGeTensors(const std::vector<GeTensorPtr> &ge_tensors,
const std::vector<std::vector<int>> &request_dims);
const std::vector<ShapeVector> &request_dims);
/*
* Parameters:
* ge_tensors: [std::vector<GeTensorPtr>] the data tensor in GE
@ -131,13 +131,12 @@ class TransformUtil {
/*
* Parameters:
* ge_tensor: [GeTensor] the data tensor in GE
* me_dims: [std::vector<int>] the shape of created Me tensor
* me_dims: [ShapeVector] the shape of created Me tensor
* me_type: [TypeId] the type of created Me tensor
* Return
* [MeTensor] the data tensor in ME
* */
static MeTensorPtr GenerateMeTensor(const GeTensorPtr &ge_tensor, const std::vector<int> &me_dims,
const TypeId &me_type);
static MeTensorPtr GenerateMeTensor(const GeTensorPtr &ge_tensor, const ShapeVector &me_dims, const TypeId &me_type);
/*
* Parameters:
* type: [GeDataType] the ge tensor data type
@ -148,11 +147,11 @@ class TransformUtil {
/*
* Parameters:
* me_dims: [std::vector<int>] the me shape
* me_dims: [ShapeVector] the me shape
* Return
* [GeShape] the ge shape
* */
static GeShape ConvertMeShape(const std::vector<int> &me_dims);
static GeShape ConvertMeShape(const ShapeVector &me_dims);
/*
* Parameters:
@ -160,7 +159,7 @@ class TransformUtil {
* Return
* [vector<int>] the me shape
* */
static std::vector<int> ConvertGeShape(const GeShape &ge_shape);
static ShapeVector ConvertGeShape(const GeShape &ge_shape);
/* Function:
* Convert GeShape to Me request shape, Support pattern:
@ -176,11 +175,11 @@ class TransformUtil {
* Return
* [vector<int>] the me shape
* */
static std::vector<int> ConvertGeShape(const GeShape &ge_shape, const std::vector<int> &request_dims);
static ShapeVector ConvertGeShape(const GeShape &ge_shape, const ShapeVector &request_dims);
/*
* Parameters:
* vec: [std::vector<int>] the vector to print
* vec: [ShapeVector] the vector to print
* Return
* [string] value string
* */

@ -22,6 +22,7 @@
#include "pipeline/jit/parse/data_converter.h"
#include "pipeline/jit/parse/python_adapter.h"
#include "utils/visible.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace callbacks {
@ -36,7 +37,7 @@ using mindspore::transform::Status;
using mindspore::transform::TransformUtil;
bool GetParameterShape(const FuncGraphPtr &graph, const std::string &param_name,
const std::shared_ptr<std::vector<int>> &shape) {
const std::shared_ptr<ShapeVector> &shape) {
if (graph == nullptr) {
MS_LOG(ERROR) << "Graph is null, can not get graph parameter";
return false;
@ -74,7 +75,7 @@ static TensorPtr GetMeTensorTransformed(uint32_t graph_id, const std::string &pa
return nullptr;
}
std::shared_ptr<std::vector<int>> parameter_shape_ptr = std::make_shared<std::vector<int>>();
std::shared_ptr<ShapeVector> parameter_shape_ptr = std::make_shared<ShapeVector>();
if (!GetParameterShape(anf_graph, parameter_name, parameter_shape_ptr)) {
MS_LOG(ERROR) << "Can not get parameter shape during callback";
return nullptr;
@ -133,7 +134,7 @@ static TensorPtr GetMeTensorForSummary(const std::string &name, const std::share
// process the scalar type summary
// Because the ge tensor is dim = 4, so set the (1,1,1,1)-->(1,)
// We do the (1,) shape is scalar
auto shape = std::vector<int>({ONE_SHAPE});
auto shape = ShapeVector({ONE_SHAPE});
return TransformUtil::ConvertGeTensor(ge_tensor_ptr, shape);
}
if (tname == "[:Tensor]" || tname == "[:Histogram]") {

@ -33,6 +33,7 @@
#include "ir/param_info.h"
#include "utils/base_ref_extends.h"
#include "utils/ms_context.h"
#include "utils/shape_utils.h"
namespace mindspore {
py::object BuiltinsToPyData(const Any &value);
@ -374,7 +375,7 @@ py::object VectorRefToPyData(const VectorRef &value_list) {
AbstractBasePtr PyListDtype2AbstractTensor(const py::object &shape_obj, const py::object &type_obj,
const py::object &min_shape, const py::object &max_shape) {
if ((py::isinstance<py::list>(shape_obj) || py::isinstance<py::tuple>(shape_obj)) && py::isinstance<Type>(type_obj)) {
auto ret_vec = shape_obj.cast<std::vector<int>>();
auto ret_vec = shape_obj.cast<ShapeVector>();
auto ret_dtype = type_obj.cast<TypePtr>();
MS_EXCEPTION_IF_NULL(ret_dtype);
// if the size of shape list is empty, return an scalar abstract
@ -383,13 +384,13 @@ AbstractBasePtr PyListDtype2AbstractTensor(const py::object &shape_obj, const py
return abs_scalar;
}
AbstractBasePtr tensor = nullptr;
std::vector<int> min_shape_vec;
std::vector<int> max_shape_vec;
ShapeVector min_shape_vec;
ShapeVector max_shape_vec;
if (!min_shape.is_none()) {
min_shape_vec = min_shape.cast<std::vector<int>>();
min_shape_vec = min_shape.cast<ShapeVector>();
}
if (!max_shape.is_none()) {
max_shape_vec = max_shape.cast<std::vector<int>>();
max_shape_vec = max_shape.cast<ShapeVector>();
}
auto ret_shape = std::make_shared<abstract::Shape>(ret_vec, min_shape_vec, max_shape_vec);
if (ret_dtype->isa<TensorType>()) {

@ -26,6 +26,7 @@
#include "abstract/abstract_value.h"
#include "proto/onnx.pb.h"
#include "utils/log_adapter.h"
#include "utils/shape_utils.h"
using std::string;
@ -96,7 +97,7 @@ bool MSANFModelParser::BuildParameterForFuncGraph(const ParameterPtr &node, cons
return false;
}
const onnx::TensorShapeProto &tensor_shape = tensor_typeproto.shape();
std::vector<int> shape;
ShapeVector shape;
for (int i = 0; i < tensor_shape.dim_size(); ++i) {
shape.push_back(tensor_shape.dim(i).dim_value());
}
@ -241,7 +242,7 @@ bool MSANFModelParser::GetAttrValueForCNode(const PrimitivePtr &prim, const onnx
bool MSANFModelParser::ObtainValueNodeInTensorForm(const std::string &value_node_name,
const onnx::TensorProto &attr_tensor) {
const int attr_tensor_type = attr_tensor.data_type();
std::vector<int> shape;
ShapeVector shape;
for (int i = 0; i < attr_tensor.dims_size(); ++i) {
shape.push_back(attr_tensor.dims(i));
}
@ -355,7 +356,7 @@ bool MSANFModelParser::BuildValueNodeForFuncGraph(const onnx::NodeProto &node_pr
}
AbstractBasePtr MSANFModelParser::GetAbstractForCNode(const onnx::AttributeProto &attr_proto) {
std::vector<int> shape_vec;
ShapeVector shape_vec;
const onnx::TensorProto &attr_tensor = attr_proto.t();
for (int i = 0; i < attr_tensor.dims_size(); ++i) {
shape_vec.push_back(attr_tensor.dims(i));
@ -471,7 +472,7 @@ bool MSANFModelParser::BuildReturnForFuncGraph(const FuncGraphPtr &outputFuncGra
const onnx::ValueInfoProto &output_node = importProto.output(0);
const onnx::TypeProto &output_typeproto = output_node.type();
int output_type = output_typeproto.tensor_type().elem_type();
std::vector<int> output_shape;
ShapeVector output_shape;
for (int i = 0; i < output_typeproto.tensor_type().shape().dim_size(); ++i) {
output_shape.push_back(output_typeproto.tensor_type().shape().dim(i).dim_value());
}

@ -22,6 +22,7 @@
#include "ir/tensor.h"
#include "pybind11/pybind11.h"
#include "utils/ms_utils.h"
#include "utils/shape_utils.h"
#ifndef NO_DLIB
#include "tdt/tsd_client.h"
#include "tdt/tdt_host_interface.h"
@ -59,7 +60,7 @@ std::string GetParseType(const std::string &tensorType_) {
return type_iter->second;
}
bool ParseTensorShape(const std::string &input_shape_str, std::vector<int> *const tensor_shape, size_t *dims) {
bool ParseTensorShape(const std::string &input_shape_str, ShapeVector *const tensor_shape, size_t *dims) {
if (tensor_shape == nullptr) {
return false;
}
@ -189,7 +190,7 @@ bool ConvertDataItem2Tensor(const std::vector<tdt::DataItem> &items) {
continue;
}
std::vector<int> tensor_shape;
ShapeVector tensor_shape;
size_t totaldims = 1;
if (!ParseTensorShape(item.tensorShape_, &tensor_shape, &totaldims)) {
MS_LOG(ERROR) << "Tensor print can not parse tensor shape, receive info" << item.tensorShape_;
@ -235,7 +236,7 @@ bool SaveDataItem2File(const std::vector<tdt::DataItem> &items, const std::strin
}
}
std::vector<int> tensor_shape;
ShapeVector tensor_shape;
size_t totaldims = 1;
if (!ParseTensorShape(item.tensorShape_, &tensor_shape, &totaldims)) {
MS_LOG(ERROR) << "Tensor print can not parse tensor shape, receive info" << item.tensorShape_;

@ -33,6 +33,7 @@
#include "ir/value.h"
#include "ir/tensor.h"
#include "abstract/dshape.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace abstract {
@ -250,7 +251,7 @@ class AbstractUndetermined : public AbstractBase {
}
set_shape(shape);
}
AbstractUndetermined(const TypePtr &element_type, const std::vector<int> &shape)
AbstractUndetermined(const TypePtr &element_type, const ShapeVector &shape)
: AbstractBase(kAnyValue), element_(std::make_shared<AbstractScalar>(kAnyValue, element_type)) {
if (element_type == nullptr) {
MS_LOG(EXCEPTION) << "element_type is nullptr";
@ -273,8 +274,7 @@ class AbstractTensor : public AbstractUndetermined {
// only element_ and value, shape track are valid member, type track are unknown.
explicit AbstractTensor(const AbstractBasePtr &element, const BaseShapePtr &shape = std::make_shared<Shape>())
: AbstractUndetermined(element, shape) {}
AbstractTensor(const TypePtr &element_type, const std::vector<int> &shape)
: AbstractUndetermined(element_type, shape) {}
AbstractTensor(const TypePtr &element_type, const ShapeVector &shape) : AbstractUndetermined(element_type, shape) {}
explicit AbstractTensor(const tensor::TensorPtr &tensor) : AbstractUndetermined(tensor->Dtype(), tensor->shape()) {}
~AbstractTensor() override = default;
MS_DECLARE_PARENT(AbstractTensor, AbstractUndetermined)
@ -632,7 +632,7 @@ class AbstractRowTensor : public AbstractUndetermined {
public:
explicit AbstractRowTensor(const AbstractBasePtr &element, const BaseShapePtr &shape = std::make_shared<Shape>())
: AbstractUndetermined(element, shape) {}
AbstractRowTensor(const TypePtr &element_type, const std::vector<int> &shape)
AbstractRowTensor(const TypePtr &element_type, const ShapeVector &shape)
: AbstractUndetermined(element_type, shape) {}
~AbstractRowTensor() override = default;
MS_DECLARE_PARENT(AbstractRowTensor, AbstractUndetermined)
@ -661,7 +661,7 @@ class AbstractSparseTensor : public AbstractUndetermined {
public:
explicit AbstractSparseTensor(const AbstractBasePtr &element, const BaseShapePtr &shape = std::make_shared<Shape>())
: AbstractUndetermined(element, shape) {}
AbstractSparseTensor(const TypePtr &element_type, const std::vector<int> &shape)
AbstractSparseTensor(const TypePtr &element_type, const ShapeVector &shape)
: AbstractUndetermined(element_type, shape) {}
~AbstractSparseTensor() override = default;
MS_DECLARE_PARENT(AbstractSparseTensor, AbstractUndetermined)

@ -29,6 +29,7 @@
#include "utils/log_adapter.h"
#include "base/base.h"
#include "utils/shape_utils.h"
namespace mindspore {
namespace abstract {
@ -69,12 +70,12 @@ class Shape : public BaseShape {
(void)std::transform(list_in.begin(), list_in.end(), std::back_inserter(shape_),
[](const int64_t &value) { return static_cast<int>(value); });
}
explicit Shape(const std::vector<int> &list) : shape_(list) {}
explicit Shape(const ShapeVector &list) : shape_(list) {}
explicit Shape(const std::vector<int64_t> &list) {
(void)std::transform(list.begin(), list.end(), std::back_inserter(shape_),
[](const int64_t &value) { return static_cast<int>(value); });
}
Shape(const std::vector<int> &list, const std::vector<int> &min_shape, const std::vector<int> &max_shape)
Shape(const ShapeVector &list, const ShapeVector &min_shape, const ShapeVector &max_shape)
: shape_(list), min_shape_(min_shape), max_shape_(max_shape) {}
~Shape() override = default;
MS_DECLARE_PARENT(Shape, BaseShape)
@ -83,13 +84,13 @@ class Shape : public BaseShape {
bool operator==(const BaseShape &other) const override;
BaseShapePtr Clone() const override { return std::make_shared<Shape>(shape_, min_shape_, max_shape_); }
void Broaden() override;
std::vector<int> &shape() { return shape_; }
std::vector<int> &min_shape() { return min_shape_; }
std::vector<int> &max_shape() { return max_shape_; }
ShapeVector &shape() { return shape_; }
ShapeVector &min_shape() { return min_shape_; }
ShapeVector &max_shape() { return max_shape_; }
std::vector<int> shape_; // use SHP_ANY to implement the any shape in python
std::vector<int> min_shape_; // record mininum length for each dynamic dimention
std::vector<int> max_shape_; // record maximum length for each dynamic dimention
ShapeVector shape_; // use SHP_ANY to implement the any shape in python
ShapeVector min_shape_; // record mininum length for each dynamic dimention
ShapeVector max_shape_; // record maximum length for each dynamic dimention
};
using ShapePtr = std::shared_ptr<Shape>;
using ShapePtrList = std::vector<ShapePtr>;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save