Merged
同步f2209ee61066ae89d4efd1782a30b6235e0e0548 #4
AtomGit-BotAdd on Jul 5, 2021
同步f2209ee61066ae89d4efd1782a30b6235e0e0548 #4
Merged
AtomGit-BotAdd on Jul 5, 2021
Merged frommasterintomaster
Total: 381 files changed+3298-3098
@@ -606,7 +606,7 @@
606 dispatch:606 dispatch:
607 CPU: bernoulli_scalar_cpu_607 CPU: bernoulli_scalar_cpu_
608 CUDA: bernoulli_scalar_cuda_608 CUDA: bernoulli_scalar_cuda_
609- supports_named_tensor: True 609+ supports_named_tensor: True
610 npu_dispatch:610 npu_dispatch:
611 NPU: bernoulli_npu_611 NPU: bernoulli_npu_
612 612 
@@ -1040,7 +1040,7 @@
1040 CUDA: _cosh_out_cuda1040 CUDA: _cosh_out_cuda
1041 npu_dispatch:1041 npu_dispatch:
1042 NPU: cosh_out_npu1042 NPU: cosh_out_npu
1043- 1043+ 
1044- func: cosine_embedding_loss(Tensor input1, Tensor input2, Tensor target, float margin=0.0, int reduction=Mean) -> Tensor1044- func: cosine_embedding_loss(Tensor input1, Tensor input2, Tensor target, float margin=0.0, int reduction=Mean) -> Tensor
1045 use_c10_dispatcher: full1045 use_c10_dispatcher: full
1046 1046 
@@ -1271,7 +1271,7 @@
1271- func: det(Tensor self) -> Tensor1271- func: det(Tensor self) -> Tensor
1272 use_c10_dispatcher: full1272 use_c10_dispatcher: full
1273 variants: function, method1273 variants: function, method
1274- 1274+ 
1275- func: diag_embed(Tensor self, int offset=0, int dim1=-2, int dim2=-1) -> Tensor1275- func: diag_embed(Tensor self, int offset=0, int dim1=-2, int dim2=-1) -> Tensor
1276 use_c10_dispatcher: full1276 use_c10_dispatcher: full
1277 variants: function, method1277 variants: function, method
@@ -1381,7 +1381,7 @@
1381 CUDA: embedding_renorm_cuda_1381 CUDA: embedding_renorm_cuda_
1382 npu_dispatch:1382 npu_dispatch:
1383 NPU: embedding_renorm_npu_1383 NPU: embedding_renorm_npu_
1384- 1384+ 
1385- func: embedding_sparse_backward(Tensor grad, Tensor indices, int num_weights, int padding_idx, bool scale_grad_by_freq) -> Tensor1385- func: embedding_sparse_backward(Tensor grad, Tensor indices, int num_weights, int padding_idx, bool scale_grad_by_freq) -> Tensor
1386 use_c10_dispatcher: full1386 use_c10_dispatcher: full
1387 1387 
@@ -1657,7 +1657,7 @@
1657 SparseCPU: floor_divide_sparse1657 SparseCPU: floor_divide_sparse
1658 SparseCUDA: floor_divide_sparse1658 SparseCUDA: floor_divide_sparse
1659 supports_named_tensor: True1659 supports_named_tensor: True
1660- npu_dispatch: 1660+ npu_dispatch:
1661 NPU: floor_divide_npu1661 NPU: floor_divide_npu
1662 1662 
1663- func: floor_divide_.Tensor(Tensor(a!) self, Tensor other) -> Tensor(a!)1663- func: floor_divide_.Tensor(Tensor(a!) self, Tensor other) -> Tensor(a!)
@@ -1668,7 +1668,7 @@
1668 SparseCPU: floor_divide_sparse_1668 SparseCPU: floor_divide_sparse_
1669 SparseCUDA: floor_divide_sparse_1669 SparseCUDA: floor_divide_sparse_
1670 supports_named_tensor: True1670 supports_named_tensor: True
1671- npu_dispatch: 1671+ npu_dispatch:
1672 NPU: floor_divide_npu_1672 NPU: floor_divide_npu_
1673 1673 
1674- func: floor_divide.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)1674- func: floor_divide.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
@@ -1678,13 +1678,13 @@
1678 SparseCPU: floor_divide_out_sparse_zerodim1678 SparseCPU: floor_divide_out_sparse_zerodim
1679 SparseCUDA: floor_divide_out_sparse_zerodim1679 SparseCUDA: floor_divide_out_sparse_zerodim
1680 supports_named_tensor: True1680 supports_named_tensor: True
1681- npu_dispatch: 1681+ npu_dispatch:
1682 NPU: floor_divide_out_npu1682 NPU: floor_divide_out_npu
1683 1683 
1684- func: floor_divide.Scalar(Tensor self, Scalar other) -> Tensor1684- func: floor_divide.Scalar(Tensor self, Scalar other) -> Tensor
1685 variants: function, method1685 variants: function, method
1686 supports_named_tensor: True1686 supports_named_tensor: True
1687- npu_dispatch: 1687+ npu_dispatch:
1688 NPU: floor_divide_npu1688 NPU: floor_divide_npu
1689 1689 
1690- func: floor_divide_.Scalar(Tensor(a!) self, Scalar other) -> Tensor(a!)1690- func: floor_divide_.Scalar(Tensor(a!) self, Scalar other) -> Tensor(a!)
@@ -1793,15 +1793,15 @@
1793- func: hamming_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor1793- func: hamming_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
1794 npu_dispatch:1794 npu_dispatch:
1795 NPU: hamming_window_npu1795 NPU: hamming_window_npu
1796- 1796+ 
1797- func: hamming_window.periodic_alpha(int window_length, bool periodic, float alpha, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor1797- func: hamming_window.periodic_alpha(int window_length, bool periodic, float alpha, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
1798 npu_dispatch:1798 npu_dispatch:
1799 NPU: hamming_window_npu1799 NPU: hamming_window_npu
1800- 1800+ 
1801- func: hamming_window.periodic_alpha_beta(int window_length, bool periodic, float alpha, float beta, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor1801- func: hamming_window.periodic_alpha_beta(int window_length, bool periodic, float alpha, float beta, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
1802 npu_dispatch:1802 npu_dispatch:
1803 NPU: hamming_window_npu1803 NPU: hamming_window_npu
1804- 1804+ 
1805- func: hinge_embedding_loss(Tensor self, Tensor target, float margin=1.0, int reduction=Mean) -> Tensor1805- func: hinge_embedding_loss(Tensor self, Tensor target, float margin=1.0, int reduction=Mean) -> Tensor
1806 use_c10_dispatcher: full1806 use_c10_dispatcher: full
1807 1807 
@@ -1995,7 +1995,7 @@
1995 dispatch:1995 dispatch:
1996 CPU: kthvalue_out_cpu1996 CPU: kthvalue_out_cpu
1997 CUDA: kthvalue_out_cuda1997 CUDA: kthvalue_out_cuda
1998- npu_dispatch: 1998+ npu_dispatch:
1999 NPU: kthvalue_out_npu1999 NPU: kthvalue_out_npu
2000 2000 
2001- func: kthvalue.dimname(Tensor self, int k, Dimname dim, bool keepdim=False) -> (Tensor values, Tensor indices)2001- func: kthvalue.dimname(Tensor self, int k, Dimname dim, bool keepdim=False) -> (Tensor values, Tensor indices)
@@ -2006,7 +2006,7 @@
2006 2006 
2007- func: kthvalue.dimname_out(Tensor self, int k, Dimname dim, bool keepdim=False, *, Tensor(a!) values, Tensor(b!) indices) -> (Tensor(a!) values, Tensor(b!) indices)2007- func: kthvalue.dimname_out(Tensor self, int k, Dimname dim, bool keepdim=False, *, Tensor(a!) values, Tensor(b!) indices) -> (Tensor(a!) values, Tensor(b!) indices)
2008 supports_named_tensor: True2008 supports_named_tensor: True
2009- npu_dispatch: 2009+ npu_dispatch:
2010 NPU: kthvalue_out_npu2010 NPU: kthvalue_out_npu
2011 2011 
2012- func: layer_norm(Tensor input, int[] normalized_shape, Tensor? weight=None, Tensor? bias=None, float eps=1e-05, bool cudnn_enable=True) -> Tensor2012- func: layer_norm(Tensor input, int[] normalized_shape, Tensor? weight=None, Tensor? bias=None, float eps=1e-05, bool cudnn_enable=True) -> Tensor
@@ -2090,16 +2090,22 @@
2090 use_c10_dispatcher: full2090 use_c10_dispatcher: full
2091 supports_named_tensor: True2091 supports_named_tensor: True
2092 variants: function, method2092 variants: function, method
2093+ npu_dispatch:
2094+ NPU: log10_npu
2093 2095 
2094- func: log10_(Tensor(a!) self) -> Tensor(a!)2096- func: log10_(Tensor(a!) self) -> Tensor(a!)
2095 supports_named_tensor: True2097 supports_named_tensor: True
2096 variants: function, method2098 variants: function, method
2099+ npu_dispatch:
2100+ NPU: log10_npu_
2097 2101 
2098- func: log10.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)2102- func: log10.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)
2099 supports_named_tensor: True2103 supports_named_tensor: True
2100 dispatch:2104 dispatch:
2101 CPU: log10_out2105 CPU: log10_out
2102 CUDA: log10_out2106 CUDA: log10_out
2107+ npu_dispatch:
2108+ NPU: log10_out_npu
2103 2109 
2104- func: log1p(Tensor self) -> Tensor2110- func: log1p(Tensor self) -> Tensor
2105 use_c10_dispatcher: full2111 use_c10_dispatcher: full
@@ -2730,14 +2736,14 @@
2730 use_c10_dispatcher: full2736 use_c10_dispatcher: full
2731 npu_dispatch:2737 npu_dispatch:
2732 NPU: _pdist_forward_npu2738 NPU: _pdist_forward_npu
2733- 2739+ 
2734- func: _pdist_backward(Tensor grad, Tensor self, float p, Tensor pdist) -> Tensor2740- func: _pdist_backward(Tensor grad, Tensor self, float p, Tensor pdist) -> Tensor
2735 use_c10_dispatcher: full2741 use_c10_dispatcher: full
2736 2742 
2737- func: cosine_similarity(Tensor input, Tensor input2, int dim=1, float eps=1e-08) -> Tensor2743- func: cosine_similarity(Tensor input, Tensor input2, int dim=1, float eps=1e-08) -> Tensor
2738 use_c10_dispatcher: full2744 use_c10_dispatcher: full
2739 variants: function2745 variants: function
2740- 2746+ 
2741- func: permute(Tensor(a) self, int[] dims) -> Tensor(a)2747- func: permute(Tensor(a) self, int[] dims) -> Tensor(a)
2742 variants: method # This is method-only to match the previous tensor API. In the future we could make this a function too.2748 variants: method # This is method-only to match the previous tensor API. In the future we could make this a function too.
2743 2749 
@@ -2753,7 +2759,7 @@
2753 2759 
2754- func: pixel_shuffle(Tensor self, int upscale_factor) -> Tensor2760- func: pixel_shuffle(Tensor self, int upscale_factor) -> Tensor
2755 use_c10_dispatcher: full2761 use_c10_dispatcher: full
2756- 2762+ 
2757- func: is_pinned(Tensor self) -> bool2763- func: is_pinned(Tensor self) -> bool
2758 use_c10_dispatcher: full2764 use_c10_dispatcher: full
2759 variants: method2765 variants: method
@@ -2770,7 +2776,7 @@
2770- func: poisson_nll_loss(Tensor input, Tensor target, bool log_input, bool full, float eps, int reduction) -> Tensor2776- func: poisson_nll_loss(Tensor input, Tensor target, bool log_input, bool full, float eps, int reduction) -> Tensor
2771 use_c10_dispatcher: full2777 use_c10_dispatcher: full
2772 variants: function2778 variants: function
2773- 2779+ 
2774- func: scalar_tensor(Scalar s, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor2780- func: scalar_tensor(Scalar s, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
2775 2781 
2776- func: rand.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor2782- func: rand.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
@@ -3011,7 +3017,7 @@
3011 CUDA: gelu_cuda3017 CUDA: gelu_cuda
3012 npu_dispatch:3018 npu_dispatch:
3013 NPU: gelu_npu3019 NPU: gelu_npu
3014- 3020+ 
3015- func: gelu_backward(Tensor grad, Tensor self) -> Tensor3021- func: gelu_backward(Tensor grad, Tensor self) -> Tensor
3016 use_c10_dispatcher: full3022 use_c10_dispatcher: full
3017 python_module: nn3023 python_module: nn
@@ -3075,8 +3081,12 @@
3075 3081 
3076- func: celu(Tensor self, Scalar alpha=1.0) -> Tensor3082- func: celu(Tensor self, Scalar alpha=1.0) -> Tensor
3077 use_c10_dispatcher: full3083 use_c10_dispatcher: full
3084+ npu_dispatch:
3085+ NPU: celu_npu
3078 3086 
3079- func: celu_(Tensor(a!) self, Scalar alpha=1.0) -> Tensor(a!)3087- func: celu_(Tensor(a!) self, Scalar alpha=1.0) -> Tensor(a!)
3088+ npu_dispatch:
3089+ NPU: celu_npu_
3080 3090 
3081- func: sigmoid(Tensor self) -> Tensor3091- func: sigmoid(Tensor self) -> Tensor
3082 use_c10_dispatcher: full3092 use_c10_dispatcher: full
@@ -3423,14 +3433,14 @@
3423 npu_dispatch:3433 npu_dispatch:
3424 NPU: prod_out_npu3434 NPU: prod_out_npu
3425 #NPU: prod_out_npu_ext3435 #NPU: prod_out_npu_ext
3426- 3436+ 
3427- func: prod.dim_Dimname(Tensor self, Dimname dim, bool keepdim=False, *, ScalarType? dtype=None) -> Tensor3437- func: prod.dim_Dimname(Tensor self, Dimname dim, bool keepdim=False, *, ScalarType? dtype=None) -> Tensor
3428 variants: function, method3438 variants: function, method
3429 supports_named_tensor: True3439 supports_named_tensor: True
3430 npu_dispatch:3440 npu_dispatch:
3431 NPU: prod_npu3441 NPU: prod_npu
3432 #NPU: prod_npu_ext3442 #NPU: prod_npu_ext
3433- 3443+ 
3434- func: prod.Dimname_out(Tensor self, Dimname dim, bool keepdim=False, *, ScalarType? dtype=None, Tensor(a!) out) -> Tensor(a!)3444- func: prod.Dimname_out(Tensor self, Dimname dim, bool keepdim=False, *, ScalarType? dtype=None, Tensor(a!) out) -> Tensor(a!)
3435 supports_named_tensor: True3445 supports_named_tensor: True
3436 npu_dispatch:3446 npu_dispatch:
@@ -3799,7 +3809,7 @@
3799 3809 
3800- func: norm_except_dim(Tensor v, int pow=2, int dim=0) -> Tensor3810- func: norm_except_dim(Tensor v, int pow=2, int dim=0) -> Tensor
3801 variants: function3811 variants: function
3802- 3812+ 
3803# VariableType::_weight_norm does not want to be given a gap in the autograd graph,3813# VariableType::_weight_norm does not want to be given a gap in the autograd graph,
3804# so we don't define "dispatch" variants for it.3814# so we don't define "dispatch" variants for it.
3805- func: _weight_norm(Tensor v, Tensor g, int dim=0) -> Tensor3815- func: _weight_norm(Tensor v, Tensor g, int dim=0) -> Tensor
@@ -5005,12 +5015,12 @@
5005 variants: method, function5015 variants: method, function
5006 npu_dispatch:5016 npu_dispatch:
5007 NPU: bitwise_and_npu5017 NPU: bitwise_and_npu
5008- 5018+ 
5009- func: bitwise_and_.Scalar(Tensor(a!) self, Scalar other) -> Tensor(a!)5019- func: bitwise_and_.Scalar(Tensor(a!) self, Scalar other) -> Tensor(a!)
5010 variants: method5020 variants: method
5011 npu_dispatch:5021 npu_dispatch:
5012 NPU: bitwise_and_npu_5022 NPU: bitwise_and_npu_
5013- 5023+ 
5014- func: bitwise_and_.Tensor(Tensor(a!) self, Tensor other) -> Tensor(a!)5024- func: bitwise_and_.Tensor(Tensor(a!) self, Tensor other) -> Tensor(a!)
5015 variants: method5025 variants: method
5016 npu_dispatch:5026 npu_dispatch:
@@ -5315,14 +5325,14 @@
5315 CPU: legacy::cpu::_th_addbmm_5325 CPU: legacy::cpu::_th_addbmm_
5316 CUDA: legacy::cuda::_th_addbmm_5326 CUDA: legacy::cuda::_th_addbmm_
5317 npu_dispatch:5327 npu_dispatch:
5318- NPU: addbmm_npu_ 5328+ NPU: addbmm_npu_
5319 5329 
5320- func: addbmm.out(Tensor self, Tensor batch1, Tensor batch2, *, Scalar beta=1, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!)5330- func: addbmm.out(Tensor self, Tensor batch1, Tensor batch2, *, Scalar beta=1, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!)
5321 dispatch:5331 dispatch:
5322 CPU: legacy::cpu::_th_addbmm_out5332 CPU: legacy::cpu::_th_addbmm_out
5323 CUDA: legacy::cuda::_th_addbmm_out5333 CUDA: legacy::cuda::_th_addbmm_out
5324 npu_dispatch:5334 npu_dispatch:
5325- NPU: addbmm_out_npu 5335+ NPU: addbmm_out_npu
5326 5336 
5327- func: addbmm(Tensor self, Tensor batch1, Tensor batch2, *, Scalar beta=1, Scalar alpha=1) -> Tensor5337- func: addbmm(Tensor self, Tensor batch1, Tensor batch2, *, Scalar beta=1, Scalar alpha=1) -> Tensor
5328 use_c10_dispatcher: full5338 use_c10_dispatcher: full
@@ -5331,7 +5341,7 @@
5331 CPU: legacy::cpu::_th_addbmm5341 CPU: legacy::cpu::_th_addbmm
5332 CUDA: legacy::cuda::_th_addbmm5342 CUDA: legacy::cuda::_th_addbmm
5333 npu_dispatch:5343 npu_dispatch:
5334- NPU: addbmm_npu 5344+ NPU: addbmm_npu
5335 5345 
5336- func: addcdiv_(Tensor(a!) self, Tensor tensor1, Tensor tensor2, *, Scalar value=1) -> Tensor(a!)5346- func: addcdiv_(Tensor(a!) self, Tensor tensor1, Tensor tensor2, *, Scalar value=1) -> Tensor(a!)
5337 variants: method5347 variants: method
@@ -5794,7 +5804,7 @@
5794- func: gather.dimname_out(Tensor self, Dimname dim, Tensor index, *, bool sparse_grad=False, Tensor(a!) out) -> Tensor(a!)5804- func: gather.dimname_out(Tensor self, Dimname dim, Tensor index, *, bool sparse_grad=False, Tensor(a!) out) -> Tensor(a!)
5795 npu_dispatch:5805 npu_dispatch:
5796 NPU: gather_out_npu5806 NPU: gather_out_npu
5797- 5807+ 
5798- func: gather.dimname(Tensor self, Dimname dim, Tensor index, *, bool sparse_grad=False) -> Tensor5808- func: gather.dimname(Tensor self, Dimname dim, Tensor index, *, bool sparse_grad=False) -> Tensor
5799 variants: method, function5809 variants: method, function
5800 npu_dispatch:5810 npu_dispatch:
@@ -6752,8 +6762,6 @@
6752 dispatch:6762 dispatch:
6753 CPU: multilabel_margin_loss_backward_cpu_out6763 CPU: multilabel_margin_loss_backward_cpu_out
6754 CUDA: legacy::cuda::_thnn_multilabel_margin_loss_backward_out6764 CUDA: legacy::cuda::_thnn_multilabel_margin_loss_backward_out
6755- npu_dispatch:
6756- NPU: multilabel_margin_loss_backward_npu_out
6757 6765 
6758- func: multilabel_margin_loss_backward(Tensor grad_output, Tensor self, Tensor target, int reduction, Tensor is_target) -> Tensor6766- func: multilabel_margin_loss_backward(Tensor grad_output, Tensor self, Tensor target, int reduction, Tensor is_target) -> Tensor
6759 use_c10_dispatcher: full6767 use_c10_dispatcher: full
@@ -6761,8 +6769,6 @@
6761 dispatch:6769 dispatch:
6762 CPU: multilabel_margin_loss_backward_cpu6770 CPU: multilabel_margin_loss_backward_cpu
6763 CUDA: legacy::cuda::_thnn_multilabel_margin_loss_backward6771 CUDA: legacy::cuda::_thnn_multilabel_margin_loss_backward
6764- npu_dispatch:
6765- NPU: multilabel_margin_loss_backward_npu
6766 6772 
6767- func: nll_loss.out(Tensor self, Tensor target, Tensor? weight=None, int reduction=Mean, int ignore_index=-100, *, Tensor(a!) out) -> Tensor(a!)6773- func: nll_loss.out(Tensor self, Tensor target, Tensor? weight=None, int reduction=Mean, int ignore_index=-100, *, Tensor(a!) out) -> Tensor(a!)
6768 python_module: nn6774 python_module: nn
@@ -7757,7 +7763,7 @@
7757 CUDA: upsample_bicubic2d_out_cuda7763 CUDA: upsample_bicubic2d_out_cuda
7758 npu_dispatch:7764 npu_dispatch:
7759 NPU: upsample_bicubic2d_out_npu7765 NPU: upsample_bicubic2d_out_npu
7760- 7766+ 
7761- func: upsample_bicubic2d(Tensor self, int[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None) -> Tensor7767- func: upsample_bicubic2d(Tensor self, int[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None) -> Tensor
7762 python_module: nn7768 python_module: nn
7763 dispatch:7769 dispatch:
@@ -7765,7 +7771,7 @@
7765 CUDA: upsample_bicubic2d_cuda7771 CUDA: upsample_bicubic2d_cuda
7766 npu_dispatch:7772 npu_dispatch:
7767 NPU: upsample_bicubic2d_npu7773 NPU: upsample_bicubic2d_npu
7768- 7774+ 
7769- func: upsample_bicubic2d_backward.grad_input(Tensor grad_output, int[2] output_size, int[4] input_size, bool align_corners, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)7775- func: upsample_bicubic2d_backward.grad_input(Tensor grad_output, int[2] output_size, int[4] input_size, bool align_corners, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)
7770 python_module: nn7776 python_module: nn
7771 dispatch:7777 dispatch:
@@ -7787,24 +7793,32 @@
7787 dispatch:7793 dispatch:
7788 CPU: upsample_trilinear3d_out_cpu7794 CPU: upsample_trilinear3d_out_cpu
7789 CUDA: upsample_trilinear3d_out_cuda7795 CUDA: upsample_trilinear3d_out_cuda
7796+ npu_dispatch:
7797+ NPU: upsample_trilinear3d_out_npu
7790 7798 
7791- func: upsample_trilinear3d(Tensor self, int[3] output_size, bool align_corners, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor7799- func: upsample_trilinear3d(Tensor self, int[3] output_size, bool align_corners, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor
7792 python_module: nn7800 python_module: nn
7793 dispatch:7801 dispatch:
7794 CPU: upsample_trilinear3d_cpu7802 CPU: upsample_trilinear3d_cpu
7795 CUDA: upsample_trilinear3d_cuda7803 CUDA: upsample_trilinear3d_cuda
7804+ npu_dispatch:
7805+ NPU: upsample_trilinear3d_npu
7796 7806 
7797- func: upsample_trilinear3d_backward.grad_input(Tensor grad_output, int[3] output_size, int[5] input_size, bool align_corners, float? scales_d=None, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)7807- func: upsample_trilinear3d_backward.grad_input(Tensor grad_output, int[3] output_size, int[5] input_size, bool align_corners, float? scales_d=None, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)
7798 python_module: nn7808 python_module: nn
7799 dispatch:7809 dispatch:
7800 CPU: upsample_trilinear3d_backward_out_cpu7810 CPU: upsample_trilinear3d_backward_out_cpu
7801 CUDA: upsample_trilinear3d_backward_out_cuda7811 CUDA: upsample_trilinear3d_backward_out_cuda
7812+ npu_dispatch:
7813+ NPU: upsample_trilinear3d_backward_out_npu
7802 7814 
7803- func: upsample_trilinear3d_backward(Tensor grad_output, int[3] output_size, int[5] input_size, bool align_corners, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor7815- func: upsample_trilinear3d_backward(Tensor grad_output, int[3] output_size, int[5] input_size, bool align_corners, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor
7804 python_module: nn7816 python_module: nn
7805 dispatch:7817 dispatch:
7806 CPU: upsample_trilinear3d_backward_cpu7818 CPU: upsample_trilinear3d_backward_cpu
7807 CUDA: upsample_trilinear3d_backward_cuda7819 CUDA: upsample_trilinear3d_backward_cuda
7820+ npu_dispatch:
7821+ NPU: upsample_trilinear3d_backward_npu
7808 7822 
7809- func: upsample_nearest1d.out(Tensor self, int[1] output_size, float? scales=None, *, Tensor(a!) out) -> Tensor(a!)7823- func: upsample_nearest1d.out(Tensor self, int[1] output_size, float? scales=None, *, Tensor(a!) out) -> Tensor(a!)
7810 python_module: nn7824 python_module: nn
@@ -7876,6 +7890,8 @@
7876 dispatch:7890 dispatch:
7877 CPU: upsample_nearest3d_out_cpu7891 CPU: upsample_nearest3d_out_cpu
7878 CUDA: upsample_nearest3d_out_cuda7892 CUDA: upsample_nearest3d_out_cuda
7893+ npu_dispatch:
7894+ NPU: upsample_nearest3d_out_npu
7879 7895 
7880- func: upsample_nearest3d(Tensor self, int[3] output_size, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor7896- func: upsample_nearest3d(Tensor self, int[3] output_size, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor
7881 python_module: nn7897 python_module: nn
@@ -7883,18 +7899,24 @@
7883 CPU: upsample_nearest3d_cpu7899 CPU: upsample_nearest3d_cpu
7884 CUDA: upsample_nearest3d_cuda7900 CUDA: upsample_nearest3d_cuda
7885 QuantizedCPU: quantized_upsample_nearest3d_cpu7901 QuantizedCPU: quantized_upsample_nearest3d_cpu
7902+ npu_dispatch:
7903+ NPU: upsample_nearest3d_npu
7886 7904 
7887- func: upsample_nearest3d_backward.grad_input(Tensor grad_output, int[3] output_size, int[5] input_size, float? scales_d=None, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)7905- func: upsample_nearest3d_backward.grad_input(Tensor grad_output, int[3] output_size, int[5] input_size, float? scales_d=None, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)
7888 python_module: nn7906 python_module: nn
7889 dispatch:7907 dispatch:
7890 CPU: upsample_nearest3d_backward_out_cpu7908 CPU: upsample_nearest3d_backward_out_cpu
7891 CUDA: upsample_nearest3d_backward_out_cuda7909 CUDA: upsample_nearest3d_backward_out_cuda
7910+ npu_dispatch:
7911+ NPU: upsample_nearest3d_backward_out_npu
7892 7912 
7893- func: upsample_nearest3d_backward(Tensor grad_output, int[3] output_size, int[5] input_size, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor7913- func: upsample_nearest3d_backward(Tensor grad_output, int[3] output_size, int[5] input_size, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor
7894 python_module: nn7914 python_module: nn
7895 dispatch:7915 dispatch:
7896 CPU: upsample_nearest3d_backward_cpu7916 CPU: upsample_nearest3d_backward_cpu
7897 CUDA: upsample_nearest3d_backward_cuda7917 CUDA: upsample_nearest3d_backward_cuda
7918+ npu_dispatch:
7919+ NPU: upsample_nearest3d_backward_npu
7898 7920 
7899- func: sigmoid_backward.grad_input(Tensor grad_output, Tensor output, *, Tensor(a!) grad_input) -> Tensor(a!)7921- func: sigmoid_backward.grad_input(Tensor grad_output, Tensor output, *, Tensor(a!) grad_input) -> Tensor(a!)
7900 python_module: nn7922 python_module: nn
@@ -8333,7 +8355,7 @@
8333 npu_dispatch_only:8355 npu_dispatch_only:
8334 NPU: ptiou_npu8356 NPU: ptiou_npu
8335 8357 
8336-- func: npu_nms_with_mask(Tensor input, Scalar iou_threshold) -> (Tensor, Tensor, Tensor) 8358+- func: npu_nms_with_mask(Tensor input, Scalar iou_threshold) -> (Tensor, Tensor, Tensor)
8337 variants: function8359 variants: function
8338 npu_dispatch_only:8360 npu_dispatch_only:
8339 NPU: nms_with_mask_npu8361 NPU: nms_with_mask_npu
@@ -8406,7 +8428,7 @@
8406 variants: function, method8428 variants: function, method
8407 npu_dispatch_only:8429 npu_dispatch_only:
8408 NPU: indexing_npu8430 NPU: indexing_npu
8409- 8431+ 
8410- func: npu_indexing.out(Tensor self, int[] begin, int[] end, int[] strides, *, Tensor(a!) out) -> Tensor(a!)8432- func: npu_indexing.out(Tensor self, int[] begin, int[] end, int[] strides, *, Tensor(a!) out) -> Tensor(a!)
8411 npu_dispatch_only:8433 npu_dispatch_only:
8412 NPU: indexing_out_npu8434 NPU: indexing_out_npu
@@ -8435,7 +8457,7 @@
8435- func: npu_apply_adam(Tensor(a!) var, Tensor(b!) m, Tensor(c!) v, Scalar beta1_power, Scalar beta2_power, Scalar lr, Scalar beta1, Scalar beta2, Scalar epsilon, Tensor grad, bool? use_locking, bool? use_nesterov) -> (Tensor(a!), Tensor(b!), Tensor(c!))8457- func: npu_apply_adam(Tensor(a!) var, Tensor(b!) m, Tensor(c!) v, Scalar beta1_power, Scalar beta2_power, Scalar lr, Scalar beta1, Scalar beta2, Scalar epsilon, Tensor grad, bool? use_locking, bool? use_nesterov) -> (Tensor(a!), Tensor(b!), Tensor(c!))
8436 npu_dispatch_only:8458 npu_dispatch_only:
8437 NPU: apply_adam_npu8459 NPU: apply_adam_npu
8438- 8460+ 
8439- func: npu_layer_norm_eval(Tensor input, int[] normalized_shape, Tensor? weight=None, Tensor? bias=None, float eps=1e-05) -> Tensor8461- func: npu_layer_norm_eval(Tensor input, int[] normalized_shape, Tensor? weight=None, Tensor? bias=None, float eps=1e-05) -> Tensor
8440 npu_dispatch_only:8462 npu_dispatch_only:
8441 NPU: layer_norm_eval_npu8463 NPU: layer_norm_eval_npu
@@ -8464,7 +8486,7 @@
8464 npu_dispatch_only:8486 npu_dispatch_only:
8465 NPU: confusion_transpose_backward_npu8487 NPU: confusion_transpose_backward_npu
8466 8488 
8467-- func: npu_bmmV2(Tensor self, Tensor mat2) -> Tensor8489+- func: npu_bmmV2(Tensor self, Tensor mat2, int[] output_sizes) -> Tensor
8468 variants: function, method8490 variants: function, method
8469 npu_dispatch_only:8491 npu_dispatch_only:
8470 NPU: bmm_v2_npu8492 NPU: bmm_v2_npu
@@ -8512,14 +8534,6 @@
8512 npu_dispatch_only:8534 npu_dispatch_only:
8513 NPU: grid_assign_positive_npu8535 NPU: grid_assign_positive_npu
8514 8536 
8515-- func: global_step_inc() -> ()
8516- variants: function
8517- use_c10_dispatcher: full
8518- 
8519-- func: set_start_fuzz_compile_step(int step) -> ()
8520- variants: function
8521- use_c10_dispatcher: full
8522- 
8523- func: npu_mish_backward(Tensor grad, Tensor input) -> Tensor8537- func: npu_mish_backward(Tensor grad, Tensor input) -> Tensor
8524 npu_dispatch_only:8538 npu_dispatch_only:
8525 NPU: mish_backward_npu8539 NPU: mish_backward_npu
@@ -8527,4 +8541,9 @@
8527- func: npu_normalize_batch(Tensor self, Tensor seq_len, int normalize_type=0) -> Tensor8541- func: npu_normalize_batch(Tensor self, Tensor seq_len, int normalize_type=0) -> Tensor
8528 variants: function, method8542 variants: function, method
8529 npu_dispatch_only:8543 npu_dispatch_only:
8530- NPU: normalize_batch_npu8544+ NPU: normalize_batch_npu
8545+ 
8546+- func: npu_masked_fill_range(Tensor self, Tensor start, Tensor end, Tensor value, int axis=-1) -> Tensor
8547+ variants: function, method
8548+ npu_dispatch_only:
8549+ NPU: masked_fill_range_npu
@@ -32,13 +32,7 @@ Tensor& acos_out_npu(Tensor& result, const Tensor& self) {
32}32}
33 33 
34Tensor acos_npu(const Tensor& self) {34Tensor acos_npu(const Tensor& self) {
35- // calculate the output size35+ Tensor result = OpPreparation::ApplyTensor(self);
36- auto outputSize = input_same_output_size(self);
37- 
38- // construct the output tensor of the NPU
39- Tensor result = at::empty_with_format(
40- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
41- 
42 // calculate the output result of the NPU36 // calculate the output result of the NPU
43 acos_out_npu(result, self);37 acos_out_npu(result, self);
44 38 
@@ -46,9 +40,7 @@ Tensor acos_npu(const Tensor& self) {
46}40}
47 41 
48Tensor& acos_npu_(Tensor& self) {42Tensor& acos_npu_(Tensor& self) {
49- SmallVector<Tensor, N> inputs = {self};43+ OpPreparation::CheckMemory({self}, {self});
50- SmallVector<Tensor, N> outputs = {self};
51- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
52 44 
53 if (!NpuUtils::check_match(&self)) {45 if (!NpuUtils::check_match(&self)) {
54 Tensor contiguousSelf = NpuUtils::format_contiguous(self);46 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
@@ -12,10 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/CalcuOpUtil.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
17-#include "ATen/native/npu/utils/NpuUtils.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 16 
20namespace at {17namespace at {
21namespace native {18namespace native {
@@ -45,8 +42,7 @@ Tensor addbmm_npu(
45 // calculate the output size42 // calculate the output size
46 auto outputSize = addbmm_npu_output_size(self, batch1, batch2, beta, alpha);43 auto outputSize = addbmm_npu_output_size(self, batch1, batch2, beta, alpha);
47 // construct the output tensor of the NPU44 // construct the output tensor of the NPU
48- Tensor result = at::empty_with_format(45+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
49- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
50 // calculate the output result of the NPU46 // calculate the output result of the NPU
51 addbmm_out_npu(result, self, batch1, batch2, beta, alpha);47 addbmm_out_npu(result, self, batch1, batch2, beta, alpha);
52 return result;48 return result;
@@ -58,9 +54,7 @@ Tensor& addbmm_npu_(
58 const Tensor& batch2,54 const Tensor& batch2,
59 Scalar beta,55 Scalar beta,
60 Scalar alpha) {56 Scalar alpha) {
61- SmallVector<Tensor, N> inputs = {self, batch1, batch2};57+ OpPreparation::CheckMemory({self, batch1, batch2}, {self});
62- SmallVector<Tensor, N> outputs = {self};
63- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
64 if (!NpuUtils::check_match(&self)) {58 if (!NpuUtils::check_match(&self)) {
65 Tensor contiguousSelf = NpuUtils::format_contiguous(self);59 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
66 Tensor result = addbmm_out_npu(contiguousSelf, contiguousSelf, batch1, batch2, beta, alpha);60 Tensor result = addbmm_out_npu(contiguousSelf, contiguousSelf, batch1, batch2, beta, alpha);
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -46,9 +45,7 @@ Tensor addcdiv_npu(
46 Scalar value) {45 Scalar value) {
47 auto divOutputSize = broadcast_ops_npu_output_size(tensor1, tensor2);46 auto divOutputSize = broadcast_ops_npu_output_size(tensor1, tensor2);
48 auto outputSize = broadcast_ops_npu_output_size(self.sizes(), divOutputSize);47 auto outputSize = broadcast_ops_npu_output_size(self.sizes(), divOutputSize);
49- Tensor result = at::empty_with_format(48+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
50- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
51- 
52 addcdiv_out_npu(result, self, tensor1, tensor2, value);49 addcdiv_out_npu(result, self, tensor1, tensor2, value);
53 50 
54 return result;51 return result;
@@ -59,9 +56,7 @@ Tensor& addcdiv_npu_(
59 const Tensor& tensor1,56 const Tensor& tensor1,
60 const Tensor& tensor2,57 const Tensor& tensor2,
61 Scalar value) {58 Scalar value) {
62- SmallVector<Tensor, N> inputs = {self, tensor1, tensor2};59+ OpPreparation::CheckMemory({self, tensor1, tensor2}, {self});
63- SmallVector<Tensor, N> outputs = {self};
64- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
65 if (!NpuUtils::check_match(&self)) {60 if (!NpuUtils::check_match(&self)) {
66 Tensor contiguousSelf = NpuUtils::format_contiguous(self);61 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
67 Tensor result = addcdiv_out_npu(contiguousSelf, contiguousSelf, tensor1, tensor2, value);62 Tensor result = addcdiv_out_npu(contiguousSelf, contiguousSelf, tensor1, tensor2, value);
@@ -50,8 +50,7 @@ Tensor& addcmul_out_npu(
50 OpPreparation::CheckOut(50 OpPreparation::CheckOut(
51 {self},51 {self},
52 result,52 result,
53- CalcuOpUtil::get_tensor_npu_format(self),53+ self,
54- self.scalar_type(),
55 outputSize);54 outputSize);
56 55 
57 OpPipeWithDefinedOut pipe;56 OpPipeWithDefinedOut pipe;
@@ -81,10 +80,7 @@ Tensor& addcmul_npu_(
81 const Tensor& tensor1,80 const Tensor& tensor1,
82 const Tensor& tensor2,81 const Tensor& tensor2,
83 Scalar value) {82 Scalar value) {
84- SmallVector<Tensor, N> inputs = {self};83+ OpPreparation::CheckMemory({self}, {self});
85- SmallVector<Tensor, N> outputs = {self};
86- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
87- 
88 if (!NpuUtils::check_match(&self)) {84 if (!NpuUtils::check_match(&self)) {
89 Tensor contiguousSelf = NpuUtils::format_contiguous(self);85 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
90 Tensor result = addcmul_out_npu_nocheck(86 Tensor result = addcmul_out_npu_nocheck(
@@ -12,8 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/CalcuOpUtil.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
17#include "ATen/native/npu/utils/NpuUtils.h"16#include "ATen/native/npu/utils/NpuUtils.h"
18 17 
19namespace at {18namespace at {
@@ -64,14 +63,8 @@ Tensor addmv_npu(
64 Scalar alpha) {63 Scalar alpha) {
65 64
66 check_1d(vec, "vec", "addmv");65 check_1d(vec, "vec", "addmv");
67- // calculate the output size
68 auto outputSize = addmv_npu_output_size(self, mat, vec, beta, alpha);66 auto outputSize = addmv_npu_output_size(self, mat, vec, beta, alpha);
69- 67+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
70- // construct the output tensor of the NPU
71- Tensor result = at::empty_with_format(
72- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
73- 
74- // calculate the output result of the NPU
75 addmv_out_npu(result, self, mat, vec, beta, alpha);68 addmv_out_npu(result, self, mat, vec, beta, alpha);
76 69 
77 return result;70 return result;
@@ -85,9 +78,7 @@ Tensor& addmv_npu_(
85 Scalar alpha) {78 Scalar alpha) {
86 79
87 check_1d(vec, "vec", "addmv");80 check_1d(vec, "vec", "addmv");
88- SmallVector<Tensor, N> inputs = {self, mat, vec};81+ OpPreparation::CheckMemory({self, mat, vec}, {self});
89- SmallVector<Tensor, N> outputs = {self};
90- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
91 if (!NpuUtils::check_match(&self)) {82 if (!NpuUtils::check_match(&self)) {
92 Tensor contiguousSelf = NpuUtils::format_contiguous(self);83 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
93 Tensor result =84 Tensor result =
@@ -12,8 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/CalcuOpUtil.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
17#include "ATen/native/npu/utils/NpuUtils.h"16#include "ATen/native/npu/utils/NpuUtils.h"
18 17 
19namespace at {18namespace at {
@@ -64,15 +63,8 @@ Tensor _addr_npu(
64 const Tensor& vec2,63 const Tensor& vec2,
65 Scalar beta,64 Scalar beta,
66 Scalar alpha) {65 Scalar alpha) {
67- 
68- // calculate the output size
69 auto outputSize = addr_npu_output_size(self, vec1, vec2, beta, alpha);66 auto outputSize = addr_npu_output_size(self, vec1, vec2, beta, alpha);
70- 67+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
71- // construct the output tensor of the NPU
72- Tensor result = at::empty_with_format(
73- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
74- 
75- // calculate the output result of the NPU
76 _addr_out_npu(result, self, vec1, vec2, beta, alpha);68 _addr_out_npu(result, self, vec1, vec2, beta, alpha);
77 69 
78 return result;70 return result;
@@ -95,9 +87,7 @@ Tensor& _addr_npu_(
95 const Tensor& vec2,87 const Tensor& vec2,
96 Scalar beta,88 Scalar beta,
97 Scalar alpha) {89 Scalar alpha) {
98- SmallVector<Tensor, N> inputs = {self, vec1, vec2};90+ OpPreparation::CheckMemory({self, vec1, vec2}, {self});
99- SmallVector<Tensor, N> outputs = {self};
100- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
101 if (!NpuUtils::check_match(&self)) {91 if (!NpuUtils::check_match(&self)) {
102 Tensor contiguousSelf = NpuUtils::format_contiguous(self);92 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
103 Tensor result =93 Tensor result =
@@ -35,8 +35,7 @@ Tensor& affine_grid_generator_backward_nocheck(
35 const Tensor& grad, 35 const Tensor& grad,
36 IntArrayRef size,36 IntArrayRef size,
37 bool align_corners) {37 bool align_corners) {
38- Tensor assist = at::empty_with_format( 38+ Tensor assist = OpPreparation::ApplyTensor(grad, {size[0], size[2], size[3], 3});
39- {size[0], size[2], size[3], 3}, grad.options(), CalcuOpUtil::get_tensor_npu_format(grad));
40 assist.select(-1, 0).copy_(_linspace_from_neg_one(grad, size[3], align_corners));39 assist.select(-1, 0).copy_(_linspace_from_neg_one(grad, size[3], align_corners));
41 assist.select(-1, 1).copy_(_linspace_from_neg_one(grad, size[2], align_corners).unsqueeze_(-1));40 assist.select(-1, 1).copy_(_linspace_from_neg_one(grad, size[2], align_corners).unsqueeze_(-1));
42 assist.select(-1, 2).fill_(1);41 assist.select(-1, 2).fill_(1);
@@ -17,7 +17,7 @@
17#include "ATen/native/npu/utils/CalcuOpUtil.h"17#include "ATen/native/npu/utils/CalcuOpUtil.h"
18#include "ATen/native/npu/utils/KernelNpuOutputSize.h"18#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
19#include "ATen/native/npu/utils/NpuUtils.h"19#include "ATen/native/npu/utils/NpuUtils.h"
20-#include "ATen/native/npu/utils/OpTemplate.h"20+#include "ATen/native/npu/utils/OpAdapter.h"
21 21 
22namespace at {22namespace at {
23namespace native {23namespace native {
@@ -62,9 +62,7 @@ Tensor affine_grid_generator_npu(
62 }62 }
63 63 
64 // construct the output tensor of the NPU64 // construct the output tensor of the NPU
65- Tensor result = at::empty_with_format(65+ Tensor result = OpPreparation::ApplyTensor(theta, outputSize);
66- outputSize, theta.options(), CalcuOpUtil::get_tensor_npu_format(theta));
67- 
68 // calculate the output result of the NPU66 // calculate the output result of the NPU
69 affine_grid_generator_npu_nocheck(67 affine_grid_generator_npu_nocheck(
70 result, 68 result,
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18#include "c10/npu/OptionsManager.h"19#include "c10/npu/OptionsManager.h"
19 20 
20namespace at {21namespace at {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -32,10 +32,10 @@ Tensor argmin_npu(const Tensor& self, optional<int64_t> dim, bool keepdim) {
32 auto outputSize = reduce_ops_npu_output_size(input, realDim, realKeepDim);32 auto outputSize = reduce_ops_npu_output_size(input, realDim, realKeepDim);
33 33 
34 // construct the output tensor of the NPU34 // construct the output tensor of the NPU
35- Tensor result = at::empty_with_format(35+ Tensor result = OpPreparation::ApplyTensor(
36 outputSize,36 outputSize,
37 self.options().dtype(at::kInt),37 self.options().dtype(at::kInt),
38- CalcuOpUtil::get_tensor_npu_format(self));38+ self);
39 SmallVector<int64_t, N> DimVec = {realDim};39 SmallVector<int64_t, N> DimVec = {realDim};
40 // calculate the output result of the NPU40 // calculate the output result of the NPU
41 OpCommand cmd;41 OpCommand cmd;
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include<ATen/NamedTensorUtils.h>
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -12,8 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"
17 16 
18namespace at {17namespace at {
19namespace native {18namespace native {
@@ -32,26 +31,13 @@ Tensor& asin_out_npu(
32}31}
33 32 
34Tensor asin_npu(const Tensor& self) {33Tensor asin_npu(const Tensor& self) {
35- // calculate the output size34+ Tensor result = OpPreparation::ApplyTensor(self);
36- auto outputSize = input_same_output_size(self);
37- 
38- // construct the output tensor of the NPU
39- Tensor result = at::empty_with_format(
40- outputSize,
41- self.options(),
42- CalcuOpUtil::get_tensor_npu_format(self));
43- 
44- // calculate the output result of the NPU
45 asin_out_npu(result, self);35 asin_out_npu(result, self);
46- 
47 return result;36 return result;
48}37}
49 38 
50Tensor& asin_npu_(Tensor& self) {39Tensor& asin_npu_(Tensor& self) {
51- SmallVector<Tensor, N> inputs = {self};40+ OpPreparation::CheckMemory({self}, {self});
52- SmallVector<Tensor, N> outputs = {self};
53- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
54- 
55 if (!NpuUtils::check_match(&self)) {41 if (!NpuUtils::check_match(&self)) {
56 Tensor contiguousSelf = NpuUtils::format_contiguous(self);42 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
57 Tensor result = asin_out_npu(contiguousSelf, contiguousSelf);43 Tensor result = asin_out_npu(contiguousSelf, contiguousSelf);
@@ -12,8 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"
17 16 
18namespace at {17namespace at {
19namespace native {18namespace native {
@@ -44,8 +43,7 @@ Tensor& atan2_out_npu(
44 OpPreparation::CheckOut(43 OpPreparation::CheckOut(
45 {self},44 {self},
46 result,45 result,
47- CalcuOpUtil::get_tensor_npu_format(self),46+ self,
48- self.scalar_type(),
49 outputSize);47 outputSize);
50 48 
51 atan2_out_npu_nocheck(result, self, other);49 atan2_out_npu_nocheck(result, self, other);
@@ -54,25 +52,14 @@ Tensor& atan2_out_npu(
54}52}
55 53 
56Tensor atan2_npu(const Tensor& self, const Tensor& other) {54Tensor atan2_npu(const Tensor& self, const Tensor& other) {
57- // calculate the output size
58 auto outputSize = broadcast_ops_npu_output_size(self, other);55 auto outputSize = broadcast_ops_npu_output_size(self, other);
59- 56+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
60- // construct the output tensor of the NPU
61- Tensor result = at::empty_with_format(
62- outputSize,
63- self.options(),
64- CalcuOpUtil::get_tensor_npu_format(self));
65- 
66- // calculate the output result of the NPU
67 atan2_out_npu_nocheck(result, self, other);57 atan2_out_npu_nocheck(result, self, other);
68- 
69 return result;58 return result;
70}59}
71 60 
72Tensor& atan2_npu_(Tensor& self, const Tensor& other) {61Tensor& atan2_npu_(Tensor& self, const Tensor& other) {
73- SmallVector<Tensor, N> inputs = {self, other};62+ OpPreparation::CheckMemory({self, other}, {self});
74- SmallVector<Tensor, N> outputs = {self};
75- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
76 63 
77 if (!NpuUtils::check_match(&self)) {64 if (!NpuUtils::check_match(&self)) {
78 Tensor contiguousSelf = NpuUtils::format_contiguous(self);65 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
@@ -31,23 +31,14 @@ Tensor& atan_out_npu(Tensor& result, const Tensor& self) {
31}31}
32 32
33Tensor atan_npu(const Tensor& self) { 33Tensor atan_npu(const Tensor& self) {
34- //calculate the output size 34+ Tensor result = OpPreparation::ApplyTensor(self);
35- auto outputSize = input_same_output_size(self);
36-
37- //construct the output tensor of the NPU
38- Tensor result = at::empty_with_format(
39- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
40-
41 //calculate the output result of the NPU 35 //calculate the output result of the NPU
42 atan_out_npu(result, self); 36 atan_out_npu(result, self);
43 return result; 37 return result;
44} 38}
45 39
46Tensor& atan_npu_(Tensor& self) { 40Tensor& atan_npu_(Tensor& self) {
47- SmallVector<Tensor, N> inputs = {self}; 41+ OpPreparation::CheckMemory({self}, {self});
48- SmallVector<Tensor, N> outputs = {self};
49- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
50-
51 if (!NpuUtils::check_match(&self)) { 42 if (!NpuUtils::check_match(&self)) {
52 Tensor contiguousSelf = NpuUtils::format_contiguous(self); 43 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
53 Tensor result = atan_out_npu(contiguousSelf, contiguousSelf); 44 Tensor result = atan_out_npu(contiguousSelf, contiguousSelf);
@@ -28,25 +28,24 @@ std::tuple<Tensor, Tensor, Tensor, Tensor> batch_nms_npu(
28 bool change_coordinate_frame,28 bool change_coordinate_frame,
29 bool transpose_box) {29 bool transpose_box) {
30 // construct the output tensor of the NPU30 // construct the output tensor of the NPU
31- Tensor nmsed_boxes = at::empty_with_format(31+ Tensor nmsed_boxes = OpPreparation::ApplyTensor(
32 {self.size(0), max_total_size, 4},32 {self.size(0), max_total_size, 4},
33 self.options().dtype(at::kHalf),33 self.options().dtype(at::kHalf),
34- CalcuOpUtil::get_tensor_npu_format(self));34+ self);
35- 35+ Tensor nmsed_scores = OpPreparation::ApplyTensor(
36- Tensor nmsed_scores = at::empty_with_format(
37 {self.size(0), max_total_size},36 {self.size(0), max_total_size},
38 self.options().dtype(at::kHalf),37 self.options().dtype(at::kHalf),
39- CalcuOpUtil::get_tensor_npu_format(self));38+ self);
40 39 
41- Tensor nmsed_classes = at::empty_with_format(40+ Tensor nmsed_classes = OpPreparation::ApplyTensor(
42 {self.size(0), max_total_size},41 {self.size(0), max_total_size},
43 self.options().dtype(at::kHalf),42 self.options().dtype(at::kHalf),
44- CalcuOpUtil::get_tensor_npu_format(self));43+ self);
45 44 
46- Tensor nmsed_num = at::empty_with_format(45+ Tensor nmsed_num = OpPreparation::ApplyTensor(
47 {self.size(0)},46 {self.size(0)},
48 self.options().dtype(at::kInt),47 self.options().dtype(at::kInt),
49- CalcuOpUtil::get_tensor_npu_format(self));48+ self);
50 49 
51 OpCommand cmd;50 OpCommand cmd;
52 cmd.Name("BatchMultiClassNonMaxSuppression")51 cmd.Name("BatchMultiClassNonMaxSuppression")
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -44,10 +43,7 @@ Tensor& bernoulli_out_npu(Tensor& result, const Tensor& self, const Tensor& p) {
44}43}
45 44 
46Tensor& bernoulli_npu_(Tensor& self, double p, Generator* gen) {45Tensor& bernoulli_npu_(Tensor& self, double p, Generator* gen) {
47- SmallVector<Tensor, N> inputs = {self};46+ OpPreparation::CheckMemory({self}, {self});
48- SmallVector<Tensor, N> outputs = {self};
49- 
50- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
51 ScalarType selfType = self.scalar_type();47 ScalarType selfType = self.scalar_type();
52 Tensor selfFp32 = self;48 Tensor selfFp32 = self;
53 if (self.scalar_type() == ScalarType::Half) {49 if (self.scalar_type() == ScalarType::Half) {
@@ -70,10 +66,7 @@ Tensor& bernoulli_npu_(Tensor& self, double p, Generator* gen) {
70}66}
71 67 
72Tensor& bernoulli_npu_(Tensor& self, const Tensor& p, Generator* gen) {68Tensor& bernoulli_npu_(Tensor& self, const Tensor& p, Generator* gen) {
73- SmallVector<Tensor, N> inputs = {self};69+ OpPreparation::CheckMemory({self}, {self});
74- SmallVector<Tensor, N> outputs = {self};
75- 
76- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
77 ScalarType selfType = self.scalar_type();70 ScalarType selfType = self.scalar_type();
78 Tensor selfFp32 = self;71 Tensor selfFp32 = self;
79 Tensor pFp32 = OpPreparation::CastBackToOriFormat(p);;72 Tensor pFp32 = OpPreparation::CastBackToOriFormat(p);;
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -62,13 +61,7 @@ Tensor binary_cross_entropy_backward_npu(
62 const Tensor& target,61 const Tensor& target,
63 const Tensor& weight,62 const Tensor& weight,
64 int64_t reduction) {63 int64_t reduction) {
65- // calculate the output size64+ Tensor gradInput = OpPreparation::ApplyTensor(self);
66- auto outputSize = input_same_output_size(self);
67- 
68- // construct the output tensor of the NPU
69- Tensor gradInput = at::empty_with_format(
70- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
71- 
72 // calculate the output result of the NPU65 // calculate the output result of the NPU
73 binary_cross_entropy_backward_out_npu(66 binary_cross_entropy_backward_out_npu(
74 gradInput, grad_output, self, target, weight, reduction);67 gradInput, grad_output, self, target, weight, reduction);
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -68,10 +67,7 @@ Tensor binary_cross_entropy_npu(
68 }67 }
69 68 
70 // construct the output tensor of the NPU69 // construct the output tensor of the NPU
71- Tensor result = at::empty_with_format(70+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
72- outputSize,
73- self.options(),
74- CalcuOpUtil::get_tensor_npu_format(self));
75 71 
76 // calculate the output result of the NPU72 // calculate the output result of the NPU
77 binary_cross_entropy_out_npu(result, self, target, weight, reduction);73 binary_cross_entropy_out_npu(result, self, target, weight, reduction);
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -28,12 +27,7 @@ Tensor binary_cross_entropy_with_logits_backward_npu(
28 const Tensor& weight,27 const Tensor& weight,
29 const Tensor& pos_weight,28 const Tensor& pos_weight,
30 int64_t reduction) {29 int64_t reduction) {
31- // calculate the output size30+ Tensor gradInput = OpPreparation::ApplyTensor(self);
32- auto outputSize = input_same_output_size(self);
33- 
34- // construct the output tensor of the NPU
35- Tensor gradInput = at::empty_with_format(
36- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
37 31 
38 // calculate the output result of the NPU32 // calculate the output result of the NPU
39 Tensor weightTensor;33 Tensor weightTensor;
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
@@ -12,8 +12,8 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"16+#include "ATen/native/npu/utils/CalcuOpUtil.h"
17 17 
18namespace at {18namespace at {
19namespace native {19namespace native {
@@ -38,9 +38,7 @@ Tensor& bitwise_not_out_npu(Tensor& result, const Tensor& self) {
38 OpPreparation::CheckOut(38 OpPreparation::CheckOut(
39 {self},39 {self},
40 result,40 result,
41- CalcuOpUtil::get_tensor_npu_format(self),41+ self);
42- self.scalar_type(),
43- self.sizes());
44 42 
45 OpPipeWithDefinedOut pipe;43 OpPipeWithDefinedOut pipe;
46 return pipe.CheckMemory({self}, {result})44 return pipe.CheckMemory({self}, {result})
@@ -12,8 +12,8 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"16+#include "ATen/native/npu/utils/CalcuOpUtil.h"
17 17 
18namespace at {18namespace at {
19namespace native {19namespace native {
@@ -44,9 +44,7 @@ Tensor& bitwise_or_out_npu(
44 OpPreparation::CheckOut(44 OpPreparation::CheckOut(
45 {self},45 {self},
46 result,46 result,
47- CalcuOpUtil::get_tensor_npu_format(self),47+ self);
48- self.scalar_type(),
49- self.sizes());
50 48 
51 bitwise_or_out_npu_nocheck(result, self, other);49 bitwise_or_out_npu_nocheck(result, self, other);
52 50 
@@ -120,11 +118,7 @@ Tensor bitwise_or_npu(const Tensor& self, const Tensor& other) {
120 auto outputSize = broadcast_ops_npu_output_size(self, other);118 auto outputSize = broadcast_ops_npu_output_size(self, other);
121 119 
122 // construct the output tensor of the NPU120 // construct the output tensor of the NPU
123- Tensor result = at::empty_with_format(121+ Tensor result = OpPreparation::ApplyTensor(outputTensor, outputSize);
124- outputSize,
125- outputTensor.options(),
126- CalcuOpUtil::get_tensor_npu_format(outputTensor));
127- 
128 // calculate the output result of the NPU122 // calculate the output result of the NPU
129 bitwise_or_out_npu_nocheck(result, self, other);123 bitwise_or_out_npu_nocheck(result, self, other);
130 124 
@@ -132,12 +126,7 @@ Tensor bitwise_or_npu(const Tensor& self, const Tensor& other) {
132}126}
133 127 
134Tensor bitwise_or_npu(const Tensor& self, Scalar other) {128Tensor bitwise_or_npu(const Tensor& self, Scalar other) {
135- // calculate the output size129+ Tensor result = OpPreparation::ApplyTensor(self);
136- auto outputSize = input_same_output_size(self);
137- 
138- // construct the output tensor of the NPU
139- Tensor result = at::empty_with_format(
140- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
141 130 
142 // calculate the output result of the NPU131 // calculate the output result of the NPU
143 bitwise_or_out_npu_nocheck(result, self, other);132 bitwise_or_out_npu_nocheck(result, self, other);
@@ -146,9 +135,7 @@ Tensor bitwise_or_npu(const Tensor& self, Scalar other) {
146}135}
147 136 
148Tensor& bitwise_or_npu_(Tensor& self, const Tensor& other) {137Tensor& bitwise_or_npu_(Tensor& self, const Tensor& other) {
149- SmallVector<Tensor, N> inputs = {self, other};138+ OpPreparation::CheckMemory({self, other}, {self});
150- SmallVector<Tensor, N> outputs = {self};
151- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
152 139 
153 if (!NpuUtils::check_match(&self)) {140 if (!NpuUtils::check_match(&self)) {
154 Tensor contiguousSelf = NpuUtils::format_contiguous(self);141 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
@@ -12,8 +12,8 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"16+#include "ATen/native/npu/utils/CalcuOpUtil.h"
17 17 
18namespace at {18namespace at {
19namespace native {19namespace native {
@@ -44,9 +44,7 @@ Tensor& bitwise_xor_out_npu(
44 OpPreparation::CheckOut(44 OpPreparation::CheckOut(
45 {self},45 {self},
46 result,46 result,
47- CalcuOpUtil::get_tensor_npu_format(self),47+ self);
48- self.scalar_type(),
49- self.sizes());
50 48 
51 bitwise_xor_out_npu_nocheck(result, self, other);49 bitwise_xor_out_npu_nocheck(result, self, other);
52 50 
@@ -122,11 +120,7 @@ Tensor bitwise_xor_npu(const Tensor& self, const Tensor& other) {
122 auto outputSize = broadcast_ops_npu_output_size(self, other);120 auto outputSize = broadcast_ops_npu_output_size(self, other);
123 121 
124 // construct the output tensor of the NPU122 // construct the output tensor of the NPU
125- Tensor result = at::empty_with_format(123+ Tensor result = OpPreparation::ApplyTensor(outputTensor, outputSize);
126- outputSize,
127- outputTensor.options(),
128- CalcuOpUtil::get_tensor_npu_format(outputTensor));
129- 
130 // calculate the output result of the NPU124 // calculate the output result of the NPU
131 bitwise_xor_out_npu_nocheck(result, self, other);125 bitwise_xor_out_npu_nocheck(result, self, other);
132 126 
@@ -134,15 +128,7 @@ Tensor bitwise_xor_npu(const Tensor& self, const Tensor& other) {
134}128}
135 129 
136Tensor bitwise_xor_npu(const Tensor& self, Scalar other) {130Tensor bitwise_xor_npu(const Tensor& self, Scalar other) {
137- // calculate the output size131+ Tensor result = OpPreparation::ApplyTensor(self);
138- auto outputSize = input_same_output_size(self);
139- 
140- // construct the output tensor of the NPU
141- Tensor result = at::empty_with_format(
142- outputSize,
143- self.options(),
144- CalcuOpUtil::get_tensor_npu_format(self));
145- 
146 // calculate the output result of the NPU132 // calculate the output result of the NPU
147 bitwise_xor_out_npu_nocheck(result, self, other);133 bitwise_xor_out_npu_nocheck(result, self, other);
148 134 
@@ -150,10 +136,7 @@ Tensor bitwise_xor_npu(const Tensor& self, Scalar other) {
150}136}
151 137 
152Tensor& bitwise_xor_npu_(Tensor& self, const Tensor& other) {138Tensor& bitwise_xor_npu_(Tensor& self, const Tensor& other) {
153- SmallVector<Tensor, N> inputs = {self, other};139+ OpPreparation::CheckMemory({self, other}, {self});
154- SmallVector<Tensor, N> outputs = {self};
155- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
156- 
157 if (!NpuUtils::check_match(&self)) {140 if (!NpuUtils::check_match(&self)) {
158 Tensor contiguousSelf = NpuUtils::format_contiguous(self);141 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
159 Tensor result = bitwise_xor_out_npu_nocheck(contiguousSelf, contiguousSelf, other);142 Tensor result = bitwise_xor_out_npu_nocheck(contiguousSelf, contiguousSelf, other);
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19#include "c10/npu/OptionsManager.h"19#include "c10/npu/OptionsManager.h"
20 20 
21namespace at {21namespace at {
@@ -14,75 +14,281 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
22using namespace at::native::npu;22using namespace at::native::npu;
23 23 
24-SmallVector<int64_t, SIZE> bmm_v2_output_size(const Tensor& mat1, const Tensor& mat2) {24+bool is_transpose_last_two_dims_v2(const Tensor& tensor) {
25- auto dim_tensor1 = mat1.dim();25+ if (tensor.dim() < 2) {
26- auto dim_tensor2 = mat2.dim();26+ return false;
27- TORCH_CHECK(dim_tensor1 > 2, "mat1's dim must be greater than 2");27+ }
28- TORCH_CHECK(dim_tensor2 >= 2, "mat2's dim must be greater than or equal to 2");28+ auto storage_size = tensor.storage().get_npu_desc().storage_sizes_;
29- if (dim_tensor2 == 2) {29+ int64_t numel = at::prod_intlist(storage_size);
30- auto output_size(array_to_small_vector(mat1.sizes().slice(0, dim_tensor1-1)));30+ 
31- output_size.emplace_back(mat2.size(-1));31+ int64_t dim1 = tensor.dim() - 1;
32- return output_size;32+ int64_t dim2 = tensor.dim() - 2;
33+ 
34+ auto tensor_desc = tensor.storage().get_npu_desc();
35+ if (tensor_desc.base_sizes_.size() == tensor.dim() &&
36+ tensor.stride(dim2) == 1 && tensor.stride(dim1) == tensor.size(dim2) &&
37+ tensor.size(dim1) == tensor_desc.base_sizes_[dim2] &&
38+ tensor.size(dim2) == tensor_desc.base_sizes_[dim1] &&
39+ tensor.storage().size() == numel) {
40+ return true;
33 } else {41 } else {
34- TORCH_CHECK(dim_tensor1 == dim_tensor2, "if mat2's dim > 2, mat1's and mat2's batch size must be same");42+ return false;
35- IntArrayRef batch_tensor1(mat1.sizes().data(), std::max<int64_t>(dim_tensor1 - 2, 0));
36- SmallVector<int64_t, SIZE> output_size = array_to_small_vector(batch_tensor1);
37- output_size.emplace_back(mat1.size(-2));
38- output_size.emplace_back(mat2.size(-1));
39- return output_size;
40 }43 }
41}44}
42 45 
46+SmallVector<int64_t, SIZE> bmm_v2_output_size(const Tensor& mat1, const Tensor& mat2) {
47+ auto dim_tensor1 = mat1.dim();
48+ auto dim_tensor2 = mat2.dim();
43 49 
44-Tensor bmm_v2_npu(const Tensor& self, const Tensor& mat2) {50+ int64_t m = dim_tensor1 == 1 ? 1 : mat1.size(-2);
45- auto outputSize = bmm_v2_output_size(self, mat2);51+ int64_t n = dim_tensor2 == 1 ? 1 : mat2.size(-1);
46- Tensor result;
47 52 
48- if ((self.scalar_type() == ScalarType::Float || self.scalar_type() == ScalarType::Half)) {53+ auto batch_a = array_to_small_vector(IntArrayRef(mat1.sizes().data(), std::max<int64_t>(dim_tensor1 - 2, 0)));
49- result = at::empty_with_format(outputSize, self.options(), ACL_FORMAT_FRACTAL_NZ);54+ auto batch_b = array_to_small_vector(IntArrayRef(mat2.sizes().data(), std::max<int64_t>(dim_tensor2 - 2, 0)));
55+ 
56+ batch_a.insert(batch_a.begin(), std::max<int64_t>(batch_a.size(), batch_b.size()) - batch_a.size(), 1);
57+ batch_b.insert(batch_b.begin(), std::max<int64_t>(batch_a.size(), batch_b.size()) - batch_b.size(), 1);
58+ 
59+ SmallVector<int64_t, SIZE> output_size;
60+ for (size_t i = 0; i < batch_a.size(); ++i) {
61+ if (batch_a[i] == 1) {
62+ output_size.emplace_back(batch_b[i]);
63+ } else if (batch_b[i] == 1) {
64+ output_size.emplace_back(batch_a[i]);
65+ } else if (batch_a[i] != batch_b[i]) {
66+ AT_ERROR("mat1 and mat2 cannot broadcast, but they are mat1 ",
67+ mat1.sizes().data(), " mat2 ", mat2.sizes().data());
68+ } else {
69+ output_size.emplace_back(batch_a[i]);
70+ }
71+ }
72+ output_size.emplace_back(m);
73+ output_size.emplace_back(n);
74+ 
75+ return output_size;
76+}
77+ 
78+Tensor pure_bmm_v2_npu(const Tensor& self, const Tensor& mat2, const SmallVector<int64_t, SIZE>& output_size) {
79+ auto tensor1 = self.dim() == 1 ? self.view({1, self.size(0)}) : self;
80+ auto tensor2 = mat2.dim() == 1 ? mat2.view({mat2.size(0), 1}) : mat2;
81+ 
82+ Tensor result;
83+ 
84+ if ((tensor1.scalar_type() == ScalarType::Half)) {
85+ result = at::empty_with_format(output_size, tensor1.options(), ACL_FORMAT_FRACTAL_NZ);
50 } else {86 } else {
51- result = at::empty_with_format(outputSize, self.options(), ACL_FORMAT_ND);87+ result = at::empty_with_format(output_size, tensor1.options(), ACL_FORMAT_ND);
52 }88 }
53 89 
54- Tensor contiguousSelf = self;90+ Tensor contiguous_self = tensor1;
55- Tensor contiguousMat2 = mat2;91+ Tensor contiguous_mat2 = tensor2;
56- if(! CalcuOpUtil::is_transpose_last_two_dims(self)){92+ bool is_self_t = is_transpose_last_two_dims_v2(tensor1);
57- contiguousSelf = NpuUtils::format_contiguous(self);93+ bool is_mat2_t = is_transpose_last_two_dims_v2(tensor2);
94+ 
95+ if(!is_self_t) {
96+ contiguous_self = NpuUtils::format_contiguous(tensor1);
58 }97 }
59- if(! CalcuOpUtil::is_transpose_last_two_dims(mat2)){98+ if(!is_mat2_t) {
60- contiguousMat2 = NpuUtils::format_contiguous(mat2);99+ contiguous_mat2 = NpuUtils::format_contiguous(tensor2);
61 }100 }
62 101 
63- auto func1 = [&contiguousSelf]() {102+ auto func1 = [&contiguous_self]() {
64 bool pass = false;103 bool pass = false;
65- return std::tie(pass, contiguousSelf);104+ return std::tie(pass, contiguous_self);
66 };105 };
67- auto func2 = [&contiguousMat2]() {106+ auto func2 = [&contiguous_mat2]() {
68 bool pass = false;107 bool pass = false;
69- return std::tie(pass, contiguousMat2);108+ return std::tie(pass, contiguous_mat2);
70 };109 };
71 110 
72- bool isSelfT = CalcuOpUtil::is_transpose_last_two_dims(self);
73- bool isMat2T = CalcuOpUtil::is_transpose_last_two_dims(mat2);
74- 
75 // executing the NPU operator111 // executing the NPU operator
76 OpCommand cmd;112 OpCommand cmd;
77 cmd.Name("BatchMatMul")113 cmd.Name("BatchMatMul")
78 .InputWithFunc(func1)114 .InputWithFunc(func1)
79 .InputWithFunc(func2)115 .InputWithFunc(func2)
80 .Output(result)116 .Output(result)
81- .Attr("adj_x1", isSelfT)117+ .Attr("adj_x1", is_self_t)
82- .Attr("adj_x2", isMat2T)118+ .Attr("adj_x2", is_mat2_t)
83 .Run();119 .Run();
84 120 
85 return result;121 return result;
86}122}
123+ 
124+Tensor reshape_tensor_self(const Tensor& self, SmallVector<int64_t, SIZE>& expect_output_size) {
125+ // self, expect_output: [5,6,7,17], [1,6,7,65]
126+ // self permute + reshape: [5,6,7,17] -> [6,7,5,17] -> [6,7,85]
127+ SmallVector<int64_t, SIZE> self_permute_idx;
128+ SmallVector<int64_t, SIZE> self_batch_idx;
129+ 
130+ for (int64_t i = 0; i < self.dim(); ++i) {
131+ if (i < self.dim() - 2) {
132+ if (expect_output_size[i] == 1) {
133+ self_batch_idx.emplace_back(i);
134+ continue;
135+ }
136+ } else if (i == self.dim() - 1) {
137+ for (int64_t j = 0; j < self_batch_idx.size(); ++j) {
138+ self_permute_idx.emplace_back(self_batch_idx[j]);
139+ }
140+ }
141+ self_permute_idx.emplace_back(i);
142+ }
143+ Tensor tmp_self = self.permute(self_permute_idx);
144+ 
145+ int64_t m_idx = 0;
146+ SmallVector<int64_t, SIZE> tmp_self_size;
147+ SmallVector<int64_t, SIZE> tmp_self_size_low;
148+ 
149+ m_idx = self.dim() - self_batch_idx.size() - 1;
150+ tmp_self_size = array_to_small_vector(tmp_self.sizes());
151+ tmp_self_size_low.insert(tmp_self_size_low.end(), tmp_self_size.begin(), tmp_self_size.begin() + m_idx);
152+ tmp_self_size_low.emplace_back(-1);
153+ tmp_self = tmp_self.reshape(tmp_self_size_low);
154+ return tmp_self;
155+}
156+ 
157+Tensor reshape_tensor_mat2(const Tensor& mat2, SmallVector<int64_t, SIZE>& expect_output_size) {
158+ // mat2, expect_output_size: [5,6,17,65], [1,6,7,65]
159+ // mat2 permute + reshape: [5,6,17,65] -> [6,5,17,65] -> [6,85,65]
160+ SmallVector<int64_t, SIZE> mat2_permute_idx;
161+ SmallVector<int64_t, SIZE> mat2_batch_idx;
162+ 
163+ for (int64_t i = 0; i < mat2.dim(); ++i) {
164+ if (i < mat2.dim() - 2) {
165+ if (expect_output_size[i] == 1) {
166+ mat2_batch_idx.emplace_back(i);
167+ continue;
168+ }
169+ } else if (i == mat2.dim() - 2) {
170+ for (int64_t j = 0; j < mat2_batch_idx.size(); ++j) {
171+ mat2_permute_idx.emplace_back(mat2_batch_idx[j]);
172+ }
173+ }
174+ mat2_permute_idx.emplace_back(i);
175+ }
176+ Tensor tmp_mat2 = mat2.permute(mat2_permute_idx);
177+ 
178+ int64_t k_idx = 0;
179+ SmallVector<int64_t, SIZE> tmp_mat2_size;
180+ SmallVector<int64_t, SIZE> tmp_mat2_size_low;
181+ 
182+ k_idx = mat2.dim() - mat2_batch_idx.size() - 2;
183+ tmp_mat2_size = array_to_small_vector(tmp_mat2.sizes());
184+ tmp_mat2_size_low.insert(tmp_mat2_size_low.end(), tmp_mat2_size.begin(), tmp_mat2_size.begin() + k_idx);
185+ tmp_mat2_size_low.insert(tmp_mat2_size_low.end(), {-1, mat2.size(-1)});
186+ tmp_mat2 = tmp_mat2.reshape(tmp_mat2_size_low);
187+ return tmp_mat2;
188+}
189+ 
190+SmallVector<int64_t, SIZE> align_small_vector(SmallVector<int64_t, SIZE> svec,
191+ SmallVector<int64_t, SIZE> golden_svec) {
192+ // svec, golden: [6,7,65], [5,6,7,65]
193+ // expect: [6,7,65] -> [1,6,7,65]
194+ SmallVector<int64_t, SIZE> tmp_svec;
195+ tmp_svec = svec;
196+ int64_t size_to_fill = golden_svec.size() - svec.size();
197+ if (size_to_fill > 0) {
198+ tmp_svec.insert(tmp_svec.begin(), size_to_fill, 1);
199+ }
200+ return tmp_svec;
201+}
202+ 
203+void expand_tensor(Tensor& self, Tensor& mat2, SmallVector<int64_t, SIZE>& expand_output_size) {
204+ self = self.dim() == 1 ? self.view({1, self.size(0)}) : self;
205+ mat2 = mat2.dim() == 1 ? mat2.view({mat2.size(0), 1}) : mat2;
206+ int64_t m = self.size(-2);
207+ int64_t k1 = self.size(-1);
208+ int64_t k2 = mat2.size(-2);
209+ int64_t n = mat2.size(-1);
210+ 
211+ std::vector<int64_t> expand_batch_portion(expand_output_size.begin(), expand_output_size.end() - 2);
212+ std::vector<int64_t> self_expand_size(expand_batch_portion);
213+ std::vector<int64_t> mat2_expand_size(expand_batch_portion);
214+ 
215+ self_expand_size.insert(self_expand_size.end(), {m, k1});
216+ mat2_expand_size.insert(mat2_expand_size.end(), {k2, n});
217+ 
218+ int64_t expand_batch_product = std::accumulate(expand_batch_portion.begin(), expand_batch_portion.end(),
219+ 1L, std::multiplies<int64_t>());
220+ 
221+ std::vector<int64_t> self_bmm_view({expand_batch_product});
222+ std::vector<int64_t> mat2_bmm_view({expand_batch_product});
223+ self_bmm_view.insert(self_bmm_view.end(), {m, k1});
224+ mat2_bmm_view.insert(mat2_bmm_view.end(), {k2, n});
225+ 
226+ self = self.expand(self_expand_size).reshape(self_bmm_view);
227+ mat2 = mat2.expand(mat2_expand_size).reshape(mat2_bmm_view);
228+}
229+ 
230+Tensor bmm_v2_npu(const Tensor& self, const Tensor& mat2, IntArrayRef output_sizes) {
231+ auto expect_output_size = array_to_small_vector(output_sizes);
232+ auto infer_output_size = bmm_v2_output_size(self, mat2);
233+ Tensor tmp_self = self;
234+ Tensor tmp_mat2 = mat2;
235+ 
236+ // forward propagation
237+ if (expect_output_size.empty()) {
238+ // avoid some accuracy error caused by transdata
239+ expand_tensor(tmp_self, tmp_mat2, infer_output_size);
240+ expect_output_size = infer_output_size;
241+ infer_output_size = bmm_v2_output_size(tmp_self, tmp_mat2);
242+ 
243+ auto res = pure_bmm_v2_npu(tmp_self, tmp_mat2, infer_output_size).view(expect_output_size);
244+ infer_output_size = expect_output_size;
245+ 
246+ if (self.dim() == 1) {
247+ // [k][b, k, n] -> [b, 1, n] -> [b, n]
248+ infer_output_size.erase(infer_output_size.end() - 2);
249+ return res.view(infer_output_size);
250+ } else if (mat2.dim() == 1) {
251+ // [b, m, k][k] -> [b, m, 1] -> [b, m]
252+ infer_output_size.erase(infer_output_size.end() - 1);
253+ return res.view(infer_output_size);
254+ }
255+ return res;
256+ }
257+ 
258+ // backward propagation
259+ SmallVector<int64_t, SIZE> tmp_expect_output_size = expect_output_size;
260+ SmallVector<int64_t, SIZE> axis_reduce;
261+ SmallVector<int64_t, SIZE> tmp_self_size;
262+ SmallVector<int64_t, SIZE> tmp_mat2_size;
263+ 
264+ tmp_expect_output_size = align_small_vector(expect_output_size, infer_output_size);
265+ for (int i = 0; i < tmp_expect_output_size.size(); ++i) {
266+ if (tmp_expect_output_size[i] != infer_output_size[i]) {
267+ axis_reduce.emplace_back(i);
268+ }
269+ }
270+ 
271+ // no reduce_sum
272+ if (axis_reduce.empty()) {
273+ // avoid some accuracy error caused by transdata
274+ expand_tensor(tmp_self, tmp_mat2, infer_output_size);
275+ infer_output_size = bmm_v2_output_size(tmp_self, tmp_mat2);
276+ return pure_bmm_v2_npu(tmp_self, tmp_mat2, infer_output_size).view(expect_output_size);
277+ }
278+ 
279+ // reduce sum without accuracy error
280+ tmp_self_size = align_small_vector(array_to_small_vector(self.sizes()), infer_output_size);
281+ tmp_mat2_size = align_small_vector(array_to_small_vector(mat2.sizes()), infer_output_size);
282+ tmp_self = self.reshape(tmp_self_size);
283+ tmp_mat2 = mat2.reshape(tmp_mat2_size);
284+ tmp_self = reshape_tensor_self(tmp_self, tmp_expect_output_size);
285+ tmp_mat2 = reshape_tensor_mat2(tmp_mat2, tmp_expect_output_size);
286+ infer_output_size = bmm_v2_output_size(tmp_self, tmp_mat2);
287+ // avoid some accuracy error caused by transdata
288+ expand_tensor(tmp_self, tmp_mat2, infer_output_size);
289+ infer_output_size = bmm_v2_output_size(tmp_self, tmp_mat2);
290+ return pure_bmm_v2_npu(tmp_self, tmp_mat2, infer_output_size).view(expect_output_size);
291+}
292+ 
87} // namespace native293} // namespace native
88} // namespace at294} // namespace at
@@ -14,9 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include <ATen/ATen.h>17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19-#include "ATen/native/npu/utils/OpTemplate.h"
20 19 
21namespace at {20namespace at {
22namespace native {21namespace native {
@@ -59,9 +58,7 @@ Tensor bounding_box_decode_npu(
59 double wh_ratio_clip) {58 double wh_ratio_clip) {
60 SmallVector<int64_t, SIZE> outputSize = {rois.size(0), 4};59 SmallVector<int64_t, SIZE> outputSize = {rois.size(0), 4};
61 // construct the output tensor of the NPU60 // construct the output tensor of the NPU
62- Tensor result = at::empty_with_format(61+ Tensor result = OpPreparation::ApplyTensor(rois, outputSize);
63- outputSize, rois.options(), CalcuOpUtil::get_tensor_npu_format(rois));
64- 
65 SmallVector<float, SIZE> means = {62 SmallVector<float, SIZE> means = {
66 static_cast<float>(means0),63 static_cast<float>(means0),
67 static_cast<float>(means1),64 static_cast<float>(means1),
@@ -51,11 +51,7 @@ Tensor bounding_box_encode_npu(
51 double stds2,51 double stds2,
52 double stds3) {52 double stds3) {
53 // construct the output tensor of the NPU53 // construct the output tensor of the NPU
54- Tensor delats = at::empty_with_format(54+ Tensor delats = OpPreparation::ApplyTensor(anchor_box, {anchor_box.size(0), 4});
55- {anchor_box.size(0), 4},
56- anchor_box.options(),
57- CalcuOpUtil::get_tensor_npu_format(anchor_box));
58- 
59 SmallVector<float, SIZE> means = {55 SmallVector<float, SIZE> means = {
60 static_cast<float>(means0),56 static_cast<float>(means0),
61 static_cast<float>(means1),57 static_cast<float>(means1),
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18#include "c10/npu/OptionsManager.h"19#include "c10/npu/OptionsManager.h"
19 20 
20namespace at {21namespace at {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -16,6 +16,7 @@
16 16 
17#include "c10/npu/OptionsManager.h"17#include "c10/npu/OptionsManager.h"
18#include "ATen/native/npu/utils/OpAdapter.h"18#include "ATen/native/npu/utils/OpAdapter.h"
19+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 20 
20namespace at {21namespace at {
21namespace native {22namespace native {
@@ -12,10 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"
17-#include "ATen/native/npu/utils/CalcuOpUtil.h"
18-#include "ATen/native/npu/utils/NpuUtils.h"
19 16 
20namespace at {17namespace at {
21namespace native {18namespace native {
@@ -81,12 +78,7 @@ Tensor _cdist_backward_npu(
81 78 
82 //Executing the NPU operator.79 //Executing the NPU operator.
83 auto outputSize = input_same_output_size(x1);80 auto outputSize = input_same_output_size(x1);
84- 81+ Tensor result = OpPreparation::ApplyTensor(tensor1_broadcast, outputSize);
85- Tensor result = at::empty_with_format(
86- outputSize,
87- tensor1_broadcast.options(),
88- CalcuOpUtil::get_tensor_npu_format(tensor1_broadcast));
89-
90 OpCommand cmd;82 OpCommand cmd;
91 cmd.Name("CdistGrad")83 cmd.Name("CdistGrad")
92 .Input(grad_broadcast)84 .Input(grad_broadcast)
@@ -33,24 +33,13 @@ Tensor& ceil_out_npu(Tensor& result, const Tensor& self) {
33}33}
34 34 
35Tensor ceil_npu(const Tensor& self) {35Tensor ceil_npu(const Tensor& self) {
36- // calculate the output size36+ Tensor result = OpPreparation::ApplyTensor(self);
37- auto outputSize = input_same_output_size(self);
38- 
39- // construct the output tensor of the NPU
40- Tensor result = at::empty_with_format(
41- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
42- 
43- // calculate the output result of the NPU
44 ceil_out_npu(result, self);37 ceil_out_npu(result, self);
45- 
46 return result;38 return result;
47}39}
48 40 
49Tensor& ceil_npu_(Tensor& self) {41Tensor& ceil_npu_(Tensor& self) {
50- SmallVector<Tensor, N> inputs = {self};42+ OpPreparation::CheckMemory({self}, {self});
51- SmallVector<Tensor, N> outputs = {self};
52- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
53- 
54 if (!NpuUtils::check_match(&self)) {43 if (!NpuUtils::check_match(&self)) {
55 Tensor contiguousSelf = NpuUtils::format_contiguous(self);44 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
56 Tensor result = ceil_out_npu(contiguousSelf, contiguousSelf);45 Tensor result = ceil_out_npu(contiguousSelf, contiguousSelf);
Rsrc/aten/src/ATen/native/npu/TraceKernelNpu.cpp→src/aten/src/ATen/native/npu/CeluKernelNpu.cpp+36-27
@@ -1,4 +1,6 @@
1-// Copyright (c) 2020, Huawei Technologies.All rights reserved.1+// Copyright (c) 2020 Huawei Technologies Co., Ltd
2+// Copyright (c) 2019, Facebook CORPORATION.
3+// All rights reserved.
2//4//
3// Licensed under the BSD 3-Clause License (the "License");5// Licensed under the BSD 3-Clause License (the "License");
4// you may not use this file except in compliance with the License.6// you may not use this file except in compliance with the License.
@@ -12,39 +14,46 @@
12// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
13// limitations under the License.15// limitations under the License.
14 16 
15-#include "ATen/native/npu/utils/CalcuOpUtil.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
17-#include "ATen/native/npu/utils/NpuUtils.h"
18 18 
19namespace at {19namespace at {
20namespace native {20namespace native {
21using namespace at::native::npu;21using namespace at::native::npu;
22-SmallVector<NPUTensorDesc, N> trace_npu_input(const SmallVector<Tensor, N>& inputTensor) {
23- return CalcuOpUtil::create_npu_input_tensor_desc(inputTensor);
24-}
25 22 
26-SmallVector<NPUTensorDesc, N> trace_npu_output(const SmallVector<Tensor, N>& outputTensor) {23+Tensor celu_out_npu_nocheck(Tensor& result, const Tensor& self, Scalar alpha) {
27- return CalcuOpUtil::create_npu_output_tensor_desc(outputTensor);24+ float alpha3 = 1.0;
28-}25+ OpCommand cmd;
29- 26+ cmd.Name("Celu")
30-SmallVector<NPUAttrDesc, N> trace_npu_attr() {27+ .Input(self)
31- SmallVector<NPUAttrDesc, N> attrs = {};28+ .Output(result)
32- return attrs;29+ .Attr("alpha1", alpha)
33-}30+ .Attr("alpha2", alpha)
34- 31+ .Attr("alpha3", alpha3)
35-Tensor& trace_out_npu(Tensor& result, const Tensor& self) {32+ .Run();
36- auto inputs = trace_npu_input({self});
37- auto outputs = trace_npu_output({result});
38- auto attrs = trace_npu_attr();
39- CalcuOpUtil::execute_npu_operate("Trace", inputs, outputs, attrs);
40 return result;33 return result;
41}34}
42 35 
43-Tensor trace_npu(const Tensor& self) {36+Tensor celu_out_npu(Tensor& result, const Tensor& self, Scalar alpha) {
44- auto outputSize = trace_npu_output_size(self);37+ OpPipeWithDefinedOut pipe;
45- Tensor result = at::empty_with_format(outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));38+ return pipe.CheckMemory({self}, {result})
46- trace_out_npu(result, self);39+ .Func([&self, &alpha](Tensor& result){celu_out_npu_nocheck(result, self, alpha);})
47- return result.reshape({});40+ .Call(result);
48}41}
42+ 
43+Tensor celu_npu(const Tensor& self, Scalar alpha) {
44+ // construct the output tensor of the NPU
45+ Tensor result = OpPreparation::ApplyTensor(self);
46+ 
47+ // calculate the output result of the NPU
48+ celu_out_npu(result, self, alpha);
49+ 
50+ return result;
49}51}
50-}52+ 
53+Tensor& celu_npu_(Tensor& self, Scalar alpha) {
54+ celu_out_npu(self, self, alpha);
55+ return self;
56+}
57+ 
58+} // namespace native
59+} // namespace at
@@ -14,7 +14,6 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/CalcuOpUtil.h"
18#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
19#include "ATen/native/npu/utils/NpuUtils.h"18#include "ATen/native/npu/utils/NpuUtils.h"
20#include "ATen/native/npu/utils/OpTemplate.h"19#include "ATen/native/npu/utils/OpTemplate.h"
@@ -16,8 +16,6 @@
16 16 
17#include <climits>17#include <climits>
18#include <float.h>18#include <float.h>
19-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
20-#include "ATen/native/npu/utils/OpTemplate.h"
21#include "ATen/native/npu/utils/OpAdapter.h"19#include "ATen/native/npu/utils/OpAdapter.h"
22 20 
23namespace at {21namespace at {
@@ -40,14 +38,11 @@ Tensor& clamp_min_out_npu_nocheck(
40 max = NPU_HALF_MAX;38 max = NPU_HALF_MAX;
41 }39 }
42 40 
43- Tensor minTensor = CalcuOpUtil::CopyScalarToDevice(min, self.scalar_type());
44- Tensor maxTensor = CalcuOpUtil::CopyScalarToDevice(max, self.scalar_type());
45-
46 OpCommand cmd;41 OpCommand cmd;
47 cmd.Name("ClipByValue")42 cmd.Name("ClipByValue")
48 .Input(self)43 .Input(self)
49- .Input(minTensor)44+ .Input(min, self.scalar_type())
50- .Input(maxTensor)45+ .Input(max, self.scalar_type())
51 .Output(result)46 .Output(result)
52 .Run();47 .Run();
53 return result;48 return result;
@@ -60,9 +55,7 @@ Tensor& clamp_min_out_npu(
60 OpPreparation::CheckOut(55 OpPreparation::CheckOut(
61 {self},56 {self},
62 result,57 result,
63- CalcuOpUtil::get_tensor_npu_format(self),58+ self);
64- self.scalar_type(),
65- self.sizes());
66 59 
67 OpPipeWithDefinedOut pipe;60 OpPipeWithDefinedOut pipe;
68 return pipe.CheckMemory({self}, {result})61 return pipe.CheckMemory({self}, {result})
@@ -84,15 +77,12 @@ Tensor& clamp_max_out_npu(Tensor& result, const Tensor& self, Scalar max) {
84 } else {77 } else {
85 min = NPU_HALF_MIN;78 min = NPU_HALF_MIN;
86 }79 }
87- 80+ 
88- Tensor minTensor = CalcuOpUtil::CopyScalarToDevice(min, self.scalar_type());
89- Tensor maxTensor = CalcuOpUtil::CopyScalarToDevice(max, self.scalar_type());
90-
91 OpCommand cmd;81 OpCommand cmd;
92 cmd.Name("ClipByValue")82 cmd.Name("ClipByValue")
93 .Input(self)83 .Input(self)
94- .Input(minTensor)84+ .Input(min, self.scalar_type())
95- .Input(maxTensor)85+ .Input(max, self.scalar_type())
96 .Output(result)86 .Output(result)
97 .Run();87 .Run();
98 return result;88 return result;
@@ -111,15 +101,12 @@ Tensor& clamp_out_npu_nocheck(
111 Scalar minScalar = min.value();101 Scalar minScalar = min.value();
112 clamp_min_out_npu(result, self, minScalar);102 clamp_min_out_npu(result, self, minScalar);
113 103 
114- } else { 104+ } else {
115- Tensor minTensor = CalcuOpUtil::CopyScalarToDevice(min.value(), self.scalar_type());
116- Tensor maxTensor = CalcuOpUtil::CopyScalarToDevice(max.value(), self.scalar_type());
117-
118 OpCommand cmd;105 OpCommand cmd;
119 cmd.Name("ClipByValue")106 cmd.Name("ClipByValue")
120 .Input(self)107 .Input(self)
121- .Input(minTensor)108+ .Input(min.value(), self.scalar_type())
122- .Input(maxTensor)109+ .Input(max.value(), self.scalar_type())
123 .Output(result)110 .Output(result)
124 .Run(); 111 .Run();
125 }112 }
@@ -135,9 +122,7 @@ Tensor& clamp_out_npu(
135 OpPreparation::CheckOut(122 OpPreparation::CheckOut(
136 {self},123 {self},
137 result,124 result,
138- CalcuOpUtil::get_tensor_npu_format(self),125+ self);
139- self.scalar_type(),
140- self.sizes());
141 126 
142 OpPipeWithDefinedOut pipe;127 OpPipeWithDefinedOut pipe;
143 return pipe.CheckMemory({self}, {result})128 return pipe.CheckMemory({self}, {result})
@@ -148,16 +133,8 @@ Tensor& clamp_out_npu(
148}133}
149 134 
150Tensor clamp_min_npu(const Tensor& self, Scalar min) {135Tensor clamp_min_npu(const Tensor& self, Scalar min) {
151- // calculate the output size136+ Tensor result = OpPreparation::ApplyTensor(self);
152- auto outputSize = input_same_output_size(self);
153- 
154- // construct the output tensor of the NPU
155- Tensor result = at::empty_with_format(
156- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
157- 
158- // calculate the output result of the NPU
159 clamp_min_out_npu_nocheck(result, self, min);137 clamp_min_out_npu_nocheck(result, self, min);
160- 
161 return result;138 return result;
162}139}
163 140 
@@ -168,24 +145,14 @@ Tensor& clamp_min_npu_(Tensor& self, Scalar min) {
168}145}
169 146 
170Tensor clamp_max_npu(const Tensor& self, Scalar max) {147Tensor clamp_max_npu(const Tensor& self, Scalar max) {
171- // calculate the output size148+ Tensor result = OpPreparation::ApplyTensor(self);
172- auto outputSize = input_same_output_size(self);
173- 
174- // construct the output tensor of the NPU
175- Tensor result = at::empty_with_format(
176- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
177- 
178- // calculate the output result of the NPU
179 clamp_max_out_npu(result, self, max);149 clamp_max_out_npu(result, self, max);
180 150 
181 return result;151 return result;
182}152}
183 153 
184Tensor& clamp_max_npu_(Tensor& self, Scalar max) {154Tensor& clamp_max_npu_(Tensor& self, Scalar max) {
185- SmallVector<Tensor, N> inputs = {self};155+ OpPreparation::CheckMemory({self}, {self});
186- SmallVector<Tensor, N> outputs = {self};
187- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
188- 
189 if (!NpuUtils::check_match(&self)) {156 if (!NpuUtils::check_match(&self)) {
190 Tensor contiguousSelf = NpuUtils::format_contiguous(self);157 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
191 Tensor result = clamp_max_out_npu(contiguousSelf, contiguousSelf, max);158 Tensor result = clamp_max_out_npu(contiguousSelf, contiguousSelf, max);
@@ -201,22 +168,13 @@ Tensor clamp_npu(
201 const Tensor& self,168 const Tensor& self,
202 optional<Scalar> min,169 optional<Scalar> min,
203 optional<Scalar> max) {170 optional<Scalar> max) {
204- // calculate the output size171+ Tensor result = OpPreparation::ApplyTensor(self);
205- auto outputSize = input_same_output_size(self);
206- 
207- // construct the output tensor of the NPU
208- Tensor result = at::empty_with_format(
209- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
210- 
211- // calculate the output result of the NPU
212 clamp_out_npu_nocheck(result, self, min, max);172 clamp_out_npu_nocheck(result, self, min, max);
213- 
214 return result;173 return result;
215}174}
216 175 
217Tensor& clamp_npu_(Tensor& self, optional<Scalar> min, optional<Scalar> max) {176Tensor& clamp_npu_(Tensor& self, optional<Scalar> min, optional<Scalar> max) {
218 clamp_out_npu(self, self, min, max);177 clamp_out_npu(self, self, min, max);
219- 
220 return self;178 return self;
221}179}
222 180 
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -36,8 +35,7 @@ Tensor confusion_transpose_npu(
36 }35 }
37 36 
38 // construct the output tensor of the NPU37 // construct the output tensor of the NPU
39- Tensor result = at::empty_with_format(output_size, self.options(), CalcuOpUtil::get_tensor_npu_format(self));38+ Tensor result = OpPreparation::ApplyTensor(self, output_size);
40- 
41 OpCommand cmd;39 OpCommand cmd;
42 cmd.Name("ConfusionTransposeD")40 cmd.Name("ConfusionTransposeD")
43 .Input(self)41 .Input(self)
@@ -12,72 +12,12 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/CalcuOpUtil.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
17-#include "ATen/native/npu/utils/NpuUtils.h"
18 16 
19namespace at {17namespace at {
20namespace native {18namespace native {
21using namespace at::native::npu;19using namespace at::native::npu;
22 20 
23-SmallVector<NPUTensorDesc, N> conv_tbc_npu_input(
24- const SmallVector<Tensor, N>& inputTensor) {
25- SmallVector<Tensor, N> inputTensors;
26- for (int i = 0; i < inputTensor.size(); i++) {
27- if (inputTensor[i].defined()) {
28- inputTensors.emplace_back(inputTensor[i]);
29- }
30- }
31- 
32- return CalcuOpUtil::create_npu_input_tensor_desc(inputTensors);
33-}
34- 
35-SmallVector<NPUTensorDesc, N> conv_tbc_npu_output(
36- const SmallVector<Tensor, N>& outputTensor) {
37- return CalcuOpUtil::create_npu_output_tensor_desc(outputTensor);
38-}
39- 
40-SmallVector<NPUAttrDesc, N> conv_tbc_npu_attr(int64_t pad) {
41- SmallVector<int64_t, N> paddings = {0, 0, pad, pad};
42- SmallVector<int64_t, N> stridesSize = {1, 1, 1, 1};
43- SmallVector<int64_t, N> dilations = {1, 1, 1, 1};
44- 
45- string dataFormat = "NCHW";
46- 
47- NPUAttrDesc npuAttrPads = NPUAttrDesc("pads", paddings);
48- NPUAttrDesc npuAttrStrides = NPUAttrDesc("strides", stridesSize);
49- NPUAttrDesc npuAttrDilations = NPUAttrDesc("dilations", dilations);
50- NPUAttrDesc npuAttrDataFormat = NPUAttrDesc("data_format", dataFormat);
51- 
52- SmallVector<NPUAttrDesc, N> attrs = {
53- npuAttrPads, npuAttrStrides, npuAttrDilations, npuAttrDataFormat};
54- 
55- return attrs;
56-}
57- 
58-Tensor& conv_tbc_out_npu(
59- Tensor& result,
60- const Tensor& self,
61- const Tensor& weight,
62- const Tensor& bias,
63- int64_t pad) {
64- // constructs the input and output NPUTensorDesc
65- 
66- auto inputs = conv_tbc_npu_input(
67- {self.transpose(0, 2).transpose(0, 1).unsqueeze(2),
68- weight.transpose(0, 2).unsqueeze(2),
69- bias});
70- 
71- auto outputs = conv_tbc_npu_output({result});
72- 
73- // constructs the attr of the NPUAttrDesc
74- auto attrs = conv_tbc_npu_attr(pad);
75- // executing the NPU operator
76- CalcuOpUtil::execute_npu_operate("Conv2D", inputs, outputs, attrs);
77- 
78- return result;
79-}
80- 
81Tensor conv_tbc_npu(21Tensor conv_tbc_npu(
82 const Tensor& self,22 const Tensor& self,
83 const Tensor& weight,23 const Tensor& weight,
@@ -101,14 +41,32 @@ Tensor conv_tbc_npu(
101 "the weight tensor (output channels).");41 "the weight tensor (output channels).");
102 42 
103 // calculate the output size43 // calculate the output size
104- auto outputSize = conv_tbc_npu_output_size(self, weight, bias, pad);44+ int64_t Co = weight.size(2);
45+ int64_t Wo = (self.size(0) + 2 * pad - (weight.size(0) - 1) - 1) + 1;
46+ 
47+ SmallVector<int64_t, SIZE> outputSize = {self.size(1), Co, 1, Wo};
105 48 
106 // construct the output tensor of the NPU49 // construct the output tensor of the NPU
107- Tensor result =50+ Tensor result = OpPreparation::ApplyTensorWithFormat(self, outputSize, ACL_FORMAT_NCHW);
108- at::empty_with_format(outputSize, self.options(), ACL_FORMAT_NCHW);
109 51 
110- // calculate the output result of the NPU52+ SmallVector<int64_t, N> paddings = {0, 0, pad, pad};
111- conv_tbc_out_npu(result, self, weight, bias, pad);53+ SmallVector<int64_t, N> stridesSize = {1, 1, 1, 1};
54+ SmallVector<int64_t, N> dilations = {1, 1, 1, 1};
55+ 
56+ Tensor self_tensor = self.transpose(0, 2).transpose(0, 1).unsqueeze(2);
57+ Tensor weight_tensor = weight.transpose(0, 2).unsqueeze(2);
58+ 
59+ OpCommand cmd;
60+ cmd.Name("Conv2D")
61+ .Input(self_tensor)
62+ .Input(weight_tensor)
63+ .Input(bias)
64+ .Output(result)
65+ .Attr("pads", paddings)
66+ .Attr("strides", stridesSize)
67+ .Attr("dilations", dilations)
68+ .Attr("data_format", (string)"NCHW")
69+ .Run();
112 70 
113 result = result.squeeze(2).transpose(0, 2).transpose(1, 2);71 result = result.squeeze(2).transpose(0, 2).transpose(1, 2);
114 return result;72 return result;
@@ -12,8 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"
17 16 
18namespace at {17namespace at {
19namespace native {18namespace native {
@@ -32,26 +31,13 @@ Tensor& cos_out_npu(
32}31}
33 32 
34Tensor cos_npu(const Tensor& self) {33Tensor cos_npu(const Tensor& self) {
35- // calculate the output size34+ Tensor result = OpPreparation::ApplyTensor(self);
36- auto outputSize = input_same_output_size(self);
37- 
38- // construct the output tensor of the NPU
39- Tensor result = at::empty_with_format(
40- outputSize,
41- self.options(),
42- CalcuOpUtil::get_tensor_npu_format(self));
43- 
44- // calculate the output result of the NPU
45 cos_out_npu(result, self);35 cos_out_npu(result, self);
46- 
47 return result;36 return result;
48}37}
49 38 
50Tensor& cos_npu_(Tensor& self) {39Tensor& cos_npu_(Tensor& self) {
51- SmallVector<Tensor, N> inputs = {self};40+ OpPreparation::CheckMemory({self}, {self});
52- SmallVector<Tensor, N> outputs = {self};
53- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
54- 
55 if (!NpuUtils::check_match(&self)) {41 if (!NpuUtils::check_match(&self)) {
56 Tensor contiguousSelf = NpuUtils::format_contiguous(self);42 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
57 Tensor result = cos_out_npu(contiguousSelf, contiguousSelf);43 Tensor result = cos_out_npu(contiguousSelf, contiguousSelf);
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -32,9 +31,7 @@ Tensor& cosh_out_npu(Tensor& result, const Tensor& self) {
32}31}
33 32 
34Tensor& cosh_npu_(Tensor& self) {33Tensor& cosh_npu_(Tensor& self) {
35- SmallVector<Tensor, N> inputs = {self};34+ OpPreparation::CheckMemory({self}, {self});
36- SmallVector<Tensor, N> outputs = {self};
37- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
38 35 
39 if (!NpuUtils::check_match(&self)) {36 if (!NpuUtils::check_match(&self)) {
40 Tensor contiguousSelf = NpuUtils::format_contiguous(self);37 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
@@ -48,13 +45,7 @@ Tensor& cosh_npu_(Tensor& self) {
48}45}
49 46 
50Tensor cosh_npu(const Tensor& self) {47Tensor cosh_npu(const Tensor& self) {
51- // calculate the output size48+ Tensor result = OpPreparation::ApplyTensor(self);
52- auto outputSize = input_same_output_size(self);
53- 
54- // construct the output tensor of the NPU
55- Tensor result = at::empty_with_format(
56- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
57- 
58 // calculate the output result of the NPU49 // calculate the output result of the NPU
59 cosh_out_npu(result, self);50 cosh_out_npu(result, self);
60 return result;51 return result;
@@ -12,8 +12,8 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"16+#include "ATen/native/npu/utils/CalcuOpUtil.h"
17 17 
18namespace at {18namespace at {
19namespace native {19namespace native {
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -50,30 +49,29 @@ Tensor ctc_loss_backward_npu(
50 if (logAlpha.scalar_type() == ScalarType::Half) {49 if (logAlpha.scalar_type() == ScalarType::Half) {
51 logAlphaNeed = logAlphaNeed.to(ScalarType::Float);50 logAlphaNeed = logAlphaNeed.to(ScalarType::Float);
52 }51 }
52+
53+ Tensor targetsCast = targets;
54+ if(targets.scalar_type() == ScalarType::Long){
55+ targetsCast = targetsCast.to(ScalarType::Int);
56+ }
57+
58+ auto inputLengthsTensor = at::tensor(inputLengths, targetsCast.options().dtype(at::kInt));
59+ auto targetLengthsTensor = at::tensor(targetLengths, targetsCast.options().dtype(at::kInt));
53 60 
54- // IntArrayRef to Tensor61+ auto outputSize = {logProbs.size(1), logProbs.size(0), logProbs.size(2)};
55- auto inputLengthsTensor = at::tensor(inputLengths, targets.options().dtype(at::kLong));
56- auto targetLengthsTensor = at::tensor(targetLengths, targets.options().dtype(at::kLong));
57- 
58- // calculate the output size
59- auto outputSize = input_same_output_size(logProbs);
60 62 
61 // construct the output tensor of the NPU63 // construct the output tensor of the NPU
62- Tensor grad = at::empty_with_format(64+ Tensor grad = OpPreparation::ApplyTensor(logProbsNeed, outputSize);
63- outputSize,
64- logProbsNeed.options(),
65- CalcuOpUtil::get_tensor_npu_format(logProbsNeed));
66- 
67 // calculate the output result of the NPU65 // calculate the output result of the NPU
68 OpCommand cmd;66 OpCommand cmd;
69 cmd.Name("CTCLossV2Grad")67 cmd.Name("CTCLossV2Grad")
70 .Input(gradOutNeed)68 .Input(gradOutNeed)
71 .Input(logProbsNeed)69 .Input(logProbsNeed)
72- .Input(targets)70+ .Input(targetsCast)
73- .Input(negLogLikelihoodNeed)
74- .Input(logAlphaNeed)
75 .Input(inputLengthsTensor)71 .Input(inputLengthsTensor)
76- .Input(targetLengthsTensor)72+ .Input(targetLengthsTensor)
73+ .Input(negLogLikelihoodNeed)
74+ .Input(logAlphaNeed)
77 .Output(grad)75 .Output(grad)
78 .Attr("blank", blank)76 .Attr("blank", blank)
79 .Attr("zero_infinity", zeroInfinity)77 .Attr("zero_infinity", zeroInfinity)
@@ -82,8 +80,9 @@ Tensor ctc_loss_backward_npu(
82 if (gradOut.scalar_type() == ScalarType::Half) {80 if (gradOut.scalar_type() == ScalarType::Half) {
83 grad = grad.to(ScalarType::Half);81 grad = grad.to(ScalarType::Half);
84 }82 }
85- 83+
86- return grad;84+ //return grad;
85+ return grad.permute({1,0,2});
87}86}
88} // namespace native87} // namespace native
89} // namespace at88} // namespace at
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
@@ -33,12 +33,18 @@ std::tuple<Tensor, Tensor> ctc_loss_npu(
33 logProbsNeed = logProbsNeed.to(ScalarType::Float);33 logProbsNeed = logProbsNeed.to(ScalarType::Float);
34 }34 }
35 35
36+ //Aicore supports only the int type
37+ Tensor targetsCast = targets;
38+ if(targets.scalar_type() == ScalarType::Long){
39+ targetsCast = targetsCast.to(ScalarType::Int);
40+ }
41+
36 // IntArrayRef to Tensor42 // IntArrayRef to Tensor
37- auto inputLengthsTensor = at::tensor(inputLengths, targets.options().dtype(at::kLong));43+ auto inputLengthsTensor = at::tensor(inputLengths, targetsCast.options());
38- auto targetLengthsTensor = at::tensor(targetLengths, targets.options().dtype(at::kLong));44+ auto targetLengthsTensor = at::tensor(targetLengths, targetsCast.options());
39 45
40 // calculate the output size46 // calculate the output size
41- auto outputSizes = ctc_loss_npu_output_size(logProbs, targets, targetLengths);47+ auto outputSizes = ctc_loss_npu_output_size(logProbs, targetsCast, targetLengths);
42 48 
43 // construct the output tensor of the NPU49 // construct the output tensor of the NPU
44 Tensor negLogLikelihood = at::empty_with_format(50 Tensor negLogLikelihood = at::empty_with_format(
@@ -55,7 +61,7 @@ std::tuple<Tensor, Tensor> ctc_loss_npu(
55 OpCommand cmd;61 OpCommand cmd;
56 cmd.Name("CTCLossV2")62 cmd.Name("CTCLossV2")
57 .Input(logProbsNeed)63 .Input(logProbsNeed)
58- .Input(targets)64+ .Input(targetsCast)
59 .Input(inputLengthsTensor)65 .Input(inputLengthsTensor)
60 .Input(targetLengthsTensor)66 .Input(targetLengthsTensor)
61 .Output(negLogLikelihood)67 .Output(negLogLikelihood)
@@ -13,6 +13,7 @@
13// limitations under the License.13// limitations under the License.
14 14 
15#include "ATen/native/npu/utils/OpAdapter.h"15#include "ATen/native/npu/utils/OpAdapter.h"
16+#include<ATen/NamedTensorUtils.h>
16 17 
17namespace at {18namespace at {
18namespace native {19namespace native {
@@ -73,8 +73,7 @@ Tensor& diag_out_npu(Tensor& result, const Tensor& self, int64_t diagonal) {
73 OpPreparation::CheckOut(73 OpPreparation::CheckOut(
74 {self},74 {self},
75 result,75 result,
76- CalcuOpUtil::get_tensor_npu_format(self),76+ self,
77- self.scalar_type(),
78 outputSize);77 outputSize);
79 78 
80 OpPipeWithDefinedOut pipe;79 OpPipeWithDefinedOut pipe;
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
@@ -12,10 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/CalcuOpUtil.h" 15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
17-#include "ATen/native/npu/utils/NpuUtils.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 16 
20namespace at {17namespace at {
21namespace native {18namespace native {
@@ -34,9 +31,8 @@ Tensor& dot_out_npu(Tensor& result, const Tensor& self, const Tensor& tensor) {
34 return result;31 return result;
35}32}
36Tensor dot_npu(const Tensor& self, const Tensor& tensor) {33Tensor dot_npu(const Tensor& self, const Tensor& tensor) {
37- // calculate the output size
38 SmallVector<int64_t, SIZE> outputSize = dot_npu_output_size(self, tensor);34 SmallVector<int64_t, SIZE> outputSize = dot_npu_output_size(self, tensor);
39- Tensor result = at::empty_with_format(outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));35+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
40 dot_out_npu(result, self, tensor);36 dot_out_npu(result, self, tensor);
41 return result;37 return result;
42}38}
@@ -13,9 +13,8 @@
13// See the License for the specific language governing permissions and13// See the License for the specific language governing permissions and
14// limitations under the License.14// limitations under the License.
15 15 
16+#include "ATen/native/npu/utils/OpAdapter.h"
16#include "ATen/native/npu/utils/CalcuOpUtil.h"17#include "ATen/native/npu/utils/CalcuOpUtil.h"
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -31,12 +30,8 @@ Tensor dropout_backward_npu(
31 TORCH_CHECK(30 TORCH_CHECK(
32 mask.scalar_type() == at::ScalarType::Byte,31 mask.scalar_type() == at::ScalarType::Byte,
33 "mask should be torch.uint8 dtype");32 "mask should be torch.uint8 dtype");
34- auto outputSize = input_same_output_size(grad_output);
35 double retain = 1. - scale;33 double retain = 1. - scale;
36- Tensor result = at::empty_with_format(34+ Tensor result = OpPreparation::ApplyTensor(grad_output);
37- outputSize,
38- grad_output.options(),
39- CalcuOpUtil::get_tensor_npu_format(grad_output));
40 Tensor prob =35 Tensor prob =
41 CalcuOpUtil::CopyScalarToDevice(retain, grad_output.scalar_type());36 CalcuOpUtil::CopyScalarToDevice(retain, grad_output.scalar_type());
42 37 
@@ -13,8 +13,7 @@
13// See the License for the specific language governing permissions and13// See the License for the specific language governing permissions and
14// limitations under the License.14// limitations under the License.
15 15 
16-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"16+#include "ATen/native/npu/utils/OpAdapter.h"
17-#include "ATen/native/npu/utils/OpTemplate.h"
18 17 
19namespace at {18namespace at {
20namespace native {19namespace native {
@@ -53,9 +52,7 @@ Tensor dropout_v2_backward_npu(const Tensor& grad_output, const Tensor& mask, do
53 if (maskCopy.scalar_type() == ScalarType::Byte){52 if (maskCopy.scalar_type() == ScalarType::Byte){
54 maskCopy = maskCopy.to(ScalarType::Half);53 maskCopy = maskCopy.to(ScalarType::Half);
55 }54 }
56- auto outputSize = input_same_output_size(grad_output);55+ auto result = OpPreparation::ApplyTensor(grad_output);
57- auto result = at::empty_with_format(
58- outputSize, grad_output.options(), CalcuOpUtil::get_tensor_npu_format(grad_output));
59 dropout_v2_backward_out_npu(result, grad_output, maskCopy, p);56 dropout_v2_backward_out_npu(result, grad_output, maskCopy, p);
60 57 
61 return result;58 return result;
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -46,11 +45,8 @@ tuple <Tensor, Tensor, Tensor> dropout_v2_npu(const Tensor& self, Tensor& seed,
46 Tensor formatCastOfSelf = OpPreparation::CastBackToOriFormat(self);45 Tensor formatCastOfSelf = OpPreparation::CastBackToOriFormat(self);
47 Tensor formatCastOfSeed = OpPreparation::CastBackToOriFormat(seed);46 Tensor formatCastOfSeed = OpPreparation::CastBackToOriFormat(seed);
48 47
49- Tensor result = at::empty_with_format(48+ Tensor result = OpPreparation::ApplyTensor(formatCastOfSelf);
50- formatCastOfSelf.sizes(), formatCastOfSelf.options(), CalcuOpUtil::get_tensor_npu_format(formatCastOfSelf));49+ Tensor mask = OpPreparation::ApplyTensor(formatCastOfSelf, formatCastOfSeed.options());
51- Tensor mask = at::empty_with_format(
52- formatCastOfSelf.sizes(), formatCastOfSeed.options(), CalcuOpUtil::get_tensor_npu_format(formatCastOfSelf));
53- 
54 dropout_v2_out_npu(result, mask, formatCastOfSeed, formatCastOfSelf, formatCastOfSeed, p);50 dropout_v2_out_npu(result, mask, formatCastOfSeed, formatCastOfSelf, formatCastOfSeed, p);
55 NpuUtils::format_fresh_view(seed, formatCastOfSeed);51 NpuUtils::format_fresh_view(seed, formatCastOfSeed);
56 return std::tuple<Tensor, Tensor, Tensor>(result, mask, seed);52 return std::tuple<Tensor, Tensor, Tensor>(result, mask, seed);
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18#include "c10/npu/OptionsManager.h"19#include "c10/npu/OptionsManager.h"
19 20 
20namespace at {21namespace at {
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
@@ -34,9 +34,7 @@ Tensor& exp_out_npu(Tensor& result, const Tensor& self) {
34 OpPreparation::CheckOut(34 OpPreparation::CheckOut(
35 {self},35 {self},
36 result,36 result,
37- CalcuOpUtil::get_tensor_npu_format(self),37+ self);
38- self.scalar_type(),
39- self.sizes());
40 38 
41 OpPipeWithDefinedOut pipe;39 OpPipeWithDefinedOut pipe;
42 return pipe.CheckMemory({self}, {result})40 return pipe.CheckMemory({self}, {result})
@@ -51,11 +49,7 @@ Tensor& exp_npu_(Tensor& self) {
51}49}
52 50 
53Tensor exp_npu(const Tensor& self) {51Tensor exp_npu(const Tensor& self) {
54- // construct the output tensor of the NPU52+ Tensor result = OpPreparation::ApplyTensor(self);
55- Tensor result = at::empty_with_format(
56- self.sizes(), self.options(), CalcuOpUtil::get_tensor_npu_format(self));
57- 
58- // calculate the output result of the NPU
59 exp_out_npu_nocheck(result, self);53 exp_out_npu_nocheck(result, self);
60 return result;54 return result;
61}55}
@@ -44,12 +44,11 @@ Tensor& fill_out_npu(Tensor& result, Tensor& self, const Tensor& other) {
44Tensor& fills_out_npu(Tensor& result, Tensor& self, Scalar value) {44Tensor& fills_out_npu(Tensor& result, Tensor& self, Scalar value) {
45 AT_DISPATCH_ALL_TYPES_AND3(kHalf, kBool, kBFloat16, self.scalar_type(), "fills_out_npu", [&]() {45 AT_DISPATCH_ALL_TYPES_AND3(kHalf, kBool, kBFloat16, self.scalar_type(), "fills_out_npu", [&]() {
46 auto value_converted = value.to<scalar_t>();}); 46 auto value_converted = value.to<scalar_t>();});
47- float scalar = CalcuOpUtil::get_scalar_float_value(value);
48 OpCommand cmd;47 OpCommand cmd;
49 cmd.Name("Fills")48 cmd.Name("Fills")
50 .Input(self)49 .Input(self)
51 .Output(result)50 .Output(result)
52- .Attr("value", scalar)51+ .Attr("value", value)
53 .Run();52 .Run();
54 53 
55 return result;54 return result;
@@ -12,7 +12,6 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
16#include "c10/npu/OptionsManager.h"15#include "c10/npu/OptionsManager.h"
17#include "ATen/native/npu/utils/OpAdapter.h"16#include "ATen/native/npu/utils/OpAdapter.h"
18 17 
@@ -21,12 +20,7 @@ namespace native {
21using namespace at::native::npu;20using namespace at::native::npu;
22 21 
23Tensor flip_npu(const Tensor& self, IntArrayRef dims){22Tensor flip_npu(const Tensor& self, IntArrayRef dims){
24- // calculate the output size23+ Tensor result = OpPreparation::ApplyTensor(self);
25- auto outputSize = input_same_output_size(self);
26-
27- // construct the output tensor of the NPU
28- Tensor result = at::empty_with_format(outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
29- 
30 SmallVector<int64_t,N> dimVec = array_to_small_vector(dims);24 SmallVector<int64_t,N> dimVec = array_to_small_vector(dims);
31 if (!c10::npu::OptionsManager::CheckDynamicEnable()) { 25 if (!c10::npu::OptionsManager::CheckDynamicEnable()) {
32 OpCommand cmd;26 OpCommand cmd;
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
@@ -34,9 +34,7 @@ Tensor& floor_out_npu(Tensor& result, const Tensor& self) {
34 OpPreparation::CheckOut(34 OpPreparation::CheckOut(
35 {self},35 {self},
36 result,36 result,
37- CalcuOpUtil::get_tensor_npu_format(self),37+ self);
38- self.scalar_type(),
39- self.sizes());
40 38 
41 OpPipeWithDefinedOut pipe;39 OpPipeWithDefinedOut pipe;
42 return pipe.CheckMemory({self}, {result})40 return pipe.CheckMemory({self}, {result})
@@ -51,11 +49,7 @@ Tensor& floor_npu_(Tensor& self) {
51}49}
52 50 
53Tensor floor_npu(const Tensor& self) {51Tensor floor_npu(const Tensor& self) {
54- // construct the output tensor of the NPU52+ Tensor result = OpPreparation::ApplyTensor(self);
55- Tensor result = at::empty_with_format(
56- self.sizes(), self.options(), CalcuOpUtil::get_tensor_npu_format(self));
57- 
58- // calculate the output result of the NPU
59 floor_out_npu_nocheck(result, self);53 floor_out_npu_nocheck(result, self);
60 return result;54 return result;
61}55}
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -49,9 +48,8 @@ Tensor& fmod_out_npu(Tensor& result, const Tensor& self, const Tensor& other) {
49 auto outputSize = broadcast_ops_npu_output_size(self, other);48 auto outputSize = broadcast_ops_npu_output_size(self, other);
50 OpPreparation::CheckOut(49 OpPreparation::CheckOut(
51 {self, other}, 50 {self, other},
52- result, 51+ result,
53- CalcuOpUtil::get_tensor_npu_format(self), 52+ self,
54- self.scalar_type(),
55 outputSize);53 outputSize);
56 54
57 fmod_out_npu_nocheck(result, self, other);55 fmod_out_npu_nocheck(result, self, other);
@@ -65,10 +63,7 @@ Tensor& fmod_out_npu(Tensor& result, const Tensor& self, Scalar other) {
65}63}
66 64 
67Tensor& fmod_npu_(Tensor& self, Scalar other) {65Tensor& fmod_npu_(Tensor& self, Scalar other) {
68- SmallVector<Tensor, N> inputs = {self};66+ OpPreparation::CheckMemory({self}, {self});
69- SmallVector<Tensor, N> outputs = {self};
70- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
71- 
72 if (!NpuUtils::check_match(&self)) {67 if (!NpuUtils::check_match(&self)) {
73 Tensor contiguousSelf = NpuUtils::format_contiguous(self);68 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
74 Tensor result = fmod_out_npu_nocheck(contiguousSelf, contiguousSelf, other);69 Tensor result = fmod_out_npu_nocheck(contiguousSelf, contiguousSelf, other);
@@ -81,10 +76,7 @@ Tensor& fmod_npu_(Tensor& self, Scalar other) {
81}76}
82 77 
83Tensor& fmod_npu_(Tensor& self, const Tensor& other) {78Tensor& fmod_npu_(Tensor& self, const Tensor& other) {
84- SmallVector<Tensor, N> inputs = {self, other};79+ OpPreparation::CheckMemory({self, other}, {self});
85- SmallVector<Tensor, N> outputs = {self};
86- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
87- 
88 if (!NpuUtils::check_match(&self)) {80 if (!NpuUtils::check_match(&self)) {
89 Tensor contiguousSelf = NpuUtils::format_contiguous(self);81 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
90 Tensor result = fmod_out_npu_nocheck(contiguousSelf, contiguousSelf, other);82 Tensor result = fmod_out_npu_nocheck(contiguousSelf, contiguousSelf, other);
@@ -97,26 +89,14 @@ Tensor& fmod_npu_(Tensor& self, const Tensor& other) {
97}89}
98 90 
99Tensor fmod_npu(const Tensor& self, Scalar other) {91Tensor fmod_npu(const Tensor& self, Scalar other) {
100- // calculate the output size92+ Tensor result = OpPreparation::ApplyTensor(self);
101- auto outputSize = input_same_output_size(self);
102- // construct the output tensor of the NPU
103- Tensor result = at::empty_with_format(
104- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
105- 
106- // calculate the output result of the NPU
107 fmod_out_npu_nocheck(result, self, other);93 fmod_out_npu_nocheck(result, self, other);
108 return result;94 return result;
109}95}
110 96 
111Tensor fmod_npu(const Tensor& self, const Tensor& other) {97Tensor fmod_npu(const Tensor& self, const Tensor& other) {
112- // calculate the output size
113 auto outputSize = broadcast_ops_npu_output_size(self, other);98 auto outputSize = broadcast_ops_npu_output_size(self, other);
114- 99+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
115- // construct the output tensor of the NPU
116- Tensor result = at::empty_with_format(
117- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
118- 
119- // calculate the output result of the NPU
120 fmod_out_npu_nocheck(result, self, other);100 fmod_out_npu_nocheck(result, self, other);
121 return result;101 return result;
122}102}
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -11,18 +11,16 @@
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"14+ 
15-#include "ATen/native/npu/utils/OpTemplate.h"15+ 
16+#include "ATen/native/npu/utils/OpAdapter.h"
16 17 
17namespace at {18namespace at {
18namespace native {19namespace native {
19using namespace at::native::npu;20using namespace at::native::npu;
20 21 
21Tensor gelu_npu(const Tensor& self) {22Tensor gelu_npu(const Tensor& self) {
22- // calculate the output size23+ Tensor result = OpPreparation::ApplyTensor(self);
23- auto outputSize = input_same_output_size(self);
24- // construct the output tensor of the NPU
25- Tensor result = at::empty_with_format(outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
26 // calculate the output result of the NPU24 // calculate the output result of the NPU
27 OpCommand cmd;25 OpCommand cmd;
28 cmd.Name("Gelu")26 cmd.Name("Gelu")
@@ -54,8 +54,7 @@ Tensor& ger_out_npu(Tensor& result, const Tensor& self , const Tensor& vec2) {
54 OpPreparation::CheckOut(54 OpPreparation::CheckOut(
55 {self},55 {self},
56 result,56 result,
57- CalcuOpUtil::get_tensor_npu_format(self),57+ self,
58- self.scalar_type(),
59 outputSize);58 outputSize);
60 59 
61 OpPipeWithDefinedOut pipe;60 OpPipeWithDefinedOut pipe;
@@ -15,7 +15,6 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include <c10/npu/OptionsManager.h>17#include <c10/npu/OptionsManager.h>
18-#include "ATen/native/npu/utils/CalcuOpUtil.h"
19#include "ATen/native/npu/utils/OpAdapter.h"18#include "ATen/native/npu/utils/OpAdapter.h"
20 19 
21namespace at {20namespace at {
@@ -15,7 +15,6 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include <c10/npu/OptionsManager.h>17#include <c10/npu/OptionsManager.h>
18-#include "ATen/native/npu/utils/CalcuOpUtil.h"
19#include "ATen/native/npu/utils/OpAdapter.h"18#include "ATen/native/npu/utils/OpAdapter.h"
20 19 
21namespace at {20namespace at {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -39,10 +39,7 @@ Tensor hardsigmoid_npu(const Tensor& self) {
39}39}
40 40 
41Tensor& hardsigmoid_npu_(Tensor& self) {41Tensor& hardsigmoid_npu_(Tensor& self) {
42- SmallVector<Tensor, N> inputs = {self};42+ OpPreparation::CheckMemory({self}, {self});
43- SmallVector<Tensor, N> outputs = {self};
44- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
45- 
46 if (!NpuUtils::check_match(&self)) {43 if (!NpuUtils::check_match(&self)) {
47 Tensor contiguousSelf = NpuUtils::format_contiguous(self);44 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
48 Tensor result = hardsigmoid_out_npu(contiguousSelf, contiguousSelf);45 Tensor result = hardsigmoid_out_npu(contiguousSelf, contiguousSelf);
@@ -27,15 +27,13 @@ Tensor& hardtanh_backward_out_npu(
27 const Tensor& self,27 const Tensor& self,
28 Scalar min_val,28 Scalar min_val,
29 Scalar max_val) {29 Scalar max_val) {
30- float max_value = CalcuOpUtil::get_scalar_float_value(max_val);
31- float min_value = CalcuOpUtil::get_scalar_float_value(min_val);
32 OpCommand cmd;30 OpCommand cmd;
33 cmd.Name("HardtanhGrad")31 cmd.Name("HardtanhGrad")
34 .Input(self)32 .Input(self)
35 .Input(grad_output)33 .Input(grad_output)
36 .Output(grad_input)34 .Output(grad_input)
37- .Attr("max_val", max_value)35+ .Attr("max_val", max_val)
38- .Attr("min_val", min_value)36+ .Attr("min_val", min_val)
39 .Run();37 .Run();
40 38 
41 return grad_input;39 return grad_input;
@@ -46,13 +44,7 @@ Tensor hardtanh_backward_npu(
46 const Tensor& self,44 const Tensor& self,
47 Scalar min_val,45 Scalar min_val,
48 Scalar max_val) {46 Scalar max_val) {
49- // calculate the output size47+ Tensor grad_input = OpPreparation::ApplyTensor(self);
50- auto outputSize = input_same_output_size(self);
51- 
52- // construct the output tensor of the NPU
53- Tensor grad_input = at::empty_with_format(
54- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
55- 
56 // calculate the output result of the NPU48 // calculate the output result of the NPU
57 hardtanh_backward_out_npu(grad_input, grad_output, self, min_val, max_val);49 hardtanh_backward_out_npu(grad_input, grad_output, self, min_val, max_val);
58 50 
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -38,24 +37,13 @@ Tensor& hardtanh_out_npu(
38}37}
39 38 
40Tensor hardtanh_npu(const Tensor& self, Scalar min, Scalar max) {39Tensor hardtanh_npu(const Tensor& self, Scalar min, Scalar max) {
41- // calculate the output size40+ Tensor result = OpPreparation::ApplyTensor(self);
42- auto outputSize = input_same_output_size(self);
43- 
44- // construct the output tensor of the NPU
45- Tensor result = at::empty_with_format(
46- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
47- 
48- // calculate the output result of the NPU
49 hardtanh_out_npu(result, self, min, max);41 hardtanh_out_npu(result, self, min, max);
50-
51 return result;42 return result;
52}43}
53 44 
54Tensor& hardtanh_npu_(Tensor& self, Scalar min, Scalar max) {45Tensor& hardtanh_npu_(Tensor& self, Scalar min, Scalar max) {
55- SmallVector<Tensor, N> inputs = {self};46+ OpPreparation::CheckMemory({self}, {self});
56- SmallVector<Tensor, N> outputs = {self};
57- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
58- 
59 if (!NpuUtils::check_match(&self)) {47 if (!NpuUtils::check_match(&self)) {
60 Tensor contiguousSelf = NpuUtils::format_contiguous(self);48 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
61 Tensor result = hardtanh_out_npu(contiguousSelf, contiguousSelf, min, max);49 Tensor result = hardtanh_out_npu(contiguousSelf, contiguousSelf, min, max);
@@ -14,9 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/CalcuOpUtil.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
19-#include "ATen/native/npu/utils/OpTemplate.h"
20 18 
21namespace at {19namespace at {
22namespace native {20namespace native {
@@ -71,8 +71,7 @@ Tensor& im2col_backward_out_npu(
71 OpPreparation::CheckOut(71 OpPreparation::CheckOut(
72 {grad_output},72 {grad_output},
73 grad_input,73 grad_input,
74- CalcuOpUtil::get_tensor_npu_format(grad_output),74+ grad_output,
75- grad_output.scalar_type(),
76 outputSize);75 outputSize);
77 76 
78 OpPipeWithDefinedOut pipe;77 OpPipeWithDefinedOut pipe;
@@ -124,8 +124,7 @@ Tensor& im2col_out_npu(Tensor& result, const Tensor &self, IntArrayRef kernel_si
124 OpPreparation::CheckOut(124 OpPreparation::CheckOut(
125 {self},125 {self},
126 result,126 result,
127- CalcuOpUtil::get_tensor_npu_format(self),127+ self,
128- self.scalar_type(),
129 image_to_col_npu_output_size(self, kernel_size, stride, dilation, padding));128 image_to_col_npu_output_size(self, kernel_size, stride, dilation, padding));
130 129 
131 OpPipeWithDefinedOut pipe;130 OpPipeWithDefinedOut pipe;
@@ -139,10 +138,7 @@ Tensor im2col_npu(const Tensor &self, IntArrayRef kernel_size, IntArrayRef dilat
139 // calculate the output size138 // calculate the output size
140 auto outputSize =139 auto outputSize =
141 image_to_col_npu_output_size(self, kernel_size, stride, dilation, padding);140 image_to_col_npu_output_size(self, kernel_size, stride, dilation, padding);
142- 141+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
143- Tensor result = at::empty_with_format(
144- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
145- 
146 im2col_out_npu(result, self, kernel_size, dilation, padding, stride);142 im2col_out_npu(result, self, kernel_size, dilation, padding, stride);
147 143 
148 return result;144 return result;
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include<ATen/NamedTensorUtils.h>
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -51,10 +52,7 @@ Tensor& index_add_npu_(
51 int64_t dim,52 int64_t dim,
52 const Tensor& index,53 const Tensor& index,
53 const Tensor& source) {54 const Tensor& source) {
54- SmallVector<Tensor, N> inputs = {self, index, source};55+ OpPreparation::CheckMemory({self, index, source}, {self});
55- SmallVector<Tensor, N> outputs = {self};
56- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
57- 
58 if (!NpuUtils::check_match(&self)) {56 if (!NpuUtils::check_match(&self)) {
59 Tensor contiguousSelf = NpuUtils::format_contiguous(self);57 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
60 Tensor result = index_add_out_npu(contiguousSelf, contiguousSelf, dim, index, source);58 Tensor result = index_add_out_npu(contiguousSelf, contiguousSelf, dim, index, source);
@@ -13,6 +13,7 @@
13// limitations under the License.13// limitations under the License.
14 14 
15#include "ATen/native/npu/utils/OpAdapter.h"15#include "ATen/native/npu/utils/OpAdapter.h"
16+#include "ATen/native/npu/utils/CalcuOpUtil.h"
16#include <vector>17#include <vector>
17 18 
18namespace at{19namespace at{
@@ -14,6 +14,7 @@
14// limitations under the License.14// limitations under the License.
15 15 
16#include "ATen/native/npu/utils/OpAdapter.h"16#include "ATen/native/npu/utils/OpAdapter.h"
17+#include "ATen/native/npu/utils/CalcuOpUtil.h"
17 18 
18namespace at {19namespace at {
19namespace native {20namespace native {
@@ -37,10 +38,9 @@ Tensor& index_put_nocheck(
37 }38 }
38 }39 }
39 40 
40- Tensor masksTensor = CalcuOpUtil::copy_tensor_host_to_device(41+ auto masksTensor = CalcuOpUtil::copy_tensor_host_to_device(
41 from_blob(masks.data(), {masks.size()}, dtype(ScalarType::Long)));42 from_blob(masks.data(), {masks.size()}, dtype(ScalarType::Long)));
42 43 
43- 
44 OpCommand cmd;44 OpCommand cmd;
45 cmd.Name("IndexPut")45 cmd.Name("IndexPut")
46 .Input(self)46 .Input(self)
@@ -78,10 +78,7 @@ Tensor& _index_put_impl_npu_(
78 const Tensor& value,78 const Tensor& value,
79 const bool accumulate,79 const bool accumulate,
80 const bool unsafe) {80 const bool unsafe) {
81- SmallVector<Tensor, N> inputs = {self};81+ OpPreparation::CheckMemory({self}, {self});
82- SmallVector<Tensor, N> outputs = {self};
83- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
84- 
85 OpPreparation::CastBackToOriFormat(self);82 OpPreparation::CastBackToOriFormat(self);
86 83 
87 Tensor valueCopy = value;84 Tensor valueCopy = value;
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18#include "c10/npu/OptionsManager.h"19#include "c10/npu/OptionsManager.h"
19 20 
20namespace at {21namespace at {
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -56,9 +55,7 @@ Tensor indexing_npu(
56 outputSize.emplace_back((end[i] + strides[i] - 1 - begin[i]) / strides[i]);55 outputSize.emplace_back((end[i] + strides[i] - 1 - begin[i]) / strides[i]);
57 }56 }
58 // construct the output tensor of the NPU57 // construct the output tensor of the NPU
59- Tensor result = at::empty_with_format(58+ Tensor result = OpPreparation::ApplyTensor(self, outputSize);
60- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
61- 
62 indexing_out_npu(result, self, begin, end, strides);59 indexing_out_npu(result, self, begin, end, strides);
63 60 
64 return result;61 return result;
@@ -1,95 +0,0 @@
1-// Copyright (c) 2020, Huawei Technologies.All rights reserved.
2-//
3-// Licensed under the BSD 3-Clause License (the "License");
4-// you may not use this file except in compliance with the License.
5-// You may obtain a copy of the License at
6-//
7-// https://opensource.org/licenses/BSD-3-Clause
8-//
9-// Unless required by applicable law or agreed to in writing, software
10-// distributed under the License is distributed on an "AS IS" BASIS,
11-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-// See the License for the specific language governing permissions and
13-// limitations under the License.
14- 
15-#include <c10/npu/NPUCachingAllocator.h>
16-#include "ATen/native/npu/utils/CalcuOpUtil.h"
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
18-#include "ATen/native/npu/utils/NpuUtils.h"
19- 
20-namespace at {
21-namespace native {
22-using namespace at::native::npu;
23- 
24-SmallVector<NPUTensorDesc, N> instance_norm_npu_input(const SmallVector<Tensor, N>& inputTensor) {
25- return CalcuOpUtil::create_npu_input_tensor_desc(inputTensor);
26-}
27- 
28-SmallVector<NPUTensorDesc, N> instance_norm_npu_output(const Tensor& result) {
29- return CalcuOpUtil::create_npu_output_tensor_desc({result});
30-}
31- 
32-SmallVector<NPUAttrDesc, N> instance_norm_npu_attr(bool use_input_stats, double momentum, double eps) {
33- NPUAttrDesc npuAttrStats = NPUAttrDesc("use_input_stats", use_input_stats);
34- NPUAttrDesc npuAttrMomentum = NPUAttrDesc("momentum", static_cast<float>(momentum));
35- NPUAttrDesc npuAttrEpsilon = NPUAttrDesc("eps", static_cast<float>(eps));
36- SmallVector<NPUAttrDesc, N> attrs = {npuAttrStats, npuAttrMomentum, npuAttrEpsilon};
37- return attrs;
38-}
39- 
40-Tensor& instance_norm_out_npu(
41- Tensor& result,
42- const Tensor& self,
43- const Tensor& weight,
44- const Tensor& bias,
45- const Tensor& running_mean,
46- const Tensor& running_var,
47- bool use_input_stats,
48- double momentum,
49- double eps) {
50- // constructs the input and output NPUTensorDesc
51- auto inputs = instance_norm_npu_input(
52- {self, weight, bias, running_mean, running_var});
53- auto outputs = instance_norm_npu_output(result);
54- 
55- // constructs the attr of the NPUAttrDesc
56- auto attrs = instance_norm_npu_attr(use_input_stats, momentum, eps);
57- 
58- // executing the NPU operator
59- CalcuOpUtil::execute_npu_operate("InstanceNorm", inputs, outputs, attrs);
60- 
61- return result;
62-}
63- 
64-Tensor instance_norm_npu(
65- const Tensor& self,
66- const Tensor& weight,
67- const Tensor& bias,
68- const Tensor& running_mean,
69- const Tensor& running_var,
70- bool use_input_stats,
71- double momentum,
72- double eps,
73- bool cudnn_enabled) {
74- TORCH_CHECK(use_input_stats || (running_mean.defined() && running_var.defined()),
75- "Expected running_mean and running_var to be defined when use_input_stats is false");
76- Tensor result = at::empty_with_format(self.sizes(), self.options(),
77- CalcuOpUtil::get_tensor_npu_format(self));
78- 
79- // calculate the output result of the NPU
80- instance_norm_out_npu(
81- result,
82- self,
83- weight,
84- bias,
85- running_mean,
86- running_var,
87- use_input_stats,
88- momentum,
89- eps);
90- 
91- return result;
92-}
93- 
94-} // namespace native
95-} // namespace at
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -36,8 +35,7 @@ Tensor& inverse_out_npu(
36}35}
37 36 
38Tensor inverse_npu(const Tensor& self) {37Tensor inverse_npu(const Tensor& self) {
39- Tensor result = at::empty_with_format(38+ Tensor result = OpPreparation::ApplyTensor(self);
40- self.sizes(), self.options(), CalcuOpUtil::get_tensor_npu_format(self));
41 39 
42 inverse_out_npu(result, self);40 inverse_out_npu(result, self);
43 41 
@@ -13,6 +13,7 @@
13// limitations under the License.13// limitations under the License.
14 14 
15#include "ATen/native/npu/utils/OpAdapter.h"15#include "ATen/native/npu/utils/OpAdapter.h"
16+#include "ATen/native/npu/utils/CalcuOpUtil.h"
16 17 
17namespace at {18namespace at {
18namespace native {19namespace native {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -27,13 +26,12 @@ Tensor leaky_relu_backward_out_npu(
27 const Tensor& self,26 const Tensor& self,
28 Scalar negval,27 Scalar negval,
29 bool is_result) {28 bool is_result) {
30- float negvalValue = CalcuOpUtil::get_scalar_float_value(negval);
31 OpCommand cmd;29 OpCommand cmd;
32 cmd.Name("LeakyReluGrad")30 cmd.Name("LeakyReluGrad")
33 .Input(grad_output)31 .Input(grad_output)
34 .Input(self)32 .Input(self)
35 .Output(result)33 .Output(result)
36- .Attr("negative_slope", negvalValue)34+ .Attr("negative_slope", negval)
37 .Run();35 .Run();
38 return result;36 return result;
39}37}
@@ -43,14 +41,7 @@ Tensor leaky_relu_backward_npu(
43 const Tensor& self,41 const Tensor& self,
44 Scalar negval,42 Scalar negval,
45 bool is_result) {43 bool is_result) {
46- // calculate the output size44+ Tensor result = OpPreparation::ApplyTensor(self);
47- auto outputSize = input_same_output_size(self);
48- 
49- // construct the output tensor of the NPU
50- Tensor result = at::empty_with_format(
51- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
52- 
53- // calculate the output result of the NPU
54 leaky_relu_backward_out_npu(result, grad_output, self, negval, is_result);45 leaky_relu_backward_out_npu(result, grad_output, self, negval, is_result);
55 return result;46 return result;
56}47}
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -33,23 +32,14 @@ Tensor& leaky_relu_out_npu(Tensor& result, const Tensor& self, Scalar negval) {
33}32}
34 33 
35Tensor leaky_relu_npu(const Tensor& self, Scalar negval) {34Tensor leaky_relu_npu(const Tensor& self, Scalar negval) {
36- // calculate the output size35+ Tensor result = OpPreparation::ApplyTensor(self);
37- auto outputSize = input_same_output_size(self);
38- 
39- // construct the output tensor of the NPU
40- Tensor result = at::empty_with_format(
41- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
42- 
43 // calculate the output result of the NPU36 // calculate the output result of the NPU
44 leaky_relu_out_npu(result, self, negval);37 leaky_relu_out_npu(result, self, negval);
45 return result;38 return result;
46}39}
47 40 
48Tensor& leaky_relu_npu_(Tensor& self, Scalar neg_val) {41Tensor& leaky_relu_npu_(Tensor& self, Scalar neg_val) {
49- SmallVector<Tensor, N> inputs = {self};42+ OpPreparation::CheckMemory({self}, {self});
50- SmallVector<Tensor, N> outputs = {self};
51- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
52- 
53 if (!NpuUtils::check_match(&self)) {43 if (!NpuUtils::check_match(&self)) {
54 Tensor contiguousSelf = NpuUtils::format_contiguous(self);44 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
55 Tensor result = leaky_relu_out_npu(contiguousSelf, contiguousSelf, neg_val);45 Tensor result = leaky_relu_out_npu(contiguousSelf, contiguousSelf, neg_val);
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -0,0 +1,65 @@
1+// Copyright (c) 2020 Huawei Technologies Co., Ltd
2+// Copyright (c) 2019, Facebook CORPORATION.
3+// All rights reserved.
4+//
5+// Licensed under the BSD 3-Clause License (the "License");
6+// you may not use this file except in compliance with the License.
7+// You may obtain a copy of the License at
8+//
9+// https://opensource.org/licenses/BSD-3-Clause
10+//
11+// Unless required by applicable law or agreed to in writing, software
12+// distributed under the License is distributed on an "AS IS" BASIS,
13+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+// See the License for the specific language governing permissions and
15+// limitations under the License.
16+ 
17+#include "ATen/native/npu/utils/OpAdapter.h"
18+ 
19+namespace at {
20+namespace native {
21+using namespace at::native::npu;
22+ 
23+Tensor& log10_out_npu_nocheck(Tensor& result, const Tensor& self) {
24+ OpCommand cmd;
25+ cmd.Name("Log")
26+ .Input(self)
27+ .Output(result)
28+ .Attr("base", (float)10.0)
29+ .Attr("scale", (float)1.0)
30+ .Attr("shift", (float)0.0)
31+ .Run();
32+ 
33+ return result;
34+}
35+ 
36+Tensor& log10_out_npu(Tensor& result, const Tensor& self) {
37+ OpPreparation::CheckOut(
38+ {self},
39+ result,
40+ self);
41+ 
42+ OpPipeWithDefinedOut pipe;
43+ return pipe.CheckMemory({self}, {result})
44+ .Func([&self](Tensor& result){log10_out_npu_nocheck(result, self);})
45+ .Call(result);
46+}
47+ 
48+Tensor log10_npu(const Tensor& self) {
49+ // construct the output tensor of the NPU
50+ Tensor result = OpPreparation::ApplyTensor(self);
51+ 
52+ // calculate the output result of the NPU
53+ log10_out_npu_nocheck(result, self);
54+ 
55+ return result;
56+}
57+ 
58+Tensor& log10_npu_(Tensor& self) {
59+ log10_out_npu(self, self);
60+ 
61+ return self;
62+}
63+ 
64+} // namespace native
65+} // namespace at
@@ -29,13 +29,7 @@ Tensor& log1p_out_npu(Tensor& result, const Tensor& self){
29}29}
30 30 
31Tensor log1p_npu(const Tensor& self) {31Tensor log1p_npu(const Tensor& self) {
32- //calculate the output size32+ Tensor result = OpPreparation::ApplyTensor(self);
33- auto outputSize = input_same_output_size(self);
34- 
35- //construct the output tensor of the NPU
36- Tensor result = at::empty_with_format(outputSize,
37- self.options(), CalcuOpUtil::get_tensor_npu_format(self));
38- 
39 //calculate the output result of the NPU33 //calculate the output result of the NPU
40 log1p_out_npu(result, self);34 log1p_out_npu(result, self);
41 35 
@@ -43,9 +37,7 @@ Tensor log1p_npu(const Tensor& self) {
43}37}
44 38 
45Tensor& log1p_npu_(Tensor& self) {39Tensor& log1p_npu_(Tensor& self) {
46- SmallVector<Tensor, N> inputs = {self};40+ OpPreparation::CheckMemory({self}, {self});
47- SmallVector<Tensor, N> outputs = {self};
48- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
49 41 
50 if (!NpuUtils::check_match(&self)) {42 if (!NpuUtils::check_match(&self)) {
51 Tensor contiguousSelf = NpuUtils::format_contiguous(self);43 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -35,24 +34,13 @@ Tensor& log2_out_npu(Tensor& result, const Tensor& self) {
35}34}
36 35 
37Tensor log2_npu(const Tensor& self) {36Tensor log2_npu(const Tensor& self) {
38- // calculate the output size37+ Tensor result = OpPreparation::ApplyTensor(self);
39- auto outputSize = input_same_output_size(self);
40- 
41- // construct the output tensor of the NPU
42- Tensor result = at::empty_with_format(
43- outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
44- 
45- // calculate the output result of the NPU
46 log2_out_npu(result, self);38 log2_out_npu(result, self);
47- 
48 return result;39 return result;
49}40}
50 41 
51Tensor& log2_npu_(Tensor& self) {42Tensor& log2_npu_(Tensor& self) {
52- SmallVector<Tensor, N> inputs = {self};43+ OpPreparation::CheckMemory({self}, {self});
53- SmallVector<Tensor, N> outputs = {self};
54- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
55- 
56 if (!NpuUtils::check_match(&self)) {44 if (!NpuUtils::check_match(&self)) {
57 Tensor contiguousSelf = NpuUtils::format_contiguous(self);45 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
58 Tensor result = log2_out_npu(contiguousSelf, contiguousSelf);46 Tensor result = log2_out_npu(contiguousSelf, contiguousSelf);
@@ -21,16 +21,13 @@ namespace native {
21using namespace at::native::npu;21using namespace at::native::npu;
22 22 
23Tensor& log_out_npu_nocheck(Tensor& result, const Tensor& self) {23Tensor& log_out_npu_nocheck(Tensor& result, const Tensor& self) {
24- float baseValue = CalcuOpUtil::get_scalar_float_value(-1);
25- float scaleValue = CalcuOpUtil::get_scalar_float_value(1);
26- float shiftValue = CalcuOpUtil::get_scalar_float_value(0);
27 OpCommand cmd;24 OpCommand cmd;
28 cmd.Name("Log")25 cmd.Name("Log")
29 .Input(self)26 .Input(self)
30 .Output(result)27 .Output(result)
31- .Attr("base", baseValue)28+ .Attr("base", (float)-1)
32- .Attr("scale", scaleValue)29+ .Attr("scale", (float)1)
33- .Attr("shift", shiftValue)30+ .Attr("shift", (float)0)
34 .Run();31 .Run();
35 32 
36 return result;33 return result;
@@ -40,9 +37,7 @@ Tensor& log_out_npu(Tensor& result, const Tensor& self) {
40 OpPreparation::CheckOut(37 OpPreparation::CheckOut(
41 {self},38 {self},
42 result,39 result,
43- CalcuOpUtil::get_tensor_npu_format(self),40+ self);
44- self.scalar_type(),
45- self.sizes());
46 41 
47 OpPipeWithDefinedOut pipe;42 OpPipeWithDefinedOut pipe;
48 return pipe.CheckMemory({self}, {result})43 return pipe.CheckMemory({self}, {result})
@@ -12,8 +12,7 @@
12// See the License for the specific language governing permissions and12// See the License for the specific language governing permissions and
13// limitations under the License.13// limitations under the License.
14 14 
15-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"15+#include "ATen/native/npu/utils/OpAdapter.h"
16-#include "ATen/native/npu/utils/OpTemplate.h"
17 16 
18namespace at {17namespace at {
19namespace native {18namespace native {
@@ -33,11 +32,8 @@ tuple<Tensor&, Tensor&> log_sigmoid_forward_out_npu(
33}32}
34 33 
35tuple<Tensor, Tensor> log_sigmoid_forward_npu(const Tensor& self) {34tuple<Tensor, Tensor> log_sigmoid_forward_npu(const Tensor& self) {
36- // construct the output tensor of the NPU35+ Tensor output = OpPreparation::ApplyTensor(self);
37- Tensor output = at::empty_with_format(
38- self.sizes(), self.options(), CalcuOpUtil::get_tensor_npu_format(self));
39 Tensor buffer = at::empty({0}, self.options());36 Tensor buffer = at::empty({0}, self.options());
40- 
41 // calculate the output result of the NPU37 // calculate the output result of the NPU
42 log_sigmoid_forward_out_npu(output, buffer, self);38 log_sigmoid_forward_out_npu(output, buffer, self);
43 return tuple<Tensor, Tensor>(output, buffer);39 return tuple<Tensor, Tensor>(output, buffer);
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -27,16 +26,8 @@ Tensor _log_softmax_backward_npu(
27 int64_t dim,26 int64_t dim,
28 const Tensor& self) {27 const Tensor& self) {
29 SmallVector<int64_t, N> dimList = {dim};28 SmallVector<int64_t, N> dimList = {dim};
30- // calculate the output size29+ Tensor grad_input = OpPreparation::ApplyTensor(grad_output);
31- auto outputSize = input_same_output_size(grad_output);
32 30 
33- // construct the output tensor of the NPU
34- Tensor grad_input = at::empty_with_format(
35- outputSize,
36- grad_output.options(),
37- CalcuOpUtil::get_tensor_npu_format(grad_output));
38- 
39- // calculate the output result of the NPU
40 OpCommand cmd;31 OpCommand cmd;
41 cmd.Name("LogSoftmaxGrad")32 cmd.Name("LogSoftmaxGrad")
42 .Input(grad_output)33 .Input(grad_output)
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include<ATen/NamedTensorUtils.h>
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -40,8 +40,6 @@ Tensor& logspace_out_npu(
40 inputs = at::arange(0, steps, at::device(at::kNPU).dtype(at::kFloat));40 inputs = at::arange(0, steps, at::device(at::kNPU).dtype(at::kFloat));
41 }41 }
42 42 
43- float startAttr = CalcuOpUtil::get_scalar_float_value(start);
44- float endAttr = CalcuOpUtil::get_scalar_float_value(end);
45 int64_t dtype = 0;43 int64_t dtype = 0;
46 if (result.scalar_type() == at::ScalarType::Half) {44 if (result.scalar_type() == at::ScalarType::Half) {
47 dtype = 0;45 dtype = 0;
@@ -55,8 +53,8 @@ Tensor& logspace_out_npu(
55 cmd.Name("LogSpaceD")53 cmd.Name("LogSpaceD")
56 .Input(inputs)54 .Input(inputs)
57 .Output(result)55 .Output(result)
58- .Attr("start", startAttr)56+ .Attr("start", start)
59- .Attr("end", endAttr)57+ .Attr("end", end)
60 .Attr("steps", steps)58 .Attr("steps", steps)
61 .Attr("base", static_cast<float>(base))59 .Attr("base", static_cast<float>(base))
62 .Attr("dtype", dtype)60 .Attr("dtype", dtype)
@@ -14,8 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"
19 18 
20namespace at {19namespace at {
21namespace native {20namespace native {
@@ -49,15 +48,8 @@ Tensor logical_not_npu(const Tensor& self) {
49}48}
50 49 
51Tensor& logical_not_npu_(Tensor& self) {50Tensor& logical_not_npu_(Tensor& self) {
52- SmallVector<Tensor, N> inputs = {self};51+ OpPreparation::CheckMemory({self}, {self});
53- SmallVector<Tensor, N> outputs = {self};52+ Tensor result = OpPreparation::ApplyTensor(self, self.options().dtype(ScalarType::Byte));
54- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
55- 
56- Tensor result = at::empty_with_format(
57- self.sizes(),
58- self.options().dtype(ScalarType::Byte),
59- CalcuOpUtil::get_tensor_npu_format(self));
60- 
61 if (!NpuUtils::check_match(&self)) {53 if (!NpuUtils::check_match(&self)) {
62 Tensor contiguousSelf = NpuUtils::format_contiguous(self);54 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
63 logical_not_out_npu(result, contiguousSelf);55 logical_not_out_npu(result, contiguousSelf);
@@ -14,8 +14,8 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/KernelNpuOutputSize.h"17+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18-#include "ATen/native/npu/utils/OpTemplate.h"18+#include "ATen/native/npu/utils/OpAdapter.h"
19 19 
20namespace at {20namespace at {
21namespace native {21namespace native {
@@ -15,6 +15,7 @@
15// limitations under the License.15// limitations under the License.
16 16 
17#include "ATen/native/npu/utils/OpAdapter.h"17#include "ATen/native/npu/utils/OpAdapter.h"
18+#include "ATen/native/npu/utils/CalcuOpUtil.h"
18 19 
19namespace at {20namespace at {
20namespace native {21namespace native {
@@ -14,7 +14,7 @@
14// See the License for the specific language governing permissions and14// See the License for the specific language governing permissions and
15// limitations under the License.15// limitations under the License.
16 16 
17-#include "ATen/native/npu/utils/OpTemplate.h"17+#include "ATen/native/npu/utils/OpAdapter.h"
18 18 
19namespace at {19namespace at {
20namespace native {20namespace native {
@@ -80,10 +80,7 @@ Tensor& masked_fill_out_npu(Tensor& result, const Tensor& self, const Tensor& ma
80}80}
81 81 
82Tensor& masked_fill_npu_(Tensor& self, const Tensor& mask, const Tensor& value) {82Tensor& masked_fill_npu_(Tensor& self, const Tensor& mask, const Tensor& value) {
83- SmallVector<Tensor, N> inputs = {self, mask, value};83+ OpPreparation::CheckMemory({self, mask, value}, {self});
84- SmallVector<Tensor, N> outputs = {self};
85- 
86- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
87 if (!NpuUtils::check_match(&self)) {84 if (!NpuUtils::check_match(&self)) {
88 Tensor contiguousSelf = NpuUtils::format_contiguous(self);85 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
89 Tensor result = masked_fill_out_npu(contiguousSelf, contiguousSelf, mask, value);86 Tensor result = masked_fill_out_npu(contiguousSelf, contiguousSelf, mask, value);
@@ -95,10 +92,7 @@ Tensor& masked_fill_npu_(Tensor& self, const Tensor& mask, const Tensor& value)
95}92}
96 93 
97Tensor& masked_fill_npu_(Tensor& self, const Tensor& mask, Scalar value) {94Tensor& masked_fill_npu_(Tensor& self, const Tensor& mask, Scalar value) {
98- SmallVector<Tensor, N> inputs = {self, mask};95+ OpPreparation::CheckMemory({self, mask}, {self});
99- SmallVector<Tensor, N> outputs = {self};
100- 
101- CalcuOpUtil::check_memory_over_laps(inputs, outputs);
102 96 
103 if (!NpuUtils::check_match(&self)) {97 if (!NpuUtils::check_match(&self)) {
104 Tensor contiguousSelf = NpuUtils::format_contiguous(self);98 Tensor contiguousSelf = NpuUtils::format_contiguous(self);
@@ -0,0 +1,74 @@
1+// Copyright (c) 2020 Huawei Technologies Co., Ltd
2+// Copyright (c) 2019, Facebook CORPORATION.
3+// All rights reserved.
4+//
5+// Licensed under the BSD 3-Clause License (the "License");
6+// you may not use this file except in compliance with the License.
7+// You may obtain a copy of the License at
8+//
9+// https://opensource.org/licenses/BSD-3-Clause
10+//
11+// Unless required by applicable law or agreed to in writing, software
12+// distributed under the License is distributed on an "AS IS" BASIS,
13+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+// See the License for the specific language governing permissions and
15+// limitations under the License.
16+ 
17+#include "ATen/native/npu/utils/OpAdapter.h"
18+ 
19+namespace at {
20+namespace native {
21+using namespace at::native::npu;
22+ 
23+void mask_fill_range_check(
24+ const Tensor& self,
25+ const Tensor& start,
26+ const Tensor& end,
27+ const Tensor& value,
28+ int64_t axis){
29+ int64_t x_dim = self.dim();
30+ int64_t min = -x_dim;
31+ int64_t max = x_dim - 1;
32+ TORCH_CHECK(
33+ !(axis < min || axis > max),
34+ "axis overfloaw the range, expected in range [",
35+ -x_dim,
36+ " ",
37+ x_dim - 1,
38+ "] ");
39+ TORCH_CHECK(
40+ start.ndimension() == 2 && start.sizes() == end.sizes(),
41+ "Expected noempty 2D start tensor and start' sizes() should be equal end's sizes() ");
42+ TORCH_CHECK(
43+ start.size(0) == value.size(0),
44+ "Expected value.length equal start loop num ");
45+ TORCH_CHECK(
46+ self.scalar_type() == value.scalar_type(),
47+ "value dtype should be equal self dtype !, but value dtype is ",
48+ value.scalar_type(),
49+ " and self dtype is ",
50+ self.scalar_type());
51+}
52+ 
53+Tensor masked_fill_range_npu(
54+ const Tensor& self,
55+ const Tensor& start,
56+ const Tensor& end,
57+ const Tensor& value,
58+ int64_t axis){
59+ mask_fill_range_check(self, start, end, value, axis);
60+ Tensor result = OpPreparation::ApplyTensor(self);
61+ OpCommand cmd;
62+ cmd.Name("MaskedFillRange")
63+ .Input(self)
64+ .Input(start)
65+ .Input(end)
66+ .Input(value)
67+ .Output(result)
68+ .Attr("axis", axis)
69+ .Run();
70+ return result;
71+}
72+ 
73+}
74+}
Rsrc/aten/src/ATen/native/npu/loss/MultilabelMarginLossNpu.cpp→src/aten/src/ATen/native/npu/loss/MultilabelMarginLossKernelNpu.cpp+14-60
Rsrc/aten/src/ATen/native/GlobalStep.cpp→src/aten/src/ATen/native/npu/utils/NpuProfilingDispatch.cpp+36-40
Rsrc/aten/src/ATen/native/GlobalStep.h→src/aten/src/ATen/native/npu/utils/NpuProfilingDispatch.h+21-21
Rtest/test_npu/test__Ixor__.py→test/test_npu/test_network_ops/test__Ixor__.py+0-0
Rtest/test_npu/test___iand__.py→test/test_npu/test_network_ops/test___iand__.py+0-1
Rtest/test_npu/test__nnpack_spatial_convolution.py→test/test_npu/test_network_ops/test__nnpack_spatial_convolution.py+0-1
Rtest/test_npu/test_acos.py→test/test_npu/test_network_ops/test_acos.py+0-1
Rtest/test_npu/test_adaptive_avg_pool2d_backward.py→test/test_npu/test_network_ops/test_adaptive_avg_pool2d_backward.py+0-0
Rtest/test_npu/test_adaptive_max_pool2d_backward.py→test/test_npu/test_network_ops/test_adaptive_max_pool2d_backward.py+0-0
Rtest/test_npu/test_addbmm.py→test/test_npu/test_network_ops/test_addbmm.py+0-0
Rtest/test_npu/test_addcdiv.py→test/test_npu/test_network_ops/test_addcdiv.py+0-0
Rtest/test_npu/test_addmv.py→test/test_npu/test_network_ops/test_addmv.py+0-0
Rtest/test_npu/test_addr.py→test/test_npu/test_network_ops/test_addr.py+0-0
Rtest/test_npu/test_affine_grid_generator_backward.py→test/test_npu/test_network_ops/test_affine_grid_generator_backward.py+0-0
Rtest/test_npu/test_asin.py→test/test_npu/test_network_ops/test_asin.py+0-1
Rtest/test_npu/test_bartlett_window.py→test/test_npu/test_network_ops/test_bartlett_window.py+0-1
Rtest/test_npu/test_batch_norm.py→test/test_npu/test_network_ops/test_batch_norm.py+0-0
Rtest/test_npu/test_binary_cross_entropy_with_logits.py→test/test_npu/test_network_ops/test_binary_cross_entropy_with_logits.py+0-0
Rtest/test_npu/test_blackman_window.py→test/test_npu/test_network_ops/test_blackman_window.py+0-1
Rtest/test_npu/test_cast_Byte.py→test/test_npu/test_network_ops/test_cast_Byte.py+1-1
Rtest/test_npu/test_cast_Char.py→test/test_npu/test_network_ops/test_cast_Char.py+0-0
Rtest/test_npu/test_cast_Float.py→test/test_npu/test_network_ops/test_cast_Float.py+0-0
Rtest/test_npu/test_cast_Half.py→test/test_npu/test_network_ops/test_cast_Half.py+0-0
Rtest/test_npu/test_cast_Int.py→test/test_npu/test_network_ops/test_cast_Int.py+0-0
Rtest/test_npu/test_cast_Long.py→test/test_npu/test_network_ops/test_cast_Long.py+0-0
Rtest/test_npu/test_cast_Short.py→test/test_npu/test_network_ops/test_cast_Short.py+0-0
Rtest/test_npu/test_cdist.py→test/test_npu/test_network_ops/test_cdist.py+0-1
Rtest/test_npu/test_cdist_backward.py→test/test_npu/test_network_ops/test_cdist_backward.py+0-1
Rtest/test_npu/test_celu.py→test/test_npu/test_network_ops/test_celu.py+78-6
Rtest/test_npu/test_conv_tbc.py→test/test_npu/test_network_ops/test_conv_tbc.py+0-7
Rtest/test_npu/test_conv_transpose2d.py→test/test_npu/test_network_ops/test_conv_transpose2d.py+33-21
Rtest/test_npu/test_convolution_backward_weight.py→test/test_npu/test_network_ops/test_convolution_backward_weight.py+3-4
Rtest/test_npu/test_convolution_transpose_backward_weight.py→test/test_npu/test_network_ops/test_convolution_transpose_backward_weight.py+0-1
Rtest/test_npu/test_copy.py→test/test_npu/test_network_ops/test_copy.py+0-1
Rtest/test_npu/test_cos.py→test/test_npu/test_network_ops/test_cos.py+0-1
Rtest/test_npu/test_cosh.py→test/test_npu/test_network_ops/test_cosh.py+0-1
Rtest/test_npu/test_cosinesimilarity.py→test/test_npu/test_network_ops/test_cosinesimilarity.py+0-0
Rtest/test_npu/test_cross.py→test/test_npu/test_network_ops/test_cross.py+0-0
Rtest/test_npu/test_cudnn_convolution_backward_bias.py→test/test_npu/test_network_ops/test_cudnn_convolution_backward_bias.py+0-1
Rtest/test_npu/test_cudnn_convolution_transpose_backward_bias.py→test/test_npu/test_network_ops/test_cudnn_convolution_transpose_backward_bias.py+0-1
Rtest/test_npu/test_cumprod.py→test/test_npu/test_network_ops/test_cumprod.py+0-0
Rtest/test_npu/test_cumsum.py→test/test_npu/test_network_ops/test_cumsum.py+0-0
Rtest/test_npu/test_dim_arange.py→test/test_npu/test_network_ops/test_dim_arange.py+0-0
Rtest/test_npu/test_diml.py→test/test_npu/test_network_ops/test_diml.py+0-0
Rtest/test_npu/test_dirichlet_grad.py→test/test_npu/test_network_ops/test_dirichlet_grad.py+0-0
Rtest/test_npu/test_dot.py→test/test_npu/test_network_ops/test_dot.py+0-1
Rtest/test_npu/test_elu.py→test/test_npu/test_network_ops/test_elu.py+0-0
Rtest/test_npu/test_embedding.py→test/test_npu/test_network_ops/test_embedding.py+0-0
Rtest/test_npu/test_equal.py→test/test_npu/test_network_ops/test_equal.py+0-0
Rtest/test_npu/test_erf.py→test/test_npu/test_network_ops/test_erf.py+0-1
Rtest/test_npu/test_erfinv.py→test/test_npu/test_network_ops/test_erfinv.py+0-1
Rtest/test_npu/test_expm1.py→test/test_npu/test_network_ops/test_expm1.py+0-1
Rtest/test_npu/test_eye.py→test/test_npu/test_network_ops/test_eye.py+0-1
Rtest/test_npu/test_floordivide.py→test/test_npu/test_network_ops/test_floordivide.py+0-0
Rtest/test_npu/test_frac.py→test/test_npu/test_network_ops/test_frac.py+0-1
Rtest/test_npu/test_frobenius_norm.py→test/test_npu/test_network_ops/test_frobenius_norm.py+0-1
Rtest/test_npu/test_full_like.py→test/test_npu/test_network_ops/test_full_like.py+0-1
Rtest/test_npu/test_gelu.py→test/test_npu/test_network_ops/test_gelu.py+0-0
Rtest/test_npu/test_glu.py→test/test_npu/test_network_ops/test_glu.py+0-1
Rtest/test_npu/test_glugrad.py→test/test_npu/test_network_ops/test_glugrad.py+0-1
Rtest/test_npu/test_grid_sampler_2d.py→test/test_npu/test_network_ops/test_grid_sampler_2d.py+0-1
Rtest/test_npu/test_grid_sampler_2d_backward.py→test/test_npu/test_network_ops/test_grid_sampler_2d_backward.py+0-1
Rtest/test_npu/test_group_norm.py→test/test_npu/test_network_ops/test_group_norm.py+0-1
Rtest/test_npu/test_hamming_window.py→test/test_npu/test_network_ops/test_hamming_window.py+0-1
Rtest/test_npu/test_hammingwindow.py→test/test_npu/test_network_ops/test_hammingwindow.py+0-0
Rtest/test_npu/test_hanning_window.py→test/test_npu/test_network_ops/test_hanning_window.py+0-1
Rtest/test_npu/test_hard_sigmoid_backward.py→test/test_npu/test_network_ops/test_hard_sigmoid_backward.py+0-0
Rtest/test_npu/test_hardshrink.py→test/test_npu/test_network_ops/test_hardshrink.py+0-0
Rtest/test_npu/test_hardshrink_backward.py→test/test_npu/test_network_ops/test_hardshrink_backward.py+0-0
Rtest/test_npu/test_hardsigmoid.py→test/test_npu/test_network_ops/test_hardsigmoid.py+0-0
Rtest/test_npu/test_hinge_embedding_loss.py→test/test_npu/test_network_ops/test_hinge_embedding_loss.py+0-0
Rtest/test_npu/test_im2col.py→test/test_npu/test_network_ops/test_im2col.py+0-0
Rtest/test_npu/test_index_fill_d.py→test/test_npu/test_network_ops/test_index_fill_d.py+0-0
Rtest/test_npu/test_index_select.py→test/test_npu/test_network_ops/test_index_select.py+0-0
Rtest/test_npu/test_isclose.py→test/test_npu/test_network_ops/test_isclose.py+0-0
Rtest/test_npu/test_kthvalue.py→test/test_npu/test_network_ops/test_kthvalue.py+0-1
Rtest/test_npu/test_l1_loss.py→test/test_npu/test_network_ops/test_l1_loss.py+0-0
Rtest/test_npu/test_l1_loss_backward.py→test/test_npu/test_network_ops/test_l1_loss_backward.py+0-0
Rtest/test_npu/test_leaky_relu.py→test/test_npu/test_network_ops/test_leaky_relu.py+0-1
Rtest/test_npu/test_log_sigmoid.py→test/test_npu/test_network_ops/test_log_sigmoid.py+0-1
Rtest/test_npu/test_log_sigmoid_backward.py→test/test_npu/test_network_ops/test_log_sigmoid_backward.py+0-1
Rtest/test_npu/test_logical_not.py→test/test_npu/test_network_ops/test_logical_not.py+0-1
Rtest/test_npu/test_logsigmoid.py→test/test_npu/test_network_ops/test_logsigmoid.py+0-1
Rtest/test_npu/test_logsigmoidforward.py→test/test_npu/test_network_ops/test_logsigmoidforward.py+0-1
Rtest/test_npu/test_logsumexp.py→test/test_npu/test_network_ops/test_logsumexp.py+0-0
Rtest/test_npu/test_max_pool2d_backward.py→test/test_npu/test_network_ops/test_max_pool2d_backward.py+0-0
Rtest/test_npu/test_miopen_batch_norm.py→test/test_npu/test_network_ops/test_miopen_batch_norm.py+0-0
Rtest/test_npu/test_miopen_batch_norm_backward.py→test/test_npu/test_network_ops/test_miopen_batch_norm_backward.py+0-0
Rtest/test_npu/test_miopen_convolution.py→test/test_npu/test_network_ops/test_miopen_convolution.py+0-1
Rtest/test_npu/test_miopen_convolution_backward.py→test/test_npu/test_network_ops/test_miopen_convolution_backward.py+0-1
Rtest/test_npu/test_miopen_convolution_backward_bias.py→test/test_npu/test_network_ops/test_miopen_convolution_backward_bias.py+0-1
Rtest/test_npu/test_miopen_convolution_backward_input.py→test/test_npu/test_network_ops/test_miopen_convolution_backward_input.py+0-1
Rtest/test_npu/test_miopen_convolution_backward_weight.py→test/test_npu/test_network_ops/test_miopen_convolution_backward_weight.py+0-1
Rtest/test_npu/test_mkldnn_adaptive_avg_pool2d.py→test/test_npu/test_network_ops/test_mkldnn_adaptive_avg_pool2d.py+0-1
Rtest/test_npu/test_mkldnn_convolution_backward.py→test/test_npu/test_network_ops/test_mkldnn_convolution_backward.py+0-1
Rtest/test_npu/test_mkldnn_convolution_backward_input.py→test/test_npu/test_network_ops/test_mkldnn_convolution_backward_input.py+0-1
Rtest/test_npu/test_mkldnn_convolution_backward_weights.py→test/test_npu/test_network_ops/test_mkldnn_convolution_backward_weights.py+0-1
Rtest/test_npu/test_multilabel_margin_loss.py→test/test_npu/test_network_ops/test_multilabel_margin_loss.py+0-0
Rtest/test_npu/test_multinomial.py→test/test_npu/test_network_ops/test_multinomial.py+0-0
Rtest/test_npu/test_narrow_copy.py→test/test_npu/test_network_ops/test_narrow_copy.py+0-0
Rtest/test_npu/test_nllloss2d.py→test/test_npu/test_network_ops/test_nllloss2d.py+0-0
Rtest/test_npu/test_norm_except_dim.py→test/test_npu/test_network_ops/test_norm_except_dim.py+1-2
Rtest/test_npu/test_norm_ext.py→test/test_npu/test_network_ops/test_norm_ext.py+3-4
Rtest/test_npu/test_one_hot.py→test/test_npu/test_network_ops/test_one_hot.py+0-1
Rtest/test_npu/test_ones.py→test/test_npu/test_network_ops/test_ones.py+0-0
Rtest/test_npu/test_pdist.py→test/test_npu/test_network_ops/test_pdist.py+0-1
Rtest/test_npu/test_pixel_shuffle.py→test/test_npu/test_network_ops/test_pixel_shuffle.py+0-1
Rtest/test_npu/test_prelu.py→test/test_npu/test_network_ops/test_prelu.py+0-1
Rtest/test_npu/test_prelu_backward.py→test/test_npu/test_network_ops/test_prelu_backward.py+0-1
Rtest/test_npu/test_quantize_per_channel.py→test/test_npu/test_network_ops/test_quantize_per_channel.py+0-0
Rtest/test_npu/test_quantize_per_tensor.py→test/test_npu/test_network_ops/test_quantize_per_tensor.py+0-0
Rtest/test_npu/test_real.py→test/test_npu/test_network_ops/test_real.py+0-0
Rtest/test_npu/test_renorm.py→test/test_npu/test_network_ops/test_renorm.py+0-1
Rtest/test_npu/test_repeat_interleave.py→test/test_npu/test_network_ops/test_repeat_interleave.py+0-0
Rtest/test_npu/test_roll.py→test/test_npu/test_network_ops/test_roll.py+0-0
Rtest/test_npu/test_selu.py→test/test_npu/test_network_ops/test_selu.py+0-0
Rtest/test_npu/test_sinh.py→test/test_npu/test_network_ops/test_sinh.py+0-0
Rtest/test_npu/test_slow_conv_dilated2d.py→test/test_npu/test_network_ops/test_slow_conv_dilated2d.py+0-0
Rtest/test_npu/test_slow_conv_dilated2d_backward.py→test/test_npu/test_network_ops/test_slow_conv_dilated2d_backward.py+0-0
Rtest/test_npu/test_slow_conv_transpose2d.py→test/test_npu/test_network_ops/test_slow_conv_transpose2d.py+0-0
Rtest/test_npu/test_slow_conv_transpose2d_backward.py→test/test_npu/test_network_ops/test_slow_conv_transpose2d_backward.py+0-0
Rtest/test_npu/test_slow_conv_transpose3d.py→test/test_npu/test_network_ops/test_slow_conv_transpose3d.py+0-1
Rtest/test_npu/test_soft_margin_loss.py→test/test_npu/test_network_ops/test_soft_margin_loss.py+3-4
Rtest/test_npu/test_softmax_backward.py→test/test_npu/test_network_ops/test_softmax_backward.py+0-0
Rtest/test_npu/test_softshrink.py→test/test_npu/test_network_ops/test_softshrink.py+0-1
Rtest/test_npu/test_softshrink_backward.py→test/test_npu/test_network_ops/test_softshrink_backward.py+0-1
Rtest/test_npu/test_split_with_sizes.py→test/test_npu/test_network_ops/test_split_with_sizes.py+0-1
Rtest/test_npu/test_square.py→test/test_npu/test_network_ops/test_square.py+0-0
Rtest/test_npu/test_sum_to_size.py→test/test_npu/test_network_ops/test_sum_to_size.py+0-1
Rtest/test_npu/test_take.py→test/test_npu/test_network_ops/test_take.py+0-0
Rtest/test_npu/test_tan.py→test/test_npu/test_network_ops/test_tan.py+0-0
Rtest/test_npu/test_tensor_npu.py→test/test_npu/test_network_ops/test_tensor_npu.py+8-7
Rtest/test_npu/test_thnn_conv_depthwise2d_backward.py→test/test_npu/test_network_ops/test_thnn_conv_depthwise2d_backward.py+0-0
Rtest/test_npu/test_thnn_conv_depthwise2d_forward.py→test/test_npu/test_network_ops/test_thnn_conv_depthwise2d_forward.py+0-0
Rtest/test_npu/test_threshold_grad_v2_d.py→test/test_npu/test_network_ops/test_threshold_grad_v2_d.py+0-1
Rtest/test_npu/test_threshold_v2_d.py→test/test_npu/test_network_ops/test_threshold_v2_d.py+0-0
Rtest/test_npu/test_trapz_dx.py→test/test_npu/test_network_ops/test_trapz_dx.py+1-2
Rtest/test_npu/test_trapz_x.py→test/test_npu/test_network_ops/test_trapz_x.py+0-1
Rtest/test_npu/test_true_divide.py→test/test_npu/test_network_ops/test_true_divide.py+0-1
Rtest/test_npu/test_trunc.py→test/test_npu/test_network_ops/test_trunc.py+0-1
Rtest/test_npu/test_upsample_bilinear2d.py→test/test_npu/test_network_ops/test_upsample_bilinear2d.py+0-1
Rtest/test_npu/test_upsample_linear1d.py→test/test_npu/test_network_ops/test_upsample_linear1d.py+0-1
Rtest/test_npu/test_upsample_nearest2d.py→test/test_npu/test_network_ops/test_upsample_nearest2d.py+0-0
Rtest/test_npu/test_upsample_nearest2d_backward.py→test/test_npu/test_network_ops/test_upsample_nearest2d_backward.py+0-0