§
    Ÿ²Åj+R  ã                   óú  — d Z ddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlZg d¢Zd(deddfd„Zdefd	„Zd(deddfd
„Zdefd„Zd(deddfd„Zdefd„Zdeddfd„Zdefd„Zdeddfd„Zdefd„Zd)dededdfd„Zdefd„Zdeeeeef         fd„Zdeeef         fd„Zdeddfd„Z d*de
e         defd„Z!d*de
e         defd„Z"deddfd„Z#dede$e         fd „Z%d+d!„Z&d"ed#eddfd$„Z'd+d%„Z(ded&eddfd'„Z)dS ),a}  
This module exposes a TunableOp interface.

Some operations, such as GEMMs, could be implemented using more than one library
or more than one technique. For example, a GEMM could be implemented for CUDA or
ROCm using either the blas or blasLt libraries. Further, ROCm's rocblas and
hipblaslt libraries allow the user to query for all possible algorithms and then
choose one. How does one know which implementation is the fastest and should be
chosen? That's what TunableOp provides.

Enabling TunableOp and Tuning Separately
========================================

The TunableOp feature is enabled separately from enabling the tuning phase
itself. Enabling TunableOp means that PyTorch will replace any standard
operators with their Tunable implementations. Any call to a TunableOp first
checks whether it has already been tuned for the given operator inputs. If so,
it will immediately call the tuned operation; no further tuning will take place
even when the tuning setting is enabled. Instead if no tuning result is found,
and tuning is enabled, the TunableOp will benchmark every registered
implementation of that operator for the given set of inputs and select the
fastest.

File Input and Output
=====================

The first time any TunableOp is invoked, the internal database of tuned
operations will be prepared by attempting to read the results from the given
file. The default filename is 'tunableop_results.csv'. To support tuning when
multiple GPUs are used across multiple processes, the GPU device ordinal is
automatically inserted into the filename to avoid multiple processes overwriting
the same file.

If tuning is enabled and new tunings are discovered during the course of your
workload, it will also write out to this same filename with all tunings, both
the ones it read in at startup as well as the new ones found at runtime. This
can be used, for example, to build up a tunings file across many workloads by
reusing the same file. The output file is automatically created when the
application terminates. This behavior can be controlled by the C++ and Python
APIs but not the environment variables.

Assuming you specified a filename, you'll end up with a CSV file with contents
like so::

  Validator,PT_VERSION,2.2.0
  Validator,ROCM_VERSION,6.0.0.0-12969-1544e39
  Validator,HIPBLASLT_VERSION,0.6.0-a9c5cc7
  Validator,ROCBLAS_VERSION,4.0.0-72e57364-dirty
  GemmTunableOp_float_NT,nt_25088_4096_64,1219,1.262
  GemmTunableOp_float_NT,nt_4096_4096_64,1216,0.033

Note the "Validator" lines. If you change a library version, or ROCm version, or
PyTorch version, TunableOp will detect this and reject the tunings file because
the prior tunings are likely affected by other software changes.

The remaining lines are the tuned solutions for each TunableOp encountered
during your execution. Each line consists of 4 comma-separated fields: operator
name, operator parameters, solution name, and average execution time. The
execution time is an optional field. The CSV file can be edited, but with
caution. For example, the solution name (field 3) can be changed to "Default"
and it will fall back to the original PyTorch untuned implementation. Or, in the
case of ROCm's hipBLAS or hipBLASLt libraries, if you know the specific solution
index you can override the solution that TunableOp selected by replacing the
value. The operator name and parameters (fields 1 and 2) are internally named
and should not be modified. In the case of GemmTunableOp, field 1 indicates the
datatype and whether the inputs are transposed (T) or not (N) and field 2
indicates the M, N, K input shapes.

There is an option to enable verbose output but it is only recommended for
debugging purposes. This will produce a lot of diagnostic messages but may be
useful to see if TunableOp is being used at all. Otherwise, TunableOp is
completely silent, besides file output, unless there is a warning or error
during its use. The verbose option is only available by setting the environment
variable PYTORCH_TUNABLEOP_VEROBSE=1.

A Note on Tuning Behavior
=========================

Tuning an operator consists of iterating through the list or registered
implementations and profiling each one. The profile is established by running a
single implementation in a loop multiple times and taking the average execution
time.

By default, each possible solution for a given operator will be run for either
100 iterations or as many iterations that can be run within 30ms, whichever is
smaller, and its average execution will be calculated. The fastest solution
among all that were successfully profiled will be chosen. A profile might fail
if the given solution doesn't achieve the same accuracy as the default
implementation or if the solution returns an error code.

Current Tunable Operators
=========================

TunableGemm for ROCm
--------------------

Currently only a TunableGemm for ROCm is implemented. Note that CUDA builds of
PyTorch will function correctly when using TunableOp but the only solution
available to CUDA builds is the 'Default' implementation i.e. the original
cuBLAS default, now called through TunableOp. Any call to at::cuda::blas::gemm()
or ::bgemm() will be routed through TunableOp when enabled. Calling gemm() for a
given set of input arguments (transa, transb, m, n, k) will attempt to use the
fastest available implementation across both rocblas and hipblaslt.

Tuning Context
==============

The behavior of TunableOp is currently manipulated through environment
variables, the C++ interface of at::cuda::tunable::getTuningContext(), or the
torch.cuda.tunable python interfaces that wrap the C++ TuningContext. The
environment variables take precedence over any setting you manipulate using the
C++ or Python APIs.

é    N)ÚOptionalÚTuple)ÚenableÚ
is_enabledÚtuning_enableÚtuning_is_enabledÚrecord_untuned_enableÚrecord_untuned_is_enabledÚset_max_tuning_durationÚget_max_tuning_durationÚset_max_tuning_iterationsÚget_max_tuning_iterationsÚset_filenameÚget_filenameÚget_resultsÚget_validatorsÚwrite_file_on_exitÚ
write_fileÚ	read_fileÚtune_gemm_in_fileÚmgpu_tune_gemm_in_fileTÚvalÚreturnc                 óD   — t           j                             | ¦  «         dS )z@This is the big on/off switch for all TunableOp implementations.N)ÚtorchÚ_CÚ_cuda_tunableop_enable©r   s    úCC:\Projects\Historical\venv\Lib\site-packages\torch/cuda/tunable.pyr   r   •   s   € å	„H×#Ò# CÑ(Ô(Ð(Ð(Ð(ó    c                  ó>   — t           j                             ¦   «         S )z1Returns whether the TunableOp feature is enabled.)r   r   Ú_cuda_tunableop_is_enabled© r    r   r   r   š   s   € åŒ8×.Ò.Ñ0Ô0Ð0r    c                 óD   — t           j                             | ¦  «         dS )z�Enable tuning of TunableOp implementations.

    When enabled, if a tuned entry isn't found, run the tuning step and record
    the entry.
    N)r   r   Ú_cuda_tunableop_tuning_enabler   s    r   r   r   Ÿ   s    € õ 
„H×*Ò*¨3Ñ/Ô/Ð/Ð/Ð/r    c                  ó>   — t           j                             ¦   «         S )z7Returns whether TunableOp implementations can be tuned.)r   r   Ú!_cuda_tunableop_tuning_is_enabledr#   r    r   r   r   ¨   s   € åŒ8×5Ò5Ñ7Ô7Ð7r    c                 óD   — t           j                             | ¦  «         dS )z—Enable recording untuned of TunableOp perations for offline tuning.

    When enabled, if a tuned entry isn't found, write it to the untuned file.
    N)r   r   Ú_cuda_record_untuned_enabler   s    r   r	   r	   ­   s    € õ
 
„H×(Ò(¨Ñ-Ô-Ð-Ð-Ð-r    c                  ó>   — t           j                             ¦   «         S )zEReturns whether TunableOp operations are recorded for offline tuning.)r   r   Ú_cuda_record_untuned_is_enabledr#   r    r   r
   r
   µ   s   € åŒ8×3Ò3Ñ5Ô5Ð5r    Údurationc                 óD   — t           j                             | ¦  «         dS )zÚSet max time in milliseconds to spend tuning a given solution.

    If both max tuning duration and iterations are set, the smaller of the two
    will be honored. At minimum 1 tuning iteration will always be run.
    N)r   r   Ú'_cuda_tunableop_set_max_tuning_duration)r,   s    r   r   r   º   s    € õ 
„H×4Ò4°XÑ>Ô>Ð>Ð>Ð>r    c                  ó>   — t           j                             ¦   «         S )z.Get max time to spend tuning a given solution.)r   r   Ú'_cuda_tunableop_get_max_tuning_durationr#   r    r   r   r   Ã   s   € åŒ8×;Ò;Ñ=Ô=Ð=r    Ú
iterationsc                 óD   — t           j                             | ¦  «         dS )zÚSet max number of iterations to spend tuning a given solution.

    If both max tuning duration and iterations are set, the smaller of the two
    will be honored. At minimum 1 tuning iteration will always be run.
    N)r   r   Ú)_cuda_tunableop_set_max_tuning_iterations)r1   s    r   r   r   È   s    € õ 
„H×6Ò6°zÑBÔBÐBÐBÐBr    c                  ó>   — t           j                             ¦   «         S )z4Get max iterations to spend tuning a given solution.)r   r   Ú)_cuda_tunableop_get_max_tuning_iterationsr#   r    r   r   r   Ñ   s   € åŒ8×=Ò=Ñ?Ô?Ð?r    FÚfilenameÚinsert_device_ordinalc                 óF   — t           j                             | |¦  «         dS )a/  Set the filename to use for input/output of tuning results.

    If :attr:`insert_device_ordinal` is ``True`` then the current device ordinal
    will be added to the given filename automatically. This can be used in a
    1-process-per-gpu cenario to ensure all processes write to a separate file.
    N)r   r   Ú_cuda_tunableop_set_filename)r6   r7   s     r   r   r   Ö   s#   € õ 
„H×)Ò)¨(Ð4IÑJÔJÐJÐJÐJr    c                  ó>   — t           j                             ¦   «         S )zGet the results filename.)r   r   Ú_cuda_tunableop_get_filenamer#   r    r   r   r   à   s   € åŒ8×0Ò0Ñ2Ô2Ð2r    c                  ó>   — t           j                             ¦   «         S )zReturn all TunableOp results.)r   r   Ú_cuda_tunableop_get_resultsr#   r    r   r   r   å   s   € åŒ8×/Ò/Ñ1Ô1Ð1r    c                  ó>   — t           j                             ¦   «         S )z Return the TunableOp validators.)r   r   Ú_cuda_tunableop_get_validatorsr#   r    r   r   r   ê   s   € åŒ8×2Ò2Ñ4Ô4Ð4r    c                 óD   — t           j                             | ¦  «         dS )a  During Tuning Context destruction, write file to disk.

    This is useful as a final flush of your results to disk if your application
    terminates as result of normal operation or an error. Manual flushing of
    your results can be achieved by manually calling ``write_file()``.N)r   r   Ú"_cuda_tunableop_write_file_on_exitr   s    r   r   r   ï   s    € õ 
„H×/Ò/°Ñ4Ô4Ð4Ð4Ð4r    c                 ó`   — | €t          ¦   «         } t          j                             | ¦  «        S )zfWrite results to a CSV file.

    If :attr:`filename` is not given, ``get_filename()`` is called.
    )r   r   r   Ú_cuda_tunableop_write_file©r6   s    r   r   r   ø   s)   € ð
 ÐÝ‘>”>ˆÝŒ8×.Ò.¨xÑ8Ô8Ð8r    c                 ó`   — | €t          ¦   «         } t          j                             | ¦  «        S )zqRead results from a TunableOp CSV file.

    If :attr:`filename` is not given, ``get_filename()`` is called.
    )r   r   r   Ú_cuda_tunableop_read_filerD   s    r   r   r     s)   € ð
 ÐÝ‘>”>ˆÝŒ8×-Ò-¨hÑ7Ô7Ð7r    c                 ó(  — t          ¦   «         sJ ‚t          ¦   «         sJ ‚t          j                             ¦   «         }t          | ¦  «        5 }|D ]'}|                     d¦  «        rt          ||¦  «         Œ(	 ddd¦  «         dS # 1 swxY w Y   dS )ztune GEMM in file.©ÚGemmÚ
ScaledGemmN)r   r   r   ÚcudaÚcurrent_deviceÚopenÚ
startswithÚ_process_single_offline_gemm)r6   ÚdeviceidÚfileÚlines       r   r   r     sß   € õ ‰<Œ<ÐÐˆ<ÝÑÔÐÐÐåŒz×(Ò(Ñ*Ô*€Hå	ˆh‰Œð =˜4Øð 	=ð 	=ˆDØ�ŠÐ5Ñ6Ô6ð =Ý,¨T°8Ñ<Ô<Ð<øð	=ð=ð =ð =ñ =ô =ð =ð =ð =ð =ð =ð =ð =øøøð =ð =ð =ð =ð =ð =s   Á+BÂBÂBÚfilename_patternc                 óþ   — t          ¦   «         }t          j        | ¦  «        D ]Y}t          |¦  «        5 }|D ],}|                     d¦  «        r|                     |¦  «         Œ-	 ddd¦  «         n# 1 swxY w Y   ŒZ|S )zOProcess multiple untuned results file and return a set with duplicates removed.rH   N)ÚsetÚglobrM   rN   Úadd)rS   Úunique_gemm_entriesÚ	file_pathrQ   rR   s        r   Ú&_gather_unique_untuned_gemm_from_filesrZ     sË   € å™%œ%Ðå”YÐ/Ñ0Ô0ð 2ð 2ˆ	Ý�)‰_Œ_ð 	2 Øð 2ð 2�Ø—?’?Ð#9Ñ:Ô:ð 2Ø'×+Ò+¨DÑ1Ô1Ð1øð2ð	2ð 	2ð 	2ñ 	2ô 	2ð 	2ð 	2ð 	2ð 	2ð 	2ð 	2øøøð 	2ð 	2ð 	2ð 	2øð
 Ðs   ´0A1Á1A5	Á8A5	c                  ó0  — t          ¦   «         } g }t          ¦   «         }|�F|dk    r@|                     d¦  «        }|dk    r"|dk    r|d|dz
  …         dz   ||d…         z   }nSd}nPt          j        d¦  «        }|�|dk    rd	}n1d
|v r|                     d
d¦  «        }n|                     dd¦  «        }d|v sJ ‚d}t          j        |¦  «        }t          |¦  «        }|D ]s}	t          |	¦  «        5 }
|
D ]D}| 	                    d¦  «        r|s| 
                    |¦  «         Œ/|                      |¦  «         ŒE	 ddd¦  «         n# 1 swxY w Y   d}Œt|                     dd¦  «        }t          |d¦  «        5 }|D ]}|                     |¦  «         Œ| D ]}|                     |¦  «         Œ	 ddd¦  «         n# 1 swxY w Y   t          d|¦  «        D ]:}|                     dt          |¦  «        ¦  «        }t          j        ||¦  «         Œ;dS )zMGather results from multiple tunableop results file and create a single file.NÚ ú.éÿÿÿÿr   é   ú?ÚPYTORCH_TUNABLEOP_FILENAMEztunableop_results?.csvz%dz?.FÚ	ValidatorTÚ_full0ÚwÚ0)rU   r   ÚfindÚosÚgetenvÚreplacerV   ÚlenrM   rN   ÚappendrW   ÚwriteÚrangeÚstrÚshutilÚcopy)Ú
gemm_linesÚvalidator_linesÚresults_filenameÚdot_posrS   Úresults_filename_envÚ	FirstFileÚmatching_filesÚnum_matching_filesrY   rQ   rR   Úoutput_fileÚout_fileÚiÚduplicate_files                   r   Ú_gather_tunableop_resultsr}   '  s  € å‘”€JØ€Oõ $‘~”~Ðð 	Ð$Ð)9¸RÒ)?Ð)?à"×'Ò'¨Ñ,Ô,ˆØ�bŠ=ˆ=˜W qš[˜[ð !  7¨Q¡; Ô/°#Ñ5Ð8HÈÈÈÔ8RÑRð Ðð  "ÐÐå!œyÐ)EÑFÔFÐØÐ'Ð+?À2Ò+EÐ+EØ7ÐÐØÐ)Ð)Ð)Ø3×;Ò;¸DÀ#ÑFÔFÐÐà3×;Ò;¸CÀÑFÔFÐàÐ"Ð"Ð"Ð"Ð"à€IÝ”YÐ/Ñ0Ô0€NÝ˜^Ñ,Ô,ÐØ#ð 
ð 
ˆ	Ý�)‰_Œ_ð 	) Øð )ð )�Ø—?’? ;Ñ/Ô/ð )Ø%ð 5à'×.Ò.¨tÑ4Ô4Ð4øà—N’N 4Ñ(Ô(Ð(Ð(ð)ð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð ˆ	ˆ	à"×*Ò*¨3°Ñ9Ô9€Kå	ˆk˜3Ñ	Ô	ð ! 8Ø#ð 	!ð 	!ˆDØ�NŠN˜4Ñ Ô Ð Ð Øð 	!ð 	!ˆDØ�NŠN˜4Ñ Ô Ð Ð ð	!ð!ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !õ �1Ð(Ñ)Ô)ð 1ð 1ˆØ$×,Ò,¨Sµ#°a±&´&Ñ9Ô9ˆÝŒ�K Ñ0Ô0Ð0Ð0ð1ð 1s%   Ã5AE
Å
E	ÅE	Å>5G Ç GÇGÚuntuned_gemm_lineÚgpu_idc                 ó"  — dt          |¦  «        z   }t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j	        t          j
        t          j        dœ
}|                      ¦   «                              d¦  «        dd…         }|d                              d¦  «        }d}d}d}d}	|dk    rM|d                              d¦  «        \  }
}}|d         dk    }|d	         dk    }|                     |¦  «        }nÂ|d                              d¦  «        }|d         }
|d	         dz   |d         z   }|d
         dz   |d         z   }|d         dz   |d         z   }|d         d         dk    }|d         d	         dk    }|                     |¦  «        }|                     |¦  «        }|                     |¦  «        }	d„ |d	                              d¦  «        d	d…         D ¦   «         \  }}}|
dk    rŸ|r*t          j        ||||¬¦  «                             ¦   «         nt          j        ||||¬¦  «        }|r*t          j        ||||¬¦  «                             ¦   «         nt          j        ||||¬¦  «        }t          j        ||¦  «         dS |
dk    râd„ |d	                              d¦  «        dd…         D ¦   «         \  }|rt          j        |||||¬¦  «        nt          j        |||||¬¦  «        }|rt          j        |||||¬¦  «        nt          j        |||||¬¦  «        }|r|                     d	d¦  «        n|}|r|                     d	d¦  «        n|}t          j        ||¦  «         dS |
dk    rÛd}d}t          j        d|¬¦  «        }t          j        d|¬¦  «        }|r,t          j        ||f|||¬¦  «                             ¦   «         nt          j        ||f|||¬¦  «        }|r,t          j        ||f|||¬¦  «                             ¦   «         nt          j        ||f|||¬¦  «        }t          j        |||||	¬¦  «         dS |
dk    rè||k    sJ ‚|r*t          j        ||||¬¦  «                             ¦   «         nt          j        ||||¬¦  «        }|rt          j        ||||¬¦  «        n)t          j        ||||¬¦  «                             ¦   «         }|rt          j        |||¬¦  «        nt          j        |||¬¦  «        }t          j        j                             |||¦  «         dS t7          j        d|
› �¦  «         dS )zProcess a single untuned GEMM.zcuda:)
ÚfloatÚdoubleÚBFloat16ÚHalfzc10::complex<double>zc10::complex<float>ÚFloat8_e4m3fnÚFloat8_e5m2ÚFloat8_e4m3fnuzÚFloat8_e5m2fnuzú,Nr   Ú_é   ÚTr_   é   é   é   é   é   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r#   ©Úint©Ú.0Úgs     r   ú
<listcomp>z0_process_single_offline_gemm.<locals>.<listcomp>“  s   € ÐAÐAÐA˜A•�Q‘”ÐAÐAÐAr    ÚGemmTunableOp)ÚdtypeÚdeviceÚGemmStridedBatchedTunableOpc                 ó,   — g | ]}t          |¦  «        ‘ŒS r#   r“   r•   s     r   r˜   z0_process_single_offline_gemm.<locals>.<listcomp>¡  s   € Ð?Ð?Ð?˜!�s�1‰vŒvÐ?Ð?Ð?r    ÚScaledGemmTunableOpg      Ð?g      è?gš™™™™™é?)r›   gÍÌÌÌÌÌì?)Úscale_aÚscale_bÚ	out_dtypeÚGemmAndBiasTunableOpzerror: unknown op )rn   r   Úfloat32Úfloat64Úbfloat16ÚhalfÚ
complex128Ú	complex64Úfloat8_e4m3fnÚfloat8_e5m2Úfloat8_e4m3fnuzÚfloat8_e5m2fnuzÚstripÚsplitÚcountÚgetÚrandÚtÚmmÚ	transposeÚbmmÚtensorÚfullÚ
_scaled_mmÚnnÚ
functionalÚlinearÚwarningsÚwarn)r~   r   rP   Ú
dtype_dictÚuntuned_gemmÚunderscore_countrš   ÚdtypeAÚdtypeBÚdtypeCÚop_sigÚ	data_typeÚlayoutÚtransAÚtransBÚuntuned_gemm_tempÚ
data_typeAÚ
data_typeBÚ
data_typeCÚnÚmÚkÚmatAÚmatBÚbÚfillAÚfillBÚscaleAÚscaleBÚXÚbiass                                  r   rO   rO   f  s	  € ð �˜V™œÑ$€Hõ ”Ý”-Ý”NÝ”
Ý %Ô 0Ý$œÝÔ,ÝÔ(Ý Ô0Ý Ô0ðð €Jð %×*Ò*Ñ,Ô,×2Ò2°3Ñ7Ô7¸¸¸Ô:€Là# A”×,Ò,¨SÑ1Ô1Ðð €EØ€FØ€FØ€Fà˜1ÒÐØ&2°1¤o×&;Ò&;¸CÑ&@Ô&@Ñ#ˆ�˜FØ˜”˜cÒ!ˆØ˜”˜cÒ!ˆØ—’˜yÑ)Ô)ˆˆà(¨œO×1Ò1°#Ñ6Ô6ÐØ" 1Ô%ˆØ& qÔ)¨CÑ/Ð2CÀAÔ2FÑFˆ
Ø& qÔ)¨CÑ/Ð2CÀAÔ2FÑFˆ
Ø& qÔ)¨CÑ/Ð2CÀAÔ2FÑFˆ
Ø" 1Ô% aÔ(¨CÒ/ˆØ" 1Ô% aÔ(¨CÒ/ˆØ—’ 
Ñ+Ô+ˆØ—’ 
Ñ+Ô+ˆØ—’ 
Ñ+Ô+ˆàAÐA ¨a¤×!6Ò!6°sÑ!;Ô!;¸A¸a¸CÔ!@ÐAÑAÔA�I€Qˆˆ1Ø�Ò Ð ð ð@�EŒJ�q˜! 5°Ð:Ñ:Ô:×<Ò<Ñ>Ô>Ð>å”˜A˜q¨°hÐ?Ñ?Ô?ð 	ð ð@�EŒJ�q˜! 5°Ð:Ñ:Ô:×<Ò<Ñ>Ô>Ð>å”˜A˜q¨°hÐ?Ñ?Ô?ð 	õ
 	Œ��tÑÔÐÐÐØ	Ð0Ò	0Ð	0Ø?Ð?˜|¨Aœ×4Ò4°SÑ9Ô9¸!¸A¸#Ô>Ð?Ñ?Ô?‰ˆð ðC�EŒJ�q˜!˜Q e°HÐ=Ñ=Ô=Ð=å”˜A˜q !¨5¸ÐBÑBÔBð 	ð ðC�EŒJ�q˜!˜Q e°HÐ=Ñ=Ô=Ð=å”˜A˜q !¨5¸ÐBÑBÔBð 	ð
 (.Ð7ˆt�~Š~˜a Ñ#Ô#Ð#°4ˆØ'-Ð7ˆt�~Š~˜a Ñ#Ô#Ð#°4ˆÝŒ	�$˜ÑÔÐÐÐØ	Ð(Ò	(Ð	(ØˆØˆÝ”˜c¨(Ð3Ñ3Ô3ˆÝ”˜c¨(Ð3Ñ3Ô3ˆð ðJ�EŒJ˜˜1�v˜u¨F¸8ÐDÑDÔD×FÒFÑHÔHÐHå”˜Q ˜F E°ÀÐIÑIÔIð 	ð ðJ�EŒJ˜˜1�v˜u¨F¸8ÐDÑDÔD×FÒFÑHÔHÐHå”˜Q ˜F E°ÀÐIÑIÔIð 	õ
 	Ô˜˜t¨V¸VÈvÐVÑVÔVÐVÐVÐVØ	Ð)Ò	)Ð	)à˜ÒÐÐÐð ð@�EŒJ�q˜! 5°Ð:Ñ:Ô:×<Ò<Ñ>Ô>Ð>å”˜A˜q¨°hÐ?Ñ?Ô?ð 	
ð ðD�EŒJ�q˜! 5°Ð:Ñ:Ô:Ð:å”˜A˜q¨°hÐ?Ñ?Ô?×AÒAÑCÔCð 	ð ð=�EŒJ�q ¨hÐ7Ñ7Ô7Ð7å”˜A U°8Ð<Ñ<Ô<ð 	õ
 	ŒÔ×"Ò" 1 d¨DÑ1Ô1Ð1Ð1Ð1åŒÐ3¨6Ð3Ð3Ñ4Ô4Ð4Ð4Ð4r    c                  óF   — t          ¦   «         sJ ‚t          ¦   «         sJ ‚dS )zHelper function for multi-GPU tuning case. Need to check that TunableOp feature
    is enabled and that tuning is enabled.
    N)r   r   r#   r    r   Ú_check_tuning_assertionsrÚ   ×  s+   € õ ‰<Œ<ÐÐˆ<ÝÑÔÐÐÐÐÐr    Únum_gpusc                 óJ  — t          | ¦  «        }t          j                             ¦   «         }d|cxk    r|k    sn J ‚t	          j        d¦  «        }g }g }g }d}t          j                             ||¬¦  «        5 }	t          |¦  «        D ]1}
|	 
                    t          ¦  «        }|                     |¦  «         Œ2t          j                             |¦  «        D ]}|                     ¦   «          Œ|D ];}|	 
                    t          ||¦  «        }|                     |¦  «         |dz   |z  }Œ<t          j                             |¦  «        D ]}|                     ¦   «          Œt          |¦  «        D ]1}
|	 
                    t           ¦  «        }|                     |¦  «         Œ2t          j                             |¦  «        D ]}|                     ¦   «          Œ	 ddd¦  «         n# 1 swxY w Y   t          j                             ¦   «          t%          ¦   «          dS )zDProcess one or more files and distribute work over one or more GPUs.r_   Úspawnr   )Úmax_workersÚ
mp_contextN)rZ   r   rK   Údevice_countÚmpÚget_contextÚ
concurrentÚfuturesÚProcessPoolExecutorrm   ÚsubmitrÚ   rk   Úas_completedÚresultrO   r   Úsynchronizer}   )rS   rÛ   rX   Ú
total_gpusrß   Úchecksrä   Úflush_resultsÚhÚexecutorr—   ÚcheckrR   ÚfutureÚflush_results                  r   r   r   ß  sf  € å@ÐAQÑRÔRÐå”×(Ò(Ñ*Ô*€Jà�Ð&Ð&Ò&Ð&˜JÒ&Ð&Ð&Ð&Ð&Ð&å” Ñ(Ô(€Jà€FØ€GØ€Mð 	
€AÝ	Ô	×	/Ò	/Ø¨ð 
0ñ 
ô 
ð "à	õ �x‘”ð 	!ð 	!ˆAØ—O’OÕ$<Ñ=Ô=ˆEØ�MŠM˜%Ñ Ô Ð Ð åÔ'×4Ò4°VÑ<Ô<ð 	ð 	ˆEØ�LŠL‰NŒNˆNˆNà'ð 	#ð 	#ˆDØ—_’_Õ%AÀ4ÈÑKÔKˆFØ�NŠN˜6Ñ"Ô"Ð"Ø�Q‘˜(Ñ"ˆAˆAå Ô(×5Ò5°gÑ>Ô>ð 	ð 	ˆFØ�MŠM‰OŒOˆOˆOå�x‘”ð 	/ð 	/ˆAØ#Ÿ?š?­:Ñ6Ô6ˆLØ× Ò  Ñ.Ô.Ð.Ð.å&Ô.×;Ò;¸MÑJÔJð 	"ð 	"ˆLØ×ÒÑ!Ô!Ð!Ð!ð	"ð9"ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "õ> 
„J×ÒÑÔÐåÑÔÐÐÐs   Á<E#G,Ç,G0Ç3G0)T)F)N)r   N)*Ú__doc__Úconcurrent.futuresrã   rV   Úmultiprocessingrá   rg   ro   r¼   Útypingr   r   r   Ú__all__Úboolr   r   r   r   r	   r
   r”   r   r   r   r   rn   r   r   r�   r   r   r   r   r   r   rU   rZ   r}   rO   rÚ   r   r#   r    r   ú<module>rø      s·  ððqð qðd Ð Ð Ð Ø €€€Ø Ð Ð Ð Ø 	€	€	€	Ø €€€Ø €€€Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à €€€ðð ð €ð.)ð )�ð ) ð )ð )ð )ð )ð
1�Dð 1ð 1ð 1ð 1ð
0ð 0�tð 0 tð 0ð 0ð 0ð 0ð8˜4ð 8ð 8ð 8ð 8ð
.ð .˜tð .¨tð .ð .ð .ð .ð6 4ð 6ð 6ð 6ð 6ð
? cð ?¨dð ?ð ?ð ?ð ?ð> ð >ð >ð >ð >ð
C¨#ð C°$ð Cð Cð Cð Cð@ 3ð @ð @ð @ð @ð
Kð K˜3ð K°tð KÈð Kð Kð Kð Kð3�cð 3ð 3ð 3ð 3ð
2�U˜3  S¨%Ð/Ô0ð 2ð 2ð 2ð 2ð
5˜˜c 3˜hœð 5ð 5ð 5ð 5ð
5˜Dð 5 Tð 5ð 5ð 5ð 5ð9ð 9˜ #œð 9°$ð 9ð 9ð 9ð 9ð8ð 8˜ œð 8°ð 8ð 8ð 8ð 8ð= ð =¨ð =ð =ð =ð =ð
¸Sð 
ÀSÈÄXð 
ð 
ð 
ð 
ð<1ð <1ð <1ð <1ð~n5°Cð n5Àð n5Èð n5ð n5ð n5ð n5ðbð ð ð ð1 ¨Sð 1 ¸Cð 1 ÀDð 1 ð 1 ð 1 ð 1 ð 1 ð 1 r    