o
    Y۷iT                     @   sd   d dl Zd dlmZmZ d dlmZmZmZ dd Z	dd Z
G dd	 d	eZed
kr0e  dS dS )    N)cudaerrors)unittestCUDATestCaseskip_on_cudasimc                 C   s$   t |jd D ]}| | ||< qd S Nr   )rangeshapeinpouti r   Z/home/ubuntu/vllm_env/lib/python3.10/site-packages/numba/cuda/tests/cudapy/test_slicing.pyfoo   s   r   c                 C   s0   t d}t| |d d f ||d d f  d S )N   )r   gridcufoor
   r   r   r   copy   s   
&r   c                   @   s4   e Zd Zdd Zdd Zdd Zeddd	 Zd
S )TestCudaSlicingc                 C   sT   t jdddtat dt}tjdtjddd}t	|}|d || d S )	Nzvoid(int32[:], int32[:])T)devicezvoid(int32[:,:], int32[:,:])d   )dtype
   )r   r   )
r   jitr   r   r   nparangeint32reshape
zeros_like)selfcucopyr   r   r   r   r   test_slice_as_arg   s
   
z!TestCudaSlicing.test_slice_as_argc                 C   s0   d}t |}tt|}t||d d < d S r   )r   r   device_arraylen	to_device)r    Naarrr   r   r   test_assign_empty_slice   s   z'TestCudaSlicing.test_assign_empty_slicec                 C   s   t ddd }d S )Nzvoid(f4[:, :, :], i4, i4)c                 S   s   d| ||f< d S )N)r   r   r   r   )tmpr'   br   r   r   check_sequence_setslice;      zqTestCudaSlicing.test_array_slice_assignment_from_sequence_error_handling_codegen.<locals>.check_sequence_setslice)r   r   )r    r,   r   r   r   @test_array_slice_assignment_from_sequence_error_handling_codegen7   s   zPTestCudaSlicing.test_array_slice_assignment_from_sequence_error_handling_codegenz$No NRT codegen in the CUDA simulatorc                 C   sX   |  tj}tddd }W d    n1 sw   Y  d}| |t|j d S )Nz void(f4[:, :, :], f4[:], i4, i4)c                 S   s   || ||f< d S )Nr   )r*   valuer'   r+   r   r   r   check_array_setsliceD   r-   zkTestCudaSlicing.test_array_slice_assignment_from_array_error_handling_codegen.<locals>.check_array_setslicezNRT required but not enabled)assertRaisesr   NumbaRuntimeErrorr   r   assertInstr	exception)r    raisesr0   msgr   r   r   =test_array_slice_assignment_from_array_error_handling_codegen?   s   zMTestCudaSlicing.test_array_slice_assignment_from_array_error_handling_codegenN)__name__
__module____qualname__r"   r)   r.   r   r8   r   r   r   r   r      s    
r   __main__)numpyr   numbar   r   numba.cuda.testingr   r   r   r   r   r   r9   mainr   r   r   r   <module>   s    <