
    PhƠ              	       "   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
mc mZ d dlmc mZ d dlmc mZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZ d dl m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/ d d	l0m1Z1m2Z2m3Z3 d
e%de4de4dee5   fdZ6d
e%deee5   ee5   f   fdZ7d
e%dee5   fdZ8d
e%dee5   fdZ9d
e%dee5   fdZ:d
e%dee5   fdZ;d
e%dee5   fdZ< ed       G d d             Z= ed       G d de=             Z>y)    N)	dataclass)ListLiteralOptionalTupleUnion)	translate)	BaseCTypeBindingConstRefCTypeCppSignatureCppSignatureGroupDispatcherSignatureExprkernel_signatureMutRefCType
NamedCTypeNativeSignaturetensorT)method_with_native_functionnative_function_manager)
ArgumentBackendIndexDeviceCheckTypeDispatchKey"gets_generated_out_inplace_wrapperis_cuda_dispatch_keyNativeFunctionNativeFunctionsGroup
SchemaKindTensorOptionsArguments)SelectiveBuilder)assert_nevermapMaybeTargetbackend_indexper_operator_headersrocmreturnc                    |rdg}ndg}| j                   t        j                  t        j                  fv r|j	                  d       |S | j                   t        j
                  k(  r(|r|j	                  d       |S |j	                  d       |S | j                   t        j                  k(  r|j	                  d       |S |r	|g dz  }|S |j	                  d       |S )	Nz'#include <ATen/ops/as_strided_native.h>z!#include <ATen/NativeFunctions.h>z#include <ATen/EmptyTensor.h>z!#include <ATen/hip/EmptyTensor.h>z"#include <ATen/cuda/EmptyTensor.h>z!#include <ATen/mps/EmptyTensor.h>)z#include <ATen/ops/empty.h>z##include <ATen/ops/empty_strided.h>z+#include <ATen/ops/_copy_from_and_resize.h>z #include <ATen/ops/_copy_from.h>z#include <ATen/Functions.h>)dispatch_keyr   CPUMetaappendCUDAMPS)r&   r'   r(   headerss       nC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchgen/dest/register_dispatch_key.pygen_registration_headersr3   *   s    
 <=67!!koo{7G7G%HH67$ N# 
	#	#{'7'7	7NN>? N NN?@ N 
	#	#{	6:; N 
 
 	
 N 	45N    c                    d }d }| j                   t        j                  t        j                  t        j                  t        j
                  fv r1t        | j                         j                         }d| }d| }||fS | j                   t        j                  t        j                  t        j                  fv rd}d}||fS )Nzat::detail::empty_zat::detail::empty_strided_z	at::emptyzat::empty_strided)r+   r   r-   r,   r/   r0   strlower&CompositeExplicitAutogradNonFunctionalQuantizedCPUQuantizedCUDA)r&   
empty_implempty_strided_impldispatchs       r2   gen_empty_impl_namesr>   J   s     J!!	&  }11288:)(4
9(D ))) 
	#	#::  !!( 

 !
0)))r4   c           	          | j                   t        j                  k(  rd}nd}t        |       \  }}|g S d| d| d| d| d	gS )Nzoptions.device(at::kMeta)optionsz
Tensor create_out(IntArrayRef sizes, IntArrayRef strides, const TensorOptions &options) {
  if (strides.empty()) {
      return z(sizes, z);
  } else {
      return z(sizes, strides, z	);
  }
}
)r+   r   r-   r>   )r&   empty_optionsr;   r<   s       r2   gen_create_out_helperrB   d   st    !![%5%553!%9-%H"J"	 \- 1 !!2=/ B	
 
r4   c                 4    t        |       \  }}|g S d| dgS )Nz
c10::optional<Tensor> maybe_create_proxy(const Tensor &out, IntArrayRef sizes, IntArrayRef strides, const TensorOptions &options) {
  if (out.strides() != strides) {
    return z8(sizes, strides, options);
  }
  return c10::nullopt;
}
)r>   )r&   _r<   s      r2   gen_maybe_create_proxy_helperrE   {   sE    0?A % 	   	
r4   c                 F    | j                   t        j                  k(  rg S dgS )Na  
void resize_out(const Tensor &out, IntArrayRef sizes, IntArrayRef strides, const TensorOptions &options) {
  TORCH_CHECK(options.dtype() == out.dtype(),
      "Expected out tensor to have dtype ", options.dtype(), ", but got ", out.dtype(), " instead");
  TORCH_CHECK(options.device() == out.device(),
      "Expected out tensor to have device ", options.device(), ", but got ", out.device(), " instead");
  const bool resized = at::native::resize_output(out, sizes);
  // Only restride if a resize occurred; otherwise we ignore the (advisory)
  // strides from the meta function and directly use the output tensor's
  // preexisting strides
  if (resized) {
    if (!strides.empty()) {
      TORCH_INTERNAL_ASSERT(!options.memory_format_opt().has_value());
      // TODO: avoid the redispatch here
      out.as_strided_(sizes, strides);
    } else if (options.memory_format_opt().has_value()) {
      out.unsafeGetTensorImpl()->empty_tensor_restride(*options.memory_format_opt());
    }
  }
}
)r+   r   r8   r&   s    r2   gen_resize_out_helperrH      s,    !![%W%WW 		 r4   c                     dgS )Na  
void check_inplace(const Tensor &self, IntArrayRef sizes, const TensorOptions &options) {
  // These checks are needed on those operators that:
  //   1) don't use 'TensorIterator' (e.g. 'addmm' and 'baddbmm')
  //   2) have particular typing rules (e.g. 'cumsum' and 'cumprod')
  // For other operators (e.g. 'add'), 'TensorIterator' already checks
  // these things separately.
  TORCH_CHECK(options.dtype() == self.dtype(),
      "Bad in-place call: ",
      "input tensor dtype ", self.dtype(), " and output tensor dtype ", options.dtype(), " should match");
  TORCH_CHECK(options.device() == self.device(),
      "Bad in-place call: ",
      "input tensor device ", self.device(), " and output tensor device ", options.device(), " should match");
  TORCH_CHECK(sizes == self.sizes(),
      "Bad in-place call: ",
      "input tensor size ", self.sizes(), " and output tensor size ", sizes, " should match");
}
 rG   s    r2   gen_check_inplace_helperrK      s    	 r4   c                 ^    g t        |       t        |       t        |       t        |       S N)rB   rH   rK   rE   rG   s    r2   gen_registration_helpersrN      sD    	}	-	}	- 
"-	0 
'}	5	 r4   T)frozenc            	       ~   e Zd ZU eed<   eej                  ej                  ej                  ej                  f   ed<   eed<   eed<   eed<   ee   ed<   eed<   eded	ee   d
edefd       Zedeeef   dee   fd       Zdedeeef   fdZdedee   dee   fdZdedee   fdZ	 ddedee   dee   fdZy)RegisterDispatchKeyr&   targetselectorr(   symintclass_method_nameskip_dispatcher_op_registrationtypeargsmethod_namer)   c           	          | t         j                  k(  ryd}|dz  }|D ]@  }|j                  j                         s|d|j                   d| d|j                   dz  }B |S )N  // No device check
z/c10::optional<Device> common_device = nullopt;
z9(void)common_device; // Suppress unused variable warning
z<
  c10::impl::check_and_update_common_device(common_device, z, "z", "z");)r   NoCheckrW   is_tensor_likename)rW   rX   rY   device_checkargs        r2   gen_device_checkz$RegisterDispatchKey.gen_device_check   s~     ?***+ITTCxx&&( %<<?HH:SUYZ]ZbZbYccf!j j 
 r4   fc                     t        |t              rF|j                  r j                        S t	        t         fdj                                     S t        |t              r j                  |      }|g S |gS t        |       y )Nc                 (    j                  |       S rM   gen_unstructuredrb   gselfs    r2   <lambda>z.RegisterDispatchKey.__call__.<locals>.<lambda>  s    t'<'<Q'Br4   )

isinstancer   
structuredgen_structuredlistr$   	functionsr   rf   r#   )ri   rb   rrh   s   `  @r2   __call__zRegisterDispatchKey.__call__  s    a-.&'A ||**1--BAKKMR  >*%%a(A2++Or4   c                     t        j                  |j                  d| j                  j                   d|j                  j
                  j                   d| j                        S )Nwrapper_rD   prefixrT   )r   from_schemafuncr&   r+   r^   overload_namerT   )ri   rb   s     r2   wrapper_kernel_sigz&RegisterDispatchKey.wrapper_kernel_sig"  sT     #..FFd00==>a@Y@Y?ZZ[\;;
 	
r4   rh   c                    |y |j                   j                         }|t        j                  u rdn |t        j                  u rdnt        d      | j                  |      }|j                         }| dt        j                  |      }t        |      dkD  rXdj                  fdt        |      D              }|j                         j                          dd	j                  |       d
}nt        |      dk(  r|d   }	 d d	|	 d}|	}nt        |j                   j                  j                        dk(  sJ d}|j                   j                  j                  d   }
|
j                   j#                         rd d d d|
j                   d	}n d d	|
j                   d}| j                  |j$                        }|j                         }|j'                  |       d d|j                          dd	j                  d t)        |j                         |j                               D               d| d| dS )Nzat::_copy_fromzat::_copy_from_and_resizez1gen_out_inplace_wrapper called on a functional op_tmp   z
  c           	   3   @   K   | ]  \  }} d | d d| d  yw)z
(std::get<z>(z), );NrJ   ).0iret_namecopy_opfunc_ress      r2   	<genexpr>z>RegisterDispatchKey.gen_out_inplace_wrapper.<locals>.<genexpr>?  s6      "#:KAx ):aS8*CzD#:s   (, )r   r~    z    for (int64_t i = 0; i < z.size(); ++i) {
        z[i], z[i]);
    }r^   z
 {
  auto z = c              3   4   K   | ]  }|j                     y wrM   exprr   es     r2   r   z>RegisterDispatchKey.gen_out_inplace_wrapper.<locals>.<genexpr>Y  s     6~G}!qvvG}   z);
  

  return ;
}
)rw   kindr    inplaceoutAssertionErrorry   r^   cppreturn_nameslenjoin	enumeratereturns_typecpp_type	argumentsrW   is_list_like
functionaldefnr	   )ri   rb   rh   ksigr^   r   updatesreturnsr   out_argfunctional_sigwrapper_namer   r   s                @@r2   gen_out_inplace_wrapperz+RegisterDispatchKey.gen_out_inplace_wrapper,  sU    9FFKKM
"""&G*.. 1G !TUU%%a(xxzV4=''*|q kk "#,\#:" G ))+4467q<9P8QQRSG!##AH 	8*Bxj;GGqvv''++,111Gff&&**1-G||((*%J '			8*E',, 0

 %IQxj7<<.C00>xxz |  z^((*+1TYY6~yQTQ^Q^Q`bpbzbzb|G}6~-~, @
) 

 	 	r4   c           
           j                   j                        } j                   j                  t        j                  k(  r, j                   j                  j                        rJ d        j                   j                  t        j                  k(  r, j                   j                  j                        r<J d       ||j                  s't        t         fdj                                     S t         j                    j                   j                   j                   j                    j"                   j$                        }t        t        |j&                  j                                     S )NzqDo not explicitly specify Meta dispatch key on structured functions, they will be automatically generated for youzDo not explicitly specify CompositeExplicitAutograd dispatch key on structured functions, they will be automatically generated for youc                 (    j                  |       S rM   re   rg   s    r2   rj   z4RegisterDispatchKey.gen_structured.<locals>.<lambda>o  s    4+@+@A+Fr4   )r&   
get_kernelr+   r   r-   
has_kernelr   r8   rl   rn   r$   ro   StructuredRegisterDispatchKeyrR   rS   r(   rT   rU   rV   gen_one)ri   rh   metadatastructured_gens   ``  r2   rm   z"RegisterDispatchKey.gen_structured_  s8   %%003**k.>.>>))44QUU; J;
 ++AAB ))44QUU; J; X%8%8!FVWW6KKMMIIKK""00	
 H^33Q[[]CDDr4   Nc                    t        |      5  d}d}| j                  j                  |      s| j                  j                  t        j
                  k(  r[|j                  j                         t        j                  u r1|j                  s%t        |j                  j                        dk(  rd}n<| j                  j                  s|t        ||| j                        rd}n
	 d d d        y |j                  r
	 d d d        y | j                   t"        j$                  u r%| j&                  j)                  |      s
	 d d d        y | j+                  |      j-                         }j/                         j1                         }j3                         }dj5                  d |D              }t7        j8                  |dd      }	| j                   t"        j:                  u rEd}
|	j=                  | j>                        D ]  }|
d	|jA                          d
z  }
 |
cd d d        S | j                   t"        jB                  u rKdtD        dtF        ffd}d}
|	j=                  | j>                        D ]  }|
 ||      z  }
 |
cd d d        S | j                   t"        jH                  u rL|rq|j                  j2                  jJ                  J |j                  j2                  jJ                  jL                  j,                  }d| d| d| d| d| dcd d d        S |r| jO                  ||      cd d d        S | j                  jQ                  |      }|
	 d d d        y | jR                  |jT                   d|jV                   }n(|jT                   d| jR                   d|jV                   }tY        || j                        }dj5                  d t[        j3                         |j3                         d      D              }d}| j                  j\                  r|t_        j`                  |j                  j2                  jb                  |j                  j2                  jd                        }tf        ji                  |jj                  tm        |      |      }d}|j\                  r+| j                  j\                  rto        d |j                  j2                  jp                  D              }|r'd}ts        | j                  j                        rd| }n|j                  j2                  jJ                  +|j                  j2                  jJ                  jL                  gng }t_        j`                  ||j                  j2                  jb                  |j                  j2                  jd                        }tu        d |D        d       }|d| d}d| d| d| d | d!| d"| d| d#cd d d        S | j                   t"        j$                  u rN|j                  s| jv                  r
	 d d d        y d$| d%}d&|j                  j,                   d'| d(cd d d        S ty        | j                          	 d d d        y # 1 sw Y   y xY w))NFr|   Tr   c              3   <   K   | ]  }|j                           y wrM   )r   r   as     r2   r   z7RegisterDispatchKey.gen_unstructured.<locals>.<genexpr>  s      84a4   methodfallback_bindingr   rT   
TORCH_API ;
cpp_sigr)   c                     d| j                          dj                          ddj                  d t        | j	                         j	                               D               dS )N

 {
return r   r   c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   zNRegisterDispatchKey.gen_unstructured.<locals>.generate_defn.<locals>.<genexpr>       _/^!qvv/^r   );
}
r   r^   r   r	   r   r   r   s    r2   generate_defnz;RegisterDispatchKey.gen_unstructured.<locals>.generate_defn  s`       
|1TYY_y9J9J9Lcmmo/^__` a r4   r    r   z") {
  TORCH_CHECK_NOT_IMPLEMENTED(z[.is_meta(),
    "Cannot inplace into non-meta tensor with meta tensor argument");
  return r   z::c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   z7RegisterDispatchKey.gen_unstructured.<locals>.<genexpr>  s       + FFr   r   r[   z// DeviceGuard omittedc              3   <   K   | ]  }t        |t                y wrM   )rk   r!   r   s     r2   r   z7RegisterDispatchKey.gen_unstructured.<locals>.<genexpr>  s       -!9A #1&<=!9r   z=
  const DeviceGuard device_guard(device_or_default(device));z globalContext().lazyInitCUDA();
c              3   j   K   | ]+  }|j                   j                         r|j                    - y wrM   )rW   r]   r^   r   s     r2   r   z7RegisterDispatchKey.gen_unstructured.<locals>.<genexpr>  s0      )7A#$66#8#8#: $%66()7s   13z1const OptionalDeviceGuard device_guard(device_of());znamespace {

z) {
  z

  r   z);
}

} // anonymous namespace
z	TORCH_FN(r   m.impl("z",
z);
)=r   r&   r   r+   r   r-   rw   r   r    r   has_composite_kernelr   r   use_out_as_primaryr   manual_kernel_registrationrR   r%   REGISTRATIONrS   is_native_function_selectedry   r^   r   r   r   r   r   from_native_functionNAMESPACED_DECLARATION
signaturesrT   declNAMESPACED_DEFINITIONr   r6   ANONYMOUS_DEFINITIONself_argargumentr   r   rU   cpp_namespacekernelr   r	   device_guard	itertoolschainr   flat_positionalrQ   ra   r_   rn   anynon_outr   nextrV   r#   )ri   rb   rh   inplace_metagets_out_inplace_wrapperr^   r   rX   args_strcpp_sig_groupresultr   r   self_arg_namer   	impl_name
kernel_sigargs_exprs_strr_   device_check_argsr   has_tensor_optionsr   candidate_args	device_ofpayloadr   s                             @r2   rf   z$RegisterDispatchKey.gen_unstructured|  s    %Q' L',$%%003&&33{7G7GG););; .. '1,#'L**==:1aASAST 04,/ ('0 ++3 ('8 v222AA!D? ('B ))!,C88:D++-668L==?Dyy 84 88H .BB%%M
 {{f;;;,77t{{7KG
7<<>*:#>>F  Le ('f  < <<< C  ,77t{{7KGmG44F  L ('B  ; ;;66++44@@@$%FF$4$4$=$=$F$F$K$KM avQxj !,o .

 	O ('` ,771=c ('f  --88;#k ('l ))1#+#9#9":"X__<M NI#+#9#9":"T=S=S<TTVW_WfWfVg hI-a1C1CD
!% +&)=)=)?+ "  8%%22(1((,,aff.>.>.N.N)% $7#G#G->(?$L  8>>d&8&8&E&E), -!"!1!1!9!9- *& *(@ 00B0B0O0OP"CL> R )  !vv//88D VV--66??@!# !
 *3$FF,,00FF,,<<* %))7
 !%	 %0-^_h^iil+mL avQxj !. . 

An% &u ('N  3 33//43W3WS ('V !*$q1G%affkk]$witDY ('\ T[[)] (''sR   CY;+Y;8Y;CY;"AY;	BY;Y;6Y;JY;25Y;0"Y;Y;;ZrM   )__name__
__module____qualname__r   __annotations__r   r%   r   r   r   r   r"   boolr   r6   staticmethodr   r   r   ra   r   r   r   r   rq   r   r   ry   r   rm   rf   rJ   r4   r2   rQ   rQ      sd   ##$$%%	   J
 L  }$ &*)%)(^BE	  !% 4n DE $s)  !"

	 33	4
11$,-A$B1	#1fE 4 Ec E< FJq*q*$,-A$Bq*	#q*r4   rQ   c                       e Zd ZU eed<   dedededefdZdededefdZ	ded	ed
e
defdZdeded	edededefdZededee   fd       Zy)r   rh   r   parent_classgenerate_superr)   c                      |r| dnddt         dt        dt         f fd}d |dd	
       d |dd
       dS )NzE::set_output_raw_strided(output_idx, sizes, strides, options, names);r   r^   maybe_create_proxyr)   c           	          d|  dt        j                  j                  |      d       dt        j                  d       dS )Nz
void set_output_z|(
    int64_t output_idx, IntArrayRef sizes, IntArrayRef strides,
    TensorOptions options, DimnameList names
) override {
    z
    if (!names.empty()) {
      namedinference::propagate_names(outputs_[output_idx], names);
    }
    // super must happen after, so that downstream can use maybe_get_output
    // to retrieve the output

}
)textwrapindentgen_class_set_output_body)r^   r   r   ri   set_output_supers     r2   gen_set_output_functionz]StructuredRegisterDispatchKey.gen_class_set_output_functions.<locals>.gen_set_output_functionC  s\      
//3EFO P Q 
!6* + , r4   r   stridedT)r   raw_stridedF)r6   r   )ri   r   r   r   r  r  s   ``   @r2   gen_class_set_output_functionsz<StructuredRegisterDispatchKey.gen_class_set_output_functions;  sj     "./tu!	# 	4 	C 	 t< = >5A B C 	r4   r   c                    | j                   j                  t        j                  t        j                  t        j
                  fv rd}|dz   }ndx}}|rd}nd}|t        j                  u rj| j                   j                  t        j                  t        j                  t        j                  t        j                  t        j
                  fv sJ | dS |t        j                  u r| d| S |t        j                  u r| d| S |t        j                  u s|t        j                  u rt        | d      t        |       y )	Na  
auto current_device = guard_.current_device();
if (C10_UNLIKELY(current_device.has_value())) {
  TORCH_INTERNAL_ASSERT(*current_device == options.device(),
    "structured kernels don't support multi-device outputs");
} else {
  guard_.reset_device(options.device());
}
r   r   z
auto maybe_proxy = maybe_create_proxy(out, sizes, strides, options);
if (C10_UNLIKELY(maybe_proxy.has_value())) {
    proxy_outputs_[output_idx] = std::move(maybe_proxy).value();
}
z<
outputs_[output_idx] = create_out(sizes, strides, options);zS
const auto& out = outputs_[output_idx].get();
check_inplace(out, sizes, options);
zY
const auto& out = outputs_[output_idx].get();
resize_out(out, sizes, strides, options);
1 structured operators are currently not supported)r&   r+   r   r/   r0   r8   r    r   r-   r,   r   r   mutablescratchr   r#   )ri   r   r   maybe_set_guardmaybe_set_guard_linecreate_proxys         r2   r  z7StructuredRegisterDispatchKey.gen_class_set_output_bodyX  sg   **OO>>/
 

O $3T#9 577 ?L L
%%%%%22    BB7    -- .< ? ?*$$$,- .   *.. ,- .   *$$$Z-?-?(? #FG  Or4   
class_namer   c                    |t         j                  u ry|t         j                  u r| dS |t         j                  u rMdj	                  d t        |      D              }dj	                  d t        |      D              }| d| d| dS |t         j                  u s|t         j                  u rt        | d	      t        |       y )
Nr   z,(Tensor& self) : outputs_{std::ref(self)} {}r   c              3   &   K   | ]	  }d |   yw)zTensor& outNrJ   r   r   s     r2   r   z?StructuredRegisterDispatchKey.gen_class_ctor.<locals>.<genexpr>  s      KNq;qc!2Ns   c              3   (   K   | ]
  }d | d  yw)zstd::ref(outr   NrJ   r  s     r2   r   z?StructuredRegisterDispatchKey.gen_class_ctor.<locals>.<genexpr>  s      Mn<s!!4n   r   z) : outputs_{ z } {}r  )
r    r   r   r   r   ranger	  r
  r   r#   )ri   r   r  r   out_argsout_refss         r2   gen_class_ctorz,StructuredRegisterDispatchKey.gen_class_ctor  s    
%%%*$$$ \!QRR*.. yy KE'N KKHyy MeGn MMH \8*OH:XNN*$$$Z-?-?(? #FG  Or4   rb   c                   |t         j                  u rd}d}d}ns|t         j                  u r(d}d}dt        |j                  j
                         d}n9|t         j                  u r'd}d}dt        |j                  j
                         d}| j                  j                  t        j                  k(  r| j                  rd}	nYd	}	nV| j                  j                  t        j                  k(  rd
}	n,| j                  j                  t        j                  k(  rd
}	nd}	d}
| j                  ||t        |j                  j
                              }d| d| dt        j                   ||
       t        j                   | j#                  |||      |
       dd ddd dt        |j                  j
                         dt        j                   |
       t        j                   |	|
       df
}dj%                  d |D              S )NTensorzoutputs_[output_idx]r   zstd::reference_wrapper<Tensor>zaproxy_outputs_[output_idx].has_value() ? *proxy_outputs_[output_idx] : outputs_[output_idx].get()z"std::array<c10::optional<Tensor>, z> proxy_outputs_;z4c10::hip::OptionalHIPGuardMasqueradingAsCUDA guard_;z$c10::cuda::OptionalCUDAGuard guard_;z c10::OptionalDeviceGuard guard_;r   zstruct z final : public z {zA    const Tensor& maybe_get_output(int64_t output_idx) override {z      return r   z    }z    std::array<r   z> outputs_;z};r   c              3   &   K   | ]	  }|s|  y wrM   rJ   )r   lines     r2   r   z:StructuredRegisterDispatchKey.gen_class.<locals>.<genexpr>  s     8%$4%s   )r    r   r   r   rw   r   r   r&   r+   r   r/   r(   r8   r0   r  r   r   r  r   )ri   rb   r   r  r   r   output_typeoutput_valueproxy_fieldguard_fieldr   class_ctor_strliness                r2   	gen_classz'StructuredRegisterDispatchKey.gen_class  s    
%%%"K1LK*$$$:K~L>s166>>?R>SSdeK*.. :K~L>s166>>?R>SSdeK**k.>.>>yyTD++AAB =K,,?<KK,,Q
C<OPj\!1,sC~v67tBB1lTbceklmOL>-k]"S-@,AM{F34{F34
 yy8%888r4   c                 <    |j                   rJ | j                  t        j                  u r| j                  j                  |      sy | j                  j                  t        j                  k(  r+|j                  j                         t        j                  u ry t        j                  |dd      }| j                  j!                  |      }t#        |j                  d| j                  j                   d|d uxr |j%                                | j                  t        j&                  u r<d}|j)                  | j*                        D ]  }|d|j-                          d	z  } |S | j                  t        j.                  u rBd
t0        dt2        f fd}d}|j)                  | j*                        D ]  }| ||      z  } |S | j                  t        j4                  u r]|j                  j                         }g }t7         j9                               }	| j                  j                  t        j:                  u rRdt=        j>                  | j@                         d|j>                   }
dt=        j>                  | j@                         }n| j                  j                  t        j                  u rRdt=        j>                  | j@                         d|j>                   }
dt=        j>                  | j@                         }n`| j                  j!                  | j@                        }|J d|jB                   d|j>                   }
|jD                   d|jB                   }| j                  jF                  rtI        jJ                  |j                  j8                  j                  |j                  j8                  jL                        }|jO                  tP        jS                  |jT                  t7        |       j?                                      |t        jV                  u r|jO                  |
 d       n|t        jX                  u r|jO                  |
 d       n_|t        j                  u rMdj[                  d |j                  j8                  j                  D              }|jO                  |
 d| d       dj[                  d t]        |	t_        j`                  | j@                        d      D              }| j@                  j                  jb                  r|jO                  d| d       g | j@                  j                  jb                  jd                  jg                         | j@                  j                  jb                  jh                  }|D ]Q  }|D ]J  }|	jO                  tk        d|j>                   t_        jl                  ||j>                                     L S |jO                  d       n|jO                  d| d       t_        jn                  | j@                        }tq        |      D ]  \  }}ts        tu        tv                    |jx                  jz                  k(  sJ |t        j                  u rd | d!}nd"| d#}|	jO                  tk        |t}        |jx                  j>                  t        tu        tv                                        | j                  j                  t        j                  k(  rt        j                  | j@                  j                  d|j                        }|j                         }|j?                         }dj[                  d$ t]        |	|j9                         d      D              }|jO                  d%| d&| d       n}| j                  j                  t        j:                  k7  rVdj[                  d' t]        |	t_        j                  | j@                        d      D              }|jO                  d(| d       |t        j                  u s|t        jX                  u rHt        t        |j                  j                              D ]  }|jO                  d)| d*| d+| d,        |t        jV                  u rjt        |j                  j                        d-k(  rd.}ndj[                  d/ t        t        |j                  j                              D              }d0| d!}n|t        jX                  u rd1}n|t        j                  u rt        |j                  j                        d-k(  r.|j                  j8                  j                  d2   j>                  }n<dj[                  d3 |j                  j8                  j                  D              }d4| d!}|jO                  d5 d6       d7j[                  |      }| j                  |||
|| j@                  j                  j                  d u8       d9 j                          d:| d;S | j                  t        j                  u r+d<|j                  j>                   d= j?                          d>S t        | j                         y )?NFr   rs   rD   rt   r   r   r   r   r   r)   c                     d| j                          dj                          ddj                  d t        | j	                         j	                               D               dS )Nr   r   r   r   c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   zOStructuredRegisterDispatchKey.gen_one.<locals>.generate_defn.<locals>.<genexpr>  r   r   r   r   r   s    r2   r   z<StructuredRegisterDispatchKey.gen_one.<locals>.generate_defn  s`      
|1TYY_y9J9J9Lcmmo/^__` a r4   structured__meta_zat::meta::structured__default_backend_z::structured_z op;z
 op(self);r   c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   z8StructuredRegisterDispatchKey.gen_one.<locals>.<genexpr>G  s     (N9MA9Mr   z op(r~   c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   z8StructuredRegisterDispatchKey.gen_one.<locals>.<genexpr>L  s       #A r   r   zauto precompute = op.meta(zprecompute.)binds)r   rW   z(void)precompute;zop.meta(zop.maybe_get_output(r   zop.outputs_[]c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   z8StructuredRegisterDispatchKey.gen_one.<locals>.<genexpr>  s      &R FFRr   zat::r   c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   z8StructuredRegisterDispatchKey.gen_one.<locals>.<genexpr>  s       ' FFr   zop.impl(zif (op.proxy_outputs_[z].has_value()) op.outputs_[z!].get().copy_(*op.proxy_outputs_[z]);r|   zstd::move(op.outputs_[0])c              3   (   K   | ]
  }d | d  yw)zstd::move(op.outputs_[z])NrJ   r  s     r2   r   z8StructuredRegisterDispatchKey.gen_one.<locals>.<genexpr>  s!      &!;A 126!;r  zstd::make_tuple(ri   r   c              3   4   K   | ]  }|j                     y wrM   r   r   s     r2   r   z8StructuredRegisterDispatchKey.gen_one.<locals>.<genexpr>  s     $J5IQVV5Ir   zstd::forward_as_tuple(zreturn ;r   )r  r   r   z

z {
r   r   z", TORCH_FN(r   )Jr   rR   r%   r   rS   r   r&   r+   r   r8   rw   r   r    r   r   r   r   r   supports_symintr   r   rT   r   r   r   r6   r   rn   r   r-   metar^   rh   r   r   r   r   r   r   r.   rQ   ra   r_   r   r   r   r	   rl   meta_argumentsprecomputedreplacevaluesaddr   argument_typeout_argumentsr   r   r
   r   nctyperW   r   r   manual_cpp_bindingmost_faithful_signatureimpl_argumentsr  r   r   r"  structured_inheritsr   r#   )!ri   rb   r   kernr   r   r   r   sig_bodycontextr  r   r   r   out_args_str
meta_exprsprecomputed_valuesprecomputed_elemsr`   r  r   r   r   out_sig_groupout_sigapi_name	out_exprs
impl_exprsret_exprmovedrefssig_body_strr   s!                                   @r2   r   z%StructuredRegisterDispatchKey.gen_one  s   //// KK6...MM==a@ ++AAB/  *>>ee

 !!,,Q/FFd00==>a@t#>(<(<(>
 ;;&777F(334;;3GJw||~&6c:: HM[[F888|   F(334;;3G-00 HM[[F777A H 37s}}2GG !!..+2B2BB*499TVV+<*=VAFF8L
!6tyy7H6IJ""//EEF  +499TVV+<*==NqvvhW
!6tyy7H6IJ--88@+++*8??*;1QVVHE
"*"8"8!9xFWX!!..$-OOFF$$((!&&*:*:*J*J%! '88->(? J))):,d 34j(((:,j 9:jnn$#yy(N9I9I9M9M(NN:,d<. CD  #"Z66tvv>u# J vvzz%% "<ZL KL
&VVZZ++33::<&FFJJ**..&" *<%0 '2388*%=%/%=%=c%R  1 *<  34(:,b 9: "//7H'1
7$Yw%78GNN<O<OOOO
&1!A6D)!A.D! (#NN//Yw=O1P
 2. ""//EEF !2 F FFFJJuq?S?S! (??A"<<> II &&w0A0A0CER& 	 $xj)B ?@##00K4D4DD!YY '&!:!:466!B5' 
 (:,b 9: JNN"a:+=+=&=s166>>23AOO03NqcQrstruuxy 4 J)))qvv~~&!+:H II &!&s166>>':!;& E "2%:Hj(((!jnn$qvv~~&!+ vv//33A6;;H99$JQVV5E5E5I5I$JJD!7vQ?HOOghZq1299X.L
  1vvzz--T9	   
    [[F///affkk],sxxzl#FF%r4   N)r   r   r   r   r   r    r6   r   r  r  intr  r   r"  r   r   r   rJ   r4   r2   r   r   7  s    +.@D	:6: 64 6TW 6t
  c c "4949 49
 49 49 49 
49l !C CHSM C !Cr4   r   )?r   r   dataclassesr   typingr   r   r   r   r   torchgen.api.cppapir   torchgen.api.metar3  torchgen.api.structuredrl   torchgen.api.translater	   torchgen.api.typesr
   r   r   r   r   r   r   r   r   r   r   r   torchgen.contextr   r   torchgen.modelr   r   r   r   r   r   r   r   r    r!   !torchgen.selective_build.selectorr"   torchgen.utilsr#   r$   r%   r   r6   r3   r>   rB   rE   rH   rK   rN   rQ   r   rJ   r4   r2   <module>r]     sk     ! 8 8       , , ,    R   ? 9 9  
#Y	@**
8C=(3-'(*4 $s) . $s) $ $s) <L T#Y .L T#Y 6 $O* O* O*r
 $e$7 e er4   