Exemple #1
0
def startAnimation():
  global nPointsForCircles
  if  not GL_initialized: initGL()
  openGLWindow()
  if not CUDA_initialized: setCudaDevice( usingAnimation = True  )
  nPointsForCircles = nPointsPerCircle*nCirclesGrid
  initCudaGL()
  createVBO()
  startGL()
Exemple #2
0
animation2D.nHeight = nHeight
animation2D.windowTitle = "Ising Model 2D  spins={0}x{1}   T={2:.1f}".format(
    nHeight, nWidth, float(temp))
animation2D.initGL()

#set thread grid for CUDA kernels
block_size_x, block_size_y = 16, 16  #hardcoded, tune to your needs
gridx = nWidth // block_size_x + 1 * (nWidth % block_size_x != 0)
gridy = nHeight // block_size_y + 1 * (nHeight % block_size_y != 0)
block2D = (block_size_x, block_size_y, 1)
grid2D = (gridx, gridy, 1)
grid2D_ising = (gridx // 2, gridy, 1
                )  #special grid to avoid neighbor conflicts

#initialize pyCUDA context
cudaDevice = setCudaDevice(devN=useDevice, usingAnimation=True)

#Read and compile CUDA code
print "\nCompiling CUDA code"
cudaCodeString_raw = open("CUDAising2D.cu", "r").read()
cudaCodeString = cudaCodeString_raw  # % { "BLOCK_WIDTH":block2D[0], "BLOCK_HEIGHT":block2D[1], "BLOCK_DEPTH":block2D[2], }
cudaCode = SourceModule(cudaCodeString)
tex_spins = cudaCode.get_texref('tex_spinsIn')
isingKernel = cudaCode.get_function('ising_kernel')


########################################################################
def sendToScreen(plotData):
    floatToUchar(plotData, plotData_d)
    copyToScreenArray()
Exemple #3
0
  pAnim.viewXmin, pAnim.viewXmax = -10000., 10000.
  pAnim.viewYmin, pAnim.viewYmax = -10000., 10000.
  pAnim.viewZmin, pAnim.viewZmax = -10000000., 10000000. 
  pAnim.showGrid = False
  pAnim.nPointsPerCircle = 50
  pAnim.cirPos, pAnim.cirCol, pAnim.nCirclesGrid = geometry.circlesGrid( radius, -30., 30., -20., 20., nPoints=pAnim.nPointsPerCircle)

###########################################################################
###########################################################################
#Initialize and select CUDA device
if usingAnimation:
  pAnim.initGL()
  pAnim.CUDA_initialized = True
  configAnimation()

cudaDev = setCudaDevice( devN = devN, usingAnimation = usingAnimation )

#Read and compile CUDA code
print "\nCompiling CUDA code\n"
codeFiles = [ "vector3D.h", "sphere.h", "wall.h", "cudaBillar3D.cu"]
for fileName in codeFiles:
  codeString = open(fileName, "r").read().replace("cudaP", cudaP)
  outFile = open( fileName + "T", "w" )
  outFile.write( codeString )
  outFile.close()
  
cudaCodeStringTemp = open("cudaBillar3D.cuT", "r").read()
cudaCodeString = cudaCodeStringTemp % { "nSPHERES":nSpheres, "nWALLS":nWalls, "THREADS_PER_BLOCK":block[0], "TIME_INDEX_MAX":maxTimeIndx }
cudaCode = SourceModule(cudaCodeString, no_extern_c=True, include_dirs=[currentDirectory])
mainKernel = cudaCode.get_function("main_kernel" )
Exemple #4
0
gridx = nWidth // block_size_x + 1 * ( nWidth % block_size_x != 0 )
gridy = nHeight // block_size_y + 1 * ( nHeight % block_size_y != 0 )
gridz = nDepth // block_size_z + 1 * ( nDepth % block_size_z != 0 )
grid3D = (gridx, gridy, gridz)
block3D = (block_size_x, block_size_y, block_size_z)




#Initialize openGL
volumeRender.nWidth = nPoints
volumeRender.nHeight = nPoints
volumeRender.nDepth = nPoints
volumeRender.initGL()    
#initialize pyCUDA context 
cudaDevice = setCudaDevice(devN=useDevice, usingAnimation=True )

#Read and compile CUDA code
print "\nCompiling CUDA code"
cudaCodeString_raw = open("CUDAdensity3D.cu", "r").read()
cudaCodeString = cudaCodeString_raw % { "THREADS_PER_BLOCK":block3D[0]*block3D[1]*block3D[2] }
cudaCode = SourceModule(cudaCodeString)
densityKernel = cudaCode.get_function("density_kernel" )
########################################################################
from pycuda.elementwise import ElementwiseKernel
########################################################################
floatToUchar = ElementwiseKernel(arguments="float *input, unsigned char *output",
				operation = "output[i] = (unsigned char) ( -255*(input[i]-1));")
########################################################################
def preparePlotData( inputData ):
  plotData = inputData
Exemple #5
0
#Initialize openGL
animation2D.nWidth = nWidth
animation2D.nHeight = nHeight
#animation2D.initGL()

#set thread grid for CUDA kernels
block_size_x, block_size_y  = 16, 16   #hardcoded, tune to your needs
gridx = nWidth // block_size_x + 1 * ( nWidth % block_size_x != 0 )
gridy = nHeight // block_size_y + 1 * ( nHeight % block_size_y != 0 )
grid2D = (gridx, gridy, 1)
block2D = (block_size_x, block_size_y, 1)
mapBlock = ( nHeight, 1, 1 )
mapGrid = ( nWidth, 1, 1 )

#initialize pyCUDA context 
cudaDevice = setCudaDevice( devN=useDevice, usingAnimation=False )

#Read and compile CUDA code
print "Compiling CUDA code"
cudaCodeFile = open("CUDAchaosGlass.cu","r")
cudaCodeStringRaw = cudaCodeFile.read() 
cudaCodeString = (cudaCodeStringRaw %{"HEIGHT":mapBlock[0], "B_HEIGHT":block2D[1], "B_WIDTH":block2D[0] }).replace("cudaP", precision)
cudaCode = SourceModule(cudaCodeString)
mappingLogisticKernel = cudaCode.get_function('mappingLogistic_kernel')
maskKernel = cudaCode.get_function('mask_kernel')
plotKernel = cudaCode.get_function('plot_kernel')
########################################################################
from pycuda.elementwise import ElementwiseKernel
########################################################################
linearDouble = ElementwiseKernel(arguments="cudaP a, cudaP b, cudaP *input, cudaP *output".replace( 'cudaP', precision),
				operation = "output[i] = a*input[i] + b ")
Exemple #6
0
offsetY = 0
offsetZ = 0

nIterationsPerPlot = 100
maxVals = []
sumConc = []

#Initialize openGL
if usingAnimation:
  volumeRender.nWidth = nWidth
  volumeRender.nHeight = nHeight
  volumeRender.nDepth = nDepth
  volumeRender.windowTitle = "Percolation 3D  points={0}x{1}x{2}   p={3:.2f}".format(nHeight, nWidth, nDepth, float(probability))
  volumeRender.initGL()
#initialize pyCUDA context 
cudaDevice = setCudaDevice( devN=devN, usingAnimation=usingAnimation )

#set thread grid for CUDA kernels
block_size_x, block_size_y, block_size_z = 8,8,8   #hardcoded, tune to your needs
gridx = nWidth // block_size_x + 1 * ( nWidth % block_size_x != 0 )
gridy = nHeight // block_size_y + 1 * ( nHeight % block_size_y != 0 )
gridz = nDepth // block_size_z + 1 * ( nDepth % block_size_z != 0 )
block3D = (block_size_x, block_size_y, block_size_z)
grid3D = (gridx, gridy, gridz)

#Read and compile CUDA code
print "\nCompiling CUDA code\n"
cudaCodeString_raw = open("cudaPercolation3D.cu", "r").read().replace("cudaP", cudaP)
cudaCodeString = cudaCodeString_raw  % { "THREADS_PER_BLOCK":block3D[0]*block3D[1]*block3D[2], "B_WIDTH":block3D[0], "B_HEIGHT":block3D[1], "B_DEPTH":block3D[2] }
cudaCode = SourceModule(cudaCodeString)
#countFreeNeighborsKernel = cudaCode.get_function("countFreeNeighbors_kernel")