
    )`i`                        d Z ddlZddlZddlZddlZ	 ddlZ eed          redk    r e	d          ddl
T ddlT ddlT ddlT ddlT ddlT ddlT ddlT n+# e	$ r# ddlT ddlT ddlT ddlT ddlT ddlT ddlT ddlT Y nw xY w ej        e          Z G d d          Z G d	 d
          Z G d d          Z G d d          Z  G d d          Z!dS )zh
Utilities for filtering CUTLASS library kernels and emitting library intitialization
and building code
    NCUTLASS_IGNORE_PACKAGETz+Disabling attempt to import cutlass_library)*c                   *    e Zd ZdZd Zd Zd Zd ZdS )EmitOperationKindAlla   
  Emit the OperationKind-level CUTLASS library initialization code.
  The code is generated in the {generated_path}/{operation_kind} directory
  (e.g., tools/library/generated/gemm in the build directory,
  for OperationKind=Gemm), in the all_{operation_kind}_operations.cu file
  (e.g., all_gemm_operations.cu for OperationKind=Gemm).
  That file declares several functions in namespace cutlass::library.
  The functions all have this form,

  void initialize_{configuration_name}(Manifest& manifest);

  The file also _defines_ the following function in that namespace.

  void initialize_all_{operation_kind}_operations(Manifest& manifest);

  That function calls all of the functions declared in this file.
  Those functions are defined in subdirectories
  (which this class does not create).
  c                 v    || _         || _        || _        d| _        d| _        d| _        d| _        d| _        d S )N(  
/*
 Generated by manifest.py - Do not edit.
*/

#include "cutlass/cutlass.h"
#include "cutlass/library/library.h"
#include "cutlass/library/manifest.h"

namespace cutlass {
namespace library {

///////////////////////////////////////////////////////////////////////////////////////////////////

zv

//
// Entry point to construct operations
//
void initialize_all_${operation_name}_operations(Manifest &manifest) {
;void initialize_${configuration_name}(Manifest &manifest);
.  initialize_${configuration_name}(manifest);
}

///////////////////////////////////////////////////////////////////////////////////////////////////

} // namespace library
} // namespace cutlass

)generated_pathkindargsheader_templateentry_template configuration_prototype_templateconfiguration_templateepilogue_template)selfr   r   r   s       /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/flashinfer/data/cutlass/python/cutlass_library/manifest.py__init__zEmitOperationKindAll.__init__Z   sO    (DDIDID D -kD)!RDD    c                    t                               d           t          j                            | j        t          | j                           | _        t                               dt          | j                  z              t          j
        | j        d           t          j                            | j        dt          | j                  d          | _        t                               dt          | j                              t          | j        d          | _        | j                            | j                   | j        g| _        g | _        | S )	Nz#*** EmitOperationKindAll::__enter__z,***   operation_path (directory to create): T)exist_okall__operations.cu&***   top_level_path (file to write): w)_LOGGERdebugospathjoinr   OperationKindNamesr   operation_pathstrmakedirstop_level_pathopentop_level_filewriter   source_filesconfigurationsr   s    r   	__enter__zEmitOperationKindAll.__enter__   s   MM7888',,t':<Nty<YZZDMM@d)**+ , , ,K#d3333',,t':<pCUVZV_C`<p<p<pqqDMMU3t?R;S;SUUVVVt2C88Dd2333,.DDKr   c           	         t                               d           t                               dt          |                      t                               dt          d |                                D                                   t          |                                          D ]\  }}t                               d|            |                                D ]k\  }}t                               d|            | j                            |           | j                            t          | j
        d|i                     ld S )Nz*** EmitOperationKindAll::emitz***   len(operations): z***   min_cc list: c              3       K   | ]	\  }}|V  
d S N ).0min_cc_s      r   	<genexpr>z,EmitOperationKindAll.emit.<locals>.<genexpr>   s&      .Z.Z)&!v.Z.Z.Z.Z.Z.Zr   z***   min_cc=z***     configuration_name=configuration_name)r   r   lensorteditemsr,   appendr)   r*   SubstituteTemplater   )r   
operationsr4   r,   r7   r5   s         r   emitzEmitOperationKindAll.emit   sk   MM2333MM=C
OO==>>>MM\.Z.ZzGWGWGYGY.Z.Z.Z(Z(Z\\]]]"()9)9););"<"< J Jmm,F,,---#1#7#7#9#9 J J

aH4FHHIII""#5666!!"4T5Z]q  tF  ]G  #I  #I  	J  	J  	J  	JJJ Jr   c                    t                               d           | j                            t	          | j        dt          | j                 i                     | j        D ]1}| j                            t	          | j	        d|i                     2| j                            | j
                   | j                                         d S )Nz"*** EmitOperationKindAll::__exit__operation_namer7   )r   r   r)   r*   r<   r   r#   r   r,   r   r   close)r   exception_typeexception_value	tracebackr7   s        r   __exit__zEmitOperationKindAll.__exit__   s    MM677701DGWYklpluYvFwxxyyy"1 } }
 243NQegyPz { {||||d4555r   N__name__
__module____qualname____doc__r   r.   r>   rE   r2   r   r   r   r   E   s^         (& & &R  *J J J	  	  	  	  	 r   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )EmitOperationKindLibrarya\  
  Emit the CUTLASS library initialization code for each OperationKind.
  The code is generated in the directory
  {generated_path}/{operation_kind}/{min_cc}
  (e.g., tools/library/generated/gemm/90 in the build directory,
  for min_cc=90 and OperationKind=Gemm), in the file
  all_sm{min_cc}_{operation_kind}_operations.cu
  (e.g., all_sm90_gemm_operations.cu for min_cc=90 and OperationKind=Gemm).
  The min_cc variable here indicates the minimum GPU architecture version
  that the things to be initialized require.
  For example, min_cc=90 indicates sm90.

  That file declares several functions in namespace cutlass::library.
  The functions all have this form,

  void initialize_all_sm{min_cc}_{subclass_name}_{extended_name}_operations(Manifest& manifest);

  where extended_name is operation.extended_name() for all the operations
  given to the emit method (which see below).  (All operations for a given
  configuration_name are guaranteed to have the same extended_name().)

  The file also _defines_ the following function in that namespace.

  void initialize_all_sm{min_cc}__{operation_kind}_operations(Manifest& manifest);

  That function calls all of the functions declared in this file.
  Those functions are defined in subdirectories.
  The mapping from OperationKind to emitter handles the details
  of what happens in each of those subdirectories.
  c                    || _         || _        || _        || _        t          j        t          t          j        t          t          j	        t          t          j        t          t          j        t          t          j        t           t          j        t$          i| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d S )Nr   z

//
// Entry point to construct operations
//
void initialize_all_sm${min_cc}_${subclass_name}_${operation_name}_operations(Manifest &manifest) {
r	   r
   zV  initialize_all_sm${min_cc}_${subclass_name}_${operation_name}_operations(manifest);
zcvoid initialize_all_sm${min_cc}_${subclass_name}_${operation_name}_operations(Manifest &manifest);
r   )r   r4   r   r   OperationKindGemmEmitGemmConfigurationLibraryConv2dEmitConv2dConfigurationLibraryConv3dEmitConv3dConfigurationLibraryRankKEmitRankKConfigurationLibraryRank2KEmitRank2KConfigurationLibraryTrmmEmitTrmmConfigurationLibrarySymmEmitSymmConfigurationLibraryemittersr   r   r   r   subclass_call_templatesubclass_prototype_templater   )r   r   r4   r   r   s        r   r   z!EmitOperationKindLibrary.__init__   s    (DDKDIDI6::8:66DMDD -kD)"SD"{D (ND$Dr   c                    t                               d           t                               dt          | j                              t                               dt          | j                             t                               d| j                    t          j        	                    | j        t          | j                 t          | j                            | _
        t                               dt          | j
                              t          j        | j
                   t          j        	                    | j
        d| j         dt          | j                  d          | _        t                               d	t          | j                              t          | j        d
          | _        | j                            | j                   i | _        i | _        i | _        | S )Nz'*** EmitOperationKindLibrary::__enter__z***   generated_path: z ***   OperationKindNames[kind]: z***   min_cc: z****   operation_path (directory to make): all_smr5   r   r   r   )r   r   r%   r   r#   r   r4   r    r!   r"   r$   r&   r'   r(   r)   r*   r   r+   subclass_filessubclass_configurationsr-   s    r   r.   z"EmitOperationKindLibrary.__enter__  s   MM;<<<MME3t/B+C+CEEFFFMMT5G	5RTTUUUMM04;00111',,t':<Nty<Y[^_c_j[k[kllDMMYs4CV?W?WYYZZZK#$$$',,t':  =AT[  =A  =ASefjfoSp  =A  =A  =A  B  BDMMU3t?R;S;SUUVVVt2C88Dd2333D
 D $&D Kr   c           
         t                               d           t                               d|            t          |          dk    sJ |d                                         }t                               d|z              || j        vrt
          j                            | j        |          }t                               dt          |                      t          j
        |           g | j        |<   t
          j                            |d| j         d| dt          | j                  d          }t                               d	t          |          z              t          |d
          | j        |<   | j        |                             | j                   |g| j        |<   t
          j                            | j        |         j                  }t                               dt          |          z               | j        | j                 ||          5 }|D ]}|                    |           t                               dt          |j                  z              | j        |                             |j                   d d d            n# 1 swxY w Y   | j        |                             |           | j        |                             t3          | j        d|i                     d S )Nz"*** EmitOperationKindLibrary::emitz***   configuration_name: r   z#***   extended_name (for all ops): z***     subclass_path: ra   r5   r   zH***     subclass_top_level_path (min_cc, extended_name, OperationKind): r   z***   subclass_dir: z0***   configuration_emitter.configuration_path: r7   )r   r   r8   extended_namerb   r    r!   r"   r$   r%   mkdirrc   r4   r#   r   r(   r*   r   r+   dirnamenamer]   r>   configuration_pathr;   r<   r   )	r   r7   r=   re   subclass_pathsubclass_top_level_pathsubclass_dirconfiguration_emitter	operations	            r   r>   zEmitOperationKindLibrary.emit"  sF   MM6777MMC/ACCDDDz??Q
 qM//11MMM7-GHHH D///gll4#6FFmmmBc-.@.@BBCCCh}46d"=1 !#kkkmkk>PQUQZ>[kkk!m !mmm '),-D)E)EF G G G ,00G+M+Md-(
-(..t/CDDD*A)Bd&7??4#6}#E#JKKLMM(3|+<+<<===	!ty	!,0B	C	C XG\! . .)""9----mmF-@AAB C C C
&--.C.VWWWX X X X X X X X X X X X X X X 	 /667IJJJ&,,-?@eh|  Q  hR  .T  .T  U  U  U  U  Us   !A/JJ #J c           	      t   t                               d           t          | j                                                  D ]Z\  }}t          | j                  |t          | j                 d}| j	        
                    t          | j        |                     [| j	        
                    t          | j        t          | j                  dt          | j                 d                     t          | j                                                  D ]\  }}t          | j                  |t          | j                 d}|
                    t          | j        |                     | j        |         D ],}|
                    t          | j        d|i                     -|
                    | j                   |                                 | j	        
                    t          | j        |                     | j	        
                    | j                   | j	                                         d S )Nz&*** EmitOperationKindLibrary::__exit__)r4   subclass_namer@    r7   )r   r   r9   rb   r:   r%   r4   r#   r   r)   r*   r<   r_   r   rc   r   r   rA   r^   )r   rB   rC   rD   rp   subclass_filesubclass_cfgconfigurations           r   rE   z!EmitOperationKindLibrary.__exit__P  s8   MM:;;;(.t/B/H/H/J/J(K(K d d$}dk""&,TY7 l
  243SUa b bcccc,dk"",TY7/ / 	 	
 
 
 )/t/B/H/H/J/J(K(K _ _$}dk""&,TY7 l
 ,T-@,OOPPP7F  -
T8 -;  	 	 	 	
 $0111  243NP\ ] ]^^^^d4555r   NrF   r2   r   r   rL   rL      s_         >0 0 0f  :+U +U +U\'  '  '  '  ' r   rL   c                   *    e Zd ZdZd Zd Zd Zd ZdS )EmitInterfaceLibraryad  
  Emit the topmost-level CUTLASS library initialization code.
  The code is generated in the generated_path directory
  (e.g., tools/library/generated in the build directory),
  in the initialize_all.cpp file.
  That file declares several functions in namespace cutlass::library.
  The functions all have this form,

  void initialize_all_{operation_kind}_operations(Manifest& manifest);

  where {operation_kind} abbreviates the "kind" of operation
  (e.g., gemm for matrix-matrix multiply, conv2d for 2-d convolution,
  or trmm for triangular solve with multiple right-hand sides).
  The definitions of these functions live in subdirectories.

  The file also _defines_ the following function in that namespace.

  void initialize_all(Manifest& manifest);

  That function first prepares the manifest, and then
  calls all of the functions declared in this file.
  c                     || _         || _        g | _        g | _        t	          |          | _        d| _        d| _        d| _        d| _	        d| _
        d S )Nz0
/*
 Generated by manifest.py - Do not edit.
*/
z

#include "cutlass/library/library.h"
#include "cutlass/library/manifest.h"

namespace cutlass {
	namespace library {

${prototypes}
zP
		void initialize_all_${kind}_operations(Manifest &manifest) {
${fn_calls}
		}
zg
		void initialize_all(Manifest &manifest) {
			manifest.reserve(${operation_count});

${fn_calls}
		}
z1
	} // namespace library
} // namespace cutlass

)r   r   
prototypesfn_callsr%   operation_counttop_level_hdr_templatetop_level_prologuetop_level_initialize_kindtop_level_initializetop_level_suffix)r   r   rz   r   s       r   r   zEmitInterfaceLibrary.__init__  sg    (DDIDODM//D#D
	D&D"!DDr   c                 x   t                               d           t          j                            | j        d          | _        t                               dt          | j                  z              t          | j        d          | _	        | j	        
                    | j                   | j        g| _        | S )Nz#*** EmitInterfaceLibrary::__enter__zinitialize_all.cppz***   top_level_path: r   )r   r   r    r!   r"   r   r'   r%   r(   r)   r*   r{   r+   r-   s    r   r.   zEmitInterfaceLibrary.__enter__  s    MM7888',,t':<PQQDMM*S1D-E-EEFFFt2C88Dd9:::,.DKr   c                    t                               d           t                               d|z              | j                            t	          dd|i                     | j                            t	          dd|i                     d S )Nz*** EmitInterfaceLibrary::emitz***   operation_name: zG		void initialize_all_${operation_kind}_operations(Manifest &manifest);operation_kindz9			initialize_all_${operation_kind}_operations(manifest);)r   r   rx   r;   r<   ry   )r   r@   s     r   r>   zEmitInterfaceLibrary.emit  s    MM2333MM*^;<<<O-R.)+ + , , , 	M+D(* * + + + + +r   c           	         t                               d           | j                            t	          | j        dd                    | j                  i                     | j                            t	          | j        | j	        d                    | j
                  d                     | j                            | j                   | j                                         d S )Nz"*** EmitInterfaceLibrary::__exit__rx   
)rz   ry   )r   r   r)   r*   r<   r|   r"   rx   r~   rz   ry   r   rA   )r   rB   rC   rD   s       r   rE   zEmitInterfaceLibrary.__exit__  s    MM677701H<X\XaXabfbqXrXrJsttuuu 	01J262FSWS\S\]a]jSkSklln n o o o 	d3444r   NrF   r2   r   r   rv   rv   y  s[         .) ) )X  
+ 
+ 
+
  
  
  
  
 r   rv   c                       e Zd Zd ZdS )Optionsc                     d S r1   r2   r-   s    r   r   zOptions.__init__  s    Dr   N)rG   rH   rI   r   r2   r   r   r   r     s#        	 	 	 	 	r   r   c                   b    e Zd ZddZd ZddZd Zd	 Zd
 Zd Z	d Z
d Zd Zej        fdZdS )ManifestNc                    i | _         | _        d| _        i | _        d| _        g | _        g | _        g | _        g | _        g | _	        g | _
        dg| _        dg| _        d| _        d| _        | j        r| j        j        | _        j        | _        dj        v rt#          dj        z             t%          j                  rj                            d	          ndg| _        t)          t+          d
 | j        D                                 | _        j        dv rd| _        j         dk    rg | _        nWt,          j        t,          j        t,          j        t,          j        t,          j        t,          j        g}fd|D             | _        j        dk    rg | _        n)d j                            d          D             | _        d j                            d          D             | _	        d j                            d          D             | _
        j        g | _        ne|                      j                  | _        tB          "                    d#                    t%          | j                  j                             d| _        i | _        j$        | _$        j%        dk    o
j        dk    | _&        d| _%        	 tO          j%                  | _%        d S # tP          $ r d| _%        Y d S w xY wd S )Nr   rq   2   50.T,zThe list of architectures (CMake option CUTLASS_NVCC_ARCHS) must be semicolon-delimited.
Don't use commas to separate the architectures; use semicolons.
You specified the list as: ;c              3      K   | ]E}t          |                    d           d                             d          d                   V  FdS )ar   fN)intsplit)r3   archs     r   r6   z$Manifest.__init__.<locals>.<genexpr>  sg        6O  6O`dc$**S//!:L:R:RSV:W:WXY:Z6[6[  6O  6O  6O  6O  6O  6Or   )falseFalse0Fallc                 b    g | ]+}t           |         j                            d           v )|,S )r   )r#   r=   r   )r3   xr   s     r   
<listcomp>z%Manifest.__init__.<locals>.<listcomp>  s=    "u"u"uASTUAVZ^ZiZoZopsZtZtAtAt1AtAtAtr   c                     g | ]
}|d k    |S rq   r2   r3   r   s     r   r   z%Manifest.__init__.<locals>.<listcomp>!  s    KKK1177Q777r   c                     g | ]
}|d k    |S r   r2   r   s     r   r   z%Manifest.__init__.<locals>.<listcomp>#  s    !W!W!WqTVww!wwwr   c                     g | ]
}|d k    |S r   r2   r   s     r   r   z%Manifest.__init__.<locals>.<listcomp>$  s$    "Y"Y"YQRVXQXQX1QXQXQXr   z6Using {filter_count} kernel filters from {filter_file})filter_countfilter_filemax))r=   r   rz   operations_by_namekernel_filterkernel_filter_listkernel_namesoperations_enabledselected_kernelsignore_kernel_namesexclude_kernel_namescompute_capabilities_baseline compute_capabilities_feature_setcurr_build_dirfilter_by_cckernelsarchitecturesRuntimeErrorr8   r   r9   setrN   rO   rQ   rS   rU   rY   r[   ignore_kernelsexclude_kernelskernel_filter_fileget_kernel_filtersr   r   formatdisable_full_archs_compilationinstantiation_levelis_kernel_filter_set_to_allr   
ValueError)r   r   operations_lists    ` r   r   zManifest.__init__  si   DODID DD DD DD!D "D*,D&-1GD)DDy 3'9,d /d 
"	"	"  T  W[  Wi  i  j  j  	jORSWSeOfOf.sd.@.F.Fs.K.K.Kmqlsd++1#  6O  6Ohl  iN  6O  6O  6O  3O  3O  ,P  ,Pd(		5	5	5!	E	!	!"$ 
  !  
 #v"u"u"uo"u"u"u			KK(:(:3(?(?KKK!W!WT-@-F-Fs-K-K!W!W!Wd"Y"Yd.B.H.H.M.M"Y"Y"Yd		 	($&$
!
!$($;$;D<S$T$T$
!
--PWW !899 3 X 5 5 6 6 6 d "d,0,Od))-)AU)J)at|_aOad&!"d'%()A%B%B$
"
"
" ' ' '%&$
"
"
"
"'e3' 3's   K, ,L Lc                 n    t                               |          }| j                            |           d S r1   )recompiler   r;   )r   
filter_str	filter_res      r   add_kernel_filterzManifest.add_kernel_filter8  s0    

:&&I""9-----r   r   o   '  c                 V    | j         dk    r| j         S | j        r|S | j        dk    r|S |S )Nr   rq   )r   r   r   )r   pruned_leveldefault_levelexhaustive_levels       r   get_instantiation_levelz Manifest.get_instantiation_level=  sH     !##''		) 		r	!	! r   c                     t           j                            |          rBt          |d          5 }d |D             }d d d            n# 1 swxY w Y   d |D             }|S g S )Nrc                 `    g | ]+}|                     d           |                                ,S )#)
startswithrstripr3   lines     r   r   z/Manifest.get_kernel_filters.<locals>.<listcomp>U  s2    VVVtQTAUAUVT[[]]VVVr   c                 F    g | ]}|t                               |          S r2   )r   r   r   s     r   r   z/Manifest.get_kernel_filters.<locals>.<listcomp>W  s)    <<<dt<D!!<<<r   )r    r!   isfiler(   )r   kernelListFile
fileReaderliness       r   r   zManifest.get_kernel_filtersR  s    	w~~n%% .#&& 	W*VVzVVVE	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W =<e<<<	s   A		AAc                 @    |D ]}|                     |           dS dS )NTF)search)r   kernel_namer   kernel_filter_res       r   filter_out_kernelszManifest.filter_out_kernels]  s9    .  "";//;44 < 5r   c                     |                     d          }|D ]:}|                    |          }|dk     r dS ||t          |          z   d         };dS )z? Returns true if all substrings appear in the haystack in orderr   r   FNT)r   findr8   )r   filter_stringhaystack
substringssubidxs         r   _filter_string_matcheszManifest._filter_string_matchesg  sd    $$S))J + +MM#c	quu#C.//*hh4r   c                    | j          }| j        D ]M}||j        j        k    r;||j        j        k    r+|t
          vst
          |         t          |          k    rd} nN|sdS t          | j                  r|j	        | j        vrdS |
                                }|| j                                        v rdS t          | j                  rd}| j        D ]^}|                     ||          r%t                              d| d| d           d} n"t                              d| d| d           _| j        D ]^}|                     ||          r%t                              d| d| d           d} n"t                              d| d| d           _t          | j                  d	k    r\|                     || j                  r!t                              d| d
           d}n t                              d| d           d}| j        D ]^}|                     ||          r%t                              d| d| d           d} n"t                              d| d| d           _|S )z/ Filtering operations based on various criteriaTFzKernel z  included due to filter string 'z'.z# NOT included due to not matching 'z ignored due to filter string 'z" NOT ignored due to not matching 'r   z  matched via kernel filter file.z. culled due to no match in kernel filter file.z  excluded due to filter string 'z# NOT excluded due to not matching ')r   r   tile_descriptionminimum_compute_capabilitymaximum_compute_capabilitySharedMemPerCCCalculateSmemUsager8   r   r   procedural_namer   keysr   r   r   r   r   r   r   r   )r   rn   enabledccrh   name_substrs         r   filterzManifest.filterr  s    $%G0  	y)D	D	D	y)D	D	D
N
"
"nR&8<Ny<Y<Y&Y&Y U
4"## I,DH_,_,_U$$&&D t&++----U 4 [g * \ \+&&{D99 	\
--W$WWWWW
X
X
X'
%
--Z$ZZ;ZZZ
[
[
[
[ 1 [ [+&&{D99 	[
--V$VV{VVV
W
W
W'
%
--Y$YY+YYY
Z
Z
Z
Z
4"##a''		 	 t'>	?	? FFFFGGGTTTTUUU 0 Z Z		$	$[$	7	7 ZUUUkUUUVVVXXXXXXYYYY Nr   c                 :   |                      |          rE| j                            |                                           || j        |                                <   |                                }|j        }|j        | j        	                                vri | j        |j        <   || j        |j                 vri | j        |j                 |<   || j        |j                 |         	                                vrg | j        |j                 |         |<   | j        |j                 |         |                             |           | xj
        dz  c_
        dS t                              d                    |                                                     dS )zT
      Inserts the operation.

      operation_kind -> configuration_name -> []
       zCulled {} from manifestN)r   r   r;   r   r   r7   r   r   r=   r   rz   r   r   r   )r   rn   r7   r4   s       r   r;   zManifest.append  s}    {{9 S
""9#<#<#>#>???=Fdi7799: %7799 ~f		!)=)=)?)?	?	?46	01	ty'?@	@	@<>	01&9	4?93K#LV#T#Y#Y#[#[	[	[PR	01&9:LM
oi./78JKRRS\]]]
amm-44Y5N5N5P5PQQRRRRRr   c                    t          |d          5 }t          di           }|                    |dz              |                    dt          |                    dd                    z             t
          j                            | j        d          }| j	        
                                D ]a}t          |         }t
          j                            ||d| d	                              dd          }	|                    d
|	 d           b|                    d           | j	        
                                D ](}t          | j	        |         
                                          D ]}
t          ||         |
         
                                          D ]}t          dt          |
          t          |         |d          }|                    |dz              ||         |
         |         D ];}|                    dt          |                    dd                    z             <|                    d           | j        r|                     ||           *	 d d d            d S # 1 swxY w Y   d S )Nr   z:cutlass_target_sources(cutlass_library_objs PRIVATE
      z

z    %s
\/	generatedr   r   z    r   z)

zJcutlass_add_cutlass_library(
      SUFFIX ${kind}_sm${min_cc}_${subclass}
)r4   r   subclassz)
)r(   r<   r*   r%   replacer    r!   r"   r   r=   r   r#   r9   r   #emit_disable_full_archs_compilation)r   manifest_pathr'   r+   manifest_filetarget_textr   r   kind_strall_kind_filer4   r   source_files                r   emit_manifest_cmakezManifest.emit_manifest_cmake  s   	mS	!	! R]& (
 k+.///*s>+A+A$+L+L'M'MMNNNw||D$7EEn/&&(( 6 6$%d+^X?^h?^?^?^__gghlnqrr4=4445555'"""/&&(( R R$T_T27799:: 	R 	RF d!3F!;!@!@!B!BCC 	' 	'h, .V&8&>HVVX XK f 4555+D1&9(C T T!!*s;3F3FtS3Q3Q/R/R"RSSSS&&&&0 R44]LQQQ	RRR R R R R R R R R R R R R R R R R Rs   II99I= I=c                    d }d }d }d }d }d }t          |                                          D ]}||         D ]}	 ||	          r ||	          r |h d|	          }
nU ||	          r |dh|	          }
n< ||	          r |d	d
h|	          }
n"t          d                    |	                    |                     d                    t          |	                    dd                    |
                     Ȍd S )Nc                     d S r1   r2   rh   s    r   
for_hopperz@Manifest.emit_disable_full_archs_compilation.<locals>.for_hopper  s    
$r   c                 *    d| v pd| v pd| v pd| v od| v S )N1681616832168641688tf32r2   r  s    r   
for_amperez@Manifest.emit_disable_full_archs_compilation.<locals>.for_ampere  s=    D 6T/6T/6 T>4fn6r   c                     d| v rd| vpd| v S )Nr
  r  8816r2   r  s    r   
for_turingz@Manifest.emit_disable_full_archs_compilation.<locals>.for_turing  s$    D.7V4%7 !D.!r   c                 
    d| v S )N884r2   r  s    r   	for_voltaz?Manifest.emit_disable_full_archs_compilation.<locals>.for_volta  s    $
r   c                 ,    |                      d          S )Nz.cpp)endswithr  s    r   is_cppz<Manifest.emit_disable_full_archs_compilation.<locals>.is_cpp  s    v&&
&r   c                 $   | t          t          j                  z  }|t                      k    r;t          d                    |t          t          j                  |                     d                    t          t          |                    S )Nz
                    Empty archs set for file {} after taking
                    the intersection of {} (global requested archs) and
                    {} (per file requested archs)
                     )r   r   r   r   r   r"   mapr%   )archsr   intersected_archss      r   ,get_src_archs_str_given_requested_cuda_archszbManifest.emit_disable_full_archs_compilation.<locals>.get_src_archs_str_given_requested_cuda_archs  s    #c$*L&M&MM
#%%''  {C0R,S,SUZ[[] ] ] XXc#'899:::r   >   P   W   Z   K   F   H   zRPer file archs are not set {}, as there is no rule specified for this file patternz1cutlass_apply_cuda_gencode_flags({} SM_ARCHS {})
r   r   )r9   r   r   r   r*   r%   r   )r   r+   r  r  r  r  r  r  r4   r   	archs_strs              r   r   z,Manifest.emit_disable_full_archs_compilation  s     6 6 6! ! !  ' ' '
; 
; 
; <,,..// M M&'/ 	M 	MKvk"" 	MK(( MHHWbcc		K(( MHH"{[[		;'' MHH"bS^__		"#w#~#~  @K  $L  $L  M  M  M T [ [\_`k`s`stxz}`~`~\\  BK  !L  !L  M  M  M  M	MM Mr   c                    t           j        t          i}t           j        t          i}t           j        t          i}t
          j                            | j        d          }t
          j        	                    |          rt          j        |           t          j        |            ||         || j        | j                  5 }|j        }| j                                        D ]"}|                    t&          |                    #	 d d d            n# 1 swxY w Y   i }	| j                                        D ]4}
i |	|
<   | j        |
                                         D ]}i |	|
         |<   5| j                                        D ]\  }}t+          |                                          D ] \  }} ||         |||| j                  5 }|                                D ]a\  }}t,                              d| dt1          |           dt1          |          dk    rdnd d           |                    ||           b|j                                        D ]X\  }}||	|         |         vrg |	|         |         |<   |	|         |         |                             |j        |                    Y	 d d d            n# 1 swxY w Y   " ||         ||| j                  5 }|                    |           d d d            n# 1 swxY w Y   t
          j                            |d	          }|                     |||	           d S )
Nr   z	Emitting z with z
 operationr   rq   sr   zmanifest.cmake)GeneratorTargetLibraryrL   r   rv   r    r!   r"   r   existsshutilrmtreerf   rz   r   r'   r=   r   r>   r#   r:   r9   r   infor8   r+   extendr  )r   targetoperation_emitterskind_emittersinterface_emittersr   iface_emitterr'   r   r+   r   r4   opsr,   operation_kind_emitterr7   r=   r   filesr   s                       r   r>   zManifest.emit-  sg    7 3M
 3 W\\$"5{CCN 
w~~n%% $mN###H^	#	F	#ND4H$)	T	T ?Xe$3n O0022 ? ?.-n=>>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
 L$$&& ( (l4OD)..00 ( (&%'T6""(  $4466 ) )$*399;;$7$7 	q 	q
 &.''PTPYZZ 	q^t0>0D0D0F0F H H, *LL  A%7  A  As:  A  A`cdn`o`ost`t`tZ\Z\z}  A  A  A  B  B  B"''(:JGGGG!7!D!J!J!L!L q qoh|N;FCCC?Al>*628<(0:AABXBefnBoppppq	q 	q 	q 	q 	q 	q 	q 	q 	q 	q 	q 	q 	q 	q 	q != KK )Oe##C((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) GLL1ABBM]NLIIIIIs8   ADDDC)KKK)LL	L	r1   )r   r   r   )rG   rH   rI   r   r   r   r   r   r   r   r;   r  r   r%  r&  r>   r2   r   r   r   r     s        E' E' E' E'N. . .
   *      G G GVS S SDR R R<-M -M -M` *1 5J 5J 5J 5J 5J 5Jr   r   )"rJ   enumloggingos.pathr    r(  builtinshasattrr   ImportErrorcutlass_library.librarycutlass_library.gemm_operation cutlass_library.rank_k_operation!cutlass_library.rank_2k_operationcutlass_library.trmm_operationcutlass_library.symm_operation cutlass_library.conv2d_operation cutlass_library.conv3d_operationlibrarygemm_operationrank_k_operationrank_2k_operationtrmm_operationsymm_operationconv2d_operationconv3d_operation	getLoggerrG   r   r   rL   rv   r   r   r2   r   r   <module>rK     so  B 
    !///WX/00 E5Kt5S5S
+C
D
DD''''....00001111........000000000 ! ! !    !!!!          ! '
H
%
%j  j  j  j  j  j  j  j ZE  E  E  E  E  E  E  E Ni  i  i  i  i  i  i  i \	 	 	 	 	 	 	 	tJ tJ tJ tJ tJ tJ tJ tJ tJ tJs   AA %A>=A>