o
    8ήc                     @   s:  d dl Zd dlZd dlmZmZmZ d dlmZm	Z	 d dlm
Z
 d dlmZ d dlmZ dZejdejfd	ejfd
ejfdejeffgddZejdejfdejdfgddZedejfdejdfgZedejfdefgZe
dG dd de	ZG dd deZe
dG dd de	Zedkre  dS dS )    N)DeviceRecordfrom_record_likeauto_device)unittestCUDATestCase)skip_on_cudasim)numpy_support)cuda   abcdTaligngh   ij)   r   xyz.Device Record API unsupported in the simulatorc                       sP   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )TestCudaDeviceRecordz?
    Tests the DeviceRecord class with np.void host types.
    c                    s   t    | tj d S N)supersetUp_create_datanpzerosself	__class__ V/tmp/pip-target-vg8gfxp4/lib/python/numba/cuda/tests/cudadrv/test_cuda_devicerecord.pyr   )      
zTestCudaDeviceRecord.setUpc                 C   s\   t jdt jfdt jfgdd| _|d| jd | _|d| jd | _d| jd< d| jd< d S )	Nr   r   Tr      r   
   g      &@)r   dtypeint32float32hostzhostnz)r!   
array_ctorr$   r$   r%   r   -   s
    
z!TestCudaDeviceRecord._create_datac                 C   s   |  |jt  |  |jt  |  |j|j |  |j|jj | |j | 	|j
td t|j}|  |j| d S )Nr   )assertEqualshapetuplestridesr)   
alloc_sizeitemsizeassertIsNotNonegpu_dataassertNotEqualdevice_ctypes_pointerctypesc_void_pr   
from_dtype_numba_type_)r!   	referencerec
numba_typer$   r$   r%   _check_device_record4   s   z)TestCudaDeviceRecord._check_device_recordc                 C   s$   | j  }t| j}| || d S r   )r,   copyr   r)   r@   )r!   hostrecdevrecr$   r$   r%   test_device_record_interface?   s   

z1TestCudaDeviceRecord.test_device_record_interfacec                 C   s~   | j  }t| j}|| | j }|| tj	| j | | j }|| | j  }|| tj	|| j d S r   )
r,   rA   r   r)   copy_to_devicer-   copy_to_hostr   testingassert_equal)r!   rB   rC   hostrec2hostrec3hostrec4r$   r$   r%   test_device_record_copyD   s   








z,TestCudaDeviceRecord.test_device_record_copyc                 C   sF   | j  }t|}| || t|}| || | |j|j d S r   )r,   rA   r   r@   r7   r6   )r!   rB   rC   devrec2r$   r$   r%   test_from_record_likeV   s   
z*TestCudaDeviceRecord.test_from_record_likec                 C   sR   | j  }t|\}}| || | | | j }|| tj	|| d S r   )
r-   rA   r   r@   
assertTruer,   rF   r   rG   rH   )r!   rB   rC   new_gpu_objrI   r$   r$   r%   test_auto_devicea   s   



z%TestCudaDeviceRecord.test_auto_device)__name__
__module____qualname____doc__r   r   r@   rD   rL   rN   rQ   __classcell__r$   r$   r"   r%   r   $   s    r   c                   @   s   e Zd ZdZdd ZdS )TestCudaDeviceRecordWithRecordz@
    Tests the DeviceRecord class with np.record host types
    c                 C   s   t |  | tj d S r   )r   r   r   r   recarrayr    r$   r$   r%   r   r   r&   z$TestCudaDeviceRecordWithRecord.setUpN)rR   rS   rT   rU   r   r$   r$   r$   r%   rW   n   s    rW   z7Structured array attr access not supported in simulatorc                       sH   e Zd ZdZdd Z fddZdd Zdd	 Zd
d Zdd Z	  Z
S )TestRecordDtypeWithStructArraysz?
    Test operation of device arrays on structured arrays.
    c                 C   s<   t jdtd| _t jdtdd | _t jdtdd | _d S )Nr   r)   r'   r   )r	   device_array
recordtypesample1drecordwitharraysamplerec1darr
recwithmatsamplerecmatr    r$   r$   r%   _createSampleArrays}   s   z3TestRecordDtypeWithStructArrays._createSampleArraysc                    st   t    |   | j}t|jD ]&}|d }|d || d< ||| d< |d || d< t|t || d< qd S )Nr'   r   r   r                 ?r   r   )r   r   rb   r]   rangesizestrN_CHARSr!   aryr   r   r"   r$   r%   r      s   
z%TestRecordDtypeWithStructArrays.setUpc                 C   s   | j }t| j jD ]6}|d }| || d |d  | || d | | || d |d  | || d t|t  q	d S )Nr'   r   r   r   r   rc   r   )r]   rd   re   r/   rf   rg   rh   r$   r$   r%   test_structured_array1   s   z6TestRecordDtypeWithStructArrays.test_structured_array1c                 C   sb   | j }d|d< d|d d< d|d d< | |d d | |d d d | |d d d d S )Nr   r   g      @r   r   g      @r'   )r_   r/   )r!   ri   r$   r$   r%   test_structured_array2   s   z6TestRecordDtypeWithStructArrays.test_structured_array2c                 C   sV   | j }tjg dg dg dgtjddd}||d d d < tj|d | d S )N)g      @g      $@g      .@)g      4@g      9@g      >@)g     A@g      D@g     F@rZ   r   r   )ra   r   arrayr+   reshaperG   rH   )r!   ri   matr$   r$   r%   test_structured_array3   s   
z6TestRecordDtypeWithStructArrays.test_structured_array3c                 C   st   t jdtd}t|}d|d d d< | |d d d d d|d d d d< | |d d d d d d S )	Nr'   rZ   r   r   r   g       @r   )r   r   )r   r   recwithrecwithmatr	   	to_devicer/   )r!   arrd_arrr$   r$   r%   test_structured_array4   s   
 z6TestRecordDtypeWithStructArrays.test_structured_array4)rR   rS   rT   rU   rb   r   rj   rk   ro   rt   rV   r$   r$   r"   r%   rY   w   s    			rY   __main__)numpyr   r9   numba.cuda.cudadrv.devicearrayr   r   r   numba.cuda.testingr   r   r   numba.npr   numbar	   rg   r)   float64r*   	complex64str_r\   r+   r^   r`   rp   r   rW   rY   rR   mainr$   r$   r$   r%   <module>   sD    


I	: