
    N j                     L   S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKrSS	KJr  S
SKJr  / SQr\" S5      S\\\
4   4S j5       rS\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS&S\R                  R8                  SS4S jjr " S S5      r " S S5      r\" 5       r \ q!S&S\R                  R8                  S\4S jjr" " S S\5      r#S \S\4S! jr$S\%4S" jr&S\R                  R8                  SS4S# jr'S\4S$ jr(S\4S% jr)g)'zj
This package implements abstractions found in ``torch.cuda``
to facilitate writing device-agnostic code.
    )Mapping)AbstractContextManager)	lru_cache)MappingProxyType)AnyN   device   )amp)is_availableis_initializedsynchronizecurrent_devicecurrent_streamstream
set_devicedevice_countStreamStreamContextEventget_capabilitiesreturnc                  d    [        [        R                  R                  R	                  5       5      $ )ad  
Returns an immutable mapping of CPU capabilities detected at runtime.

This function queries the CPU for supported instruction sets and features
using cpuinfo. The result is cached after the first call for efficiency.

The returned mapping contains architecture-specific capabilities:

For x86/x86_64:
    - SSE family: sse, sse2, sse3, ssse3, sse4_1, sse4_2, sse4a
    - AVX family: avx, avx2, avx_vnni
    - AVX-512 family: avx512_f, avx512_cd, avx512_dq, avx512_bw, avx512_vl,
      avx512_ifma, avx512_vbmi, avx512_vbmi2, avx512_bitalg, avx512_vpopcntdq,
      avx512_vnni, avx512_bf16, avx512_fp16, avx512_vp2intersect,
      avx512_4vnniw, avx512_4fmaps
    - AVX10 family: avx10_1, avx10_2
    - AVX-VNNI-INT: avx_vnni_int8, avx_vnni_int16, avx_ne_convert
    - AMX: amx_bf16, amx_tile, amx_int8, amx_fp16
    - FMA: fma3, fma4
    - Other: f16c, bmi, bmi2, popcnt, lzcnt, aes, sha, clflush, clflushopt, clwb

For ARM64:
    - SIMD: neon, fp16_arith, bf16, i8mm, dot
    - SVE: sve, sve2, sve_bf16, sve_max_length (when supported)
    - SME: sme, sme2, sme_max_length (when supported)
    - Other: atomics, fhm, rdm, crc32, aes, sha1, sha2, pmull

Common to all architectures:
    - architecture: string identifying the CPU architecture

Returns:
    MappingProxyType: An immutable mapping where keys are capability names
    (e.g., 'avx2', 'sve') and values are booleans indicating
    support, or integers for properties like vector lengths.

Example:
    >>> caps = torch.cpu.get_capabilities()
    >>> if caps.get("avx2", False):
    ...     print("AVX2 is supported")
    >>> print(f"Architecture: {caps['architecture']}")
)r   torch_C_cpu_get_cpu_capability     c/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/cpu/__init__.pyr   r   #   s!    V EHHMM==?@@r    c                  6    [        5       R                  SS5      $ )z/Returns a bool indicating if CPU supports AVX2.avx2Fr   getr   r    r!   _is_avx2_supportedr&   Q   s    !!&%00r    c                  6    [        5       R                  SS5      $ )z1Returns a bool indicating if CPU supports AVX512.avx512_fFr$   r   r    r!   _is_avx512_supportedr)   V       !!*e44r    c                  6    [        5       R                  SS5      $ )z6Returns a bool indicating if CPU supports AVX512_BF16.avx512_bf16Fr$   r   r    r!   _is_avx512_bf16_supportedr-   [   s    !!-77r    c                  6    [        5       R                  SS5      $ )z/Returns a bool indicating if CPU supports VNNI.avx512_vnniFr$   r   r    r!   _is_vnni_supportedr0   `   s     !!-77r    c                  6    [        5       R                  SS5      $ )z3Returns a bool indicating if CPU supports AMX_TILE.amx_tileFr$   r   r    r!   _is_amx_tile_supportedr3   f   r*   r    c                  6    [        5       R                  SS5      $ )z3Returns a bool indicating if CPU supports AMX FP16.amx_fp16Fr$   r   r    r!   _is_amx_fp16_supportedr6   k   r*   r    c                  R    [         R                  R                  R                  5       $ )zInitializes AMX instructions.)r   r   r   	_init_amxr   r    r!   r8   r8   p   s    88==""$$r    c                      g)z}Returns a bool indicating if CPU is currently available.

N.B. This function only exists to facilitate device-agnostic code

Tr   r   r    r!   r   r   u   s     r    r
   c                     g)zWaits for all kernels in all streams on the CPU device to complete.

Args:
    device (torch.device or int, optional): ignored, there's only one CPU device.

N.B. This function only exists to facilitate device-agnostic code.
Nr   r	   s    r!   r   r   ~       r    c                   L    \ rS rSrSrSS\SS4S jjrSS jrSS jrSS	 jr	S
r
g)r      z@
N.B. This class only exists to facilitate device-agnostic code
priorityr   Nc                     g Nr   )selfr>   s     r!   __init__Stream.__init__       r    c                     g r@   r   rA   r   s     r!   wait_streamStream.wait_stream   rD   r    c                     g r@   r   rA   s    r!   record_eventStream.record_event   rD   r    c                     g r@   r   )rA   events     r!   
wait_eventStream.wait_event   rD   r    r   )r   N)__name__
__module____qualname____firstlineno____doc__intrB   rG   rK   rO   __static_attributes__r   r    r!   r   r      s)     d r    r   c                   H    \ rS rSrS\4S jrS	S
S jjrS
S jrS	S
S jjrSr	g)r      r   c                     g)NTr   rJ   s    r!   queryEvent.query   s    r    Nc                     g r@   r   rF   s     r!   recordEvent.record   rD   r    c                     g r@   r   rJ   s    r!   r   Event.synchronize   rD   r    c                     g r@   r   rF   s     r!   wait
Event.wait   rD   r    r   r@   rR   )
rS   rT   rU   rV   boolr]   r`   r   re   rY   r   r    r!   r   r      s"    t  r    r   c                     [         $ )zReturns the currently selected :class:`Stream` for a given device.

Args:
    device (torch.device or int, optional): Ignored.

N.B. This function only exists to facilitate device-agnostic code

)_current_streamr	   s    r!   r   r      s
     r    c                   P    \ rS rSr% Sr\S-  \S'   S rS rS\	S\	S	\	S
S4S jr
Srg)r      znContext-manager that selects a given stream.

N.B. This class only exists to facilitate device-agnostic code

N
cur_streamc                 &    Xl         [        U l        g r@   )r   _default_cpu_streamprev_streamrF   s     r!   rB   StreamContext.__init__   s    .r    c                 >    U R                   nUc  g [        U l        Uqg r@   )r   ri   ro   )rA   rl   s     r!   	__enter__StreamContext.__enter__   s#    [[
 +$r    typevalue	tracebackr   c                 <    U R                   nUc  g U R                  qg r@   )r   ro   ri   )rA   rt   ru   rv   rl   s        r!   __exit__StreamContext.__exit__   s!    [[
 **r    )ro   r   )rS   rT   rU   rV   rW   r   __annotations__rB   rr   r   rx   rY   r   r    r!   r   r      s>     /%+S + + + +r    r   r   c                     [        U 5      $ )zWrapper around the Context-manager StreamContext that
selects a given stream.

N.B. This function only exists to facilitate device-agnostic code
)r   )r   s    r!   r   r      s       r    c                      g)zxReturns number of CPU devices (not cores). Always 1.

N.B. This function only exists to facilitate device-agnostic code
r   r   r   r    r!   r   r      s    
 r    c                     g)zrSets the current device, in CPU we do nothing.

N.B. This function only exists to facilitate device-agnostic code
Nr   r	   s    r!   r   r      r;   r    c                      g)zqReturns current device for cpu. Always 'cpu'.

N.B. This function only exists to facilitate device-agnostic code
cpur   r   r    r!   r   r      s    
 r    c                      g)zxReturns True if the CPU is initialized. Always True.

N.B. This function only exists to facilitate device-agnostic code
Tr   r   r    r!   r   r      s    
 r    r@   )*rW   collections.abcr   
contextlibr   	functoolsr   typesr   typingr   r    r
   _devicer   __all__strr   rg   r&   r)   r-   r0   r3   r6   r8   r   Devicer   r   r   rn   ri   r   r   r   rX   r   r   r   r   r   r    r!   <module>r      sv  
 $ -  "       4*A'#s(+ *A *AZ1D 1
5d 5
84 8
8D 85 5
5 5
%4 %
d ** d  $  h %	5;;-- 	 	+* +>!6 !4 !c u{{)) d   r    