clear the alarm information of 1.5 branch

This commit is contained in:
shen_jingxing 2021-10-08 10:22:42 +08:00
parent 2a31313a22
commit bfb75c7ece
43 changed files with 200 additions and 173 deletions

View File

@ -28,6 +28,9 @@ namespace {
abstract::TupleShapePtr LayerNormBetaGammaBackpropInferShape(const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
for (const auto &item : input_args) {
MS_EXCEPTION_IF_NULL(item);
}
ValuePtr gamma_value_ptr = primitive->GetAttr("shape_gamma");
MS_EXCEPTION_IF_NULL(gamma_value_ptr);
auto gamma_shape = GetValue<ShapeVector>(gamma_value_ptr);

View File

@ -32,8 +32,6 @@ void ImpleAbs(void *origin, void *target, size_t size) {
MS_EXCEPTION_IF_NULL(target);
auto origin_data = reinterpret_cast<T *>(origin);
auto target_data = reinterpret_cast<T *>(target);
MS_EXCEPTION_IF_NULL(origin_data);
MS_EXCEPTION_IF_NULL(target_data);
auto zero_val = static_cast<T>(0);
for (size_t i = 0; i < size; ++i) {
target_data[i] = origin_data[i] >= zero_val ? origin_data[i] : -origin_data[i];
@ -41,6 +39,7 @@ void ImpleAbs(void *origin, void *target, size_t size) {
}
abstract::ShapePtr AbsInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape];
return std::make_shared<abstract::Shape>(in_shape);
}
@ -83,47 +82,47 @@ ValuePtr AbsInferValue(const PrimitivePtr &prim, const std::vector<AbstractBaseP
auto result_datac = result_tensor->data_c();
switch (dtype) {
case kNumberTypeInt8: {
ImpleAbs<int8_t>(x_datac, result_datac, data_size);
ImpleAbs<int8_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeInt16: {
ImpleAbs<int16_t>(x_datac, result_datac, data_size);
ImpleAbs<int16_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeInt32: {
ImpleAbs<int32_t>(x_datac, result_datac, data_size);
ImpleAbs<int32_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeInt64: {
ImpleAbs<int64_t>(x_datac, result_datac, data_size);
ImpleAbs<int64_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt8: {
ImpleAbs<uint8_t>(x_datac, result_datac, data_size);
ImpleAbs<uint8_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt16: {
ImpleAbs<uint16_t>(x_datac, result_datac, data_size);
ImpleAbs<uint16_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt32: {
ImpleAbs<uint32_t>(x_datac, result_datac, data_size);
ImpleAbs<uint32_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt64: {
ImpleAbs<uint64_t>(x_datac, result_datac, data_size);
ImpleAbs<uint64_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeFloat16: {
ImpleAbs<float16>(x_datac, result_datac, data_size);
ImpleAbs<float16>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeFloat32: {
ImpleAbs<float>(x_datac, result_datac, data_size);
ImpleAbs<float>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeFloat64: {
ImpleAbs<double>(x_datac, result_datac, data_size);
ImpleAbs<double>(x_datac, result_datac, IntToSize(data_size));
break;
}
default: {

View File

@ -44,10 +44,11 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec
auto l2_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex6]->BuildShape())[kShape];
auto global_step_shape =
CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex7]->BuildShape())[kShape];
(void)CheckAndConvertUtils::CheckInteger("lr_shape size", lr_shape.size(), kEqual, 0, primitive->name());
(void)CheckAndConvertUtils::CheckInteger("l1_shape size", l1_shape.size(), kEqual, 0, primitive->name());
(void)CheckAndConvertUtils::CheckInteger("l2_shape size", l2_shape.size(), kEqual, 0, primitive->name());
(void)CheckAndConvertUtils::CheckInteger("global_step_shape size", global_step_shape.size(), kEqual, 0,
const int64_t input_nums = 0;
(void)CheckAndConvertUtils::CheckInteger("lr_shape size", lr_shape.size(), kEqual, input_nums, primitive->name());
(void)CheckAndConvertUtils::CheckInteger("l1_shape size", l1_shape.size(), kEqual, input_nums, primitive->name());
(void)CheckAndConvertUtils::CheckInteger("l2_shape size", l2_shape.size(), kEqual, input_nums, primitive->name());
(void)CheckAndConvertUtils::CheckInteger("global_step_shape size", global_step_shape.size(), kEqual, input_nums,
primitive->name());
return std::make_shared<abstract::TupleShape>(
std::vector<abstract::BaseShapePtr>{var_shape, gradient_accumulator_shape, gradient_squared_accumulator_shape});
@ -72,25 +73,25 @@ TuplePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr>
const std::set<TypePtr> valid_types = {kFloat16, kFloat32};
// gradient_accumulator、gradient_squared_accumulator、grad must have the same type as var
std::map<std::string, TypePtr> args;
args.insert({"var_type", var_type});
args.insert({"gradient_accumulator_type", gradient_accumulator_type});
args.insert({"gradient_squared_accumulator_type", gradient_squared_accumulator_type});
args.insert({"grad_type", grad_type});
CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name);
(void)args.insert({"var_type", var_type});
(void)args.insert({"gradient_accumulator_type", gradient_accumulator_type});
(void)args.insert({"gradient_squared_accumulator_type", gradient_squared_accumulator_type});
(void)args.insert({"grad_type", grad_type});
(void)CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name);
// lr、l1、l2、global_step_type must be a scalar type
std::map<std::string, TypePtr> args_lr;
std::map<std::string, TypePtr> args_l1;
std::map<std::string, TypePtr> args_l2;
std::map<std::string, TypePtr> args_global_step;
args_lr.insert({"lr_type", lr_type});
CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_lr, valid_types, prim_name);
args_l1.insert({"l1_type", l1_type});
CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l1, valid_types, prim_name);
args_l2.insert({"l2_type", l2_type});
CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l2, valid_types, prim_name);
args_global_step.insert({"global_step_type", global_step_type});
(void)args_lr.insert({"lr_type", lr_type});
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_lr, valid_types, prim_name);
(void)args_l1.insert({"l1_type", l1_type});
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l1, valid_types, prim_name);
(void)args_l2.insert({"l2_type", l2_type});
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l2, valid_types, prim_name);
(void)args_global_step.insert({"global_step_type", global_step_type});
const std::set<TypePtr> valid_types1 = {kInt32, kInt64};
CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_global_step, valid_types1, prim_name);
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_global_step, valid_types1, prim_name);
return std::make_shared<Tuple>(
std::vector<TypePtr>{var_type, gradient_accumulator_type, gradient_squared_accumulator_type});
}

View File

@ -80,9 +80,9 @@ AbstractBasePtr ApplyMomentumInfer(const abstract::AnalysisEnginePtr &, const Pr
(void)CheckAndConvertUtils::CheckTensorTypeValid("v_type", v_tensor_type, valid_types, prim_name);
(void)CheckAndConvertUtils::CheckTensorTypeValid("a_type", a_tensor_type, valid_types, prim_name);
std::map<std::string, TypePtr> args;
args.insert(std::make_pair("l_type", l_type));
args.insert(std::make_pair("g_type", g_type));
args.insert(std::make_pair("m_type", m_type));
(void)args.insert(std::make_pair("l_type", l_type));
(void)args.insert(std::make_pair("g_type", g_type));
(void)args.insert(std::make_pair("m_type", m_type));
CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args, valid_types, prim_name);
auto g_type_tensor = g_type->cast<TensorTypePtr>();
auto element = g_type_tensor->element();

View File

@ -78,7 +78,7 @@ int64_t Log2Ceil(int64_t length) {
int64_t floor = 0;
for (int64_t i = 4; i >= 0; --i) {
const int64_t shift = static_cast<int64_t>(1UL << static_cast<unsigned>(i));
int64_t tmp = SizeToLong(length >> shift);
int64_t tmp = SizeToLong(static_cast<uint64_t>(length) >> static_cast<uint64_t>(shift));
if (tmp != 0) {
length = tmp;
floor += shift;

View File

@ -111,11 +111,11 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<A
int64_t out_h = abstract::Shape::SHP_ANY;
int64_t out_w = abstract::Shape::SHP_ANY;
if (pad_mode == VALID) {
out_h = static_cast<int64_t>(ceil((in_h - (kernel_h - 1)) / stride_h));
out_w = static_cast<int64_t>(ceil((in_w - (kernel_w - 1)) / stride_w));
out_h = static_cast<int64_t>(std::ceil((in_h - (kernel_h - 1)) / static_cast<float>(stride_h)));
out_w = static_cast<int64_t>(std::ceil((in_w - (kernel_w - 1)) / static_cast<float>(stride_w)));
} else if (pad_mode == SAME) {
out_h = static_cast<int64_t>(ceil(in_h / stride_h));
out_w = static_cast<int64_t>(ceil(in_w / stride_w));
out_h = static_cast<int64_t>(std::ceil(in_h / static_cast<float>(stride_h)));
out_w = static_cast<int64_t>(std::ceil(in_w / static_cast<float>(stride_w)));
}
std::vector<int64_t> out_shape = {batch, channel, out_h, out_w};
if (format == NHWC) {

View File

@ -26,14 +26,13 @@
namespace mindspore {
namespace ops {
namespace {
constexpr size_t k5DInputDims = 5;
constexpr int64_t k5DInputDims = 5;
constexpr size_t kKernelDims = 3;
constexpr size_t kStridesDims = 3;
constexpr size_t kPadDims = 6;
void GetAttrs(const PrimitivePtr &primitive, std::vector<int64_t> *kernel_size, std::vector<int64_t> *strides,
int64_t *pad_mode, std::vector<int64_t> *pad_list, bool *ceil_mode, bool *count_include_pad,
int64_t *divisor_override) {
int64_t *pad_mode, std::vector<int64_t> *pad_list, bool *ceil_mode, bool *count_include_pad) {
MS_EXCEPTION_IF_NULL(primitive);
// attr kernel size
*kernel_size = GetValue<std::vector<int64_t>>(primitive->GetAttr(kKernelSize));
@ -56,8 +55,6 @@ void GetAttrs(const PrimitivePtr &primitive, std::vector<int64_t> *kernel_size,
CheckAndConvertUtils::GetPadModEnumValue(primitive->GetAttr(kPadMode), pad_mode, true);
// attr ceil mode
*ceil_mode = GetValue<bool>(primitive->GetAttr(kCeilMode));
// attr divisor override
*divisor_override = GetValue<int64_t>(primitive->GetAttr(kDivisorOverride));
}
std::vector<int64_t> GetOutputShape(const std::vector<int64_t> &in_shape, int64_t kernel_d, int64_t kernel_h,
@ -70,9 +67,12 @@ std::vector<int64_t> GetOutputShape(const std::vector<int64_t> &in_shape, int64_
int64_t out_h = 0;
int64_t out_w = 0;
if (ceil_mode) {
out_d = std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d + stride_d - 1) / stride_d + 1);
out_h = std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h + stride_h - 1) / stride_h + 1);
out_w = std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w + stride_w - 1) / stride_w + 1);
out_d =
static_cast<int64_t>(std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d + stride_d - 1) / stride_d + 1));
out_h =
static_cast<int64_t>(std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h + stride_h - 1) / stride_h + 1));
out_w =
static_cast<int64_t>(std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w + stride_w - 1) / stride_w + 1));
if ((out_d - 1) * stride_d >= in_d + pad_list[0]) {
out_d--;
}
@ -83,9 +83,9 @@ std::vector<int64_t> GetOutputShape(const std::vector<int64_t> &in_shape, int64_
out_w--;
}
} else {
out_d = std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d) / stride_d + 1);
out_h = std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h) / stride_h + 1);
out_w = std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w) / stride_w + 1);
out_d = static_cast<int64_t>(std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d) / stride_d + 1));
out_h = static_cast<int64_t>(std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h) / stride_h + 1));
out_w = static_cast<int64_t>(std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w) / stride_w + 1));
}
std::vector<int64_t> output_shape = {in_shape[0], in_shape[1], out_d, out_h, out_w};
return output_shape;
@ -130,8 +130,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<A
int64_t pad_mode = 0;
bool ceil_mode = false;
bool count_include_pad = true;
int64_t divisor_override = 0;
GetAttrs(primitive, &kernel_size, &strides, &pad_mode, &pad_list, &ceil_mode, &count_include_pad, &divisor_override);
GetAttrs(primitive, &kernel_size, &strides, &pad_mode, &pad_list, &ceil_mode, &count_include_pad);
auto in_d = in_shape[2];
auto in_h = in_shape[3];
auto in_w = in_shape[4];

View File

@ -49,8 +49,8 @@ TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBaseP
}
const std::set<TypePtr> valid_types = {kFloat32, kFloat16};
std::map<std::string, TypePtr> types;
types.emplace("input_x", input_args[0]->BuildType());
types.emplace("input_y", input_args[1]->BuildType());
(void)types.emplace("input_x", input_args[0]->BuildType());
(void)types.emplace("input_y", input_args[1]->BuildType());
return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, primitive->name());
}
} // namespace

View File

@ -77,13 +77,15 @@ void Conv2DPadFunction(std::vector<int64_t> *output_hw, std::vector<int64_t> *pa
int64_t out_h = -1;
int64_t out_w = -1;
if (x_h != Shape::SHP_ANY) {
out_h = static_cast<int64_t>(std::ceil(((x_h * 1.0) - dilation[0] * (kernel[0] - 1)) / stride[0]));
out_h =
static_cast<int64_t>(std::ceil(((x_h * 1.0) - static_cast<float>(dilation[0] * (kernel[0] - 1))) / stride[0]));
if (is_min_shape && out_h < 1) {
out_h = 1L;
}
}
if (x_w != Shape::SHP_ANY) {
out_w = static_cast<int64_t>(std::ceil(((x_w * 1.0) - dilation[1] * (kernel[1] - 1)) / stride[1]));
out_w =
static_cast<int64_t>(std::ceil(((x_w * 1.0) - static_cast<float>(dilation[1] * (kernel[1] - 1))) / stride[1]));
if (is_min_shape && out_w < 1) {
out_w = 1L;
}
@ -120,9 +122,9 @@ void Conv2DPadFunction(std::vector<int64_t> *output_hw, std::vector<int64_t> *pa
int64_t out_h = -1;
int64_t out_w = -1;
if (x_h != Shape::SHP_ANY) {
out_h = static_cast<int64_t>(std::floor(
1 + ((x_h * 1.0) + pad_list->at(0) + pad_list->at(1) - kernel[0] - (kernel[0] - 1) * (dilation[0] - 1)) /
stride[0]));
out_h = static_cast<int64_t>(std::floor(1 + ((x_h * 1.0) + pad_list->at(0) + pad_list->at(1) - kernel[0] -
static_cast<float>((kernel[0] - 1) * (dilation[0] - 1))) /
stride[0]));
if (is_min_shape && out_h < 1) {
out_h = 1L;
}
@ -130,7 +132,7 @@ void Conv2DPadFunction(std::vector<int64_t> *output_hw, std::vector<int64_t> *pa
if (x_w != Shape::SHP_ANY) {
out_w =
static_cast<int64_t>(std::floor(1 + ((x_w * 1.0) + pad_list->at(kInputIndex2) + pad_list->at(kInputIndex3) -
kernel[1] - (kernel[1] - 1) * (dilation[1] - 1)) /
kernel[1] - static_cast<float>((kernel[1] - 1) * (dilation[1] - 1))) /
stride[1]));
if (is_min_shape && out_w < 1) {
out_w = 1L;

View File

@ -30,7 +30,7 @@ namespace {
constexpr size_t kLenLogProbs = 3;
constexpr size_t kLenTarget = 2;
constexpr int64_t kMulti = 2;
constexpr size_t kInputSize = 4;
constexpr int64_t kInputSize = 4;
abstract::TupleShapePtr CTCLossV2InferShape(const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);

View File

@ -27,7 +27,7 @@ namespace mindspore {
namespace ops {
namespace {
constexpr size_t kLenLogProbs = 3;
constexpr size_t kInputSize = 7;
constexpr int64_t kInputSize = 7;
constexpr size_t kIdx2 = 2;
abstract::ShapePtr CTCLossV2GradInferShape(const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {

View File

@ -39,7 +39,7 @@ abstract::ShapePtr DiagPartInferShape(const PrimitivePtr &primitive, const std::
for (size_t i = 0; i < length; i++) {
CheckAndConvertUtils::Check("input_shape[i + rank(input_shape) / 2]", input_shape[i + length], kEqual,
"input_shape[i]", input_shape[i], op_name, ValueError);
out_shape.emplace_back(input_shape[i]);
(void)out_shape.emplace_back(input_shape[i]);
}
return std::make_shared<abstract::Shape>(out_shape);
}

View File

@ -40,13 +40,13 @@ int64_t CheckInputsAndGetShape(const AbstractBasePtr &input_arg, const string &p
if (max_shape.empty()) {
MS_LOG(EXCEPTION) << prim_name << " input shape is dynamic, but max shape is empty.";
}
return static_cast<size_t>(max_shape[0]);
return max_shape[0];
}
return static_cast<size_t>(input_shape[0]);
return input_shape[0];
} else if (input_arg->isa<abstract::AbstractTuple>()) {
auto x_shape = dyn_cast<abstract::AbstractTuple>(input_arg);
auto x_shape_data = x_shape->elements();
return x_shape_data.size();
return SizeToLong(x_shape_data.size());
} else {
MS_EXCEPTION(TypeError) << prim_name << " input must be a tuple or Tensor.";
}

View File

@ -27,7 +27,9 @@ namespace {
abstract::ShapePtr ErfinvInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto prim_name = primitive->name();
CheckAndConvertUtils::CheckInteger("input_x numbers", input_args.size(), kEqual, 1, prim_name);
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("input_x numbers", SizeToLong(input_args.size()), kEqual, input_num,
prim_name);
for (const auto &item : input_args) {
MS_EXCEPTION_IF_NULL(item);
}
@ -39,13 +41,14 @@ abstract::ShapePtr ErfinvInferShape(const PrimitivePtr &primitive, const std::ve
TypePtr ErfinvInferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(prim);
auto op_name = prim->name();
CheckAndConvertUtils::CheckInteger("input_x number", input_args.size(), kEqual, 1, op_name);
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("input_x number", SizeToLong(input_args.size()), kEqual, input_num, op_name);
for (const auto &item : input_args) {
MS_EXCEPTION_IF_NULL(item);
}
const std::set<TypePtr> valid_types = {kFloat16, kFloat32};
auto infer_type = input_args[0]->BuildType();
CheckAndConvertUtils::CheckTensorTypeValid("input_x", infer_type, valid_types, prim->name());
(void)CheckAndConvertUtils::CheckTensorTypeValid("input_x", infer_type, valid_types, prim->name());
return infer_type;
}
} // namespace

View File

@ -40,7 +40,7 @@ AbstractBasePtr ExpandDimsInfer(const abstract::AnalysisEnginePtr &, const Primi
auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
auto dim_val = GetValue<int64_t>(input_args[1]->BuildValue());
auto rank = x_shape.size();
CheckAndConvertUtils::CheckInRange<int64_t>("axis", dim_val, kIncludeBoth, {-rank - 1, rank}, prim_name);
(void)CheckAndConvertUtils::CheckInRange<int64_t>("axis", dim_val, kIncludeBoth, {-rank - 1, rank}, prim_name);
if (dim_val < 0) {
dim_val += SizeToLong(x_shape.size()) + 1;
}

View File

@ -27,12 +27,12 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<A
(void)CheckAndConvertUtils::CheckInteger("input args size", SizeToLong(input_args.size()), kGreaterEqual, 1,
prim_name);
auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
size_t prod = 1;
int64_t prod = 1;
size_t size = x_shape.size();
for (size_t i = 1; i < size; i++) {
prod = prod * x_shape[i];
}
std::vector<int64_t> out_shape = {x_shape[0], SizeToLong(prod)};
std::vector<int64_t> out_shape = {x_shape[0], prod};
return std::make_shared<abstract::Shape>(out_shape);
}

View File

@ -40,7 +40,7 @@ void Conv2dTransposeFusion::Init(int64_t in_channel, int64_t out_channel, const
}
void Conv2dTransposeFusion::set_kernel_size(const std::vector<int64_t> &kernel_size) {
const size_t kernel_len = 2;
const int64_t kernel_len = 2;
(void)CheckAndConvertUtils::CheckInteger(kKernelSize, SizeToLong(kernel_size.size()), kEqual, kernel_len, name());
for (int64_t item : kernel_size) {
(void)CheckAndConvertUtils::CheckInteger(kKernelSize, item, kGreaterEqual, 1, name());
@ -49,7 +49,7 @@ void Conv2dTransposeFusion::set_kernel_size(const std::vector<int64_t> &kernel_s
}
void Conv2dTransposeFusion::set_dilation(const std::vector<int64_t> &dilation) {
const size_t dilation_size = 2;
const int64_t dilation_size = 2;
(void)CheckAndConvertUtils::CheckInteger(kDilation, SizeToLong(dilation.size()), kEqual, dilation_size, name());
for (int64_t item : dilation) {
(void)CheckAndConvertUtils::CheckInteger(kDilation, item, kGreaterEqual, 1, name());

View File

@ -25,7 +25,7 @@
namespace mindspore {
namespace ops {
namespace {
constexpr size_t k5DInputDims = 5;
constexpr int64_t k5DInputDims = 5;
abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);

View File

@ -50,10 +50,10 @@ TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBaseP
}
const std::set<TypePtr> valid_types = {kFloat32, kFloat16};
std::map<std::string, TypePtr> types;
types.emplace("grad", input_args[0]->BuildType());
types.emplace("input_x", input_args[1]->BuildType());
types.emplace("input_y", input_args[2]->BuildType());
types.emplace("cdist", input_args[3]->BuildType());
(void)types.emplace("grad", input_args[0]->BuildType());
(void)types.emplace("input_x", input_args[1]->BuildType());
(void)types.emplace("input_y", input_args[2]->BuildType());
(void)types.emplace("cdist", input_args[3]->BuildType());
return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, primitive->name());
}
} // namespace

View File

@ -24,9 +24,9 @@
namespace mindspore {
namespace ops {
namespace {
constexpr size_t kDoutIndex = 0;
constexpr size_t kInputIndex = 1;
constexpr size_t kFilterSizeIdex = 2;
constexpr int64_t kDoutIndex = 0;
constexpr int64_t kInputIndex = 1;
constexpr int64_t kFilterSizeIdex = 2;
constexpr size_t kStride2dSize = 2;
constexpr size_t kStride4dSize = 4;
@ -56,7 +56,6 @@ abstract::ShapePtr Conv2DBackpropFilterInferShape(const PrimitivePtr &primitive,
std::vector<int64_t> out_shape;
abstract::ShapePtr ret_shape;
TransStrideTo4D(primitive, input_args);
auto filter_size = input_args[kFilterSizeIdex];
auto filter_size_v = filter_size->BuildValue();
MS_EXCEPTION_IF_NULL(filter_size_v);

View File

@ -27,7 +27,7 @@ namespace ops {
namespace {
constexpr size_t kDoutIndex = 0;
constexpr size_t kInputIndex = 1;
constexpr size_t kSizeIndex = 2;
constexpr int64_t kSizeIndex = 2;
void SetPadList(const PrimitivePtr &primitive, const std::vector<int64_t> &dout_shape_norm,
const std::vector<int64_t> &x_size_v) {

View File

@ -24,50 +24,55 @@ namespace {
AbstractBasePtr LstmGradInfer(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
// infer shape
MS_EXCEPTION_IF_NULL(primitive);
for (const auto &item : input_args) {
MS_EXCEPTION_IF_NULL(item);
}
return nullptr;
}
} // namespace
void LSTMGrad::set_input_size(const int64_t input_size) {
CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name());
AddAttr(kInput_size, MakeValue(input_size));
(void)CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name());
(void)AddAttr(kInput_size, MakeValue(input_size));
}
int64_t LSTMGrad::get_input_size() const { return GetValue<int64_t>(GetAttr(kInput_size)); }
void LSTMGrad::set_hidden_size(const int64_t hidden_size) {
CheckAndConvertUtils::CheckInteger(kHidden_size, hidden_size, kGreaterThan, 0, this->name());
AddAttr(kHidden_size, MakeValue(hidden_size));
(void)CheckAndConvertUtils::CheckInteger(kHidden_size, hidden_size, kGreaterThan, 0, this->name());
(void)AddAttr(kHidden_size, MakeValue(hidden_size));
}
int64_t LSTMGrad::get_hidden_size() const { return GetValue<int64_t>(GetAttr(kHidden_size)); }
void LSTMGrad::set_num_layers(const int64_t num_layers) {
CheckAndConvertUtils::CheckInteger(kNumLayers, num_layers, kGreaterThan, 0, this->name());
AddAttr(kNumLayers, MakeValue(num_layers));
(void)CheckAndConvertUtils::CheckInteger(kNumLayers, num_layers, kGreaterThan, 0, this->name());
(void)AddAttr(kNumLayers, MakeValue(num_layers));
}
int64_t LSTMGrad::get_num_layers() const { return GetValue<int64_t>(GetAttr(kNumLayers)); }
void LSTMGrad::set_has_bias(const bool has_bias) { AddAttr(kHasBias, MakeValue(has_bias)); }
void LSTMGrad::set_has_bias(const bool has_bias) { (void)AddAttr(kHasBias, MakeValue(has_bias)); }
bool LSTMGrad::get_has_bias() const {
auto value_ptr = this->GetAttr(kHasBias);
return GetValue<bool>(value_ptr);
}
void LSTMGrad::set_dropout(const float dropout) {
CheckAndConvertUtils::CheckInRange<float>(kDropout, dropout, kIncludeBoth, {0.0, 1.0}, this->name());
AddAttr(kDropout, MakeValue(dropout));
(void)CheckAndConvertUtils::CheckInRange<float>(kDropout, dropout, kIncludeBoth, {0.0, 1.0}, this->name());
(void)AddAttr(kDropout, MakeValue(dropout));
}
float LSTMGrad::get_dropout() const {
auto value_ptr = this->GetAttr(kDropout);
return GetValue<float>(value_ptr);
}
void LSTMGrad::set_bidirectional(const bool bidirectional) { AddAttr(kBidirectional, MakeValue(bidirectional)); }
void LSTMGrad::set_bidirectional(const bool bidirectional) { (void)AddAttr(kBidirectional, MakeValue(bidirectional)); }
bool LSTMGrad::get_bidirectional() const {
auto value_ptr = this->GetAttr(kBidirectional);
return GetValue<bool>(value_ptr);
}
void LSTMGrad::set_num_directions(const int64_t num_directions) { AddAttr(kNumDirections, MakeValue(num_directions)); }
void LSTMGrad::set_num_directions(const int64_t num_directions) {
(void)AddAttr(kNumDirections, MakeValue(num_directions));
}
int64_t LSTMGrad::get_num_directions() const { return GetValue<int64_t>(GetAttr(kNumDirections)); }
void LSTMGrad::set_zoneout_cell(float zoneout_cell) { AddAttr(kZoneoutCell, MakeValue(zoneout_cell)); }
void LSTMGrad::set_zoneout_cell(float zoneout_cell) { (void)AddAttr(kZoneoutCell, MakeValue(zoneout_cell)); }
float LSTMGrad::get_zoneout_cell() const { return GetValue<float>(this->GetAttr(kZoneoutCell)); }
void LSTMGrad::set_zoneout_hidden(float zoneout_hidden) { AddAttr(kZoneoutHidden, MakeValue(zoneout_hidden)); }
void LSTMGrad::set_zoneout_hidden(float zoneout_hidden) { (void)AddAttr(kZoneoutHidden, MakeValue(zoneout_hidden)); }
float LSTMGrad::get_zoneout_hidden() const { return GetValue<float>(this->GetAttr(kZoneoutHidden)); }

View File

@ -23,7 +23,7 @@
namespace mindspore {
namespace ops {
namespace {
constexpr size_t kInputSize = 3;
constexpr int64_t kInputSize = 3;
abstract::ShapePtr SoftMarginLossGradInferShape(const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);

View File

@ -26,7 +26,8 @@ abstract::ShapePtr IndexAddInferShape(const PrimitivePtr &primitive, const std::
MS_EXCEPTION_IF_NULL(primitive);
auto prim_name = primitive->name();
const int64_t input_num = 3;
(void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, input_num, prim_name);
(void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num,
prim_name);
for (const auto &item : input_args) {
MS_EXCEPTION_IF_NULL(item);
}
@ -39,16 +40,16 @@ abstract::ShapePtr IndexAddInferShape(const PrimitivePtr &primitive, const std::
CheckAndConvertUtils::CheckInRange("axis", axis, kIncludeNeither, {-x_rank - 1, x_rank}, prim_name);
auto idx_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape];
auto idx_rank = SizeToLong(idx_shape.size());
CheckAndConvertUtils::CheckInteger("idx size", idx_rank, kEqual, 1, prim_name);
(void)CheckAndConvertUtils::CheckInteger("idx size", idx_rank, kEqual, 1, prim_name);
auto axis_rank = axis;
if (axis < 0) {
axis_rank = axis + x_rank;
}
CheckAndConvertUtils::Check("size of indices", idx_shape[0], kEqual, "dimension of y[axis]", y_shape[axis_rank],
prim_name);
(void)CheckAndConvertUtils::Check("size of indices", idx_shape[0], kEqual, "dimension of y[axis]", y_shape[axis_rank],
prim_name);
for (int dim = 0; dim < x_rank; dim = dim + 1) {
if (dim != axis_rank) {
CheckAndConvertUtils::Check("x dim", x_shape[dim], kEqual, "y dim", y_shape[dim], prim_name);
(void)CheckAndConvertUtils::Check("x dim", x_shape[dim], kEqual, "y dim", y_shape[dim], prim_name);
}
}
return std::make_shared<abstract::Shape>(x_shape);
@ -66,8 +67,8 @@ TypePtr IndexAddInferType(const PrimitivePtr &prim, const std::vector<AbstractBa
auto var_type = input_args[kInputIndex0]->BuildType();
auto indices_type = input_args[kInputIndex1]->BuildType();
auto updates_type = input_args[kInputIndex2]->BuildType();
CheckAndConvertUtils::CheckTensorTypeValid("indices type", indices_type, indices_types, prim->name());
CheckAndConvertUtils::CheckTensorTypeValid("input_y type", updates_type, valid_types, prim->name());
(void)CheckAndConvertUtils::CheckTensorTypeValid("indices type", indices_type, indices_types, prim->name());
(void)CheckAndConvertUtils::CheckTensorTypeValid("input_y type", updates_type, valid_types, prim->name());
return CheckAndConvertUtils::CheckTensorTypeValid("input_x type", var_type, valid_types, prim->name());
}
} // namespace

View File

@ -41,8 +41,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<A
auto weight_shape = weight_shape_map[kShape];
auto broadcast_shape = CalBroadCastShape(start_shape, end_shape, op_name, "start", "end");
if (input_args[kInputIndex2]->isa<abstract::AbstractTensor>()) {
CalBroadCastShape(start_shape, weight_shape, op_name, "start", "weight");
CalBroadCastShape(end_shape, weight_shape, op_name, "end", "weight");
(void)CalBroadCastShape(start_shape, weight_shape, op_name, "start", "weight");
(void)CalBroadCastShape(end_shape, weight_shape, op_name, "end", "weight");
broadcast_shape = CalBroadCastShape(broadcast_shape, weight_shape, op_name);
}
return std::make_shared<abstract::Shape>(broadcast_shape);
@ -56,8 +56,8 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &
const int64_t input_num = 3;
(void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, op_name);
std::map<std::string, TypePtr> types;
types.emplace("start", input_args[0]->BuildType());
types.emplace("end", input_args[1]->BuildType());
(void)types.emplace("start", input_args[0]->BuildType());
(void)types.emplace("end", input_args[1]->BuildType());
if (input_args[kInputIndex2]->isa<abstract::AbstractTensor>()) {
(void)types.emplace("weight", input_args[kInputIndex2]->BuildType());
} else {

View File

@ -55,7 +55,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &
auto op_name = prim->name();
const int64_t input_num = 3;
(void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num, op_name);
CheckAndConvertUtils::CheckTensorTypeValid("mask", input_args[1]->BuildType(), {kBool}, op_name);
(void)CheckAndConvertUtils::CheckTensorTypeValid("mask", input_args[1]->BuildType(), {kBool}, op_name);
if (input_args[kInputIndex2]->isa<abstract::AbstractTensor>()) {
std::map<std::string, TypePtr> types;
(void)types.emplace("input", input_args[kInputIndex0]->BuildType());

View File

@ -33,7 +33,7 @@ AbstractBasePtr MergeInfer(const abstract::AnalysisEnginePtr &, const PrimitiveP
auto inputs_shape = input_args[0]->BuildShape()->cast<abstract::TupleShapePtr>()->shape();
std::map<std::string, TypePtr> args;
for (size_t i = 0; i != inputs_type.size(); i++) {
args.insert(std::make_pair("input[" + std::to_string(i) + "]", inputs_type[i]));
(void)args.insert(std::make_pair("input[" + std::to_string(i) + "]", inputs_type[i]));
}
std::set<TypePtr> template_type = common_valid_types;
(void)template_type.emplace(kBool);

View File

@ -100,11 +100,15 @@ void Check(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &in
// check empty input
auto send_rank_ids = GetValue<std::vector<int64_t>>(primitive->GetAttr(kSendRankIds));
if (send_rank_ids.empty()) {
(void)CheckAndConvertUtils::CheckInteger("input_numbers", input_args.size(), kEqual, 0, prim_name);
const int64_t input_num = 0;
(void)CheckAndConvertUtils::CheckInteger("input_numbers", SizeToLong(input_args.size()), kEqual, input_num,
prim_name);
return;
}
// check input shape & attr send shape
(void)CheckAndConvertUtils::CheckInteger("input_numbers", input_args.size(), kEqual, 1, prim_name);
const int64_t input_num_ = 1;
(void)CheckAndConvertUtils::CheckInteger("input_numbers", SizeToLong(input_args.size()), kEqual, input_num_,
prim_name);
(void)CheckAndConvertUtils::CheckArgs<abstract::AbstractTuple>(prim_name, input_args, 0);
auto abstract_tuple = input_args[0]->cast<abstract::AbstractTuplePtr>();
MS_EXCEPTION_IF_NULL(abstract_tuple);

View File

@ -31,7 +31,7 @@ abstract::ShapePtr OnesInferShape(const PrimitivePtr &primitive, const std::vect
// check
auto shape_value = input_args[0]->BuildValue();
std::vector<int64_t> out_shape = CheckAndConvertUtils::CheckAttrIntOrTupleInt("shape", shape_value, prim_name);
CheckAndConvertUtils::CheckPositiveVector("shape", out_shape, prim_name);
(void)CheckAndConvertUtils::CheckPositiveVector("shape", out_shape, prim_name);
return std::make_shared<abstract::Shape>(out_shape);
}

View File

@ -41,12 +41,12 @@ std::vector<int64_t> CalBroadCastShape(std::vector<int64_t> x_shape, std::vector
(void)std::copy(x_shape.begin(), x_shape.end() - length, std::back_inserter(broadcast_shape));
}
for (int64_t i = -length; i < 0; i++) {
if (x_shape[x_length + i] == 1) {
broadcast_shape.push_back(y_shape[y_length + i]);
} else if (y_shape[y_length + i] == 1) {
broadcast_shape.push_back(x_shape[x_length + i]);
} else if (x_shape[x_length + i] == y_shape[y_length + i]) {
broadcast_shape.push_back(x_shape[x_length + i]);
if (x_shape[LongToSize(x_length + i)] == 1) {
(void)broadcast_shape.push_back(y_shape[LongToSize(y_length + i)]);
} else if (y_shape[LongToSize(y_length + i)] == 1) {
(void)broadcast_shape.push_back(x_shape[LongToSize(x_length + i)]);
} else if (x_shape[x_length + i] == y_shape[LongToSize(y_length + i)]) {
(void)broadcast_shape.push_back(x_shape[LongToSize(x_length + i)]);
} else {
MS_EXCEPTION(ValueError) << "For op " << op_name << ", the two input '" << op_x_name << "' and '" << op_y_name
<< "' can not broadcast";

View File

@ -49,7 +49,7 @@ void InferImplReduceFuncCalShape(ShapeVector *shape, const ShapeVector &x_shape,
if (keep_dims_value) {
for (it = axis_items.begin(); it != axis_items.end(); ++it) {
auto axis_value = GetValue<int64_t>(*it);
shape->at(axis_value) = 1;
shape->at(LongToSize(axis_value)) = 1;
}
} else {
std::vector<int64_t> axis_value_list;
@ -70,7 +70,7 @@ void InferImplReduceFuncCalShape(ShapeVector *shape, const ShapeVector &x_shape,
int64_t axis_value = GetValue<int64_t>(axis);
axis_value = InferImplReduceFuncCheckAxis(axis_value, x_shape.size());
if (keep_dims_value) {
shape->at(axis_value) = 1;
shape->at(LongToSize(axis_value)) = 1;
} else {
(void)shape->erase(shape->begin() + axis_value);
}
@ -185,7 +185,9 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &
AbstractBasePtr ReduceSumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kGreaterEqual, 1, primitive->name());
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kGreaterEqual, input_num,
primitive->name());
return abstract::MakeAbstract(InferShape(primitive, input_args), InferType(primitive, input_args));
}
} // namespace ops

View File

@ -28,7 +28,9 @@ namespace {
abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto prim_name = primitive->name();
CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 1, prim_name);
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num,
prim_name);
auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
auto axis = GetValue<int64_t>(primitive->GetAttr(kAxis));
auto x_rank = SizeToLong(x_shape.size());

View File

@ -30,7 +30,7 @@ void SmoothL1Loss::set_beta(const float beta) { (void)this->AddAttr(kBeta, MakeV
float SmoothL1Loss::get_beta() const {
auto value_ptr = this->GetAttr(kBeta);
return GetValue<int64_t>(value_ptr);
return GetValue<int32_t>(value_ptr);
}
AbstractBasePtr SmoothL1LossInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,

View File

@ -23,7 +23,7 @@
namespace mindspore {
namespace ops {
namespace {
constexpr size_t kInputSize = 2;
constexpr int64_t kInputSize = 2;
abstract::ShapePtr SoftMarginLossInferShape(const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);

View File

@ -30,7 +30,9 @@ namespace ops {
namespace {
abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
(void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, primitive->name());
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num,
primitive->name());
for (const auto &item : input_args) {
MS_EXCEPTION_IF_NULL(item);
}
@ -39,7 +41,9 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<A
}
TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(prim);
(void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, prim->name());
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num,
prim->name());
if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) {
MS_LOG(EXCEPTION) << "nullptr";
}

View File

@ -38,9 +38,10 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<A
const size_t kDimsOffset = 2;
for (size_t i = 0; i < kDimsOffset; i++) {
auto padded = output_shape[i + kDimsOffset] + paddings[i][0] + paddings[i][1];
(void)CheckAndConvertUtils::CheckInteger("padded shape", SizeToLong(padded % block_shape_vector.size()), kEqual, 0,
prim_name);
output_shape[i + kDimsOffset] = SizeToLong(padded / block_shape_vector.size());
const int64_t input_num = 0;
(void)CheckAndConvertUtils::CheckInteger("padded shape", SizeToLong(padded % block_shape_vector.size()), kEqual,
input_num, prim_name);
output_shape[i + kDimsOffset] = padded / SizeToLong(block_shape_vector.size());
}
output_shape[0] *= SizeToLong(block_shape_vector.size() * block_shape_vector.size());
return std::make_shared<abstract::Shape>(output_shape);

View File

@ -43,19 +43,23 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec
auto grad_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[4]->BuildShape())[kShape];
auto indices_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[5]->BuildShape())[kShape];
// Args lr must be scalar
(void)CheckAndConvertUtils::CheckInteger("size of lr_shape", lr_shape.size(), kEqual, 0, primitive->name());
const int64_t input_num_ = 0;
(void)CheckAndConvertUtils::CheckInteger("size of lr_shape", lr_shape.size(), kEqual, input_num_, primitive->name());
// Shape of var、ms、mom、grad must be same
std::map<std::string, ShapeVector> same_shape_args_map;
same_shape_args_map.insert({"shape of ms ", ms_shape});
same_shape_args_map.insert({"shape of mom ", mom_shape});
same_shape_args_map.insert({"shape of grad ", grad_shape});
(void)same_shape_args_map.insert({"shape of ms ", ms_shape});
(void)same_shape_args_map.insert({"shape of mom ", mom_shape});
(void)same_shape_args_map.insert({"shape of grad ", grad_shape});
for (auto &elem : same_shape_args_map) {
CheckAndConvertUtils::Check(elem.first, elem.second, kEqual, "var shape", var_shape, prim_name);
}
// Indices must be rank 1
(void)CheckAndConvertUtils::CheckInteger("indices dim", indices_shape.size(), kEqual, 1, prim_name);
const int64_t input_num = 1;
(void)CheckAndConvertUtils::CheckInteger("indices dim", SizeToLong(indices_shape.size()), kEqual, input_num,
prim_name);
// Dimension of var must be equal or greater than 1
(void)CheckAndConvertUtils::CheckInteger("dimension of var", var_shape.size(), kGreaterEqual, 1, prim_name);
(void)CheckAndConvertUtils::CheckInteger("dimension of var", SizeToLong(var_shape.size()), kGreaterEqual, input_num,
prim_name);
// Indices shape must be equal to the first dimension of var
CheckAndConvertUtils::Check("indices shape", indices_shape[0], kEqual, "the first dimension of var", var_shape[0],
prim_name);
@ -79,18 +83,18 @@ TuplePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr>
const std::set<TypePtr> valid_types = {kFloat16, kFloat32};
// Args ms、mom、grad must have the same type as var
std::map<std::string, TypePtr> args;
args.insert({"var", var_type});
args.insert({"ms", ms_type});
args.insert({"mom", mom_type});
args.insert({"grad", grad_type});
(void)args.insert({"var", var_type});
(void)args.insert({"ms", ms_type});
(void)args.insert({"mom", mom_type});
(void)args.insert({"grad", grad_type});
(void)CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name);
// Args lr must be a scalar type
std::map<std::string, TypePtr> args2;
args2.insert({"lr", lr_type});
(void)args2.insert({"lr", lr_type});
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args2, valid_types, prim_name);
// Check indices type
std::map<std::string, TypePtr> args3;
args3.insert({"indices", indices_type});
(void)args3.insert({"indices", indices_type});
const std::set<TypePtr> valid_types1 = {kInt32, kInt64};
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args3, valid_types1, prim_name);
return std::make_shared<Tuple>(std::vector<TypePtr>{var_type, ms_type, mom_type});

View File

@ -21,7 +21,7 @@
namespace mindspore {
namespace ops {
void Split::Init(const std::vector<int64_t> &size_splits, const int64_t axis, const int64_t output_num) {
void Split::Init(const int64_t axis, const int64_t output_num) {
this->set_axis(axis);
this->set_output_num(output_num);
}

View File

@ -31,7 +31,7 @@ class MS_CORE_API Split : public PrimitiveC {
Split() : PrimitiveC(kNameSplit) {}
~Split() = default;
MS_DECLARE_PARENT(Split, PrimitiveC);
void Init(const std::vector<int64_t> &size_splits, const int64_t axis, const int64_t output_num);
void Init(const int64_t axis, const int64_t output_num);
void set_size_splits(const std::vector<int64_t> &size_splits);
void set_axis(const int64_t axis);
void set_output_num(const int64_t output_num);

View File

@ -36,42 +36,42 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec
if (split_dim < 0) {
split_dim += x_rank;
}
auto shape_of_split_dim = x_shape[split_dim];
auto shape_of_split_dim = x_shape[LongToSize(split_dim)];
auto num_split = GetValue<int64_t>(primitive->GetAttr("num_split"));
CheckAndConvertUtils::CheckInteger("num_split", num_split, kGreaterEqual, 1, prim_name);
(void)CheckAndConvertUtils::CheckInteger("num_split", num_split, kGreaterEqual, 1, prim_name);
auto size_splits = GetValue<std::vector<int64_t>>(primitive->GetAttr(kSizeSplits));
CheckAndConvertUtils::Check("num_split", num_split, kEqual, "rank of size_splits", SizeToLong(size_splits.size()),
prim_name);
auto default_idx = std::find(size_splits.begin(), size_splits.end(), -1);
if (default_idx == size_splits.end()) {
int sum_of_size_splits = 0;
int64_t sum_of_size_splits = 0;
for (int64_t i = 0; i < num_split; i++) {
CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth,
{0, shape_of_split_dim}, prim_name);
sum_of_size_splits += size_splits[i];
(void)CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth,
{0, shape_of_split_dim}, prim_name);
sum_of_size_splits += size_splits[LongToSize(i)];
}
CheckAndConvertUtils::Check("sum of size_splits", sum_of_size_splits, kEqual, "dimension of value along split_dim",
shape_of_split_dim, prim_name);
} else {
size_splits.erase(default_idx);
(void)size_splits.erase(default_idx);
auto excessive_default_idx = std::find(size_splits.begin(), size_splits.end(), -1);
if (excessive_default_idx != size_splits.end()) {
MS_EXCEPTION(ValueError) << "Got more than one default value -1 in size_splits.";
} else {
int sum_of_size_splits = 0;
int64_t sum_of_size_splits = 0;
for (int64_t i = 0; i < num_split - 1; i++) {
CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth,
{0, shape_of_split_dim}, prim_name);
sum_of_size_splits += size_splits[i];
(void)CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth,
{0, shape_of_split_dim}, prim_name);
sum_of_size_splits += size_splits[LongToSize(i)];
}
auto default_value = shape_of_split_dim - sum_of_size_splits;
size_splits.insert(default_idx, default_value);
(void)size_splits.insert(default_idx, default_value);
}
}
std::vector<abstract::BaseShapePtr> shape_tuple;
for (int64_t i = 0; i < num_split; i++) {
auto shape = x_shape;
shape[split_dim] = size_splits[i];
shape[split_dim] = size_splits[LongToSize(i)];
abstract::ShapePtr out_shape = std::make_shared<abstract::Shape>(shape);
shape_tuple.push_back(out_shape);
}

View File

@ -27,14 +27,13 @@ void ImpleSquare(void *origin, void *target, size_t size) {
MS_EXCEPTION_IF_NULL(target);
auto origin_data = reinterpret_cast<T *>(origin);
auto target_data = reinterpret_cast<T *>(target);
MS_EXCEPTION_IF_NULL(origin_data);
MS_EXCEPTION_IF_NULL(target_data);
for (size_t i = 0; i < size; ++i) {
target_data[i] = origin_data[i] * origin_data[i];
}
}
abstract::ShapePtr SquareInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape());
auto in_shape = shape_map[kShape];
auto min_shape = shape_map[kMinShape];
@ -80,47 +79,47 @@ ValuePtr SquareInferValue(const PrimitivePtr &prim, const std::vector<AbstractBa
auto result_datac = result_tensor->data_c();
switch (dtype) {
case kNumberTypeInt8: {
ImpleSquare<int8_t>(x_datac, result_datac, data_size);
ImpleSquare<int8_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeInt16: {
ImpleSquare<int16_t>(x_datac, result_datac, data_size);
ImpleSquare<int16_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeInt32: {
ImpleSquare<int32_t>(x_datac, result_datac, data_size);
ImpleSquare<int32_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeInt64: {
ImpleSquare<int64_t>(x_datac, result_datac, data_size);
ImpleSquare<int64_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt8: {
ImpleSquare<uint8_t>(x_datac, result_datac, data_size);
ImpleSquare<uint8_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt16: {
ImpleSquare<uint16_t>(x_datac, result_datac, data_size);
ImpleSquare<uint16_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt32: {
ImpleSquare<uint32_t>(x_datac, result_datac, data_size);
ImpleSquare<uint32_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeUInt64: {
ImpleSquare<uint64_t>(x_datac, result_datac, data_size);
ImpleSquare<uint64_t>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeFloat16: {
ImpleSquare<float16>(x_datac, result_datac, data_size);
ImpleSquare<float16>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeFloat32: {
ImpleSquare<float>(x_datac, result_datac, data_size);
ImpleSquare<float>(x_datac, result_datac, IntToSize(data_size));
break;
}
case kNumberTypeFloat64: {
ImpleSquare<double>(x_datac, result_datac, data_size);
ImpleSquare<double>(x_datac, result_datac, IntToSize(data_size));
break;
}
default: {

View File

@ -66,7 +66,6 @@ void EllipsisInferShape(const PrimitivePtr &primitive, const std::vector<int64_t
size_t slice_len = begin_v.size();
std::vector<int64_t> begin_pos = TenToTwo(GetValue<int64_t>(primitive->GetAttr(kBeginMask)));
std::vector<int64_t> end_pos = TenToTwo(GetValue<int64_t>(primitive->GetAttr(kEndMask)));
std::vector<int64_t> ellipsis_pos = TenToTwo(GetValue<int64_t>(primitive->GetAttr(kEllipsisMask)));
std::vector<int64_t> new_axis_pos = TenToTwo(GetValue<int64_t>(primitive->GetAttr(kNewAxisMask)));
std::vector<int64_t> shrink_axis_pos = TenToTwo(GetValue<int64_t>(primitive->GetAttr(kShrinkAxisMask)));
(void)CheckAndConvertUtils::CheckInteger("infer", SizeToLong(new_axis_pos.size()), kGreaterEqual,
@ -80,7 +79,7 @@ void EllipsisInferShape(const PrimitivePtr &primitive, const std::vector<int64_t
}
size_t ellipsis_occupied_dims = x_rank - i - (slice_len - (j + 1)) + num;
(void)infer_shape->insert(infer_shape->end(), x_shape.begin() + i,
(void)infer_shape->insert(infer_shape->end(), x_shape.begin() + LongToSize(i),
x_shape.begin() + SizeToLong(i + ellipsis_occupied_dims));
j += 1;
i += ellipsis_occupied_dims;

View File

@ -55,7 +55,7 @@ AbstractBasePtr UnsqueezeInfer(const abstract::AnalysisEnginePtr &, const Primit
if (ax_itr < dim_rank && dims[ax_itr] == (int64_t)i) {
(void)out_shape.emplace_back(1);
ax_itr++;
} else if (ax_itr < dim_rank && dims[ax_itr] + sz == i) {
} else if (ax_itr < dim_rank && dims[ax_itr] + sz == LongToSize(i)) {
(void)out_shape.emplace_back(1);
ax_itr++;
} else {