已合并
[2/N] cleancode #2293
zqwen创建于 2025年3月18日
[2/N] cleancode #2293
已合并
zqwen创建于 2025年3月18日
refs/pull/2293/head合入到master
3 个文件变更+153-148
Mop_plugin/ops/aclops/LstmKernelNpu.cpp+40-40
@@ -70,16 +70,16 @@ tensor_list npu_lstm_npu_nocheck(const at::Tensor &input, const at::Tensor &weig
70 .Output(f_output)70 .Output(f_output)
71 .Output(o_output)71 .Output(o_output)
72 .Output(tanhc)72 .Output(tanhc)
73- .Attr("cell_type", (string) "LSTM")73+ .Attr("cell_type", static_cast<std::string>("LSTM"))
74 .Attr("direction", direction)74 .Attr("direction", direction)
75- .Attr("cell_depth", (int64_t)1)75+ .Attr("cell_depth", static_cast<int64_t>(1))
76- .Attr("use_peephole", (bool)false)76+ .Attr("use_peephole", static_cast<bool>(false))
77- .Attr("keep_prob", (float)1.0)77+ .Attr("keep_prob", static_cast<float>(1.0))
78- .Attr("cell_clip", (float)-1.0)78+ .Attr("cell_clip", static_cast<float>(-1.0))
79- .Attr("num_proj", (int64_t)0)79+ .Attr("num_proj", static_cast<int64_t>(0))
80- .Attr("time_major", (bool)true)80+ .Attr("time_major", static_cast<bool>(true))
81- .Attr("activation", (string) "tanh")81+ .Attr("activation", static_cast<std::string>("tanh"))
82- .Attr("forget_bias", (float)0.0)82+ .Attr("forget_bias", static_cast<float>(0.0))
83 .Attr("is_training", train)83 .Attr("is_training", train)
84 .Attr("gate_order", gate_order)84 .Attr("gate_order", gate_order)
85 .Run();85 .Run();
@@ -385,13 +385,13 @@ std::tuple<at::Tensor &, at::Tensor &, at::Tensor &, at::Tensor &, at::Tensor &>
385 .Output(dct)385 .Output(dct)
386 .Attr("cell_type", "LSTM")386 .Attr("cell_type", "LSTM")
387 .Attr("direction", direction)387 .Attr("direction", direction)
388- .Attr("cell_depth", (int64_t)0)388+ .Attr("cell_depth", static_cast<int64_t>(0))
389- .Attr("use_peephole", (bool)false)389+ .Attr("use_peephole", static_cast<bool>(false))
390- .Attr("keep_prob", (float)-1.0)390+ .Attr("keep_prob", static_cast<float>(-1.0))
391- .Attr("cell_clip", (float)-1.0)391+ .Attr("cell_clip", static_cast<float>(-1.0))
392- .Attr("num_proj", (int64_t)0)392+ .Attr("num_proj", static_cast<int64_t>(0))
393- .Attr("time_major", (bool)true)393+ .Attr("time_major", static_cast<bool>(true))
394- .Attr("forget_bias", (float)0.0)394+ .Attr("forget_bias", static_cast<float>(0.0))
395 .Attr("gate_order", gate_order)395 .Attr("gate_order", gate_order)
396 .Run();396 .Run();
397 397 
@@ -586,7 +586,7 @@ std::tuple<at::Tensor, at::Tensor, at::Tensor> lstm(const at::Tensor &input, at:
586 586 
587std::tuple<at::Tensor, at::Tensor, at::Tensor> lstm(const at::Tensor &data, const at::Tensor &batch_sizes,587std::tuple<at::Tensor, at::Tensor, at::Tensor> lstm(const at::Tensor &data, const at::Tensor &batch_sizes,
588 at::TensorList hx, at::TensorList params, bool has_biases,588 at::TensorList hx, at::TensorList params, bool has_biases,
589- int64_t num_layers, double dropout_p, bool train,589+ int64_t num_layers, double dropout, bool train,
590 bool bidirectional)590 bool bidirectional)
591{591{
592 at::Tensor batch_sizes_cpu = batch_sizes.to("cpu");592 at::Tensor batch_sizes_cpu = batch_sizes.to("cpu");
@@ -597,38 +597,38 @@ std::tuple<at::Tensor, at::Tensor, at::Tensor> lstm(const at::Tensor &data, cons
597 if (num_layers == 1) {597 if (num_layers == 1) {
598 if (!bidirectional) {598 if (!bidirectional) {
599 std::tie(y, h, c) = lstm_onelayer_direc_packseq(data, batch_sizes_cpu, hx, params, has_biases, num_layers,599 std::tie(y, h, c) = lstm_onelayer_direc_packseq(data, batch_sizes_cpu, hx, params, has_biases, num_layers,
600- dropout_p, train, bidirectional);600+ dropout, train, bidirectional);
601 } else {601 } else {
602 std::tie(y, h, c) = lstm_onelayer_bidirec_packseq(data, batch_sizes_cpu, hx, params, has_biases, num_layers,602 std::tie(y, h, c) = lstm_onelayer_bidirec_packseq(data, batch_sizes_cpu, hx, params, has_biases, num_layers,
603- dropout_p, train, bidirectional);603+ dropout, train, bidirectional);
604 }604 }
605 }605 }
606 606 
607 if (num_layers == 2) {607 if (num_layers == 2) {
608 if (!bidirectional) {608 if (!bidirectional) {
609 std::tie(y, h, c) = lstm_double_layer_direc_packseq(data, batch_sizes_cpu, hx, params, has_biases,609 std::tie(y, h, c) = lstm_double_layer_direc_packseq(data, batch_sizes_cpu, hx, params, has_biases,
610- num_layers, dropout_p, train, bidirectional);610+ num_layers, dropout, train, bidirectional);
611 } else {611 } else {
612 std::tie(y, h, c) = lstm_double_layer_bidirec_packseq(data, batch_sizes_cpu, hx, params, has_biases,612 std::tie(y, h, c) = lstm_double_layer_bidirec_packseq(data, batch_sizes_cpu, hx, params, has_biases,
613- num_layers, dropout_p, train, bidirectional);613+ num_layers, dropout, train, bidirectional);
614 }614 }
615 }615 }
616 return std::tie(y, h, c);616 return std::tie(y, h, c);
617}617}
618 618 
619-tensor_list5 npu_lstm_backward(const c10::optional<at::Tensor> &grady_opt, const c10::optional<at::Tensor> &gradh_opt,619+tensor_list5 npu_lstm_backward(const c10::optional<at::Tensor> &grady, const c10::optional<at::Tensor> &gradh,
620- const c10::optional<at::Tensor> &gradc_opt, const at::Tensor &input,620+ const c10::optional<at::Tensor> &gradc, const at::Tensor &input,
621- const at::Tensor &weight, const at::Tensor &bias, const at::Tensor &init_h,621+ const at::Tensor &weight, const at::Tensor &bias, const at::Tensor &hx,
622- const at::Tensor &init_c, const at::Tensor &y, const at::Tensor &h, const at::Tensor &c,622+ const at::Tensor &cx, const at::Tensor &y_output, const at::Tensor &h_output,
623- const at::Tensor &i, const at::Tensor &j, const at::Tensor &f, const at::Tensor &o,623+ const at::Tensor &c_output, const at::Tensor &i, const at::Tensor &j,
624- const at::Tensor &tanhc)624+ const at::Tensor &f, const at::Tensor &o, const at::Tensor &tanhc)
625{625{
626- const at::Tensor &grady = c10::value_or_else(grady_opt, [] { return at::Tensor(); });626+ const at::Tensor &grady_opt = c10::value_or_else(grady, [] { return at::Tensor(); });
627- const at::Tensor &gradh = c10::value_or_else(gradh_opt, [] { return at::Tensor(); });627+ const at::Tensor &gradh_opt = c10::value_or_else(gradh, [] { return at::Tensor(); });
628- const at::Tensor &gradc = c10::value_or_else(gradc_opt, [] { return at::Tensor(); });628+ const at::Tensor &gradc_opt = c10::value_or_else(gradc, [] { return at::Tensor(); });
629 629 
630- at::Tensor inh = at::squeeze(init_h, 0);630+ at::Tensor inh = at::squeeze(hx, 0);
631- at::Tensor inc = at::squeeze(init_c, 0);631+ at::Tensor inc = at::squeeze(cx, 0);
632 632 
633 at::Tensor grad_input = npu_preparation::apply_tensor(input);633 at::Tensor grad_input = npu_preparation::apply_tensor(input);
634 at::Tensor grad_weight = npu_preparation::apply_tensor(weight);634 at::Tensor grad_weight = npu_preparation::apply_tensor(weight);
@@ -636,12 +636,12 @@ tensor_list5 npu_lstm_backward(const c10::optional<at::Tensor> &grady_opt, const
636 at::Tensor grad_ht = npu_preparation::apply_tensor(inh);636 at::Tensor grad_ht = npu_preparation::apply_tensor(inh);
637 at::Tensor grad_ct = npu_preparation::apply_tensor(inc);637 at::Tensor grad_ct = npu_preparation::apply_tensor(inc);
638 638 
639- auto grad_y = grady.defined() ? grady : at::zeros(y.sizes(), y.options());639+ auto grad_y = grady_opt.defined() ? grady_opt : at::zeros(y_output.sizes(), y_output.options());
640- auto grad_h = gradh.defined() ? gradh[input.size(0) - 1] : at::zeros(inh.sizes(), h.options());640+ auto grad_h = gradh_opt.defined() ? gradh_opt[input.size(0) - 1] : at::zeros(inh.sizes(), h_output.options());
641- auto grad_c = gradc.defined() ? gradc[input.size(0) - 1] : at::zeros(inc.sizes(), c.options());641+ auto grad_c = gradc_opt.defined() ? gradc_opt[input.size(0) - 1] : at::zeros(inc.sizes(), c_output.options());
642 642 
643 lstm_backward_out_npu_nocheck(grad_weight, grad_bias, grad_input, grad_ht, grad_ct, input, weight, bias, inh, inc,643 lstm_backward_out_npu_nocheck(grad_weight, grad_bias, grad_input, grad_ht, grad_ct, input, weight, bias, inh, inc,
644- grad_y, grad_h, grad_c, y, h, c, i, j, f, o, tanhc);644+ grad_y, grad_h, grad_c, y_output, h_output, c_output, i, j, f, o, tanhc);
645 grad_ht = at::unsqueeze(grad_ht, 0);645 grad_ht = at::unsqueeze(grad_ht, 0);
646 grad_ct = at::unsqueeze(grad_ct, 0);646 grad_ct = at::unsqueeze(grad_ct, 0);
647 647 
@@ -652,19 +652,19 @@ tensor_list5 npu_lstm_backward(const c10::optional<at::Tensor> &grady_opt, const
652tensor_list npu_lstm(const at::Tensor &input, const at::Tensor &weight, const at::Tensor &bias,652tensor_list npu_lstm(const at::Tensor &input, const at::Tensor &weight, const at::Tensor &bias,
653 const at::Tensor &seq_mask, const at::Tensor &h, const at::Tensor &c, bool has_biases,653 const at::Tensor &seq_mask, const at::Tensor &h, const at::Tensor &c, bool has_biases,
654 int64_t num_layers, double dropout, bool train, bool bidirectional, bool batch_first,654 int64_t num_layers, double dropout, bool train, bool bidirectional, bool batch_first,
655- bool flag_seq, bool flag_direction)655+ bool flag_seq, bool direction)
656{656{
657 return npu_lstm_npu_nocheck(input, weight, bias, seq_mask, h, c, has_biases, num_layers, dropout, train,657 return npu_lstm_npu_nocheck(input, weight, bias, seq_mask, h, c, has_biases, num_layers, dropout, train,
658- bidirectional, batch_first, flag_seq, flag_direction);658+ bidirectional, batch_first, flag_seq, direction);
659}659}
660 660 
661tensor_list npu_lstm_data(const at::Tensor &input, const at::Tensor &batch_sizes, const at::Tensor &weight,661tensor_list npu_lstm_data(const at::Tensor &input, const at::Tensor &batch_sizes, const at::Tensor &weight,
662 const at::Tensor &bias, const at::Tensor &seq_mask, const at::Tensor &h, const at::Tensor &c,662 const at::Tensor &bias, const at::Tensor &seq_mask, const at::Tensor &h, const at::Tensor &c,
663 bool has_biases, int64_t num_layers, double dropout, bool train, bool bidirectional,663 bool has_biases, int64_t num_layers, double dropout, bool train, bool bidirectional,
664- bool batch_first, bool flag_seq, bool flag_direction)664+ bool batch_first, bool flag_seq, bool direction)
665{665{
666 return npu_lstm_npu_nocheck(input, weight, bias, seq_mask, h, c, has_biases, num_layers, dropout, train,666 return npu_lstm_npu_nocheck(input, weight, bias, seq_mask, h, c, has_biases, num_layers, dropout, train,
667- bidirectional, batch_first, flag_seq, flag_direction);667+ bidirectional, batch_first, flag_seq, direction);
668}668}
669 669 
670tensor_list5 npu_lstm_data_backward(const c10::optional<at::Tensor> &grady_opt,670tensor_list5 npu_lstm_data_backward(const c10::optional<at::Tensor> &grady_opt,
Mop_plugin/ops/aclops/UpsampleNearest3dBackwardKernelNpu.cpp+59-54
@@ -27,27 +27,28 @@ at::SmallVector<int64_t, SIZE> upsample_nearest3d_backward_infer_size(
27 at::IntArrayRef input_size,27 at::IntArrayRef input_size,
28 c10::optional<double> scales_d,28 c10::optional<double> scales_d,
29 c10::optional<double> scales_h,29 c10::optional<double> scales_h,
30- c10::optional<double> scales_w) {30+ c10::optional<double> scales_w)
31- TORCH_CHECK(31+{
32- output_size.size() == 3,32+ TORCH_CHECK(
33- "It is expected output_size equals to 3, but got size ",33+ output_size.size() == 3,
34- output_size.size(), OPS_ERROR(ErrCode::PARAM));34+ "It is expected output_size equals to 3, but got size ",
35+ output_size.size(), OPS_ERROR(ErrCode::PARAM));
35 36 
36- TORCH_CHECK(37+ TORCH_CHECK(
37- input_size.size() == 5,38+ input_size.size() == 5,
38- "It is expected input_size equals to 5, but got size ",39+ "It is expected input_size equals to 5, but got size ",
39- input_size.size(), OPS_ERROR(ErrCode::PARAM));40+ input_size.size(), OPS_ERROR(ErrCode::PARAM));
40 41 
41- int64_t nbatch = input_size[0];42+ int64_t nbatch = input_size[0];
42- int64_t channels = input_size[1];43+ int64_t channels = input_size[1];
43- int64_t input_depth = input_size[2];44+ int64_t input_depth = input_size[2];
44- int64_t input_height = input_size[3];45+ int64_t input_height = input_size[3];
45- int64_t input_width = input_size[4];46+ int64_t input_width = input_size[4];
46 47 
47- at::SmallVector<int64_t, SIZE> output_sizes =48+ at::SmallVector<int64_t, SIZE> output_sizes =
48- {nbatch, channels, input_depth, input_height, input_width};49+ {nbatch, channels, input_depth, input_height, input_width};
49 50 
50- return output_sizes;51+ return output_sizes;
51}52}
52 53 
53at::Tensor& upsample_nearest3d_backward_out_nocheck(54at::Tensor& upsample_nearest3d_backward_out_nocheck(
@@ -57,16 +58,17 @@ at::Tensor& upsample_nearest3d_backward_out_nocheck(
57 at::IntArrayRef input_size,58 at::IntArrayRef input_size,
58 c10::optional<double> scales_d,59 c10::optional<double> scales_d,
59 c10::optional<double> scales_h,60 c10::optional<double> scales_h,
60- c10::optional<double> scales_w) {61+ c10::optional<double> scales_w)
61- at::Tensor grad_output_copy = grad_output;62+{
62- at_npu::native::OpCommand cmd;63+ at::Tensor grad_output_copy = grad_output;
63- cmd.Name("UpsampleNearest3dGrad")64+ at_npu::native::OpCommand cmd;
64- .Input(grad_output)65+ cmd.Name("UpsampleNearest3dGrad")
65- .Output(result)66+ .Input(grad_output)
66- .Attr("input_size", input_size)67+ .Output(result)
67- .Attr("output_size", output_size)68+ .Attr("input_size", input_size)
68- .Run();69+ .Attr("output_size", output_size)
69- return result;70+ .Run();
71+ return result;
70}72}
71} // namespace73} // namespace
72 74 
@@ -77,21 +79,22 @@ at::Tensor& upsample_nearest3d_backward_out(
77 c10::optional<double> scales_d,79 c10::optional<double> scales_d,
78 c10::optional<double> scales_h,80 c10::optional<double> scales_h,
79 c10::optional<double> scales_w,81 c10::optional<double> scales_w,
80- at::Tensor& grad_input) {82+ at::Tensor& grad_input)
81- auto op_infer_output_size = upsample_nearest3d_backward_infer_size(83+{
82- output_size, input_size, scales_d, scales_h, scales_w);84+ auto op_infer_output_size = upsample_nearest3d_backward_infer_size(
83- npu_preparation::CheckOut({grad_output}, grad_input, grad_output, op_infer_output_size);85+ output_size, input_size, scales_d, scales_h, scales_w);
86+ npu_preparation::CheckOut({grad_output}, grad_input, grad_output, op_infer_output_size);
84 87 
85- if (!npu_utils::check_match(&grad_input)) {88+ if (!npu_utils::check_match(&grad_input)) {
86- auto contiguous_out = npu_utils::format_contiguous(grad_input);89+ auto contiguous_out = npu_utils::format_contiguous(grad_input);
87- upsample_nearest3d_backward_out_nocheck(90+ upsample_nearest3d_backward_out_nocheck(
88- contiguous_out, grad_output, output_size, input_size, scales_d, scales_h, scales_w);91+ contiguous_out, grad_output, output_size, input_size, scales_d, scales_h, scales_w);
89- npu_utils::format_fresh_view(grad_input, contiguous_out);92+ npu_utils::format_fresh_view(grad_input, contiguous_out);
90- } else {93+ } else {
91- upsample_nearest3d_backward_out_nocheck(94+ upsample_nearest3d_backward_out_nocheck(
92- grad_input, grad_output, output_size, input_size, scales_d, scales_h, scales_w);95+ grad_input, grad_output, output_size, input_size, scales_d, scales_h, scales_w);
93- }96+ }
94- return grad_input;97+ return grad_input;
95}98}
96 99 
97at::Tensor upsample_nearest3d_backward(100at::Tensor upsample_nearest3d_backward(
@@ -100,13 +103,14 @@ at::Tensor upsample_nearest3d_backward(
100 at::IntArrayRef input_size,103 at::IntArrayRef input_size,
101 c10::optional<double> scales_d,104 c10::optional<double> scales_d,
102 c10::optional<double> scales_h,105 c10::optional<double> scales_h,
103- c10::optional<double> scales_w) {106+ c10::optional<double> scales_w)
104- auto op_infer_output_size = upsample_nearest3d_backward_infer_size(107+{
105- output_size, input_size, scales_d, scales_h, scales_w);108+ auto op_infer_output_size = upsample_nearest3d_backward_infer_size(
106- at::Tensor result = npu_preparation::apply_tensor(grad_output, op_infer_output_size);109+ output_size, input_size, scales_d, scales_h, scales_w);
107- upsample_nearest3d_backward_out_nocheck(110+ at::Tensor result = npu_preparation::apply_tensor(grad_output, op_infer_output_size);
108- result, grad_output, output_size, input_size, scales_d, scales_h, scales_w);111+ upsample_nearest3d_backward_out_nocheck(
109- return result;112+ result, grad_output, output_size, input_size, scales_d, scales_h, scales_w);
113+ return result;
110}114}
111 115 
112#if VERSION_BETWEEN(V1R11, V1R11)116#if VERSION_BETWEEN(V1R11, V1R11)
@@ -114,18 +118,19 @@ at::Tensor upsample_nearest3d_backward(
114 const at::Tensor& grad_output,118 const at::Tensor& grad_output,
115 c10::optional<at::IntArrayRef> output_size,119 c10::optional<at::IntArrayRef> output_size,
116 at::IntArrayRef input_size,120 at::IntArrayRef input_size,
117- c10::optional<at::ArrayRef<double>> scale_factors) {121+ c10::optional<at::ArrayRef<double>> scale_factors)
122+{
118 TORCH_CHECK(123 TORCH_CHECK(
119 input_size.size() == 5,124 input_size.size() == 5,
120 "It is expected input_size equals to 5, but got size ",125 "It is expected input_size equals to 5, but got size ",
121 input_size.size(), OPS_ERROR(ErrCode::PARAM));126 input_size.size(), OPS_ERROR(ErrCode::PARAM));
122 127 
123- auto osize = op_infer::upsample_infershape_with_scale(input_size, output_size, scale_factors);128+ auto osize = op_infer::upsample_infershape_with_scale(input_size, output_size, scale_factors);
124- auto scales_d = op_plugin::utils::get_scale_value(scale_factors, 0);129+ auto scales_d = op_plugin::utils::get_scale_value(scale_factors, 0);
125- auto scales_h = op_plugin::utils::get_scale_value(scale_factors, 1);130+ auto scales_h = op_plugin::utils::get_scale_value(scale_factors, 1);
126- auto scales_w = op_plugin::utils::get_scale_value(scale_factors, 2);131+ auto scales_w = op_plugin::utils::get_scale_value(scale_factors, 2);
127 132 
128- return acl_op::upsample_nearest3d_backward(grad_output, osize, input_size, scales_d, scales_h, scales_w);133+ return acl_op::upsample_nearest3d_backward(grad_output, osize, input_size, scales_d, scales_h, scales_w);
129}134}
130#endif135#endif
131 136 
Mop_plugin/ops/opapi/ScatterKernelNpuOpApi.cpp+54-54
@@ -23,74 +23,74 @@ using npu_preparation = at_npu::native::OpPreparation;
23// reduce value must be "add" or "multiply"23// reduce value must be "add" or "multiply"
24static inline bool reduce_valid(c10::string_view reduce)24static inline bool reduce_valid(c10::string_view reduce)
25{25{
26- return (reduce == "add" || reduce == "multiply");26+ return (reduce == "add" || reduce == "multiply");
27}27}
28 28 
29static int64_t get_reduce(c10::string_view reduce)29static int64_t get_reduce(c10::string_view reduce)
30{30{
31- if (reduce == "add") {31+ if (reduce == "add") {
32- return 1;32+ return 1;
33- } else if (reduce == "multiply") {33+ } else if (reduce == "multiply") {
34- return 2;34+ return 2;
35- }35+ }
36- return 0;36+ return 0;
37}37}
38 38 
39at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,39at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
40- const at::Tensor& src, at::Tensor& result)40+ const at::Tensor& src, at::Tensor& out)
41{41{
42- DO_COMPATIBILITY(aclnnScatter, acl_op::scatter_out(self, dim, index, src, result));42+ DO_COMPATIBILITY(aclnnScatter, acl_op::scatter_out(self, dim, index, src, out));
43- npu_preparation::check_tensor({self, src, index}, result, self);43+ npu_preparation::check_tensor({self, src, index}, out, self);
44- int64_t reduction = 0;
45- EXEC_NPU_CMD(aclnnScatter, self, dim, index, src, reduction, result);
46- return result;
47-}
48- 
49-at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
50- const at::Tensor& src, c10::string_view reduce, at::Tensor& result)
51-{
52- npu_preparation::check_tensor({self, src, index}, result, self);
53- TORCH_CHECK(reduce_valid(reduce), "Reduce should be either add or multiply", OPS_ERROR(ErrCode::PARAM));
54- int64_t reduction = get_reduce(reduce);
55- EXEC_NPU_CMD(aclnnScatter, self, dim, index, src, reduction, result);
56- return result;
57-}
58- 
59-at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
60- const at::Scalar& value, at::Tensor& result)
61-{
62- DO_COMPATIBILITY(aclnnScatterValue, acl_op::scatter_out(self, dim, index, value, result));
63- npu_preparation::check_tensor({self, index}, result, self);
64- int64_t reduction = 0;
65- EXEC_NPU_CMD(aclnnScatterValue, self, dim, index, value, reduction, result);
66- return result;
67-}
68- 
69-at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
70- const at::Scalar& value, c10::string_view reduce, at::Tensor& result)
71-{
72- npu_preparation::check_tensor({self, index}, result, self);
73- TORCH_CHECK(reduce_valid(reduce), "Reduce should be either add or multiply", OPS_ERROR(ErrCode::PARAM));
74- int64_t reduction = get_reduce(reduce);
75- EXEC_NPU_CMD(aclnnScatterValue, self, dim, index, value, reduction, result);
76- return result;
77-}
78- 
79-at::Tensor &scatter_(at::Tensor &self, int64_t dim, const at::Tensor &index_ex, const at::Tensor &src)
80-{
81- DO_COMPATIBILITY(aclnnInplaceScatter, acl_op::scatter_(self, dim, index_ex, src));
82- npu_preparation::check_tensor({self, src, index_ex}, self, self);
83 int64_t reduction = 0;44 int64_t reduction = 0;
84- EXEC_NPU_CMD(aclnnInplaceScatter, self, dim, index_ex, src, reduction);45+ EXEC_NPU_CMD(aclnnScatter, self, dim, index, src, reduction, out);
46+ return out;
47+}
48+ 
49+at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
50+ const at::Tensor& src, c10::string_view reduce, at::Tensor& out)
51+{
52+ npu_preparation::check_tensor({self, src, index}, out, self);
53+ TORCH_CHECK(reduce_valid(reduce), "Reduce should be either add or multiply", OPS_ERROR(ErrCode::PARAM));
54+ int64_t reduction = get_reduce(reduce);
55+ EXEC_NPU_CMD(aclnnScatter, self, dim, index, src, reduction, out);
56+ return out;
57+}
58+ 
59+at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
60+ const at::Scalar& value, at::Tensor& out)
61+{
62+ DO_COMPATIBILITY(aclnnScatterValue, acl_op::scatter_out(self, dim, index, value, out));
63+ npu_preparation::check_tensor({self, index}, out, self);
64+ int64_t reduction = 0;
65+ EXEC_NPU_CMD(aclnnScatterValue, self, dim, index, value, reduction, out);
66+ return out;
67+}
68+ 
69+at::Tensor& scatter_out(const at::Tensor& self, int64_t dim, const at::Tensor& index,
70+ const at::Scalar& value, c10::string_view reduce, at::Tensor& out)
71+{
72+ npu_preparation::check_tensor({self, index}, out, self);
73+ TORCH_CHECK(reduce_valid(reduce), "Reduce should be either add or multiply", OPS_ERROR(ErrCode::PARAM));
74+ int64_t reduction = get_reduce(reduce);
75+ EXEC_NPU_CMD(aclnnScatterValue, self, dim, index, value, reduction, out);
76+ return out;
77+}
78+ 
79+at::Tensor &scatter_(at::Tensor &self, int64_t dim, const at::Tensor &index, const at::Tensor &src)
80+{
81+ DO_COMPATIBILITY(aclnnInplaceScatter, acl_op::scatter_(self, dim, index, src));
82+ npu_preparation::check_tensor({self, src, index}, self, self);
83+ int64_t reduction = 0;
84+ EXEC_NPU_CMD(aclnnInplaceScatter, self, dim, index, src, reduction);
85 return self;85 return self;
86}86}
87 87 
88-at::Tensor &scatter_(at::Tensor &self, int64_t dim, const at::Tensor &index_ex, const at::Scalar& value)88+at::Tensor &scatter_(at::Tensor &self, int64_t dim, const at::Tensor &index, const at::Scalar& value)
89{89{
90- DO_COMPATIBILITY(aclnnInplaceScatterValue, acl_op::scatter_(self, dim, index_ex, value));90+ DO_COMPATIBILITY(aclnnInplaceScatterValue, acl_op::scatter_(self, dim, index, value));
91- npu_preparation::check_tensor({self, index_ex}, self, self);91+ npu_preparation::check_tensor({self, index}, self, self);
92 int64_t reduction = 0;92 int64_t reduction = 0;
93- EXEC_NPU_CMD(aclnnInplaceScatterValue, self, dim, index_ex, value, reduction);93+ EXEC_NPU_CMD(aclnnInplaceScatterValue, self, dim, index, value, reduction);
94 return self;94 return self;
95}95}
96}96}