§
    ŠŠtjÑ  ã                   ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlZdd	lmZ d
dlmZ g d¢Z ed¦  «        deee
f         fd„¦   «         Zdefd„Zdefd„Zdefd„Zdefd„Zdefd„Zdefd„Zdefd„Zdefd„Zd&dej        j        ddfd„Z G d„ d¦  «        Z G d„ d¦  «        Z e¦   «         Z e a!d&dej        j        defd„Z" G d„ de¦  «        Z#d edefd!„Z$de%fd"„Z&dej        j        ddfd#„Z'defd$„Z(defd%„Z)dS )'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                  ób   — t          t          j        j                             ¦   «         ¦  «        S )aè  
    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© ó    úP/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/cpu/__init__.pyr   r   #   s#   € õV �EœHœM×=Ò=Ñ?Ô?Ñ@Ô@Ð@r    c                  óF   — t          ¦   «                              dd¦  «        S )z/Returns a bool indicating if CPU supports AVX2.Úavx2F©r   Úgetr   r    r!   Ú_is_avx2_supportedr&   Q   s   € åÑÔ×!Ò! &¨%Ñ0Ô0Ð0r    c                  óF   — t          ¦   «                              dd¦  «        S )z1Returns a bool indicating if CPU supports AVX512.Úavx512_fFr$   r   r    r!   Ú_is_avx512_supportedr)   V   ó   € åÑÔ×!Ò! *¨eÑ4Ô4Ð4r    c                  óF   — t          ¦   «                              dd¦  «        S )z6Returns a bool indicating if CPU supports AVX512_BF16.Úavx512_bf16Fr$   r   r    r!   Ú_is_avx512_bf16_supportedr-   [   s   € åÑÔ×!Ò! -°Ñ7Ô7Ð7r    c                  óF   — t          ¦   «                              dd¦  «        S )z/Returns a bool indicating if CPU supports VNNI.Úavx512_vnniFr$   r   r    r!   Ú_is_vnni_supportedr0   `   s    € õ ÑÔ×!Ò! -°Ñ7Ô7Ð7r    c                  óF   — t          ¦   «                              dd¦  «        S )z3Returns a bool indicating if CPU supports AMX_TILE.Úamx_tileFr$   r   r    r!   Ú_is_amx_tile_supportedr3   f   r*   r    c                  óF   — t          ¦   «                              dd¦  «        S )z3Returns a bool indicating if CPU supports AMX FP16.Úamx_fp16Fr$   r   r    r!   Ú_is_amx_fp16_supportedr6   k   r*   r    c                  óH   — t           j        j                             ¦   «         S )zInitializes AMX instructions.)r   r   r   Ú	_init_amxr   r    r!   r8   r8   p   s   € åŒ8Œ=×"Ò"Ñ$Ô$Ð$r    c                  ó   — dS )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	   € ð ˆ4r    r
   c                 ó   — dS )zñWaits 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                   ó<   — e Zd ZdZd
deddfd„Zdd„Zdd„Zdd	„ZdS )r   zH
    N.B. This class only exists to facilitate device-agnostic code
    éÿÿÿÿÚpriorityr   Nc                 ó   — d S ©Nr   )Úselfr>   s     r!   Ú__init__zStream.__init__�   ó   € Øˆr    c                 ó   — d S r@   r   ©rA   r   s     r!   Úwait_streamzStream.wait_stream�   rC   r    c                 ó   — d S r@   r   ©rA   s    r!   Úrecord_eventzStream.record_event“   rC   r    c                 ó   — d S r@   r   )rA   Úevents     r!   Ú
wait_eventzStream.wait_event–   rC   r    )r=   ©r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintrB   rF   rI   rL   r   r    r!   r   r   ˆ   s�   € € € € € ðð ðð  ð ¨dð ð ð ð ðð ð ð ðð ð ð ðð ð ð ð ð r    r   c                   ó6   — e Zd Zdefd„Zddd„Zdd„Zddd„ZdS )	r   r   c                 ó   — dS )NTr   rH   s    r!   ÚqueryzEvent.query›   s   € Øˆtr    Nc                 ó   — d S r@   r   rE   s     r!   ÚrecordzEvent.recordž   rC   r    c                 ó   — d S r@   r   rH   s    r!   r   zEvent.synchronize¡   rC   r    c                 ó   — d S r@   r   rE   s     r!   Úwaitz
Event.wait¤   rC   r    r@   rM   )rN   rO   rP   ÚboolrU   rW   r   rZ   r   r    r!   r   r   š   su   € € € € € ð�tð ð ð ð ðð ð ð ð ðð ð ð ðð ð ð ð ð ð r    r   c                 ó   — t           S )zÓReturns 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                   óH   — e Zd ZU dZedz  ed<   d„ Zd„ Zdededed	dfd
„Z	dS )r   zvContext-manager that selects a given stream.

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

    NÚ
cur_streamc                 ó,   — || _         t          | _        d S r@   )r   Ú_default_cpu_streamÚprev_streamrE   s     r!   rB   zStreamContext.__init__Á   s   € ØˆŒÝ.ˆÔÐÐr    c                 ó8   — | j         }|€d S t          | _        |ad S r@   )r   r]   rb   )rA   r_   s     r!   Ú	__enter__zStreamContext.__enter__Å   s'   € Ø”[ˆ
ØÐØˆFõ +ˆÔØ$ˆˆˆr    ÚtypeÚvalueÚ	tracebackr   c                 ó*   — | j         }|€d S | j        ad S r@   )r   rb   r]   )rA   re   rf   rg   r_   s        r!   Ú__exit__zStreamContext.__exit__Î   s"   € Ø”[ˆ
ØÐØˆFð Ô*ˆˆˆr    )
rN   rO   rP   rQ   r   Ú__annotations__rB   rd   r   ri   r   r    r!   r   r   ¸   s€   € € € € € € ðð ð ˜‘ÐÐÑð/ð /ð /ð%ð %ð %ð+˜Sð +¨ð +¸ð +Àð +ð +ð +ð +ð +ð +r    r   r   c                 ó    — t          | ¦  «        S )z�Wrapper 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                  ó   — dS )z€Returns 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	   € ð
 ˆ1r    c                 ó   — dS )zzSets 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                  ó   — dS )zyReturns current device for cpu. Always 'cpu'.

    N.B. This function only exists to facilitate device-agnostic code
    Úcpur   r   r    r!   r   r   ï   s	   € ð
 ˆ5r    c                  ó   — dS )z€Returns 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	   € ð
 ˆ4r    r@   )*rQ   Úcollections.abcr   Ú
contextlibr   Ú	functoolsr   Útypesr   Útypingr   r   Ú r
   Ú_devicer   Ú__all__Ústrr   r[   r&   r)   r-   r0   r3   r6   r8   r   ÚDevicer   r   r   ra   r]   r   r   r   rR   r   r   r   r   r   r    r!   ú<module>r{      sJ  ððð ð
 $Ð #Ð #Ð #Ð #Ð #Ø -Ð -Ð -Ð -Ð -Ð -Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð à €€€à  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð Ð Ð ðð ð €ð  €ˆ4�„ð*A˜' # s (Ô+ð *Að *Að *Añ „ð*AðZ1˜Dð 1ð 1ð 1ð 1ð
5˜dð 5ð 5ð 5ð 5ð
8 4ð 8ð 8ð 8ð 8ð
8˜Dð 8ð 8ð 8ð 8ð5 ð 5ð 5ð 5ð 5ð
5 ð 5ð 5ð 5ð 5ð
%�4ð %ð %ð %ð %ð
�dð ð ð ð ðð ˜œÔ*ð °dð ð ð ð ðð ð ð ð ñ ô ð ð$ð ð ð ð ñ ô ð ð �f‘h”hÐ Ø%€ð	ð 	˜5œ;Ô-ð 	¸ð 	ð 	ð 	ð 	ð+ð +ð +ð +ð +Ð*ñ +ô +ð +ð>!�6ð !Ð4ð !ð !ð !ð !ð�cð ð ð ð ð�u”{Ô)ð ¨dð ð ð ð ð˜ð ð ð ð ð˜ð ð ð ð ð ð r    