fftKx_d = gpuarray.to_gpu( fftKx_h ) #OPTIMIZATION fftKy_d = gpuarray.to_gpu( fftKy_h ) fftKz_d = gpuarray.to_gpu( fftKz_h ) activity_d = gpuarray.to_gpu( np.ones( nBlocks3D, dtype=np.uint8 ) ) psiOther_d = gpuarray.to_gpu( np.zeros_like(psi_h.real) ) psiK1_d = gpuarray.to_gpu( psi_h ) psiK2_d = gpuarray.to_gpu( psi_h ) psiRunge_d = gpuarray.to_gpu( psi_h ) #For FFT version laplacian_d = gpuarray.to_gpu( np.zeros_like(psi_h) ) #TEXTURE version k1tempReal = gpuarray.to_gpu( np.zeros_like(psi_h.real) ) k1tempImag = gpuarray.to_gpu( np.zeros_like(psi_h.real) ) k2tempReal = gpuarray.to_gpu( np.zeros_like(psi_h.real) ) k2tempImag = gpuarray.to_gpu( np.zeros_like(psi_h.real) ) psiK1Real_array, copy3DpsiK1Real = gpuArray3DtocudaArray( k1tempReal, allowSurfaceBind=True, precision=cudaP ) psiK1Imag_array, copy3DpsiK1Imag = gpuArray3DtocudaArray( k1tempImag, allowSurfaceBind=True, precision=cudaP ) psiK2Real_array, copy3DpsiK2Real = gpuArray3DtocudaArray( k2tempReal, allowSurfaceBind=True, precision=cudaP ) psiK2Imag_array, copy3DpsiK2Imag = gpuArray3DtocudaArray( k2tempImag, allowSurfaceBind=True, precision=cudaP ) #memory for plotting plotData_d = gpuarray.to_gpu(np.zeros([nDepth, nHeight, nWidth], dtype = np.uint8)) volumeRender.plotData_dArray, copyToScreenArray = gpuArray3DtocudaArray( plotData_d ) if volumeRender.nTextures == 2: plotData_d_1 = gpuarray.to_gpu(np.zeros([nDepth, nHeight, nWidth], dtype = np.uint8)) volumeRender.plotData_dArray_1, copyToScreenArray_1 = gpuArray3DtocudaArray( plotData_d_1 ) print "Total Global Memory Used: {0:.2f} MB\n".format(float(initialMemory-getFreeMemory( show=False ))/1e6) def keyboard(*args): global plottingActive ESCAPE = '\033' # If escape is pressed, kill everything.
floatToUchar( plotData, plotData_d ) copyToScreenArray() ######################################################################## def stepFunction(): sendToScreen( density_d ) ######################################################################## #Initialize all gpu data print "\nInitializing Data" initialMemory = getFreeMemory( show=True ) density_h = densityAll["dm"] density_d = gpuarray.to_gpu( density_h ) #memory for plotting plotData_d = gpuarray.to_gpu(np.zeros([nDepth, nHeight, nWidth], dtype = np.uint8)) volumeRender.plotData_dArray, copyToScreenArray = gpuArray3DtocudaArray( plotData_d ) finalMemory = getFreeMemory( show=False ) print " Total Global Memory Used: {0} Mbytes".format(float(initialMemory-finalMemory)/1e6) density_h = preparePlotData( density_h ) density_d.set(density_h) #change volumeRender default step function for heat3D step function volumeRender.stepFunc = stepFunction #run volumeRender animation volumeRender.animate()
if plotVar == 0: plotVar = 3 beta = np.float32(1./temp) changePlotting() volumeRender.windowTitle = "Ising3D spins={0}x{1}x{2} T={3:.1f}".format(nHeight, nWidth, nDepth, float(temp)) ######################################################################## ######################################################################## #Initialize all gpu data print "\nInitializing Data" initialMemory = getFreeMemory( show=True ) #Set initial random distribution spins_h = (2*np.random.random_integers(0,1,[nDepth, nHeight, nWidth ]) - 1 ).astype(np.int32) #spins_h = np.ones([nDepth, nHeight, nWidth ]).astype(np.int32) spinsOut_d = gpuarray.to_gpu( spins_h ) randomNumbers_d = curandom.rand((nData)) #For texture version spinsInArray_d, copy3D_dtod = gpuArray3DtocudaArray( spinsOut_d, allowSurfaceBind=True ) #For shared version #memory for plotting plotDataFloat_d = gpuarray.to_gpu(np.zeros_like(spins_h)) plotData_d = gpuarray.to_gpu(np.zeros([nDepth, nHeight, nWidth], dtype = np.uint8)) volumeRender.plotData_dArray, copyToScreenArray = gpuArray3DtocudaArray( plotData_d ) finalMemory = getFreeMemory( show=False ) print " Total Global Memory Used: {0} Mbytes\n".format(float(initialMemory-finalMemory)/1e6) #configure volumeRender functions volumeRender.stepFunc = stepFunction volumeRender.specialKeys = specialKeyboardFunc #stepFunction()
concentration_h = np.zeros( [nDepth, nHeight, nWidth], dtype=cudaPre ) if nCenter==1: isFree_h[offsetZ + nDepth/2 - 1, offsetY + nHeight/2 - 1, offsetX + nWidth/2 - 1 ] = True concentration_h[offsetZ + nDepth/2 -1, offsetY + nHeight/2 - 1, offsetX +nWidth/2 - 1 ] = 1. else: isFree_h[ offsetZ + nDepth/2 - nCenter/2 : offsetZ + nDepth/2 + nCenter/2, offsetY + nHeight/2 - nCenter/2 : offsetY + nHeight/2 + nCenter/2, offsetX + nWidth/2 - nCenter/2 : offsetX + nWidth/2 +nCenter/2 ] = True concentration_h[ offsetZ + nDepth/2 - nCenter/2 : offsetZ + nDepth/2 + nCenter/2, offsetY + nHeight/2 - nCenter/2 : offsetY + nHeight/2 + nCenter/2, offsetX + nWidth/2 - nCenter/2 : offsetX + nWidth/2 + nCenter/2 ] = 1./nCenter**3 isFree_d = gpuarray.to_gpu( isFree_h.astype(np.int32) ) concentrationIn_d = gpuarray.to_gpu( concentration_h ) concentrationOut_d = gpuarray.to_gpu( concentration_h ) #For texture version isFree_dArray, copy3D_isFreeArray = gpuArray3DtocudaArray( isFree_d ) tex_isFree.set_array( isFree_dArray ) if cudaP == "float": concentration1_dArray, copy3D_concentrationArray1 = gpuArray3DtocudaArray( concentrationOut_d, allowSurfaceBind=True ) tex_concentrationIn.set_array( concentration1_dArray ) #memory for plotting plotDataFloat_d = gpuarray.to_gpu(np.zeros_like(concentration_h)) plotDataChars_d = gpuarray.to_gpu(np.zeros([nDepth, nHeight, nWidth], dtype = np.uint8)) volumeRender.plotData_dArray, copyToScreenArray = gpuArray3DtocudaArray( plotDataChars_d ) finalFreeMemory = getFreeMemory( show=False ) print " Total global memory used: {0:0.0f} MB\n".format( float(initialFreeMemory - finalFreeMemory)/1e6 ) ########################################################################### ########################################################################### #configure volumeRender functions if usingAnimation: volumeRender.stepFunc = stepFunction
#Initialize all gpu data print "Initializing Data" initialMemory = getFreeMemory( show=True ) #Set initial temperature temp_h = 0.5*np.ones([nDepth, nHeight, nWidth], dtype = np.float32) temp_d = gpuarray.to_gpu(temp_h) tempRunge_d = gpuarray.to_gpu( np.zeros_like(temp_h) ) tempRunge_d.set(temp_h) #For texture version temp_dArray, copyTempArray = gpuArray3DtocudaArray( temp_d, allowSurfaceBind=True ) k1Temp_dArray, copyk1TempArray = gpuArray3DtocudaArray( temp_d, allowSurfaceBind=True ) k2Temp_dArray, copyk2TempArray = gpuArray3DtocudaArray( temp_d, allowSurfaceBind=True ) #For shared version k1Temp_d = gpuarray.to_gpu(np.zeros_like(temp_h)) k2Temp_d = gpuarray.to_gpu(np.zeros_like(temp_h)) #memory for plotting plotData_d = gpuarray.to_gpu(np.zeros([nDepth, nHeight, nWidth], dtype = np.uint8)) volumeRender.plotData_dArray, copyToScreenArray = gpuArray3DtocudaArray( plotData_d ) finalMemory = getFreeMemory( show=False ) print " Total Global Memory Used: {0} Mbytes".format(float(initialMemory-finalMemory)/1e6) def stepFunction():
one_Array = np.array([ 1 ]).astype( np.int32 ) converged = gpuarray.to_gpu( one_Array ) gForceX_d = gpuarray.to_gpu( gForce_h ) gForceY_d = gpuarray.to_gpu( gForce_h ) gForceZ_d = gpuarray.to_gpu( gForce_h ) gravWork_d = gpuarray.to_gpu( gForce_h ) phiWall_l_d = gpuarray.to_gpu( np.zeros( (nHeight, nDepth), dtype=np.float32 ) ) phiWall_r_d = gpuarray.to_gpu( np.zeros( (nHeight, nDepth), dtype=np.float32 ) ) rhoReduced_d = gpuarray.to_gpu( np.zeros( nBlocksGrid, dtype=np.float32 ) ) blockX_d = gpuarray.to_gpu( np.zeros( nBlocksGrid, dtype=np.float32 ) ) blockY_d = gpuarray.to_gpu( np.zeros( nBlocksGrid, dtype=np.float32 ) ) blockZ_d = gpuarray.to_gpu( np.zeros( nBlocksGrid, dtype=np.float32 ) ) #Texture and surface arrays cnsv1_array, copy3D_cnsv1 = gpuArray3DtocudaArray( cnsv1_d, allowSurfaceBind=True, precision=cudaP ) cnsv2_array, copy3D_cnsv2 = gpuArray3DtocudaArray( cnsv2_d, allowSurfaceBind=True, precision=cudaP ) cnsv3_array, copy3D_cnsv3 = gpuArray3DtocudaArray( cnsv3_d, allowSurfaceBind=True, precision=cudaP ) cnsv4_array, copy3D_cnsv4 = gpuArray3DtocudaArray( cnsv4_d, allowSurfaceBind=True, precision=cudaP ) cnsv5_array, copy3D_cnsv5 = gpuArray3DtocudaArray( cnsv5_d, allowSurfaceBind=True, precision=cudaP ) flx1_array, copy3D_flx1_1 = gpuArray3DtocudaArray( cnsv1_d, allowSurfaceBind=True, precision=cudaP ) flx2_array, copy3D_flx2_1 = gpuArray3DtocudaArray( cnsv2_d, allowSurfaceBind=True, precision=cudaP ) flx3_array, copy3D_flx3_1 = gpuArray3DtocudaArray( cnsv3_d, allowSurfaceBind=True, precision=cudaP ) flx4_array, copy3D_flx4_1 = gpuArray3DtocudaArray( cnsv4_d, allowSurfaceBind=True, precision=cudaP ) flx5_array, copy3D_flx5_1 = gpuArray3DtocudaArray( cnsv5_d, allowSurfaceBind=True, precision=cudaP ) #Arrays for gravitational potential; checkboard iteration 2 arrays phi_array_1, copy3D_phi_1 = gpuArray3DtocudaArray( phi_d, allowSurfaceBind=True, precision=cudaP ) phi_array_2, copy3D_phi_2 = gpuArray3DtocudaArray( phi_d, allowSurfaceBind=True, precision=cudaP ) if usingAnimation: