
    `i                     f   d dl Z d dlZd dl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	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	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mZ d dlmZ da G d d          Zd dl	mZ 	 d dlmZ n# e$ r  ed          ZY nw xY w	 d dl	mZ n# e$ r  ed          ZY nw xY wd Zd Z de!f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*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*m0Z0 d d)l*m1Z1 d d*l*m2Z2 d d+l*m3Z3 d d,l*m4Z4 d d-l*m5Z5 d d.l*m6Z6 d d/l*m7Z7 d d0l*m8Z8 d d1l*m9Z9 d d2l:m;Z; d d3l<m=Z= d d4l<m>Z> d d5l<m?Z? d d6l<m@Z@ d d7l<mAZA d d8lBmCZC d d9lBmDZD d d:lBmEZE d d;lBmFZF d d<lBmGZG d d=lHmIZI e jJ        d@d>            ZKe jJ        d?             ZLdS )A    N)get_cuda_path)get_nvcc_path)get_rocm_path)get_hipcc_path)compiler)device)function)memory)memory_hook)memory_hooks)pinned_memory)profiler)stream)texture)driver)runtime)nvrtcc                       e Zd ZdZd ZdS )_UnavailableModuleFc                     || _         d S N)__name__)selfnames     f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/cuda/__init__.py__init__z_UnavailableModule.__init__   s        N)r   
__module____qualname__	availabler    r   r   r   r      s(        I    r   r   )cub)nvtxzcupy.cuda.nvtx)thrustzcupy.cuda.thrustc                    | dk    rddl m} |t          j        _        |S | dk    rddl m} |t          j        _        |S | dk    rddl m} |t          j        _        |S | dk    rdd	l m} |t          j        _        |S | d
k    rOt          j        s!t          j
                    dk    r
dd lmc m} nt          d          }|t          j        _        |S t          fD ]}d                    |j                            d          d                   }| |k    rKt%          j        d                    ||j                  t(                     t+          |t                     c S t-          d                    t           |                     )Ncusolverr   )r&   cusparse)r'   curand)r(   cublas)r)   jitifyzcupy.cuda.jitifyz
{}_enabled.z
cupy.cuda.{} has been deprecated in CuPy v8 and will be removed in the future release.
Use {}.available instead.
                z!module '{}' has no attribute '{}')cupy_backends.cuda.libsr&   _cupycudar'   r(   r)   r   is_hipr   get_build_versioncupy.cuda.jitifyr*   r   r#   formatr   splitwarningswarnDeprecationWarning
isinstanceAttributeError)keyr&   r'   r(   r)   r*   modflags           r   __getattr__r=   0   s   
j444444&
	
		444444&
	222222"
	222222"
	~ 	<&":"<"<q"@"@----------'(:;;F"
 v ; ;""3<#5#5c#:#:2#>??$;;M  F4..0BD D D "#'9::::::  +228SAAC C Cr   c                      t           lda 	 t          j                    dk    a nQ# t          $ rD} t          j        s| j        d         dk    r t          j        rd| j        d         vr Y d } ~ nd } ~ ww xY wt           S )NFr   z5cudaErrorNoDevice: no CUDA-capable device is detectedhipErrorNoDevice)
_availabler   getDeviceCount	Exceptionr0   args)es    r   is_availablerE   X   s    
	 /11A5JJ 	 	 	N qvayK(L (L $6afQi$G$G	 s   # 
A1:A,,A1returnc                  (    t          j                    S )a  
    Returns the version of the CUDA Runtime installed in the environment.

    Unlike :func:`cupy.cuda.runtime.runtimeGetVersion`, which returns the
    CUDA Runtime version statically linked to CuPy, this function returns the
    version retrieved from the shared library installed on the host.
    Use this method to probe the CUDA Runtime version installed in the
    environment.
    )r   _getLocalRuntimeVersionr!   r   r   get_local_runtime_versionrI   g   s     *,,,r   )Device)get_cublas_handle)get_device_id)Function)Module)alloc)
BaseMemory)malloc_managed)malloc_async)ManagedMemory)Memory)MemoryAsync)MemoryPointer)
MemoryPool)MemoryAsyncPool)PythonFunctionAllocator)CFunctionAllocator)set_allocator)get_allocator)UnownedMemory)
MemoryHook)alloc_pinned_memory)PinnedMemory)PinnedMemoryPointer)PinnedMemoryPool)set_pinned_memory_allocator)Event)get_current_stream)get_elapsed_time)Stream)ExternalStream)Graphc              #      K   | t           j        } t          j                    }t          j        |            	 dV  t          j        |           dS # t          j        |           w xY w)a  Sets a thread-local allocator for GPU memory inside
       context manager

    Args:
        allocator (function): CuPy memory allocator. It must have the same
            interface as the :func:`cupy.cuda.alloc` function, which takes the
            buffer size as an argument and returns the device buffer of that
            size. When ``None`` is specified, raw memory allocator will be
            used (i.e., memory pool is disabled).
    N)r
   _malloc_get_thread_local_allocator_set_thread_local_allocator)	allocatorprevious_allocators     r   using_allocatorrp      ss       N	;==
&y111?*+=>>>>>*+=>>>>s   A A)c               #      K   t          j        d           t          j                     	 dV  t          j                     dS # t          j                     w xY w)a#  Enable CUDA profiling during with statement.

    This function enables profiling on entering a with statement, and disables
    profiling on leaving the statement.

    >>> with cupy.cuda.profile():
    ...    # do something you want to measure
    ...    pass

    .. note::
        When starting ``nvprof`` from the command line, manually setting
        ``--profile-from-start off`` may be required for the desired behavior.

    .. warning:: This context manager is deprecated. Please use
        :class:`cupyx.profiler.profile` instead.
    z{cupy.cuda.profile has been deprecated since CuPy v10 and will be removed in the future. Use cupyx.profiler.profile instead.N)r5   r6   r   startstopr!   r   r   profilert      s^      $ M	  
 Ns   A Ar   )M
contextlibr5   cupyr.   cupy._environmentr   r   r   r   	cupy.cudar   r   r	   r
   r   r   r   r   r   r   cupy_backends.cuda.apir   r   r-   r   r@   r   r"   r#   ImportErrorr$   r=   rE   intrI   cupy.cuda.devicerJ   rK   rL   cupy.cuda.functionrM   rN   cupy.cuda.memoryrO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   cupy.cuda.memory_hookr^   cupy.cuda.pinned_memoryr_   r`   ra   rb   rc   cupy.cuda.streamrd   re   rf   rg   rh   cupy.cuda.graphri   contextmanagerrp   rt   r!   r   r   <module>r      s            + + + + + + + + + + + + + + + + + + , , , , , ,                         ! ! ! ! ! ! " " " " " " # # # # # #                   ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) 
             0,,,,,,, 0 0 0.//DDD04        4 4 4 233FFF4%C %C %CP  
-3 
- 
- 
- 
- $ # # # # # . . . . . . * * * * * * ' ' ' ' ' ' % % % % % % " " " " " " ' ' ' ' ' ' + + + + + + ) ) ) ) ) ) * * * * * * # # # # # # ( ( ( ( ( ( * * * * * * ' ' ' ' ' ' , , , , , , 4 4 4 4 4 4 / / / / / / * * * * * * * * * * * * * * * * * * , , , , , , 7 7 7 7 7 7 0 0 0 0 0 0 7 7 7 7 7 7 4 4 4 4 4 4 ? ? ? ? ? ? " " " " " " / / / / / / - - - - - - # # # # # # + + + + + + ! ! ! ! ! ! ? ? ? ?.     s$   	B B#"B#'B. .C C