o
    8ήc
                     @   sl   d dl Zd dlmZ eddZG dd dZG dd dZG d	d
 d
Ze Zdd Z	dddZ
dd ZdS )    N)
namedtuple_MemoryInfoz
free,totalc                   @   s   e Zd Zdd ZdS )FakeCUDADevicec                 C   s
   d| _ d S )Nz(GPU-00000000-0000-0000-0000-000000000000)uuidself r   K/tmp/pip-target-vg8gfxp4/lib/python/numba/cuda/simulator/cudadrv/devices.py__init__      
zFakeCUDADevice.__init__N)__name__
__module____qualname__r
   r   r   r   r	   r      s    r   c                   @   sv   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	edd Z
edd Zdd Zdd Zdd ZdddZdS )FakeCUDAContextz`
    This stub implements functionality only for simulating a single GPU
    at the moment.
    c                 C   s   || _ t | _d S N)
_device_idr   _device)r   	device_idr   r   r	   r
      s   zFakeCUDAContext.__init__c                 C      d S r   r   r   r   r   r	   	__enter__      zFakeCUDAContext.__enter__c                 C   r   r   r   )r   exc_typeexc_valexc_tbr   r   r	   __exit__   r   zFakeCUDAContext.__exit__c                 C   s   dj | dS )Nz<Managed Device {self.id}>r   )formatr   r   r   r	   __str__   s   zFakeCUDAContext.__str__c                 C      | j S r   )r   r   r   r   r	   id      zFakeCUDAContext.idc                 C   r   r   )r   r   r   r   r	   device"   r   zFakeCUDAContext.devicec                 C   s   dS )N)      r   r   r   r   r	   compute_capability&   s   z"FakeCUDAContext.compute_capabilityc                 C   r   r   r   r   r   r   r	   reset*   r   zFakeCUDAContext.resetc                 C   s   t tdtdS )z
        Cross-platform free / total host memory is hard without external
        dependencies, e.g. `psutil` - so return infinite memory to maintain API
        type compatibility
        inf)r   floatr   r   r   r	   get_memory_info-   s   zFakeCUDAContext.get_memory_infoc                 C   s   t j|ddS )z
        Allocates memory on the simulated device
        At present, there is no division between simulated
        host memory and simulated device memory.
        u1)dtype)npndarray)r   szr   r   r	   memalloc5   s   zFakeCUDAContext.memallocFc                 C   s
   |  |S )zAllocates memory on the host)r-   )r   r,   mappedportablewcr   r   r	   memhostalloc=   s   
zFakeCUDAContext.memhostallocN)FFF)r   r   r   __doc__r
   r   r   r   propertyr   r    r#   r$   r'   r-   r1   r   r   r   r	   r      s     


r   c                   @   sD   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dS )FakeDeviceListz
    This stub implements a device list containing a single GPU. It also
    keeps track of the GPU status, i.e. whether the context is closed or not,
    which may have been set by the user calling reset()
    c                 C   s   t df| _d| _d S )Nr   F)r   lstclosedr   r   r   r	   r
   H   s   
zFakeDeviceList.__init__c                 C   s   d| _ | j| S )NFr6   r5   )r   devnumr   r   r	   __getitem__L   s   
zFakeDeviceList.__getitem__c                 C   s   d dd | jD S )Nz, c                 S   s   g | ]}t |qS r   )str).0dr   r   r	   
<listcomp>Q   s    z*FakeDeviceList.__str__.<locals>.<listcomp>)joinr5   r   r   r   r	   r   P   s   zFakeDeviceList.__str__c                 C   
   t | jS r   )iterr5   r   r   r   r	   __iter__S   r   zFakeDeviceList.__iter__c                 C   r?   r   )lenr5   r   r   r   r	   __len__V   r   zFakeDeviceList.__len__c                 C   s   | j rd S | jd S )Nr   r7   r   r   r   r	   currentY   s   
zFakeDeviceList.currentN)r   r   r   r2   r
   r9   r   rA   rC   r3   rD   r   r   r   r	   r4   B   s    r4   c                   C   s   dt d _d S )NTr   )gpusr6   r   r   r   r	   r$   c   s   r$   c                 C   s   t | S r   )r   )r8   r   r   r	   get_contextg   s   rF   c                 C   s   | S )zP
    In the simulator, a context is always "available", so this is a no-op.
    r   )funcr   r   r	   require_contextk   s   rH   )r   )numpyr*   collectionsr   r   r   r   r4   rE   r$   rF   rH   r   r   r   r	   <module>   s    
6
