
    xKg<                        d dl Zd dlmZ d dlmZmZmZmZ d dlm	Z	 d dlm
Z
 d dlmZmZ d dlZd dlZd dlmZmZ d dlmZ efd	Z ed
       G d de             Z ed
       G d de             Zedk(  r ej2                          yy)    N)
namedtuple)voidint32float32float64)guvectorize)cuda)skip_on_cudasimCUDATestCase)NumbaPerformanceWarningTypingError)override_configc           
      |    t        t        | d d d d f   | d d d d f   | d d d d f         gdd      d        }|S )Nz(m,n),(n,p)->(m,p)r	   targetc           
          | j                   \  }}|j                   \  }}t        |      D ]E  }t        |      D ]5  }d|||f<   t        |      D ]  }|||fxx   | ||f   |||f   z  z  cc<     7 G y Nr   shaperange)	ABCmnpijks	            g/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/cuda/tests/cudapy/test_gufunc.py
matmulcorez*_get_matmulcore_gufunc.<locals>.matmulcore   s|     ww1ww1qA1X!Q$qAadGqAw1a400G "      )r   r   )dtyper!   s     r    _get_matmulcore_gufuncr$      sM    $uQT{E!Q$Kq!t=>% 1 1 r"   z&ufunc API unsupported in the simulatorc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestCUDAGufuncc                    t               }d}t        j                  |dz  dz  t        j                        j	                  |dd      }t        j                  |dz  dz  t        j                        j	                  |dd      } |||      }t        j
                  ||      }| j                  t        j                  ||             y N      r#      r$   nparanger   reshapematmul
assertTrueallcloseselfgufunc	matrix_ctr   r   r   Golds          r    test_gufunc_smallz TestCUDAGufunc.test_gufunc_small!   s    ')	IIi!ma'rzz:BB9aCDFIIi!ma'rzz:BB9aCDF 1aLyyAAt,-r"   c                    t               }d}t        j                  |dz  dz  t        j                        j	                  |dd      }t        j                  |dz  dz  t        j                        j	                  |dd      }t        j                  |      } |||      j                         }t        j                  ||      }| j                  t        j                  ||             y r(   )r$   r.   r/   r   r0   r	   	to_devicecopy_to_hostr1   r2   r3   )r5   r6   r7   r   r   dBr   r8   s           r    test_gufunc_auto_transferz(TestCUDAGufunc.test_gufunc_auto_transfer/   s    ')	IIi!ma'rzz:BB9aCDFIIi!ma'rzz:BB9aCDF ^^A1bM&&(yyAAt,-r"   c                    t               }d}t        j                  |dz  dz  t        j                        j	                  |dd      }t        j                  |dz  dz  t        j                        j	                  |dd      } |||      }t        j
                  ||      }| j                  t        j                  ||             y )N  r)   r*   r+   r,   r-   r4   s          r    test_gufunczTestCUDAGufunc.test_gufunc?   s    ')	IIi!ma'rzz:BB9aCDFIIi!ma'rzz:BB9aCDF 1aLyyAAt,-r"   c                    t               }d}t        j                  |dz  dz  t        j                        j	                  dddd      }t        j                  |dz  dz  t        j                        j	                  dddd      } |||      }t        j
                  ||      }| j                  t        j                  ||             y )Nd   r)   r*   r+      r,   r-   r4   s          r    test_gufunc_hidimz TestCUDAGufunc.test_gufunc_hidimM   s    ')	IIi!ma'rzz:BB1b!QOIIi!ma'rzz:BB1b!QO1aLyyAAt,-r"   c                    t        t              }t        j                  j	                  ddd      }t        j                  j	                  dd      }t        j
                  ||      } |||      }t        j                  j                  ||        ||t        j                  |d            }t        j                  j                  ||       y )Nr+   
      )rG      rI   )	r$   r   r.   randomrandnr1   testingassert_allclosetile)r5   r6   XYgoldres1res2s          r    test_gufunc_new_axisz#TestCUDAGufunc.test_gufunc_new_axisY   s    'g6IIOOB1%IIOOAq!yyAa|


""4.aJ/0


""4.r"   c                    t               }d}t        j                  |dz  dz  t        j                        j	                  |dd      }t        j                  |dz  dz  t        j                        j	                  |dd      }t        j                         }t        j                  ||      }t        j                  ||      }t        j                  d|j                  |      } |||||      }|j                  |	      }	|j                          t        j                  ||      }
| j                  t        j                  |	|
             y )
Nr@   r)   r*   r+   r,   )r@   r)   r,   )r   r#   stream)outrV   )rV   )r$   r.   r/   r   r0   r	   rV   r;   device_arrayr#   r<   synchronizer1   r2   r3   )r5   r6   r7   r   r   rV   dAr=   dCr   r8   s              r    test_gufunc_streamz!TestCUDAGufunc.test_gufunc_streamh   s   ') 	IIi!ma'rzz:BB9aCDFIIi!ma'rzz:BB9aCDF ^^Av&^^Av&\PB62OO6O*yyAAt,-r"   c                 ,   t        t        t        d d  t        d d        gdd      d        }t        j                  dt        j                        dz   }t        j
                  |      } |||       t        j                  j                  ||       y )	N(x)->(x)r	   r   c                 H    t        |j                        D ]
  }| |   ||<    y Nr   sizer   r   r   s      r    copyz&TestCUDAGufunc.test_copy.<locals>.copy   #     166]t! #r"   rG   r+   rI   rW   r   r   r   r.   r/   
zeros_likerL   rM   r5   rd   r   r   s       r    	test_copyzTestCUDAGufunc.test_copy   sy    	d71:wqz23"
$	
$	 IIb

+a/MM!QA


""1a(r"   c                 &   t        t        d d  t        d d  fgdd      d        }t        j                  dt        j                        dz   }t        j                  |      } |||       | j                  t        j                  ||             y )	Nr^   r	   r   c                 H    t        |j                        D ]
  }| |   ||<    y r`   ra   rc   s      r    rd   z9TestCUDAGufunc.test_copy_unspecified_return.<locals>.copy   re   r"   rG   r+   rI   rf   )r   r   r.   r/   rh   r2   r3   ri   s       r    test_copy_unspecified_returnz+TestCUDAGufunc.test_copy_unspecified_return   s|     
wqz71:./"
$	
$	 IIb

+a/MM!QAAq)*r"   c                 6   t        t        t        d d  t        d d        gdd      d        }t        j                  dt        j                        dz   }t        j
                  |      } |||       | j                  t        j                  ||             y )	Nr^   r	   r   c                 H    t        |j                        D ]
  }| |   ||<    y r`   ra   rc   s      r    rd   z*TestCUDAGufunc.test_copy_odd.<locals>.copy   re   r"      r+   rI   rf   )r   r   r   r.   r/   rh   r2   r3   ri   s       r    test_copy_oddzTestCUDAGufunc.test_copy_odd   s|    	d71:wqz23"
$	
$	 IIb

+a/MM!QAAq)*r"   c           	      n   t        t        t        d d d d f   t        d d d d f         gdd      d        }t        j                  dt        j                        j                  dd      d	z   }t        j                  |      } |||
       | j                  t        j                  ||             y )Nz(x, y)->(x, y)r	   r   c                     t        |j                  d         D ]+  }t        |j                  d         D ]  }| ||f   |||f<    - y )Nr   rI   r   r   )r   r   xys       r    copy2dz*TestCUDAGufunc.test_copy2d.<locals>.copy2d   sG     1771:&qwwqz*A1gAadG + 'r"      r+   r,      rI   rf   )	r   r   r   r.   r/   r0   rh   r2   r3   )r5   rw   r   r   s       r    test_copy2dzTestCUDAGufunc.test_copy2d   s    	d71a4='!Q$-89%"
$	&
$	&
 IIb

+33Aq9A=MM!qaAq)*r"   c                 t   t        t        t        d d  t        d d        gdd      d        t        j                  fd       }t        j                  d      j                  d      }t        j                  |      }d}| j                  t        |      5   |d	   ||       d d d        y # 1 sw Y   y xY w)
Nz(n)->(n)r	   r   c                 N    t        | j                  d         D ]
  }| |   ||<    y r   rt   )r   br   s      r    gufunc_copyzDTestCUDAGufunc.test_not_supported_call_from_jit.<locals>.gufunc_copy   s(     1771:&t! 'r"   c                      | |      S r`    )r   r}   r~   s     r    cuda_jitzATestCUDAGufunc.test_not_supported_call_from_jit.<locals>.cuda_jit   s    q!$$r"      r   z#Untyped global name 'gufunc_copy'.*)rI   rI   )r   r   r   r	   jitr.   r/   astyperh   assertRaisesRegexr   )r5   r   r   r}   msgr~   s        @r     test_not_supported_call_from_jitz/TestCUDAGufunc.test_not_supported_call_from_jit   s    	d58U1X./
0	
0	 
	% 
	% IIi ''0MM!3##K5HTN1a  655s   B..B7c           	         t        dgdd      d        }t        j                  j                  d      j	                  d      }t        j                  j                  d      j	                  d      }t        j
                  |j                  d         j	                  d      }t        d	d
      5  t        j                  d      5 } ||||       | j                  |d   j                  t               | j                  dt        |d   j                               | j                  dt        |d   j                               d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N(void(float32[:], float32[:], float32[:])(n),(n)->(n)r	   r   c                 ^    | j                   d   }t        |      D ]  }| |   ||   z  ||<    y r   r   ar}   distlenr   s        r    numba_dist_cudazMTestCUDAGufunc.test_inefficient_launch_configuration.<locals>.numba_dist_cuda   4     ''!*C3ZA$1+Q  r"   r   r   r   CUDA_LOW_OCCUPANCY_WARNINGSrI   Trecordz	Grid sizezlow occupancy)r   r.   rJ   randr   zerosr   r   warningscatch_warningsassertEqualcategoryr   assertInstrmessage)r5   r   r   r}   r   ws         r    %test_inefficient_launch_configurationz4TestCUDAGufunc.test_inefficient_launch_configuration   s   	@A#F
4	&
4	&
 IINN9%,,Y7IINN9%,,Y7xx
#**95:A>((51d+  10GHk3qt||+<=os1Q4<</@A	 6 ?>55 ?>s%   /E!A>EE!E	E!!E*c                 0   t        dgddd      d        }t        j                  j                  d      j	                  d      j                  d	      }t        j                  j                  d      j	                  d      j                  d	      }t        j                  |      }t        d
d      5  t        j                  d      5 } ||||       | j                  t        |      d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   Tr	   )nopythonr   c                 ^    | j                   d   }t        |      D ]  }| |   ||   z  ||<    y r   r   r   s        r    numba_dist_cuda2zLTestCUDAGufunc.test_efficient_launch_configuration.<locals>.numba_dist_cuda2   r   r"   i   r   )i   r)   r   rI   r   r   )r   r.   rJ   r   r   r0   rh   r   r   r   r   r   )r5   r   r   r}   r   r   s         r    #test_efficient_launch_configurationz2TestCUDAGufunc.test_efficient_launch_configuration   s    	@A#d6
C	&
C	&
 IINN:&--i8GK  	
IINN:&--i8GK  	
}}Q:A>((5 At,  Q+ 6 ?>55 ?>s$   2D	&D /D D		DDc           
      `   d } t        t        t        d d  t        d d        gddd      |       | j                  t              5 } t        t        t        d d  t        d d        gddd      |       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Nc                      y r`   r   r   r   s     r    fooz.TestCUDAGufunc.test_nopython_flag.<locals>.foo       r"   r^   r	   T)r   r   Fznopython flag must be True)r   r   r   assertRaises	TypeErrorr   r   	exception)r5   r   raisess      r    test_nopython_flagz!TestCUDAGufunc.test_nopython_flag   s    		#T'!*gaj12Jv!	##&	( y)V7Kgaj'!*56
%77:< * 	5s6;K;K7LM *)s   /B$$B-c           
         d }| j                  t              5 } t        t        t        d d  t        d d        gdddd      |       d d d        d}t        j                        }| j                  |d t        |       |       |t        |      d  j                         j                  d      }|D cg c]  }|j                  d	       }}| j                  t        d
dg      t        |             y # 1 sw Y   xY wc c}w )Nc                      y r`   r   r   s     r    r   z.TestCUDAGufunc.test_invalid_flags.<locals>.foo  r   r"   r^   r	   TF)r   what1ever2z/The following target options are not supported:,z'" r   r   )r   r   r   r   r   r   r   r   r   stripsplitset)r5   r   r   headr   itemsr   s          r    test_invalid_flagsz!TestCUDAGufunc.test_invalid_flags  s    	 y)V@Kgaj'!*56
%T@@CE * A&""#Zc$i$/CIJ%%'--c2*/0%Q%0gw/0#e*= *) 1s   0C65D6C?c                 d   t        t        t        d d  t        d d        gdd      d        }t        j                  dt        j                        x}}| j                  t              5 } ||||       d d d        d}| j                  t        j                        |       y # 1 sw Y   1xY w)	Nr^   r	   r   c                      y r`   r   )inprW   s     r    r   z2TestCUDAGufunc.test_duplicated_output.<locals>.foo  s    r"   rG   r+   rf   z<cannot specify argument 'out' as both positional and keyword)
r   r   r   r.   r   r   
ValueErrorr   r   r   )r5   r   r   rW   r   r   s         r    test_duplicated_outputz%TestCUDAGufunc.test_duplicated_output  s    	d71:wqz23Z	O	 
P	 HHRrzz22cz*fSc" + MV--.4	 +*s   *B&&B/c                 0   t        t        d d  t        d d  t        d d  fgdd      d        } |||      }t        j                  t        j                  |      t        j                  |      z  d      }t        j
                  j                  ||       y )Nz(n),(n)->()r	   r   c                 `    d}t        t        |             D ]  }|| |   ||   z  z  } ||d<   y r   )r   r   )ru   rv   rsr   s        r    	gu_reducez1TestCUDAGufunc.check_tuple_arg.<locals>.gu_reduce  s:     A3q6]QqTAaD[  #AaDr"   rI   )axis)r   r   r.   sumasarrayrL   assert_equal)r5   r   r}   r   r   expecteds         r    check_tuple_argzTestCUDAGufunc.check_tuple_arg  s|    	wqz71:wqz:;]"
$	
$	 aO66"**Q-"**Q-7a@


!,r"   c                 0    d}d}| j                  ||       y )N)      ?       @      @      @      @      @)      ?      @      @      @      @      @)r   r5   r   r}   s      r    test_tuple_of_tuple_argz&TestCUDAGufunc.test_tuple_of_tuple_arg+  s     Q"r"   c                     t        dd      } |ddd       |ddd      f} |d	d
d       |ddd      f}| j                  ||       y )NPointru   rv   zr   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r5   r   r   r}   s       r    test_tuple_of_namedtuple_argz+TestCUDAGufunc.test_tuple_of_namedtuple_arg2  s\    7O4SC3'SC3')SC3'SC3')Q"r"   c                     t        j                  d      t        j                  d      f}t        j                  d      t        j                  d      f}| j                  ||       y )Nr   r   r   r   )r.   r   r   r   s      r    test_tuple_of_array_argz&TestCUDAGufunc.test_tuple_of_array_arg:  sP    ZZ(ZZ(*ZZ(ZZ(*Q"r"   c                 P    t               }| j                  |j                  d       y )Nr!   )r$   r   __name__)r5   r6   s     r    test_gufunc_namezTestCUDAGufunc.test_gufunc_nameA  s    '),7r"   c           	      $   | j                  t              5 }t        t        t        d d  t        d d        gdd      d        }d d d        t	        j
                        }| j                  d|       | j                  d|       y # 1 sw Y   CxY w)Nz(m)->(m)r	   r   c                      y r`   r   )ru   rv   s     r    fz.TestCUDAGufunc.test_bad_return_type.<locals>.fG  s    r"   z+guvectorized functions cannot return valueszspecifies int32 return type)r   r   r   r   r   r   r   )r5   ter   r   s       r    test_bad_return_typez#TestCUDAGufunc.test_bad_return_typeE  s|    y)R%a%(34jP Q *
 ",,CSI3S9 *)s   .BBc                    t        t        d d  t        d d  t        d d  fgdd      d        }t        j                  d      }| j	                  t
              5 } ||       d d d        t        j                        }| j                  d|       | j                  d|       | j                  d|       | j	                  t
              5 } |||||       d d d        t        |j                        }| j                  d|       | j                  d|       | j                  d	|       y # 1 sw Y   xY w# 1 sw Y   axY w)
Nz(m),(m)->(m)r	   r   c                      y r`   r   r   s      r    r   z;TestCUDAGufunc.test_incorrect_number_of_pos_args.<locals>.fP       r"   r,   %gufunc accepts 2 positional argumentszor 3 positional argumentsGot 1 positional argument.zGot 4 positional arguments.	r   r   r.   r/   r   r   r   r   r   r5   r   arrr   r   s        r    !test_incorrect_number_of_pos_argsz0TestCUDAGufunc.test_incorrect_number_of_pos_argsO  s   	uQxq5845#F
4	
4	 iil y)RcF * ",,=sC1372C8 y)Rc3S! * ",,=sC1373S9 *) *)s   	D)	D5)D25D>N)r   
__module____qualname__r9   r>   rA   rE   rT   r\   rj   rm   rq   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r    r&   r&      sw    .. .
./.0)+++!(B&,&N>
5-###8::r"   r&   c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestMultipleOutputsc           	         t        t        t        d d  t        d d  t        d d        gdd      d        }t        j                  dt        j                        dz   }t        j
                  |      }t        j
                  |      } ||||       t        j                  j                  ||       t        j                  j                  ||       y )N(x)->(x),(x)r	   r   c                 X    t        |j                        D ]  }| |   ||<   | |   ||<    y r`   ra   r   r   r   r   s       r    rd   zKTestMultipleOutputs.test_multiple_outputs_same_type_passed_in.<locals>.copym  s0     166]t!t! #r"   rG   r+   rI   rg   )r5   rd   r   r   r   s        r    )test_multiple_outputs_same_type_passed_inz=TestMultipleOutputs.test_multiple_outputs_same_type_passed_inl  s    	d71:wqz71:>?#"
$	
$	
 IIb

+a/MM!MM!Q1


""1a(


""1a(r"   c           	         t        t        t        d d  t        d d  t        d d        gdd      d        }t        j                  dt        j                        dz   }t        j
                  |      }t        j
                  |      } ||||       t        j                  j                  ||       t        j                  j                  |dz  |       y )	Nr   r	   r   c                 ^    t        |j                        D ]  }| |   ||<   | |   dz  ||<    y Nr)   ra   r   s       r    copy_and_doublezRTestMultipleOutputs.test_multiple_outputs_distinct_values.<locals>.copy_and_double~  4     166]t!tax! #r"   rG   r+   rI   r)   rg   r5   r  r   r   r   s        r    %test_multiple_outputs_distinct_valuesz9TestMultipleOutputs.test_multiple_outputs_distinct_values|  s    	d71:wqz71:>?#"
$	 
$	 
 IIb

+a/MM!MM!1a 


""1a(


""1q5!,r"   c           	      Z   t        t        t        d d  t        d d  t        d d        gdd      d        }t        j                  dt        j                        dz   } ||      \  }}t        j
                  j                  ||       t        j
                  j                  |dz  |       y )	Nr   r	   r   c                 ^    t        |j                        D ]  }| |   ||<   | |   dz  ||<    y r   ra   r   s       r    r  zLTestMultipleOutputs.test_multiple_output_allocation.<locals>.copy_and_double  r  r"   rG   r+   rI   r)   )r   r   r   r.   r/   rL   rM   r  s        r    test_multiple_output_allocationz3TestMultipleOutputs.test_multiple_output_allocation  s    	d71:wqz71:>?#"
$	 
$	 
 IIb

+a/q!1


""1a(


""1q5!,r"   c           	         t        t        t        d d  t        d d  t        d d        gdd      d        }t	        j
                  dt        j                        dz   }t	        j                  |      }t	        j                  |t        j                        } ||||       t        j                  j                  ||       t        j                  j                  |t	        j                  d      z  |       y )	Nr   r	   r   c                 ^    t        |j                        D ]  }| |   ||<   | |   dz  ||<    y )Nr   ra   r   s       r    copy_and_multiplyzJTestMultipleOutputs.test_multiple_output_dtypes.<locals>.copy_and_multiply  s4     166]t!tcz! #r"   rG   r+   rI   r   )	r   r   r   r   r.   r/   rh   rL   rM   )r5   r
  r   r   r   s        r    test_multiple_output_dtypesz/TestMultipleOutputs.test_multiple_output_dtypes  s    	d58U1Xwqz:;#"
$	"
$	"
 IIb)A-MM!MM!2::.!Q"


""1a(


""1rzz##6:r"   c                    t        t        d d  t        d d  t        d d  t        d d  fgdd      d        }t        j                  d      }| j	                  t
              5 } ||       d d d        t        j                        }| j                  d|       | j                  d|       | j                  d|       | j	                  t
              5 } ||||||       d d d        t        |j                        }| j                  d|       | j                  d|       | j                  d	|       y # 1 sw Y   xY w# 1 sw Y   axY w)
Nz(m),(m)->(m),(m)r	   r   c                      y r`   r   )ru   rv   r   r   s       r    r   z@TestMultipleOutputs.test_incorrect_number_of_pos_args.<locals>.f  r   r"   r,   r   zor 4 positional argumentsr   zGot 5 positional arguments.r   r   s        r    r   z5TestMultipleOutputs.test_incorrect_number_of_pos_args  s   	uQxq58U1X>?'
8	
8	 iil y)RcF * ",,=sC1372C8 y)Rc3S#& * ",,=sC1373S9 *) *)s    	D2D>2D;>EN)r   r   r   r   r  r  r  r   r   r"   r    r   r   j  s    ) -"-;":r"   r   __main__)numpyr.   collectionsr   numbar   r   r   r   r   r	   numba.cuda.testingr
   r   unittestr   numba.core.errorsr   r   numba.tests.supportr   r$   r&   r   r   mainr   r"   r    <module>r     s     " / /   <   B / ")   9:H:\ H: ;H:V
 9:Y:, Y: ;Y:x zHMMO r"   