Ë
    üÇ:jÝ%  ã                   óâ   — d dl mZmZmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZmZmZ d dlZd dlZd dlZd dlZeZeZ G d„ de	«      Z ej.                  «       Z G d„ d	«      Z G d
„ d«      Zd„ Zy)é    )ÚbyrefÚc_charÚc_char_pÚc_intÚc_size_tÚc_void_pÚPOINTER)ÚIntEnum)Úconfig)Ú
NvrtcErrorÚNvrtcCompilationErrorÚNvrtcSupportErrorNc                   ó<   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZy)ÚNvrtcResultr   é   é   é   é   é   é   é   é   é	   é
   é   N)Ú__name__Ú
__module__Ú__qualname__ÚNVRTC_SUCCESSÚNVRTC_ERROR_OUT_OF_MEMORYÚ$NVRTC_ERROR_PROGRAM_CREATION_FAILUREÚNVRTC_ERROR_INVALID_INPUTÚNVRTC_ERROR_INVALID_PROGRAMÚNVRTC_ERROR_INVALID_OPTIONÚNVRTC_ERROR_COMPILATIONÚ%NVRTC_ERROR_BUILTIN_OPERATION_FAILUREÚ1NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATIONÚ/NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATIONÚ%NVRTC_ERROR_NAME_EXPRESSION_NOT_VALIDÚNVRTC_ERROR_INTERNAL_ERROR© ó    úm/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/numba/cuda/cudadrv/nvrtc.pyr   r      sI   „ Ø€MØ !ÐØ+,Ð(Ø !ÐØ"#ÐØ!"ÐØÐØ,-Ð)Ø89Ð5Ø67Ð3Ø,.Ð)Ø!#Ñr,   r   c                   ó,   — e Zd ZdZd„ Zed„ «       Zd„ Zy)ÚNvrtcProgramzá
    A class for managing the lifetime of nvrtcProgram instances. Instances of
    the class own an nvrtcProgram; when an instance is deleted, the underlying
    nvrtcProgram is destroyed using the appropriate NVRTC API.
    c                 ó    — || _         || _        y ©N)Ú_nvrtcÚ_handle)ÚselfÚnvrtcÚhandles      r-   Ú__init__zNvrtcProgram.__init__+   s   € ØˆŒØˆ�r,   c                 ó   — | j                   S r1   )r3   ©r4   s    r-   r6   zNvrtcProgram.handle/   s   € à�|‰|Ðr,   c                 óT   — | j                   r| j                  j                  | «       y y r1   )r3   r2   Údestroy_programr9   s    r-   Ú__del__zNvrtcProgram.__del__3   s    € Ø�<Š<Ø�K‰K×'Ñ'¨Õ-ð r,   N)r   r   r   Ú__doc__r7   Úpropertyr6   r<   r+   r,   r-   r/   r/   %   s%   „ ñò
ð ñó ðó.r,   r/   c                   ó  — e Zd ZdZe ee«       ee«      feeeee ee«       ee«      fe ee«      feee ee«      fee ee	«      feeefee ee	«      feeefee ee	«      feeefdœ
Z
dZd„ Zd„ Zd„ Zd„ Zd„ Zd	„ Zd
„ Zy)ÚNVRTCaB  
    Provides a Pythonic interface to the NVRTC APIs, abstracting away the C API
    calls.

    The sole instance of this class is a process-wide singleton, similar to the
    NVVM interface. Initialization is protected by a lock and uses the standard
    (for Numba) open_cudalib function to load the NVRTC library.
    )
ÚnvrtcVersionÚnvrtcCreateProgramÚnvrtcDestroyProgramÚnvrtcCompileProgramÚnvrtcGetPTXSizeÚnvrtcGetPTXÚnvrtcGetCUBINSizeÚnvrtcGetCUBINÚnvrtcGetProgramLogSizeÚnvrtcGetProgramLogNc                 óø  — t         5  | j                  €™ddlm} t        j                  | «      x| _        }	  |d«      }|j                  j                  «       D ]Q  \  }}t        ||«      }|d   |_        |dd  |_        t        j                  |«      ||dœd„«       }t        |||«       ŒS d d d «       | j                  S # t        $ r}d | _        t        d«      |‚d }~ww xY w# 1 sw Y   | j                  S xY w)Nr   )Úopen_cudalibr5   zNVRTC cannot be loadedr   )ÚfuncÚnamec                 óê   —  | |Ž }|t         j                  k(  r
t        «       ‚|t         j                  k7  r)	 t        |«      j                  }d|› d|› �}t        |«      ‚y # t
        $ r	 d|› d�}Y Œ%w xY w)Nz"Unknown nvrtc_result (error code: ú)zFailed to call z: )r   r%   r   r   rN   Ú
ValueErrorr   )rM   rN   ÚargsÚerrorÚ
error_nameÚmsgs         r-   Úchecked_callz#NVRTC.__new__.<locals>.checked_callx   s‘   € á $ d ˜Ø ¤K×$GÑ$GÒGÜ"7Ó"9Ð9Ø"¤k×&?Ñ&?Ò?ðHÜ-8¸Ó-?×-DÑ-D 
ð %4°D°6¸¸J¸<Ð"H˜CÜ",¨S£/Ð1ð @øô $.ò Hð/>Ø>C¸WÀAð/G¢
ðHús   ·A  Á A2Á1A2)Ú_nvrtc_lockÚ_NVRTC__INSTANCEÚnumba.cuda.cudadrv.libsrL   ÚobjectÚ__new__ÚOSErrorr   Ú_PROTOTYPESÚitemsÚgetattrÚrestypeÚargtypesÚ	functoolsÚwrapsÚsetattr)	ÚclsrL   ÚinstÚlibÚerN   ÚprotorM   rV   s	            r-   r[   zNVRTC.__new__g   s   € Üñ 	6Ø�~‰~Ð%Ý@Ü(.¯©°sÓ(;Ð;�” ðMÙ& wÓ/�Cð $(×#3Ñ#3×#9Ñ#9Ó#;ò 6‘K�D˜%Ü" 3¨Ó-�DØ#(¨¡8�D”LØ$)¨!¨" I�D”Mä—_‘_ TÓ*Ø15¸Dó 2ó +ð2ô ˜D $¨Õ5ð'6÷	6ð@ �~‰~Ðøô5 ò MØ%)�C”NÜ+Ð,DÓEÈ1ÐLûðMú÷	6ð@ �~‰~Ðús.   ‡/C%·C¿A.C%Ã	C"Ã
CÃC"Ã"C%Ã%C9c                 ó¢   — t        «       }t        «       }| j                  t        |«      t        |«      «       |j                  |j                  fS )zB
        Get the NVRTC version as a tuple (major, minor).
        )r   rA   r   Úvalue)r4   ÚmajorÚminors      r-   Úget_versionzNVRTC.get_versionŠ   s=   € ô “ˆÜ“ˆØ×Ñœ% ›,¬¨e«Ô5Ø�{‰{˜EŸK™KÐ'Ð'r,   c                 óì   — t        |t        «      r|j                  «       }t        |t        «      r|j                  «       }t        «       }| j	                  t        |«      ||ddd«       t        | |«      S )z@
        Create an NVRTC program with managed lifetime.
        r   N)Ú
isinstanceÚstrÚencodeÚnvrtc_programrB   r   r/   )r4   ÚsrcrN   r6   s       r-   Úcreate_programzNVRTC.create_program“   s`   € ô �cœ3ÔØ—*‘*“,ˆCÜ�dœCÔ Ø—;‘;“=ˆDä“ˆð
 	×Ñ¤ f£¨s°D¸!¸TÀ4ÔHÜ˜D &Ó)Ð)r,   c                 ó  — |D �cg c]  }|j                  «       ‘Œ }}|D �cg c]  }t        |«      ‘Œ }}t        t        |«      z  } ||Ž }	 | j                  |j                  t        |«      |«       yc c}w c c}w # t
        $ r Y yw xY w)zÌ
        Compile an NVRTC program. Compilation may fail due to a user error in
        the source; this function returns ``True`` if there is a compilation
        error and ``False`` on success.
        FT)rr   r   ÚlenrD   r6   r   )r4   ÚprogramÚoptionsÚoptÚencoded_optionsÚoption_pointersÚc_options_typeÚ	c_optionss           r-   Úcompile_programzNVRTC.compile_program¤   sŠ   € ð 4;Ö;¨C˜3Ÿ:™:�<Ð;ˆÐ;Ø4CÖD¨Sœ8 C�=ÐDˆÐDÜ"¤S¨£\Ñ1ˆÙ" OÐ4ˆ	ð	Ø×$Ñ$ W§^¡^´S¸³\À9ÔMØùò <ùÚDøô %ò 	Ùð	ús   …A5¢A:Á&A? Á?	BÂ
Bc                 óL   — | j                  t        |j                  «      «       y)z+
        Destroy an NVRTC program.
        N)rC   r   r6   )r4   rx   s     r-   r;   zNVRTC.destroy_program¶   s   € ð 	× Ñ ¤ w§~¡~Ó!6Õ7r,   c                 óú   — t        «       }| j                  |j                  t        |«      «       t	        |j
                  z  «       }| j                  |j                  |«       |j
                  j                  «       S )z9
        Get the compile log as a Python string.
        )r   rI   r6   r   r   rk   rJ   Údecode)r4   rx   Úlog_sizeÚlogs       r-   Úget_compile_logzNVRTC.get_compile_log¼   s[   € ô “:ˆØ×#Ñ# G§N¡N´E¸(³OÔDä˜Ÿ™Ñ&Ó)ˆØ×Ñ §¡°Ô4à�y‰y×ÑÓ!Ð!r,   c                 óú   — t        «       }| j                  |j                  t        |«      «       t	        |j
                  z  «       }| j                  |j                  |«       |j
                  j                  «       S )z:
        Get the compiled PTX as a Python string.
        )r   rE   r6   r   r   rk   rF   r‚   )r4   rx   Úptx_sizeÚptxs       r-   Úget_ptxzNVRTC.get_ptxÈ   s[   € ô “:ˆØ×Ñ˜WŸ^™^¬U°8«_Ô=ä˜Ÿ™Ñ&Ó)ˆØ×Ñ˜Ÿ™¨Ô-à�y‰y×ÑÓ!Ð!r,   )r   r   r   r=   Únvrtc_resultr	   r   rs   r   r   r]   rX   r[   rn   ru   r   r;   r…   r‰   r+   r,   r-   r@   r@   8   sì   „ ñð &¡w¨u£~±w¸u³~ÐFð  ,¨]¸HÀhØ$¡g¨hÓ&7¹ÀÓ9JðLð !-©g°mÓ.DÐEð !-¨m¸UÙ '¨Ó 1ð 3ð )¨-¹ÀÓ9JÐKà$ m°XÐ>ð +¨M¹7À8Ó;LÐMà&¨°xÐ@ð $0°Ù#*¨8Ó#4ð#6ð  ,¨]¸HÐEñA!€KðH €Jò!òF(ò*ò"ò$8ò
"ó
"r,   r@   c                 ó&  — t        «       }|j                  | |«      }|\  }}d|› |› �}dt        j                  › �}t        j
                  j                  t        j
                  j                  t        «      «      }	t        j
                  j                  |	«      }
d|
› �}|||ddg}|j                  ||«      }|j                  |«      }|rd|› d|› �}t        |«      ‚|rd|› d|› �}t        j                  |«       |j                  |«      }||fS )a~  
    Compile a CUDA C/C++ source to PTX for a given compute capability.

    :param src: The source code to compile
    :type src: str
    :param name: The filename of the source (for information only)
    :type name: str
    :param cc: A tuple ``(major, minor)`` of the compute capability
    :type cc: tuple
    :return: The compiled PTX and compilation log
    :rtype: tuple
    z--gpu-architecture=compute_z-Iz-rdcÚtruez+NVRTC Compilation failure whilst compiling z:

z$NVRTC log messages whilst compiling )r@   ru   r   ÚCUDA_INCLUDE_PATHÚosÚpathÚdirnameÚabspathÚ__file__r   r…   r   ÚwarningsÚwarnr‰   )rt   rN   Úccr5   rx   rl   rm   ÚarchÚincludeÚcudadrv_pathÚnumba_cuda_pathÚnumba_includery   Úcompile_errorr„   rU   rˆ   s                    r-   Úcompilerœ   Õ   s  € ô ‹G€EØ×"Ñ" 3¨Ó-€Gð �L€Eˆ5Ø(¨¨°¨wÐ7€DØ”6×+Ñ+Ð,Ð-€Gä—7‘7—?‘?¤2§7¡7§?¡?´8Ó#<Ó=€LÜ—g‘g—o‘o lÓ3€OØ˜Ð)Ð*€MØ�W˜m¨V°VÐ<€Gð ×)Ñ)¨'°7Ó;€Mð ×
Ñ
 Ó
(€Cñ Ø<¸T¸FÀ%ÈÀuÐMˆÜ˜‹oÐñ Ø5°d°V¸5ÀÀÐFˆÜ�‰�cÔà
�-‰-˜Ó
 €CØ�ˆ8€Or,   )Úctypesr   r   r   r   r   r   r	   Úenumr
   Ú
numba.corer   Únumba.cuda.cudadrv.errorr   r   r   rb   rŽ   Ú	threadingr“   rs   rŠ   r   ÚLockrW   r/   r@   rœ   r+   r,   r-   ú<module>r£      sr   ðß N× NÑ NÝ Ý ÷9ñ 9ó Û 	Û Û ð €ð €ô$�'ô $ð ˆi�n‰nÓ€÷.ñ .÷&Z"ñ Z"óz/r,   