已合并
【bugfix】upsample_bicubic2d_backward,upsample_linear1d,sort_without_indices,roll,roll_6d,sin,unique2,multinomial,repeat,ctc_loss #678
AtomGit-Bot创建于 2022年4月14日
【bugfix】upsample_bicubic2d_backward,upsample_linear1d,sort_without_indices,roll,roll_6d,sin,unique2,multinomial,repeat,ctc_loss #678
已合并
AtomGit-Bot创建于 2022年4月14日
refs/pull/678/head合入到master
9 个文件变更+28-19
Mtorch_npu/csrc/aten/ops/CtcLossKernelNpu.cpp+6-4
@@ -62,13 +62,15 @@ std::tuple<at::Tensor, at::Tensor> NPUNativeFunctions::_ctc_loss(
62 auto outputSizes = ctc_loss_npu_output_size(logProbs, targetsCast, targetLengths, maxLength);62 auto outputSizes = ctc_loss_npu_output_size(logProbs, targetsCast, targetLengths, maxLength);
63 63 
64 // construct the output tensor of the NPU64 // construct the output tensor of the NPU
65- at::Tensor negLogLikelihood = OpPreparation::ApplyTensorWithSizes(65+ at::Tensor negLogLikelihood = OpPreparation::ApplyTensorWithFormat(
66 std::get<0>(outputSizes),66 std::get<0>(outputSizes),
67- logProbsNeed.options());67+ logProbsNeed.options(),
68+ CalcuOpUtil::get_tensor_npu_format(logProbsNeed));
68 69
69- at::Tensor logAlpha = OpPreparation::ApplyTensorWithSizes(70+ at::Tensor logAlpha = OpPreparation::ApplyTensorWithFormat(
70 std::get<1>(outputSizes),71 std::get<1>(outputSizes),
71- logProbsNeed.options());72+ logProbsNeed.options(),
73+ CalcuOpUtil::get_tensor_npu_format(logProbsNeed));
72 74 
73 // calculate the output result of the NPU 75 // calculate the output result of the NPU
74 OpCommand cmd;76 OpCommand cmd;
Mtorch_npu/csrc/aten/ops/MultinomialKernelNpu.cpp+2-2
@@ -70,8 +70,8 @@ at::Tensor NPUNativeFunctions::multinomial(
70 auto shape = array_to_small_vector(self.sizes());70 auto shape = array_to_small_vector(self.sizes());
71 shape[dim-1] = num_samples;71 shape[dim-1] = num_samples;
72 72 
73- at::Tensor result = OpPreparation::ApplyTensorWithSizes(73+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
74- shape, self.options().dtype(at::kLong));74+ shape, self.options().dtype(at::kLong), CalcuOpUtil::get_tensor_npu_format(self));
75 multinomial_out_npu_nocheck(result, self, num_samples, replacement, gen);75 multinomial_out_npu_nocheck(result, self, num_samples, replacement, gen);
76 return result;76 return result;
77}77}
Mtorch_npu/csrc/aten/ops/RepeatKernelNpu.cpp+2-1
@@ -50,7 +50,8 @@ at::Tensor NPUNativeFunctions::repeat(const at::Tensor& self, at::IntArrayRef re
50 auto outputSize = repeat_npu_output_size(selfCp, repeats);50 auto outputSize = repeat_npu_output_size(selfCp, repeats);
51 51 
52 // construct the output tensor of the NPU52 // construct the output tensor of the NPU
53- at::Tensor result = OpPreparation::ApplyTensorWithSizes(outputSize, selfCp.options());53+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
54+ outputSize, selfCp.options(), CalcuOpUtil::get_tensor_npu_format(selfCp));
54 55 
55 // calculate the output result of the NPU56 // calculate the output result of the NPU
56 repeat_out_npu_nocheck(result, selfCp, repeats);57 repeat_out_npu_nocheck(result, selfCp, repeats);
Mtorch_npu/csrc/aten/ops/RollKernelNpu.cpp+3-2
@@ -52,9 +52,10 @@ at::Tensor& roll_transpose(
52 std::swap(perm[axis], perm[firstDim]);52 std::swap(perm[axis], perm[firstDim]);
53 at::Tensor transposeSelf = NPUNativeFunctions::npu_transpose(self, perm);53 at::Tensor transposeSelf = NPUNativeFunctions::npu_transpose(self, perm);
54 auto outputSize = transpose_npu_output_size(result, perm);54 auto outputSize = transpose_npu_output_size(result, perm);
55- at::Tensor transposeResult = OpPreparation::ApplyTensorWithSizes(55+ at::Tensor transposeResult = OpPreparation::ApplyTensorWithFormat(
56 outputSize,56 outputSize,
57- self.options());57+ self.options(),
58+ CalcuOpUtil::get_tensor_npu_format(self));
58 c10::SmallVector<int64_t, SIZE> dim = {firstDim};59 c10::SmallVector<int64_t, SIZE> dim = {firstDim};
59 c10::SmallVector<int64_t, SIZE> shift_bak = {shifts[id]};60 c10::SmallVector<int64_t, SIZE> shift_bak = {shifts[id]};
60 at::IntArrayRef dim_now = at::IntArrayRef(dim);61 at::IntArrayRef dim_now = at::IntArrayRef(dim);
Mtorch_npu/csrc/aten/ops/SinKernelNpu.cpp+2-1
@@ -46,7 +46,8 @@ at::Tensor& NPUNativeFunctions::sin_out(const at::Tensor& self, at::Tensor& resu
46 46 
47at::Tensor NPUNativeFunctions::sin(const at::Tensor& self) {47at::Tensor NPUNativeFunctions::sin(const at::Tensor& self) {
48 // construct the output tensor of the NPU48 // construct the output tensor of the NPU
49- at::Tensor result = OpPreparation::ApplyTensorWithSizes(self.sizes(), self.options());49+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
50+ self.sizes(), self.options(), CalcuOpUtil::get_tensor_npu_format(self));
50 51 
51 // calculate the output result of the NPU52 // calculate the output result of the NPU
52 sin_out_npu_nocheck(result, self);53 sin_out_npu_nocheck(result, self);
Mtorch_npu/csrc/aten/ops/SortWithoutIndicesKernelNpu.cpp+2-2
@@ -61,7 +61,7 @@ at::Tensor& NPUNativeFunctions::npu_sort_v2_out(
61 at::Tensor transposeSelf = NPUNativeFunctions::npu_transpose(self, perm);61 at::Tensor transposeSelf = NPUNativeFunctions::npu_transpose(self, perm);
62 62 
63 auto outputSize = transpose_npu_output_size(result, perm);63 auto outputSize = transpose_npu_output_size(result, perm);
64- at::Tensor transposeResult = OpPreparation::ApplyTensorWithSizes(outputSize, result.options());64+ at::Tensor transposeResult = OpPreparation::ApplyTensor(result, outputSize);
65 65 
66 sort_without_indices_no_transpose(transposeResult, transposeSelf, lastDim, descending);66 sort_without_indices_no_transpose(transposeResult, transposeSelf, lastDim, descending);
67 NPUNativeFunctions::npu_transpose_out(transposeResult, perm, result);67 NPUNativeFunctions::npu_transpose_out(transposeResult, perm, result);
@@ -97,7 +97,7 @@ at::Tensor NPUNativeFunctions::npu_sort_v2(
97 at::Tensor transposeSelf = NPUNativeFunctions::npu_transpose(self, perm);97 at::Tensor transposeSelf = NPUNativeFunctions::npu_transpose(self, perm);
98 98 
99 auto outputSize = transpose_npu_output_size(result, perm);99 auto outputSize = transpose_npu_output_size(result, perm);
100- at::Tensor transposeResult = OpPreparation::ApplyTensorWithSizes(outputSize, result.options());100+ at::Tensor transposeResult = OpPreparation::ApplyTensor(result, outputSize);
101 101 
102 sort_without_indices_no_transpose(transposeResult, transposeSelf, lastDim, descending);102 sort_without_indices_no_transpose(transposeResult, transposeSelf, lastDim, descending);
103 NPUNativeFunctions::npu_transpose_out(transposeResult, perm, result);103 NPUNativeFunctions::npu_transpose_out(transposeResult, perm, result);
Mtorch_npu/csrc/aten/ops/UpSampleBicubic2dBackwardKernelNpu.cpp+4-2
@@ -115,7 +115,8 @@ at::Tensor NPUNativeFunctions::upsample_bicubic2d_backward(
115 c10::optional<double> scales_w) {115 c10::optional<double> scales_w) {
116 // construct the output tensor of the NPU116 // construct the output tensor of the NPU
117 auto outputSize = upsample_bicubic2d_backward_npu_output_size(input_size);117 auto outputSize = upsample_bicubic2d_backward_npu_output_size(input_size);
118- at::Tensor result = OpPreparation::ApplyTensorWithSizes(outputSize, grad_output.options());118+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
119+ outputSize, grad_output.options(), CalcuOpUtil::get_tensor_npu_format(grad_output));
119 // calculate the output result of the NPU120 // calculate the output result of the NPU
120 return upsample_bicubic2d_backward_out_nocheck(grad_output, output_size, input_size, align_corners, scales_h, scales_w, result);121 return upsample_bicubic2d_backward_out_nocheck(grad_output, output_size, input_size, align_corners, scales_h, scales_w, result);
121}122}
@@ -131,7 +132,8 @@ at::Tensor NPUNativeFunctions::upsample_bicubic2d_backward(
131 auto scales_w = CalcuOpUtil::get_scale_value(scale_factors, 1);132 auto scales_w = CalcuOpUtil::get_scale_value(scale_factors, 1);
132 // construct the output tensor of the NPU133 // construct the output tensor of the NPU
133 auto outputSize = upsample_bicubic2d_backward_npu_output_size(input_size);134 auto outputSize = upsample_bicubic2d_backward_npu_output_size(input_size);
134- at::Tensor result = OpPreparation::ApplyTensorWithSizes(outputSize, grad_output.options());135+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
136+ outputSize, grad_output.options(), CalcuOpUtil::get_tensor_npu_format(grad_output));
135 // calculate the output result of the NPU137 // calculate the output result of the NPU
136 return upsample_bicubic2d_backward_out_nocheck(grad_output, osize, input_size, align_corners, scales_h, scales_w, result);138 return upsample_bicubic2d_backward_out_nocheck(grad_output, osize, input_size, align_corners, scales_h, scales_w, result);
137}139}
Mtorch_npu/csrc/aten/ops/UpsampleLinear1dKernelNpu.cpp+4-2
@@ -124,7 +124,8 @@ at::Tensor NPUNativeFunctions::upsample_linear1d(
124 self, output_size, align_corners, scales);124 self, output_size, align_corners, scales);
125 125
126 // construct the output tensor of the NPU126 // construct the output tensor of the NPU
127- at::Tensor result = OpPreparation::ApplyTensorWithSizes(outputSize, self.options());127+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
128+ outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
128 129 
129 // calculate the output result of the NPU130 // calculate the output result of the NPU
130 upsample_linear1d_out_nocheck(self, output_size, align_corners, scales, result);131 upsample_linear1d_out_nocheck(self, output_size, align_corners, scales, result);
@@ -144,7 +145,8 @@ at::Tensor NPUNativeFunctions::upsample_linear1d(
144 self, osize, align_corners, scales_w);145 self, osize, align_corners, scales_w);
145 146
146 // construct the output tensor of the NPU147 // construct the output tensor of the NPU
147- at::Tensor result = OpPreparation::ApplyTensorWithSizes(outputSize, self.options());148+ at::Tensor result = OpPreparation::ApplyTensorWithFormat(
149+ outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
148 150 
149 // calculate the output result of the NPU151 // calculate the output result of the NPU
150 upsample_linear1d_out_nocheck(self, osize, align_corners, scales_w, result);152 upsample_linear1d_out_nocheck(self, osize, align_corners, scales_w, result);
Mtorch_npu/csrc/aten/ops/_Unique2KernelNpu.cpp+3-3
@@ -64,9 +64,9 @@ tuple<at::Tensor, at::Tensor, at::Tensor> NPUNativeFunctions::_unique2(
64 }64 }
65 65
66 at::Tensor y = OpPreparation::ApplyTensor(selfCopy, std::get<0>(outputSizes));66 at::Tensor y = OpPreparation::ApplyTensor(selfCopy, std::get<0>(outputSizes));
67- at::Tensor yOutputSize = OpPreparation::ApplyTensorWithSizes(std::get<1>(outputSizes), self.options().dtype(at::kLong));67+ at::Tensor yOutputSize = OpPreparation::ApplyTensorWithFormat(std::get<1>(outputSizes), self.options().dtype(at::kLong), ACL_FORMAT_ND);
68- at::Tensor yInverse = OpPreparation::ApplyTensorWithSizes(std::get<2>(outputSizes), self.options().dtype(at::kLong));68+ at::Tensor yInverse = OpPreparation::ApplyTensorWithFormat(std::get<2>(outputSizes), self.options().dtype(at::kLong), ACL_FORMAT_ND);
69- at::Tensor yCounts = OpPreparation::ApplyTensorWithSizes(std::get<0>(outputSizes), self.options().dtype(at::kLong));69+ at::Tensor yCounts = OpPreparation::ApplyTensorWithFormat(std::get<0>(outputSizes), self.options().dtype(at::kLong), ACL_FORMAT_ND);
70 70
71 _unique2_out_npu(y, yOutputSize, yInverse, yCounts, selfCopy, sorted, return_inverse, return_counts);71 _unique2_out_npu(y, yOutputSize, yInverse, yCounts, selfCopy, sorted, return_inverse, return_counts);
72 72