1313# New operator library with a custom namespace to allow fusion etc.
1414lib = Library ("cortex_m" , "DEF" )
1515
16+ ###
17+ # add.Tensor
18+ ###
19+
20+ lib .define (
21+ "add.Tensor(Tensor self, Tensor other, ScalarType dtype) -> (Tensor Z)"
22+ )
23+
24+ lib .define (
25+ "add_Tensor.out(Tensor self, Tensor other, ScalarType dtype, Tensor(a!) out) -> Tensor(a!)"
26+ )
27+
28+ @impl (lib , "add.Tensor" , "CompositeExplicitAutograd" )
29+ def aten_add_tensor_impl (
30+ input1 : torch .Tensor ,
31+ input2 : torch .Tensor ,
32+ dtype : torch .dtype ,
33+ out : torch .Tensor ,
34+ ) -> torch .Tensor :
35+ """
36+ The implementation of aten add.Tensor.
37+ """
38+ return exir_ops .edge .cortex_m .add .Tensor (input1 , input2 , dtype )
39+
40+ ###
41+ # add.out
42+ ###
43+
44+ lib .define (
45+ "add(Tensor input1, Tensor input2, ScalarType dtype) -> (Tensor Z)"
46+ )
47+
48+ lib .define (
49+ "add.out(Tensor input1, Tensor input2, ScalarType dtype, Tensor(a!) out) -> Tensor(a!)"
50+ )
51+
52+ @impl (lib , "add.out" , "CompositeExplicitAutograd" )
53+ def add_out_impl (
54+ input1 : torch .Tensor ,
55+ input2 : torch .Tensor ,
56+ dtype : torch .dtype ,
57+ out : torch .Tensor ,
58+ ) -> torch .Tensor :
59+ """
60+ The implementation of cmsis-nn add.out.
61+ """
62+
63+ return exir_ops .edge .cortex_m .add .default (
64+ input1 , input2 , dtype , dtype
65+ )
66+
1667###
1768# dequantize_per_tensor
1869###
2576 "quantize_per_tensor.out(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!)"
2677)
2778
28-
2979@register_fake ("cortex_m::quantize_per_tensor" )
3080def quantize_per_tensor_meta (
3181 input : torch .Tensor ,
@@ -37,7 +87,6 @@ def quantize_per_tensor_meta(
3787) -> torch .Tensor :
3888 return torch .empty_like (input , dtype = dtype )
3989
40-
4190@impl (lib , "quantize_per_tensor" , "CompositeExplicitAutograd" )
4291def quantize_per_tensor_impl (
4392 input : torch .Tensor ,
@@ -96,3 +145,17 @@ def dequantize_per_tensor_impl(
96145 return exir_ops .edge .quantized_decomposed .dequantize_per_tensor .default (
97146 input , scale , zero_point , quant_min , quant_max , dtype
98147 )
148+
149+ lib .define (
150+ "softmax(Tensor self, int dim, bool half_to_float) -> Tensor"
151+ )
152+ lib .define (
153+ "softmax.out(Tensor self, int dim, bool half_to_float, *, Tensor(a!) out) -> Tensor(a!)"
154+ )
155+ @impl (lib , "softmax" , "CompositeExplicitAutograd" )
156+ def softmax_impl (self : torch .Tensor , dim : int , half_to_float : bool ) -> torch .Tensor :
157+ # Call your custom edge op or fallback
158+ return exir_ops .edge .cortex_m ._softmax (self , dim , half_to_float )
159+ @impl (lib , "softmax.out" , "CompositeExplicitAutograd" )
160+ def softmax_out_impl (self : torch .Tensor , dim : int , half_to_float : bool , out : torch .Tensor ) -> torch .Tensor :
161+ return exir_ops .edge .cortex_m ._softmax_out (self , dim , half_to_float , out )
0 commit comments