+
    ˜°³j‚b  ã                   óŽ  € R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHt ^ RI	H
t
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIt^ R	IHt R
R.t]! ]4      t ! R R
]]4      t]! RR7       ! R R4      4       tR R lt]! R4      t]! R4      t R R lt!R R lt"R R lt#R R lt$R R lt%R R lt&R  R! lt'R" R# lt(R$ R% lt)R& R' lt*R( R) lt+R* R+ lt,]! R,4      t-]! R-4      t.R. R/ lt/R0 R1 lt0R2 R3 lt1R4 R5 lt2R6 R7 lt3R8 R9 lt4R: R; lt5R< R= lt6R> R? lt7R@ RA lt8RB RC lt9RD RE lt:RF RG lt;RH RI lt<RJ RK lt=RL RM lt>R# )Naè  
In NUMA (Non-Uniform Memory Access) systems, accessing memory on remote NUMA
nodes incurs additional latency. PyTorch provides NUMA binding utilities to
promote memory locality by binding worker processes to CPUs near their assigned accelerator devices.

In practice, NUMA binding typically results in 1-10% overall performance improvements,
but some workloads may obtain much greater benefits or none at all.

To enable NUMA binding, use the ``--numa-binding`` flag with :ref:`torchrun <launcher-api>`, e.g.:

.. code-block:: bash

    torchrun --numa-binding=node --nproc_per_node=8 train.py

Alternatively, pass :class:`NumaOptions` to ``LaunchConfig``
when using ``elastic_launch``.

See :class:`AffinityMode` for available binding modes.
N)Údefaultdict)ÚCallableÚIterable)ÚasdictÚ	dataclass)ÚEnum©Úwraps)Ú	getLogger)Ú	ParamSpecÚTypeVar)Úsignpost_eventÚAffinityModeÚNumaOptionsc                   ó,   € ] tR t^,tRt Rt Rt RtRtR# )r   ÚnodeÚsocketÚ	exclusivezcore-complex© N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚNODEÚSOCKETÚ	EXCLUSIVEÚCORE_COMPLEXÚ__static_attributes__r   ó    ÚS/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/numa/binding.pyr   r   ,   s0   † Ø€Dðð €Fðð €Ið	ð "€Ló	r   T)Úfrozenc                   ó2   a € ] tR t^[t o Rt V 3R ltRtV tR# )r   Fc                ó2   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   # )é   Úaffinity_modeÚ!should_fall_back_if_binding_fails)r   Úbool)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚNumaOptions.__annotate__[   s   ø‡ ‚ áÑñ ñ (,Ñ3ò	 r   r   N)r   r   r   r   r%   Ú__annotate_func__r   Ú__classdictcell__)r(   s   @r   r   r   [   s   ø‡ € ð /4Ð%ð÷ ƒ r   c          
      óŠ   € V ^8„  d   QhR\         \        R3,          R\        R\        R,          R\         \        R3,          /# )r#   Úcommand_args.Údevice_indexÚnuma_optionsNÚreturn)ÚtupleÚstrÚintr   )r'   s   "r   r)   r)   i   sG   € ÷ 7ñ 7Üœ˜S˜•/ð7ô ð7ô  Õ$ð	7ô
 Œ3�ˆ8…_ñ7r   c               óÐ   € Vf   V # RV RVR\        V4      /p \        VVR7      p\        V VR7      p\        RR/ VCRV/CR	7       V#   \         d    \        Y#R
7       T u # i ; i)aã  
Wraps command arguments with numactl to apply NUMA CPU binding.

This function prepends numactl with appropriate CPU affinity flags to the
provided command arguments, binding the process to CPUs associated with
the specified accelerator device's NUMA node.

Args:
    command_args: The original command arguments to wrap.
    device_index: The index of the accelerator device that will be used by the subprocess.
    numa_options: Configuration for NUMA binding behavior. If None, returns
        the original command_args unchanged.

Returns:
    Tuple of command arguments, potentially wrapped with numactl for NUMA binding.
    Returns the original command_args if numa_options is None or if binding fails
    and fallback is enabled.
r.   r/   r0   ©r/   r0   ©Úoriginal_command_argsÚlogical_cpu_indicesÚnuma_bindingÚapply_successÚwrapped_command©ÚcategoryÚnameÚ
parameters©r0   Úlogger_kwargs)r   Ú&_get_validated_logical_cpus_to_bind_toÚ_assemble_numactl_command_argsr   Ú	ExceptionÚ_handle_exception)r.   r/   r0   Úkwargsr9   Úwrapped_command_argss   &$$   r   Ú*_maybe_wrap_command_args_with_numa_bindingrI   i   s£   € ð0 ÒØÐð 	˜Ø˜Øœ˜|Ó,ð€FðÜDØ%Ø%ô
Ðô
  >Ø".Ø 3ô 
Ðô 	Ø#Ø ðØðà!Ð#7ñõ	
ð $Ð#øÜô ä |ÕJØÒðús   ™/A	 Á	A%Á$A%Ú_TParamsÚ_TReturnc          
      óš   € V ^8„  d   QhR\         \        \        3,          R\        R\        R,          R\         \        \        3,          /# )r#   Úfuncr/   r0   Nr1   )r   rJ   rK   r4   r   )r'   s   "r   r)   r)   §   sK   € ÷ #ñ #Ü
”8œXÐ%Õ
&ð#ô ð#ô  Õ$ð	#ô
 ŒhœÐ Õ!ñ#r   c               óJ   a aa€ Sf   S # \        S 4      R VV V3R ll4       pV# )a€  
Wraps a function to apply NUMA CPU binding before execution.

This decorator applies NUMA CPU affinity to all threads in the current process
before calling the wrapped function, binding them to CPUs associated with the
specified accelerator device's NUMA node.

Args:
    func: The function to wrap with NUMA binding.
    device_index: The index of the accelerator device that will be used.
    numa_options: Configuration for NUMA binding behavior. If None, returns
        the original function unchanged.

Returns:
    A wrapped function that applies NUMA binding before execution, or the
    original function if numa_options is None.
c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# )r#   ÚargsrG   r1   )rJ   rP   rG   rK   )r'   s   "r   r)   Ú3_maybe_wrap_with_numa_binding.<locals>.__annotate__Â   s)   € ÷ %ñ %”x—}‘}ð %´·±ð %ÄHñ %r   c                  ó.   <€ \        SSR 7       S! V / VB # )r6   )Ú,_maybe_apply_numa_binding_to_current_process)rP   rG   r/   rM   r0   s   *,€€€r   ÚwrappedÚ._maybe_wrap_with_numa_binding.<locals>.wrappedÁ   s#   ø€ ä4Ø%à%õ	
ñ
 �TÐ$˜VÑ$Ð$r   r   )rM   r/   r0   rT   s   fdd r   Ú_maybe_wrap_with_numa_bindingrV   §   s2   ú€ ð. ÒØˆä
ˆ4ƒ[÷%ñ %ó ð%ð €Nr   c                ó4   € V ^8„  d   QhR\         R\        RR/# )r#   r/   r0   r1   N)r4   r   )r'   s   "r   r)   r)   Í   s)   € ÷ Kñ KÜðKÜ(3ðKà	ñKr   c           	      óÎ   € R V R\        V4      /p \        V VR7      p\        VR7       \        RR/ VCR\	        V4      /CR7       R	#   \
         d    \        YR7        R	# i ; i)
r/   r0   r6   ©r9   r:   r;   r9   r=   rA   N)r   rC   Ú4_bind_all_threads_in_current_process_to_logical_cpusr   Ú_get_ranges_str_from_intsrE   rF   )r/   r0   rG   r9   s   $$  r   rS   rS   Í   sŠ   € ð 	˜Øœ˜|Ó,ð€Fð
KÜDØ%Ø%ô
Ðô
 	=Ø 3õ	
ô 	Ø#Ø ðØðà%Ô'@ÐATÓ'Uñ÷	
øô ô Kä |×JÐJðKús   ‘6A	 Á	A$Á#A$c                ó†   € V ^8„  d   QhR\         \        R3,          R\        \        ,          R\         \        R3,          /# )r#   r8   .r9   r1   )r2   r3   Úsetr4   )r'   s   "r   r)   r)   ì   s8   € ÷ ñ Ü#¤C¨ H�oðÜDGÌÅHðä
Œ3�ˆ8…_ñr   c                 ó(   € R R\        V4       2.V O5# )Únumactlz--physcpubind=)r[   r7   s   $$r   rD   rD   ì   s-   € ð 	Ø
Ô2Ð3FÓGÐHÐIðð 
ñð r   c                óV   € V ^8„  d   QhR\         R\        \        \        3,          RR/# )r#   r0   rB   r1   N)r   Údictr3   Úobject)r'   s   "r   r)   r)   ö   s-   € ÷ 
ñ 
Ü ð
Ü15´c¼6°kÕ1Bð
à	ñ
r   c                 óø   € \        R R/ VCR\        P                  ! 4       /CR7       \        P	                  RV4       V P
                  '       d,   \        P                  R\        P                  ! 4       4       R# h )r:   Úapply_exceptionÚ	tracebackr=   z)Failed to apply NUMA binding for input=%rzHContinuing executing without applying NUMA binding, despite exception %sN)r   re   Ú
format_excÚloggerÚ	exceptionr%   ÚwarningrA   s   $$r   rF   rF   ö   sv   € ô ØØð
Øð
àœ×-Ò-Ó/ñ
õô ×ÑÐ@À-ÔPØ×5×5Ð5Ü�‰ØVÜ× Ò Ó"ô	
ñ 	ð 
r   c                óR   € V ^8„  d   QhR\         R\        R\        \         ,          /# ©r#   r/   r0   r1   ©r4   r   r]   )r'   s   "r   r)   r)     s,   € ÷ 
ñ 
äð
ô ð
ô 	Œ…Xñ	
r   c                 ó6   € \        WR 7      p\        VR7       V# )r6   rY   )Ú_get_logical_cpus_to_bind_toÚ_raise_if_binding_invalid)r/   r0   r9   s   $$ r   rC   rC     s#   € ô
 7Ø!ôÐô Ð2EÕFàÐr   c                ó>   € V ^8„  d   QhR\         \        ,          RR/# ©r#   r9   r1   N©r]   r4   )r'   s   "r   r)   r)     s"   € ÷ Jñ J´c¼#µhð JÀ4ñ Jr   c                 ór   € \         P                  ! R 4      f   \        R4      hV '       g   \        R4      hR# )r_   Nz(numactl CLI is required for NUMA bindingz+Must bind to a non-empty set of CPU indices)ÚshutilÚwhichÚRuntimeErrorrY   s   $r   ro   ro     s3   € ô ‡|‚|�IÓÒ&ÜÐEÓFÐFçÜÐHÓIÐIñ r   c                ó>   € V ^8„  d   QhR\         \        ,          RR/# rq   rr   )r'   s   "r   r)   r)   $  s    € ÷ ñ Ü¤�Hðà	ñr   c                 ó>  € \         P                  ! ^ 4      p\         P                  ! ^ V 4       \         P                  ! R4       FC  p \	        V4      p\         P                  ! V4      pWA8X  d   \         P                  ! W04       KC  KE  	  R#   \
         d     KW  i ; i)é    z/proc/self/taskN)ÚosÚsched_getaffinityÚsched_setaffinityÚlistdirr4   rE   )r9   Úoriginal_main_thread_affinityÚtid_strÚtidÚtid_affinitys   $    r   rZ   rZ   $  s‰   € ô
 %'×$8Ò$8¸Ó$;Ð!ô
 ×Ò˜Ð/Ô0ä—:’:Ð/Ö0ˆð	Ü�g“,ˆCä×/Ò/°Ó4ˆLð Ô<ä×$Ò$ SÖ>ñ =ó 1øô ô 	âð	ús   Á=BÂBÂBc                óR   € V ^8„  d   QhR\         R\        R\        \         ,          /# rk   rl   )r'   s   "r   r)   r)   @  s,   € ÷ ñ äðô ðô 	Œ…Xñ	r   c                óœ  € VP                   \        P                  8X  d   \        V R7      pV# VP                   \        P                  8X  d   \        V R7      pV# VP                   \        P                  8X  d   \        V R7      pV# VP                   \        P                  8X  d   \        V R7      pV# \        RVP                    R24      h)zÙ
Args:
    device_index: The index of the accelerator device that will be used by the subprocess.
        Example: 0
    numa_options: See NumaOptions for details.

Returns:
    Set of logical CPU indices to bind to.
©r/   zAffinity mode z not supported.)r$   r   r   Ú!_node_get_logical_cpus_to_bind_tor   Ú#_socket_get_logical_cpus_to_bind_tor   Ú&_exclusive_get_logical_cpus_to_bind_tor   Ú)_core_complex_get_logical_cpus_to_bind_toÚ
ValueError)r/   r0   Úlogical_cpuss   $$ r   rn   rn   @  sÂ   € ð ×!Ñ!¤\×%6Ñ%6Ô6Ü8ÀlÔSˆð Ðð 
×	#Ñ	#¤|×':Ñ':Ô	:Ü:ÈÔUˆð Ðð 
×	#Ñ	#¤|×'=Ñ'=Ô	=Ü=È<ÔXˆð Ðð 
×	#Ñ	#¤|×'@Ñ'@Ô	@Ü@Ø%ô
ˆð Ðô ˜>¨,×*DÑ*DÐ)EÀ_ÐUÓVÐVr   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# ©r#   r/   r1   ©r4   r]   )r'   s   "r   r)   r)   ^  s   € ÷ ñ ´sð ¼sÄ3½xñ r   c                ó2   € \        V R7      p\        VR7      # )z%
Core logic of 'node' numa strategy.
r„   ©Únuma_node_index)Ú%_get_numa_node_index_for_device_indexÚ._get_allowed_logical_cpu_indices_for_numa_node)r/   r�   s   $ r   r…   r…   ^  s   € ô <ÈÔV€Oä9Ø'ôð r   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# rŒ   r�   )r'   s   "r   r)   r)   i  s   € ÷ ñ ¼ð ÄÄSÅñ r   c                óª   € \        V R7      p\        VR7      p\        VR7      p\        4       pV F  pVP	                  \        VR7      4       K   	  V# )z'
Core logic of 'socket' numa strategy.
r„   r�   )Úsocket_index)r‘   Ú_get_socket_index_for_numa_nodeÚ'_get_numa_node_indices_for_socket_indexr]   Úupdater’   )r/   Únuma_node_index_of_devicer•   Únuma_node_indicesrŠ   r�   s   $     r   r†   r†   i  sg   € ô !FØ!ô!Ðô 3Ø1ô€Lô @Ø!ôÐô “5€LÛ,ˆØ×ÑÜ:Ø /ôö	
ñ -ð Ðr   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# rŒ   r�   )r'   s   "r   r)   r)   ‚  s"   € ÷ A*ñ A*¼Cð A*ÄCÌÅHñ A*r   c                ó–  € \        V R7      p\        VR7      p\        V4      pVP                  V 4      p\	        VR7      p\        VR 4      p\        \        VP                  4       4      4      p\        V4      \        V4      ,          p\        V4      \        V4      ,          pV^8  d1   \        R\        V4       RV: R2R\        V4       R2,           4      hW6,          \        W74      ,           pVV,           VV8  d   ^M^ ,           p	\        VP                  4       4      W‰  U
Uu0 uF  p
V
 F  pVkK  	  K  	  pp
pV# u upp
i )	z*
Core logic of 'exclusive' numa strategy.
r„   r�   c                 ó,   € \        \        V R 7      4      # ©©Úlogical_cpu_index)ÚminÚ6_get_logical_cpu_indices_sharing_same_physical_core_asrŸ   s   &r   Ú<lambda>Ú8_exclusive_get_logical_cpus_to_bind_to.<locals>.<lambda>”  s   € ¤#ÜBØ"3ôô#
r   zThere are only z# physical cores on numa_node_index=Ú,z but there are z( devices associated with this NUMA node.)r‘   Ú!_get_device_indices_for_numa_nodeÚsortedÚindexr’   Ú	_group_byra   ÚitemsÚlenrv   r¡   ÚlistÚvalues)r/   r�   Údev_indicesÚoriginal_device_relative_indexÚallowed_logical_cpu_indicesÚ,physical_core_to_allowed_logical_cpu_indicesÚnum_physical_cores_per_deviceÚ+num_devices_to_give_one_extra_physical_coreÚstartÚendr9   r    Úlogical_cpu_indices_for_devices   $            r   r‡   r‡   ‚  s£  € ô <ÈÔV€Oä3ÀOÔT€KÜ˜Ó%€KØ%0×%6Ñ%6°|Ó%DÐ"ä"PØ'ô#Ðô 4=Ø#ñ	
ó4Ð0ô 48ÜÐ;×AÑAÓCÓDó4Ð0ô %(Ø4ó%ä	ˆ[Ó	õ%Ð!ô 36Ø4ó3äˆKÓõ3Ð/ð % qÔ(ÜØœcÐ"NÓOÐPÐPtÐdsÑcuÐuvÐwØ¤ KÓ 0Ð1Ð1YÐZõ[ó
ð 	
ð
 +ÕJÌSØ&óNõ €Eð 	Ø
'õ	(ð .Ø9ô:ñ ð õ	
ð ô $(Ø8×?Ñ?ÓAó$
à
ñ$ô&ñ$Ðó "5Ðó	 	ñ "5ñ	 	ñ$ð #ñ &ð *Ð)ùó&s   Ä,Ec                óF   € V ^8„  d   QhR\         R\        \         ,          /# rŒ   r�   )r'   s   "r   r)   r)   Æ  s   € ÷ ,*ñ ,*¼sð ,*ÄsÌ3Åxñ ,*r   c                óN  € \        V R7      p\        VR7      p\        V4      pVP                  V 4      p\	        VR7      p\        VR 4      p\        \        VP                  4       R R7      4      pV\        V4      ,          p\        VP                  4       4      V,          pV# )z¦
Core logic of 'core-complex' numa strategy.

Each accelerator device is assigned a full core complex (group of cores sharing
L3 cache) within its affined NUMA node.
r„   r�   c                 ó,   € \        \        V R 7      4      # rž   )r¡   Ú1_get_logical_cpus_sharing_same_max_level_cache_asrŸ   s   &r   r£   Ú;_core_complex_get_logical_cpus_to_bind_to.<locals>.<lambda>Û  s   € ¤#Ü=Ø"3ôô#
r   c                 ó:   € \        V ^,          4      ) V ^ ,          3# )é   )r«   )Úitems   &r   r£   r»   ç  s   € œs 4¨¥7›|˜m¨T°!­WÑ5r   )Úkey)r‘   r¦   r§   r¨   r’   r©   ra   rª   r«   r¬   r­   )r/   r�   r®   r¯   r°   Ú.max_level_cache_to_allowed_logical_cpu_indicesÚcache_index_for_devicer¶   s   $       r   rˆ   rˆ   Æ  s¼   € ô <ÈÔV€Oä3ÀOÔT€KÜ˜Ó%€KØ%0×%6Ñ%6°|Ó%DÐ"ä"PØ'ô#Ðô 6?Ø#ñ	
ó6Ð2ô 6:ÜØ:×@Ñ@ÓBñ 6ô		
ó6Ð2ð <¼cØ6ó?õ Ðô &*Ø6×=Ñ=Ó?ó&àõ&Ð"ð *Ð)r   ÚKÚVc          	      ó®   € V ^8„  d   QhR\         \        ,          R\        \        .\        3,          R\        \        \
        \        ,          3,          /# )r#   r­   Úget_keyr1   )r   rÃ   r   rÂ   ra   r]   )r'   s   "r   r)   r)   ù  s<   € ÷ ñ ”hœq•kð ¬H´a°S¼!°VÕ,<ð ÄÄaÌÌQÍÀiÅñ r   c                ót   € \        \        4      pV  F"  pV! V4      pW$,          P                  V4       K$  	  V# )z*
Groups elements with same key into sets.
)r   r]   Úadd)r­   rÅ   Úkey_to_valuesÚvaluer¿   s   &&   r   r©   r©   ù  s:   € ô -8¼Ó,<€MÛˆÙ�e‹nˆØÕ×Ñ˜uÖ%ñ ð Ðr   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# ©r#   r    r1   r�   )r'   s   "r   r)   r)     s    € ÷ 9ñ 9Üð9äŒ…Xñ9r   c                 ó¤   € R V  R2p\        V4      ;_uu_ 4       p\        VP                  4       4      uuRRR4       #   + '       g   i     R# ; i)ú/sys/devices/system/cpu/cpuz/topology/thread_siblings_listN)ÚopenÚ_get_set_of_int_from_ranges_strÚread)r    Ú"thread_siblings_list_absolute_pathÚfs   $  r   r¢   r¢     sE   € ð &Ð&7Ð%8Ð8VÐWð 'ô 
Ð0×	1Ô	1°QÜ.¨q¯v©v«xÓ8÷ 
2×	1×	1Ó	1ús	   š>¾A	c                óF   € V ^8„  d   QhR\         R\        \         ,          /# rË   r�   )r'   s   "r   r)   r)     s    € ÷ #0ñ #0Üð#0äŒ…Xñ#0r   c                 óÊ  € R V  R2pRp\        4       p\        P                  ! V4       EFz  pVP                  R4      '       d   VR,          P	                  4       '       g   K:  \        P
                  P                  W4      p\        P
                  P                  VR4      p\        V4      ;_uu_ 4       pVP                  4       P                  4       R	9  d    RRR4       K»   RRR4       \        P
                  P                  VR4      p\        V4      ;_uu_ 4       p	\        V	P                  4       4      p
RRR4       X
V8:  d   EK#  T
p\        P
                  P                  VR4      p\        V4      ;_uu_ 4       p\        VP                  4       4      pRRR4       EK}  	  V#   + '       g   i     LÍ; i  + '       g   i     L‹; i  + '       g   i     EK¹  ; i)
rÍ   z/cacher¨   :é   NNÚtypeNÚlevelÚshared_cpu_listéÿÿÿÿ>   ÚDataÚUnified)r]   rz   r}   Ú
startswithÚ	isdecimalÚpathÚjoinrÎ   rÐ   Ústripr4   rÏ   )r    Úcpu_cache_dir_absolute_pathÚ	max_levelÚ$logical_cpus_sharing_max_level_cacheÚentryÚcache_index_absolute_pathÚtype_absolute_pathÚ	type_fileÚlevel_absolute_pathÚ
level_filer×   Úshared_cpu_list_absolute_pathÚshare_cpu_list_files   $            r   rº   rº     s�  € ð &Ð&7Ð%8¸Ð?ð  ð €IÜ+.«5Ð(Ü—’Ð7×8ˆØ×Ñ ×(Ò(°°bµ	×0CÑ0C×0EÒ0EÙÜ$&§G¡G§L¡LÐ1LÓ$TÐ!ô  ŸW™WŸ\™\Ð*CÀVÓLÐÜÐ$×%Ô%¨Ø�~‰~Ó×%Ñ%Ó'Ð/BÔBØ÷ &Ñ%ØB÷ &ô !Ÿg™gŸl™lÐ+DÀgÓNÐÜÐ%×&Ô&¨*Ü˜
Ÿ™Ó)Ó*ˆE÷ 'à�IÔÚàˆ	Ü(*¯©¯©Ø%Ð'8ó)
Ð%ô Ð/×0Ô0Ð4GÜ3RØ#×(Ñ(Ó*ó4Ð0÷ 1Ò0ñ+ 9ð4 0Ð/÷' &×%ú÷
 '×&ú÷ 1×0Ñ0ús$   Â5%F*Ä F=ÆGÆ*F:Æ=GÇG"c                óF   € V ^8„  d   QhR\         R\        \         ,          /# ©r#   r�   r1   r�   )r'   s   "r   r)   r)   4  s   € ÷ 1ñ 1Äsð 1ÌsÔSVÍxñ 1r   c                 ó>   € \        V R 7      p\        4       pW,          # ©r�   )Ú0_get_cpu_indices_for_numa_node_MAYBE_NOT_ALLOWEDÚ+_get_allowed_cpu_indices_for_current_thread)r�   Úall_cpu_indicesÚallowed_cpu_indicess   $  r   r’   r’   4  s$   € ÜFØ'ô€Oô FÓGÐØÕ0Ð0r   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# rí   r�   )r'   s   "r   r)   r)   <  s    € ÷ :ñ :Üð:äŒ…Xñ:r   c                óì   € RV  R2p \        V4      ;_uu_ 4       pVP                  4       pRRR4       \	        X4      #   + '       g   i     L; i  \         d   p\        RT : R24      ThRp?ii ; i)z�
Returns:
    Indices of all CPUs associated with numa_node_index. However, the list
    is not filtered based on whether the thread is allowed to use them.
z/sys/devices/system/node/nodez/cpulistNz:Could not determine CPUs corresponding to numa_node_index=Ú.)rÎ   rÐ   ÚFileNotFoundErrorrv   rÏ   )r�   Úcpulist_absolute_pathrÒ   Úcpu_range_strÚes   $    r   rð   rð   <  sy   € ð <¸OÐ;LÈHÐUÐðÜÐ'×(Ô(¨AØŸF™F›HˆM÷ )ô +¨=Ó9Ð9÷ )×(ûäô ÜØI¸Ñ8JÈ!ÐLó
àð	ûðús1   ˆA ›?¬A ¿A	Á
A ÁA ÁA3ÁA.Á.A3c                ó$   € V ^8„  d   QhR\         /# ©r#   r1   ©r4   )r'   s   "r   r)   r)   O  s   € ÷ ,ñ ,œ3ñ ,r   c                  ó>   € \         P                  P                  4       # )N)ÚtorchÚacceleratorÚdevice_countr   r   r   Ú_get_device_countr  O  s   € Ü×Ñ×)Ñ)Ó+Ð+r   c                ó0   € V ^8„  d   QhR\         R\         /# rŒ   rý   )r'   s   "r   r)   r)   S  s   € ÷ -ñ -¼3ð -Ä3ñ -r   c                 ó   € \         P                  P                  4       '       g   \        R 4      h\         P                  P	                  4       p\         P
                  ! V4      pVP                  V 4      pVP                  pVP                  pVP                  pVR RVR RVR R2pRV R2p\        V4      ;_uu_ 4       p	\        \        V	P                  4       P                  4       4      ^ 4      uuRRR4       #   + '       g   i     R# ; i)z)No accelerator available for NUMA bindingÚ04xÚ:Ú02xz.0z/sys/bus/pci/devices/z
/numa_nodeN)rÿ   r   Úis_availablerv   Úcurrent_acceleratorÚget_device_moduleÚget_device_propertiesÚpci_domain_idÚ
pci_bus_idÚpci_device_idrÎ   Úmaxr4   rÐ   rà   )
r/   ÚaccÚdevice_moduleÚdevice_propertiesÚdomainÚbusÚdeviceÚpci_addrÚpci_numa_node_absolute_pathrÒ   s
   $         r   r‘   r‘   S  sã   € Ü×Ñ×)Ñ)×+Ò+ÜÐFÓGÐGÜ
×
Ñ
×
/Ñ
/Ó
1€CÜ×+Ò+¨CÓ0€MØ%×;Ñ;¸LÓIÐà×,Ñ,€FØ
×
&Ñ
&€CØ×,Ñ,€Fð ˜�˜Q˜s 3˜i q¨°¨°BÐ7€Hà$9¸(¸À:Ð"NÐÜ	Ð)×	*Ô	*¨aô ”3�q—v‘v“x—~‘~Ó'Ó(¨!Ó,÷	 
+×	*×	*Ó	*ús   Ã 1C<Ã<D	c                óF   € V ^8„  d   QhR\         R\        \         ,          /# rí   r�   )r'   s   "r   r)   r)   i  s   € ÷ ñ ¼#ð Ä#ÄcÅ(ñ r   c                 óx   € \        \        4       4       Uu0 uF  p\        VR 7      V 8X  g   K  VkK  	  up# u upi )r„   )Úranger  r‘   )r�   r/   s   $ r   r¦   r¦   i  sD   € ô "Ô"3Ó"5Ô6óá6ˆLÜ0¸lÔKØñ÷ 	ˆÙ6ñð ùò s   –7®7c                ó0   € V ^8„  d   QhR\         R\         /# rí   rý   )r'   s   "r   r)   r)   r  s   € ÷ Dñ D¼ð DÄñ Dr   c                 ó2   € \        V R 7      p\        VR7      # ©r�   )Ú	cpu_index)Ú._get_arbitrary_allowed_cpu_index_for_numa_nodeÚ_get_socket_index_for_cpu)r�   Úarbitrary_cpu_indexs   $ r   r–   r–   r  s   € ÜHØ'ôÐô %Ð/BÔCÐCr   c                ó0   € V ^8„  d   QhR\         R\         /# )r#   r  r1   rý   )r'   s   "r   r)   r)   z  s   € ÷ Rñ R¬Cð R´Cñ Rr   c                 ó  € R V  R2p \        V4      ;_uu_ 4       p\        VP                  4       P                  4       4      uuRRR4       #   + '       g   i     R# ; i  \         d   p\        RT : 24      ThRp?ii ; i)rÍ   z/topology/physical_package_idNz)Could not determine socket for cpu_index=)rÎ   r4   rÐ   rà   r÷   rv   )r  Úpackage_id_absolute_pathrÒ   rú   s   $   r   r   r   z  ss   € à
% i [Ð0MÐNð ðRÜÐ*×+Ô+¨qÜ�q—v‘v“x—~‘~Ó'Ó(÷ ,×+×+Ó+ûäô RÜÐG¸Y¹LÐIÓJÐPQÐQûðRús4   ˆA! ›'AÁ
A! ÁA	ÁA! ÁA! Á!BÁ,A<Á<Bc                ó0   € V ^8„  d   QhR\         R\         /# rí   rý   )r'   s   "r   r)   r)   …  s   € ÷ ñ Äsð Ìsñ r   c                 ó,   € \        \        V R 7      4      # rï   )r¡   r’   r�   s   $r   r  r  …  s   € ÜÜ6ÀÔWóð r   c                óF   € V ^8„  d   QhR\         R\        \        ,          /# )r#   Ú
ranges_strr1   )r3   r]   r4   )r'   s   "r   r)   r)   ‹  s   € ÷ ñ ´ð ¼¼C½ñ r   c                óV  € \        4       pV P                  R4       F‰  pVP                  4       pV'       g   K  RV9   dL   VP                  R4      w  r4\        V4      \        V4      reVP	                  \        WV^,           4      4       Ko  VP                  \        V4      4       K‹  	  V# )zŽ
Util for parsing a string of int ranges, as in a sysfs file.

Args:
    ranges_str: E.g., "0-2,4,6-7"

Returns:
    E.g., {0, 1, 2, 4, 6, 7}
r¥   Ú-)r]   Úsplitrà   r4   r˜   r  rÇ   )r(  ÚintsÚ	range_strÚ	start_strÚend_strr´   rµ   s   &      r   rÏ   rÏ   ‹  s†   € ô “U€DØ×%Ñ% cÖ*ˆ	Ø—O‘OÓ%ˆ	ßÙØ�)ÔØ!*§¡°Ó!5ÑˆIÜ˜Y›¬¨W«�3Ø�K‰Kœ˜e¨1¥WÓ-Ö.à�H‰H”S˜“^Ö$ñ +ð €Kr   c                óF   € V ^8„  d   QhR\         \        ,          R\        /# )r#   r,  r1   )r   r4   r3   )r'   s   "r   r)   r)   £  s   € ÷ !ñ !¤H¬S¥Mð !´cñ !r   c                ój  € V '       g   R# \        V 4      p. pV^ ,          ;r4VR,           FF  pWT^,           8X  d   TpK  W48X  d   VP                  V 4       MVP                  V RV 24       T;r4KH  	  W48X  d   VP                  V 4       MVP                  V RV 24       RP                  V4      # )z†
Convert a set of integers to a compact string with ranges.

Args:
    ints: E.g., {0, 1, 2, 4, 6, 7}

Returns:
    E.g., "0-2,4,6-7"
Ú :r½   NNr*  r¥   )r§   Úappendrß   )r,  Úsorted_intsÚrangesr´   ÚprevÚnums   &     r   r[   r[   £  s±   € ÷ Ùä˜“,€KØ€FØ˜q•>Ð!€Eà˜2�ˆˆØ˜•(Œ?ØŠDàŒ}Ø—‘  Õ)à—‘   q¨¨Ð/Ô0ØÐˆE‘Dñ ð „}Ø�‰˜˜Õ!à�‰˜˜˜q  Ð'Ô(à�8‰8�FÓÐr   c                ó:   € V ^8„  d   QhR\         \        ,          /# rü   rr   )r'   s   "r   r)   r)   Ç  s   € ÷ ?ñ ?¬3¬s­8ñ ?r   c                  ó–   € \        R 4      ;_uu_ 4       p V P                  4       pRRR4       \        X4      #   + '       g   i     L; i)z!/sys/devices/system/node/possibleN)rÎ   rÐ   rÏ   )rÒ   Úpossible_nodes_strs     r   Ú!_get_systemwide_numa_node_indicesr;  Ç  s8   € Ü	Ð1×	2Ô	2°aØŸV™V›XÐ÷ 
3ô +Ð+=Ó>Ð>÷ 
3×	2ús	   ”8¸A	c                óF   € V ^8„  d   QhR\         R\        \         ,          /# )r#   r•   r1   r�   )r'   s   "r   r)   r)   Î  s   € ÷ &ñ &¼Sð &ÄSÌÅXñ &r   c                 ó    € \        4       p\        4       pV F3  p\        VR 7      pV \        VR7      8X  g   K"  VP	                  V4       K5  	  V# r  )r;  r]   r  r   rÇ   )r•   Úsystemwide_numa_node_indicesÚmatching_numa_node_indicesr�   r!  s   $    r   r—   r—   Î  sR   € Ü#DÓ#FÐ ä!$£ÐÛ7ˆÜLØ+ô
Ðð Ô4Ð?RÔSÖSØ&×*Ñ*¨?Ö;ñ 8ð &Ð%r   c                ó:   € V ^8„  d   QhR\         \        ,          /# rü   rr   )r'   s   "r   r)   r)   Ü  s   € ÷ #ñ #´S¼µXñ #r   c                  ó.   € \         P                  ! ^ 4      # )ry   )rz   r{   r   r   r   rñ   rñ   Ü  s   € ô ×Ò Ó"Ð"r   )?Ú__doc__rz   rt   re   Úcollectionsr   Úcollections.abcr   r   Údataclassesr   r   Úenumr   Ú	functoolsr	   Úloggingr
   Útypingr   r   rÿ   Útorch._utils_internalr   Ú__all__r   rg   r3   r   r   rI   rJ   rK   rV   rS   rD   rF   rC   ro   rZ   rn   r…   r†   r‡   rˆ   rÂ   rÃ   r©   r¢   rº   r’   rð   r  r‘   r¦   r–   r   r  rÏ   r[   r;  r—   rñ   r   r   r   Ú<module>rL     s>  ðñó( 
Û Û Ý #ß .ß )Ý Ý Ý ß %ã Ý 0ð Øð€ñ
 
�8Ó	€ô,�3˜ô ,ñ^ �$Ô÷
ð 
ó ð
õ7ñt �ZÓ €Ù�:Ó€õ#õLKõ>õ
õ.
õJõõ8õ<õõ2A*õH,*ñ^ ˆCƒL€ÙˆCƒL€õõ9õ#0õL1õ:õ&,õ-õ,õDõRõõõ0!õH?õ&÷#r   