#NEWLINE# def tune_blocksize( data , params , func_regs ) : #NEWLINE# #INDENT# "\n    For multivariate distributions-- what's the optimal block size given the\n    gpu?\n\n    Parameters\n    ----------\n    data : ndarray\n    params : ndarray\n\n    Returns\n    -------\n    (data_per, params_per) : (int, int)\n    " #NEWLINE# max_smem = ( info . shared_mem * 0.9 ) #NEWLINE# max_threads = int ( ( info . max_block_threads * 0.5 ) ) #NEWLINE# max_regs = info . max_registers #NEWLINE# max_grid = int ( info . max_grid_dim [ 0 ] ) #NEWLINE# params_per = 64 #NEWLINE# if ( len ( params ) < params_per ) : #NEWLINE# #INDENT# params_per = _next_pow2 ( len ( params ) , info . max_block_threads ) #NEWLINE# #UNINDENT# min_data_per = ( data . shape [ 0 ] / max_grid ) #NEWLINE# data_per0 = _next_pow2 ( max ( ( max_threads / params_per ) , min_data_per ) , 512 ) #NEWLINE# data_per = data_per0 #NEWLINE# def _can_fit( data_per , params_per ) : #NEWLINE# #INDENT# ok = ( compute_shmem ( data , params , data_per , params_per ) <= max_smem ) #NEWLINE# ok = ( ok and ( ( data_per * params_per ) <= max_threads ) ) #NEWLINE# return ( ok and ( ( ( func_regs * data_per ) * params_per ) <= max_regs ) ) #NEWLINE# #UNINDENT# while True : #NEWLINE# #INDENT# while ( not _can_fit ( data_per , params_per ) ) : #NEWLINE# #INDENT# if ( data_per <= min_data_per ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( params_per > 1 ) : #NEWLINE# #INDENT# params_per /= 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data_per /= 2 #NEWLINE# #UNINDENT# #UNINDENT# if ( data_per <= min_data_per ) : #NEWLINE# #INDENT# data_per = ( 2 * data_per0 ) #NEWLINE# params_per /= 2 #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# while _can_fit ( ( 2 * data_per ) , params_per ) : #NEWLINE# #INDENT# data_per *= 2 #NEWLINE# #UNINDENT# return ( data_per , params_per )