
    sh%                         S SK JrJrJrJrJrJrJr  S SKJ	r	  S SK
Jr  S SKJrJrJr  S SKrS SKrS SKrS SKr\r\r " S S\	5      r\R.                  " 5       r " S S	5      r " S
 S5      rS rg)    )byrefc_charc_char_pc_intc_size_tc_void_pPOINTER)IntEnum)config)
NvrtcErrorNvrtcCompilationErrorNvrtcSupportErrorNc                   D    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrg)NvrtcResult   r                           	   
       N)__name__
__module____qualname____firstlineno__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_FAILURE1NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION/NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION%NVRTC_ERROR_NAME_EXPRESSION_NOT_VALIDNVRTC_ERROR_INTERNAL_ERROR__static_attributes__r       l/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/cudadrv/nvrtc.pyr   r      sI    M !+,( !"#!",-)895673,.)!#r/   r   c                   4    \ rS rSrSrS r\S 5       rS rSr	g)NvrtcProgram%   z
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                     Xl         X l        g N)_nvrtc_handle)selfnvrtchandles      r0   __init__NvrtcProgram.__init__+   s    r/   c                     U R                   $ r5   )r7   r8   s    r0   r:   NvrtcProgram.handle/   s    ||r/   c                 ^    U R                   (       a  U R                  R                  U 5        g g r5   )r7   r6   destroy_programr>   s    r0   __del__NvrtcProgram.__del__3   s     <<KK''- r/   )r7   r6   N)
r   r   r    r!   __doc__r;   propertyr:   rB   r.   r   r/   r0   r2   r2   %   s%    
  .r/   r2   c                      \ rS rSrSr\\" \5      \" \5      4\\\	\	\\" \	5      \" \	5      4\\" \5      4\\\\" \	5      4\\\" \
5      4\\\	4\\\" \
5      4\\\	4\\\" \
5      4\\\	4S.
rSrS rS rS rS rS	 rS
 rS rSrg)NVRTC8   a*  
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                    [            U R                  c  SSKJn  [        R                  U 5      =U l        n U" S5      nUR                  R                  5        HP  u  pV[        X55      nUS   Ul        USS  Ul        [        R                  " U5      XuS.S j5       n[        X%U5        MR     S S S 5        U R                  $ ! [         a  nS U l        [        S5      UeS nAff = f! , (       d  f       U R                  $ = f)Nr   )open_cudalibr9   zNVRTC cannot be loadedr   )funcnamec                     U " U6 nU[         R                  :X  a
  [        5       eU[         R                  :w  a)   [        U5      R                  nSU SU 3n[        U5      eg ! [
         a	    SU S3n N&f = f)Nz"Unknown nvrtc_result (error code: )zFailed to call z: )r   r(   r   r"   rV   
ValueErrorr   )rU   rV   argserror
error_namemsgs         r0   checked_call#NVRTC.__new__.<locals>.checked_callx   s     $d K$G$GG"7"99"k&?&??H-8-?-D-D
 %4D6J<"HC",S/1 @ $. H/>>CWA/G
Hs   A" "A54A5)_nvrtc_lock_NVRTC__INSTANCEnumba.cuda.cudadrv.libsrT   object__new__OSErrorr   _PROTOTYPESitemsgetattrrestypeargtypes	functoolswrapssetattr)	clsrT   instliberV   protorU   r^   s	            r0   rd   NVRTC.__new__g   s    ~~%@(.s(;;M&w/C $(#3#3#9#9#;KD"3-D#(8DL$)!"IDM__T*15 2 +2 D5' $< @ ~~5  M%)CN+,DE1LM [@ ~~s/   0C'C A.C'
C$CC$$C''
D c                     [        5       n[        5       nU R                  [        U5      [        U5      5        UR                  UR                  4$ )z2
Get the NVRTC version as a tuple (major, minor).
)r   rI   r   value)r8   majorminors      r0   get_versionNVRTC.get_version   s=     %,e5{{EKK''r/   c                     [        U[        5      (       a  UR                  5       n[        U[        5      (       a  UR                  5       n[        5       nU R	                  [        U5      XSSS5        [        X5      $ )z0
Create an NVRTC program with managed lifetime.
r   N)
isinstancestrencodenvrtc_programrJ   r   r2   )r8   srcrV   r:   s       r0   create_programNVRTC.create_program   sb     c3**,CdC  ;;=D
 	fs!T4HD))r/   c                 (   U Vs/ s H  o3R                  5       PM     nnU Vs/ s H  n[        U5      PM     nn[        [        U5      -  nU" U6 n U R                  UR                  [        U5      U5        gs  snf s  snf ! [
         a     gf = f)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)r}   r   lenrL   r:   r   )r8   programoptionsoptencoded_optionsoption_pointersc_options_type	c_optionss           r0   compile_programNVRTC.compile_program   s     4;;7C::<7;4CDOS8C=OD"S\1"O4		$$W^^S\9M <D % 		s   A:A?&B 
BBc                 L    U R                  [        UR                  5      5        g)z
Destroy an NVRTC program.
N)rK   r   r:   )r8   r   s     r0   rA   NVRTC.destroy_program   s     	  w~~!67r/   c                     [        5       nU R                  UR                  [        U5      5        [        UR
                  -  " 5       nU R                  UR                  U5        UR
                  R                  5       $ )z)
Get the compile log as a Python string.
)r   rQ   r:   r   r   ru   rR   decode)r8   r   log_sizelogs       r0   get_compile_logNVRTC.get_compile_log   s[     :##GNNE(OD&)4yy!!r/   c                     [        5       nU R                  UR                  [        U5      5        [        UR
                  -  " 5       nU R                  UR                  U5        UR
                  R                  5       $ )z*
Get the compiled PTX as a Python string.
)r   rM   r:   r   r   ru   rN   r   )r8   r   ptx_sizeptxs       r0   get_ptxNVRTC.get_ptx   s[     :W^^U8_=&)-yy!!r/   r   )r   r   r    r!   rD   nvrtc_resultr	   r   r~   r   r   rf   ra   rd   rx   r   r   rA   r   r   r.   r   r/   r0   rG   rG   8   s     &wu~wu~F  ,]Hh$gh&79JL !-gm.DE !-mU ' 1 3 )-9JK$mX> +M78;LM&x@ $0#*8#4#6  ,]HEA!KH J!F(*"$8
"
"r/   rG   c                 4   [        5       nUR                  X5      nUu  pVSU U 3nS[        R                   3n[        R
                  R                  [        R
                  R                  [        5      5      n	[        R
                  R                  U	5      n
SU
 3nXxUSS/nUR                  XL5      nUR                  U5      nU(       a  SU SU 3n[        U5      eU(       a  SU SU 3n[        R                  " U5        UR                  U5      nUU4$ )aV  
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 )rG   r   r   CUDA_INCLUDE_PATHospathdirnameabspath__file__r   r   r   warningswarnr   )r   rV   ccr9   r   rv   rw   archincludecudadrv_pathnumba_cuda_pathnumba_includer   compile_errorr   r]   r   s                    r0   compiler      s    GE""3-G LE(w7D6++,-G77??277??8#<=Lggool3O)*MmVV<G ))';M 


(C <TF%uMo 5dV5Fc
--
 C8Or/   )ctypesr   r   r   r   r   r   r	   enumr
   
numba.corer   numba.cuda.cudadrv.errorr   r   r   rk   r   	threadingr   r~   r   r   Lockr`   r2   rG   r   r   r/   r0   <module>r      sp    N N N  9 9  	    $' $ nn. .&Z" Z"z/r/   