forked from huawei/mindspore2022
!31673 support tranpose with neg perm
Merge pull request !31673 from 范吉斌/transpose_neg
This commit is contained in:
commit
e14942017d
|
|
@ -84,7 +84,6 @@ bool BatchNormCpuKernelMod::Launch(const std::vector<kernel::AddressPtr> &inputs
|
|||
auto bias_ret = memcpy_s(wksp + (inputs[1]->size / sizeof(float)), max_size, inputs[2]->addr, inputs[2]->size);
|
||||
if (scale_ret != 0 || bias_ret != 0) {
|
||||
MS_LOG(EXCEPTION) << "Memcpy_s error.";
|
||||
return false;
|
||||
}
|
||||
if (is_train) {
|
||||
SetArgumentHandle(DNNL_ARG_SRC, inputs[0]->addr);
|
||||
|
|
|
|||
|
|
@ -111,8 +111,6 @@ void LstmCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
AddArgument(DNNL_ARG_DST_ITER, dst_h_desc);
|
||||
AddArgument(DNNL_ARG_DST_ITER_C, dst_c_desc);
|
||||
|
||||
using dt = dnnl::memory::data_type;
|
||||
using tag = dnnl::memory::format_tag;
|
||||
auto weights_dims_desc = CreateDesc<dnnl::memory::desc>(weights_dims_, dt::f32, tag::ldgoi);
|
||||
auto weights_h_dims_desc = CreateDesc<dnnl::memory::desc>(weights_h_dims_, dt::f32, tag::ldgoi);
|
||||
user_weights_memory_ = CreateDesc<dnnl::memory>(weights_dims_desc, eng);
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class mkl_threadpool : public dnnl::threadpool_interop::threadpool_iface {
|
|||
fn(i, n_jobs);
|
||||
return 0;
|
||||
};
|
||||
tp_->ParallelLaunch(func, nullptr, n_jobs);
|
||||
(void)tp_->ParallelLaunch(func, nullptr, n_jobs);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -36,8 +36,15 @@ void TransposeFwdCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
kernel_name_ = common::AnfAlgo::GetCNodeName(kernel_node);
|
||||
input_shape_ = AnfAlgo::GetInputDeviceShape(kernel_node, 0);
|
||||
output_shape_ = AnfAlgo::GetOutputDeviceShape(kernel_node, 0);
|
||||
auto tmp = common::AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, "perm");
|
||||
axes_ = {tmp.begin(), tmp.end()};
|
||||
auto perm = common::AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, "perm");
|
||||
for (auto p : perm) {
|
||||
p = (p >= 0) ? p : (perm.size() + p);
|
||||
if (p < 0) {
|
||||
MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the perm value should in [-" << perm.size() << ", "
|
||||
<< (perm.size() - 1) << "], but got " << perm;
|
||||
}
|
||||
axes_.emplace_back(p);
|
||||
}
|
||||
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
|
||||
if (axes_.size() > MAX_TRANSPOSE_DIM_SIZE) {
|
||||
MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the max dimension of input is " << MAX_TRANSPOSE_DIM_SIZE
|
||||
|
|
|
|||
|
|
@ -113,7 +113,12 @@ class TransposeFwdGpuKernelMod : public NativeGpuKernelMod {
|
|||
output_size_ = input_size_;
|
||||
std::vector<int64_t> perm = GetAttr<std::vector<int64_t>>(kernel_node, "perm");
|
||||
for (size_t j = 0; j < perm.size(); j++) {
|
||||
input_axis_.push_back(perm[j]);
|
||||
auto p = (perm[j] >= 0) ? perm[j] : (perm.size() + perm[j]);
|
||||
if (p < 0) {
|
||||
MS_LOG(EXCEPTION) << "For '" << kernel_name << "', the perm value should in [-" << perm.size() << ", "
|
||||
<< (perm.size() - 1) << "], but got " << perm;
|
||||
}
|
||||
input_axis_.push_back(p);
|
||||
}
|
||||
InitSizeLists();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ abstract::ShapePtr TransposeInferShape(const PrimitivePtr &primitive, const std:
|
|||
auto x_min_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kMinShape];
|
||||
auto x_max_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kMaxShape];
|
||||
ShapeVector p_value;
|
||||
ShapeVector p_value_raw;
|
||||
if (input_args.size() == 1) {
|
||||
if (!primitive->HasAttr("perm")) {
|
||||
MS_EXCEPTION(ValueError) << "For '" << op_name << "', the value of input_perm is required!";
|
||||
|
|
@ -40,23 +41,26 @@ abstract::ShapePtr TransposeInferShape(const PrimitivePtr &primitive, const std:
|
|||
auto perm_val = perm->cast<ValueTuplePtr>();
|
||||
MS_EXCEPTION_IF_NULL(perm_val);
|
||||
auto perm_val_data = perm_val->value();
|
||||
(void)std::transform(std::begin(perm_val_data), std::end(perm_val_data), std::back_inserter(p_value),
|
||||
(void)std::transform(std::begin(perm_val_data), std::end(perm_val_data), std::back_inserter(p_value_raw),
|
||||
[](const ValuePtr &e) -> int64_t { return GetValue<int64_t>(e); });
|
||||
} else {
|
||||
auto perm_value = input_args[1]->BuildValue();
|
||||
MS_EXCEPTION_IF_NULL(perm_value);
|
||||
if (perm_value->isa<tensor::Tensor>()) {
|
||||
p_value = CheckAndConvertUtils::CheckTensorIntValue("perm", perm_value, op_name);
|
||||
p_value_raw = CheckAndConvertUtils::CheckTensorIntValue("perm", perm_value, op_name);
|
||||
} else {
|
||||
p_value = CheckAndConvertUtils::CheckTupleInt("input[perm]", perm_value, op_name);
|
||||
p_value_raw = CheckAndConvertUtils::CheckTupleInt("input[perm]", perm_value, op_name);
|
||||
}
|
||||
}
|
||||
for (auto p : p_value_raw) {
|
||||
p = (p >= 0) ? p : (p_value_raw.size() + p);
|
||||
p_value.emplace_back(p);
|
||||
}
|
||||
if (x_shape.size() != p_value.size()) {
|
||||
MS_EXCEPTION(ValueError) << "For '" << op_name << "', The dimension of x " << x_shape.size() << " and perm "
|
||||
<< p_value.size() << " must be equal.";
|
||||
}
|
||||
for (auto i : p_value) {
|
||||
(void)CheckAndConvertUtils::CheckInteger("perm element", i, kGreaterEqual, 0, op_name);
|
||||
(void)CheckAndConvertUtils::CheckInteger("perm element", i, kLessThan, SizeToLong(p_value.size()), op_name);
|
||||
}
|
||||
std::vector<int64_t> tmp(p_value);
|
||||
|
|
|
|||
Loading…
Reference in New Issue