def test(): Nlocal = 64 Nglobal = 1024 ctx,queue = my_get_gpu_context() # inputs components = "psi hyd pet ldn lec".split() coords = [xyzHash("../dat/%s.xyzHash"%n).get_coord_clarray(queue) for n in components] if components[3][-1]=="c": hyd_stub = "stubrev(vec"+str(hyd_N_N)+",vec"+str(hyd_N_CA)+",vec"+str(hyd_N_C)+")" elif components[3][-1]=="n": hyd_stub = "stubrev(vec"+str(hyd_C_C)+",vec"+str(hyd_C_CA)+",vec"+str(hyd_C_N)+")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!"==None if components[4][-1]=="c": pet_stub = "stubrev(vec"+str(pet_N_N)+",vec"+str(pet_N_CA)+",vec"+str(pet_N_C)+")" elif components[4][-1]=="n": pet_stub = "stubrev(vec"+str(pet_C_C)+",vec"+str(pet_C_CA)+",vec"+str(pet_C_N)+")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!"==None npsi,nhyd,npet = (coords[i].size/3 for i in (0,1,2)) nlkh,nlkp = 23*3,32*3 ntot = npsi+nhyd+npet+nlkh+nlkp ranlux = pyopencl.array.empty(queue, (112*Nglobal,), dtype=numpy.int8); ranlux.fill(17) python_seed = random.getrandbits(31) # outputs out = pyopencl.array.empty(queue, (3*ntot*Nglobal,), dtype=numpy.float32) print out.size*4/1024/1024 xout = pyopencl.array.empty(queue, (12*10,) , dtype=numpy.float32) rout = pyopencl.array.empty(queue, (Nglobal,) , dtype=numpy.float32) # run kargs = [x.data for x in coords+[ranlux,out,xout,rout] ] if os.path.exists("../test/test1.pdb"): os.rename("../test/test1.pdb","../test/test1.pdb.last") print "build" my_test_kernel = pyopencl.Program(ctx,KERN%vars()).build(OPTS).my_test_kernel # print "run 1" # my_test_kernel(queue,( 1 ,Nglobal),( 1 ,1), *kargs ); dump_pdb(out.get()[0:],"../test/test1.pdb") print "run 2" my_test_kernel(queue,(Nlocal,Nglobal),(Nlocal,1), *kargs ); dump_pdb(out.get()[0:],"../test/test2.pdb")
def test(): NL, NG = 64, 1024 ctx, queue = my_get_gpu_context() # inputs components = "psi hyd pet len ldc".split() coords = [ xyzHash("../dat/%s.xyzHash" % n).get_coord_clarray(queue) for n in components ] if components[3][-1] == "c": hyd_stub = "stubrev(vec" + str(hyd_N_N) + ",vec" + str( hyd_N_CA) + ",vec" + str(hyd_N_C) + ")" elif components[3][-1] == "n": hyd_stub = "stubrev(vec" + str(hyd_C_C) + ",vec" + str( hyd_C_CA) + ",vec" + str(hyd_C_N) + ")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!" == None if components[4][-1] == "c": pet_stub = "stubrev(vec" + str(pet_N_N) + ",vec" + str( pet_N_CA) + ",vec" + str(pet_N_C) + ")" elif components[4][-1] == "n": pet_stub = "stubrev(vec" + str(pet_C_C) + ",vec" + str( pet_C_CA) + ",vec" + str(pet_C_N) + ")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!" == None npsi, nhyd, npet = (coords[i].size / 3 for i in (0, 1, 2)) lh = 50 lp = 50 nlkh, nlkp = lh * 3, lp * 3 #ntot = npsi+nhyd+npet+nlkh+nlkp ntot = nlkh + nlkp ranlux = pyopencl.array.empty(queue, (112 * NG, ), dtype=numpy.int8) #print python_seed # outputs out = pyopencl.array.empty(queue, (3 * ntot * NG, ), dtype=numpy.float32) xout = pyopencl.array.empty(queue, (12 * 3 * NG, ), dtype=numpy.float32) rout = pyopencl.array.empty(queue, (NG, ), dtype=numpy.float32) seed = pyopencl.array.empty(queue, (1, ), dtype=numpy.uint32) kargs = [x.data for x in coords + [ranlux, seed, out, xout, rout]] my_test_kernel = pyopencl.Program(ctx, KERN % vars()).build(OPTS).my_test_kernel for ITER in range(100): seed.fill(random.getrandbits(31)) ranlux.fill(17) my_test_kernel(queue, (NL, NG), (NL, 1), *kargs).wait() #; print seed.get(),rout lastout = out.get() lastxout = xout.get() ranlux.fill(17) my_test_kernel(queue, (NL, NG), (NL, 1), *kargs).wait() #; print seed.get(),rout assert numpy.all(lastxout == xout.get()) assert numpy.all(lastout == out.get()) assert numpy.sum( numpy.abs(out.get()[:-3] - out.get()[3:]) > 1.6) < 3 * 2 * NG print "1 vs 64 threads same! seed:", seed.get()[0]
def test(): Nlocal = 64 Nglobal = 1024 ctx, queue = my_get_gpu_context() # inputs components = "psi hyd pet ldn lec".split() coords = [ xyzHash("../dat/%s.xyzHash" % n).get_coord_clarray(queue) for n in components ] if components[3][-1] == "c": hyd_stub = "stubrev(vec" + str(hyd_N_N) + ",vec" + str( hyd_N_CA) + ",vec" + str(hyd_N_C) + ")" elif components[3][-1] == "n": hyd_stub = "stubrev(vec" + str(hyd_C_C) + ",vec" + str( hyd_C_CA) + ",vec" + str(hyd_C_N) + ")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!" == None if components[4][-1] == "c": pet_stub = "stubrev(vec" + str(pet_N_N) + ",vec" + str( pet_N_CA) + ",vec" + str(pet_N_C) + ")" elif components[4][-1] == "n": pet_stub = "stubrev(vec" + str(pet_C_C) + ",vec" + str( pet_C_CA) + ",vec" + str(pet_C_N) + ")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!" == None npsi, nhyd, npet = (coords[i].size / 3 for i in (0, 1, 2)) nlkh, nlkp = 23 * 3, 32 * 3 ntot = npsi + nhyd + npet + nlkh + nlkp ranlux = pyopencl.array.empty(queue, (112 * Nglobal, ), dtype=numpy.int8) ranlux.fill(17) python_seed = random.getrandbits(31) # outputs out = pyopencl.array.empty(queue, (3 * ntot * Nglobal, ), dtype=numpy.float32) print out.size * 4 / 1024 / 1024 xout = pyopencl.array.empty(queue, (12 * 10, ), dtype=numpy.float32) rout = pyopencl.array.empty(queue, (Nglobal, ), dtype=numpy.float32) # run kargs = [x.data for x in coords + [ranlux, out, xout, rout]] if os.path.exists("../test/test1.pdb"): os.rename("../test/test1.pdb", "../test/test1.pdb.last") print "build" my_test_kernel = pyopencl.Program(ctx, KERN % vars()).build(OPTS).my_test_kernel # print "run 1" # my_test_kernel(queue,( 1 ,Nglobal),( 1 ,1), *kargs ); dump_pdb(out.get()[0:],"../test/test1.pdb") print "run 2" my_test_kernel(queue, (Nlocal, Nglobal), (Nlocal, 1), *kargs) dump_pdb(out.get()[0:], "../test/test2.pdb")
def test(): NL,NG = 64,1024 ctx,queue = my_get_gpu_context() # inputs components = "psi hyd pet len ldc".split() coords = [xyzHash("../dat/%s.xyzHash"%n).get_coord_clarray(queue) for n in components] if components[3][-1]=="c": hyd_stub = "stubrev(vec"+str(hyd_N_N)+",vec"+str(hyd_N_CA)+",vec"+str(hyd_N_C)+")" elif components[3][-1]=="n": hyd_stub = "stubrev(vec"+str(hyd_C_C)+",vec"+str(hyd_C_CA)+",vec"+str(hyd_C_N)+")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!"==None if components[4][-1]=="c": pet_stub = "stubrev(vec"+str(pet_N_N)+",vec"+str(pet_N_CA)+",vec"+str(pet_N_C)+")" elif components[4][-1]=="n": pet_stub = "stubrev(vec"+str(pet_C_C)+",vec"+str(pet_C_CA)+",vec"+str(pet_C_N)+")" else: assert "CAN'T DETERMINE ORIENTATIN OF HYDA1 LINKER!!!"==None npsi,nhyd,npet = (coords[i].size/3 for i in (0,1,2)) lh = 50 lp = 50 nlkh,nlkp = lh*3,lp*3 #ntot = npsi+nhyd+npet+nlkh+nlkp ntot = nlkh+nlkp ranlux = pyopencl.array.empty(queue, (112*NG,), dtype=numpy.int8) #print python_seed # outputs out = pyopencl.array.empty(queue, (3*ntot*NG,), dtype=numpy.float32) xout = pyopencl.array.empty(queue, (12*3*NG,) , dtype=numpy.float32) rout = pyopencl.array.empty(queue, (NG,) , dtype=numpy.float32) seed = pyopencl.array.empty(queue, (1,) , dtype=numpy.uint32) kargs = [x.data for x in coords+[ranlux,seed,out,xout,rout] ] my_test_kernel = pyopencl.Program(ctx,KERN%vars()).build(OPTS).my_test_kernel for ITER in range(100): seed.fill(random.getrandbits(31)) ranlux.fill(17) my_test_kernel(queue,(NL,NG),(NL,1), *kargs ).wait()#; print seed.get(),rout lastout = out.get() lastxout = xout.get() ranlux.fill(17) my_test_kernel(queue,(NL,NG),(NL,1), *kargs ).wait()#; print seed.get(),rout assert numpy.all(lastxout == xout.get()) assert numpy.all(lastout == out.get()) assert numpy.sum(numpy.abs(out.get()[:-3]-out.get()[3:])>1.6) < 3*2*NG print "1 vs 64 threads same! seed:",seed.get()[0]
def test(): ctx, queue = clutil.my_get_gpu_context() LS, GS = 64, int(sys.argv[2]) NITER, NGPUITER = int(sys.argv[4]), int(sys.argv[3]) lh, lp = 27, 27 NC = "n" temperature = 15.0 nstat = 7 # allocate ranlux = pyopencl.array.empty(queue, (112 * GS,), dtype=numpy.int8) ranlux.fill(17) out = pyopencl.array.empty(queue, (3 * 3 * (100) * GS,), dtype=numpy.float32) out.fill(0) xout = pyopencl.array.empty(queue, (12 * 3 * GS,), dtype=numpy.float32) xout.fill(0) rout = pyopencl.array.empty(queue, (GS,), dtype=numpy.float32) rout.fill(0) vout = pyopencl.array.empty(queue, (GS, 6), dtype=numpy.float32) vout.fill(0) status = pyopencl.array.empty(queue, (GS, 2), dtype=numpy.int32) status.fill(0) seed = pyopencl.array.empty(queue, (1,), dtype=numpy.uint32) seed.fill(0) stat = pyopencl.array.empty(queue, (GS, nstat), dtype=numpy.int32) stat.fill(0) fstat = pyopencl.array.empty(queue, (GS, nstat), dtype=numpy.float32) fstat.fill(0) hist = pyopencl.array.empty(queue, (300,), dtype=numpy.uint32) hist.fill(0) hist6 = pyopencl.array.empty(queue, (9, 20, 23, 11, 24, 12), dtype=numpy.uint32) hist6.fill(0) # for temperature in (5,10,9999999999): NC = "c" for lp in (10, 20, 30, 40, 50): # for temperature in [2**x for x in range(6)]+[9e9]: for lh in (10, 20, 30, 40, 50): NOUT = NITER * NGPUITER * GS # if len(glob.glob("../test/hist6_bind_%i_%i_%s_%i_%i_*.dat"%(lh,lp,NC,temperature,NOUT))) > 3: continue # for temperature in (15,): # print temperature # inputs components = ("psi hyd pet ld%s len" % NC).split() hyd_stub = get_stub(components, "hyd") pet_stub = get_stub(components, "pet") PSI_ET = "vec(52.126627, 53.095875, 23.992003)" PET_ET = "vec( 5.468269, 20.041713, 11.962524)" HYD_ET = "vec(11.842096, 39.050866, 19.269006)" hashes = [xyzHash("../dat/%s.xyzHash" % n) for n in components] coords = [h.get_coord_clarray(queue) for h in hashes] grids = [h.get_grid_clarray(queue) for h in hashes] nxpsi, nypsi, nzpsi = hashes[0].xsize, hashes[0].ysize, hashes[0].zsize nxhyd, nyhyd, nzhyd = hashes[1].xsize, hashes[1].ysize, hashes[1].zsize nxpet, nypet, nzpet = hashes[2].xsize, hashes[2].ysize, hashes[2].zsize grid_size = 5.0 data = [d for d in reduce(operator.add, zip(coords, grids)) if d] npsi, nhyd, npet = (data[i].size / 3 for i in (0, 2, 4)) nlkh, nlkp = lh * 3, lp * 3 ntot = nlkh + nlkp # npsi+nhyd+npet+nlkh+nlkp out.fill(0) xout.fill(0) rout.fill(0) vout.fill(0) status.fill(0) seed.fill(0) stat.fill(0) fstat.fill(0) hist.fill(0) hist6.fill(0) kargs = [x.data for x in data + [ranlux, seed, out, xout, rout, vout, status, stat, fstat, hist, hist6]] my_test_kernel = pyopencl.Program(ctx, KERN % vars()).build(OPTS).my_test_kernel # os.system("rm -f ../test/*.pdb") seed.fill(random.getrandbits(31)) t = time.time() for ITER in range(1, NITER + 1): my_test_kernel(queue, (LS, GS), (LS, 1), *kargs).wait() # print lh,lp,NC,ITER,"COMPUTE RATE:",ITER*NGPUITER*GS/(time.time()-t)/1000.0 # for i in range(GS): # #if stat.get()[i,1] == 0: continue # if not ITER in vars(): ITER = 0 # ary = out.get() # fn = "../test/test_%i_%i_%i.pdb"%(i,lh,lp) # dump_pdb(ary[i*len(ary)/GS:(i+1)*len(ary)/GS],"../test/.tmp") # os.system("echo MODEL %i >> %s"%(ITER,fn)) # os.system("cat ../test/.tmp >> "+fn) # xform_pdb(nparray_to_XFORMs(xout.get())[3*i+0],"../pdb/hyda1_hash_bb.pdb","../test/.tmp") # os.system("cat ../test/.tmp >> "+fn) # xform_pdb(nparray_to_XFORMs(xout.get())[3*i+1],"../pdb/PetF_hash_bb.pdb" ,"../test/.tmp") # os.system("cat ../test/.tmp >> "+fn) # # xform_pdb(nparray_to_XFORMs(xout.get())[3*i+2],"../pdb/petf_hash_bb.pdb" ,"../test/hyda_%i.pdb"%i) # dump_pdb(vout.get()[i,],"../test/.tmp","X") # os.system("cat ../test/.tmp >> "+fn) # os.system("echo ENDMDL >> %s"%(fn)) tag = str(random.random()) Ntrial = numpy.sum(stat.get()[:, 0]) Nhist = numpy.sum(stat.get()[:, 2]) h = hist.get() # numpy.apply_along_axis(numpy.sum, 0, hist.get()) print "DONE", lp, NC, lh, temperature, "mcmc steps/sec:", int(NOUT / (time.time() - t))
def test(): ctx, queue = clutil.my_get_gpu_context() LS, GS = 64, int(sys.argv[2]) NITER, NGPUITER = int(sys.argv[4]), int(sys.argv[3]) lh, lp = 27, 27 NC = "n" temperature = 15.0 nstat = 7 # allocate ranlux = pyopencl.array.empty(queue, (112 * GS, ), dtype=numpy.int8) ranlux.fill(17) out = pyopencl.array.empty(queue, (3 * 3 * (100) * GS, ), dtype=numpy.float32) out.fill(0) xout = pyopencl.array.empty(queue, (12 * 3 * GS, ), dtype=numpy.float32) xout.fill(0) rout = pyopencl.array.empty(queue, (GS, ), dtype=numpy.float32) rout.fill(0) vout = pyopencl.array.empty(queue, (GS, 6), dtype=numpy.float32) vout.fill(0) status = pyopencl.array.empty(queue, (GS, 2), dtype=numpy.int32) status.fill(0) seed = pyopencl.array.empty(queue, (1, ), dtype=numpy.uint32) seed.fill(0) stat = pyopencl.array.empty(queue, (GS, nstat), dtype=numpy.int32) stat.fill(0) fstat = pyopencl.array.empty(queue, (GS, nstat), dtype=numpy.float32) fstat.fill(0) hist = pyopencl.array.empty(queue, (300, ), dtype=numpy.uint32) hist.fill(0) hist6 = pyopencl.array.empty(queue, (9, 20, 23, 11, 24, 12), dtype=numpy.uint32) hist6.fill(0) #for temperature in (5,10,9999999999): NC = 'c' for lp in ( 10, 20, 30, 40, 50, ): #for temperature in [2**x for x in range(6)]+[9e9]: for lh in (10, 20, 30, 40, 50): NOUT = NITER * NGPUITER * GS #if len(glob.glob("../test/hist6_bind_%i_%i_%s_%i_%i_*.dat"%(lh,lp,NC,temperature,NOUT))) > 3: continue #for temperature in (15,): #print temperature # inputs components = ("psi hyd pet ld%s len" % NC).split() hyd_stub = get_stub(components, "hyd") pet_stub = get_stub(components, "pet") PSI_ET = "vec(52.126627, 53.095875, 23.992003)" PET_ET = "vec( 5.468269, 20.041713, 11.962524)" HYD_ET = "vec(11.842096, 39.050866, 19.269006)" hashes = [xyzHash("../dat/%s.xyzHash" % n) for n in components] coords = [h.get_coord_clarray(queue) for h in hashes] grids = [h.get_grid_clarray(queue) for h in hashes] nxpsi, nypsi, nzpsi = hashes[0].xsize, hashes[0].ysize, hashes[ 0].zsize nxhyd, nyhyd, nzhyd = hashes[1].xsize, hashes[1].ysize, hashes[ 1].zsize nxpet, nypet, nzpet = hashes[2].xsize, hashes[2].ysize, hashes[ 2].zsize grid_size = 5.0 data = [d for d in reduce(operator.add, zip(coords, grids)) if d] npsi, nhyd, npet = (data[i].size / 3 for i in (0, 2, 4)) nlkh, nlkp = lh * 3, lp * 3 ntot = nlkh + nlkp #npsi+nhyd+npet+nlkh+nlkp out.fill(0) xout.fill(0) rout.fill(0) vout.fill(0) status.fill(0) seed.fill(0) stat.fill(0) fstat.fill(0) hist.fill(0) hist6.fill(0) kargs = [ x.data for x in data + [ ranlux, seed, out, xout, rout, vout, status, stat, fstat, hist, hist6 ] ] my_test_kernel = pyopencl.Program( ctx, KERN % vars()).build(OPTS).my_test_kernel #os.system("rm -f ../test/*.pdb") seed.fill(random.getrandbits(31)) t = time.time() for ITER in range(1, NITER + 1): my_test_kernel(queue, (LS, GS), (LS, 1), *kargs).wait() #print lh,lp,NC,ITER,"COMPUTE RATE:",ITER*NGPUITER*GS/(time.time()-t)/1000.0 # for i in range(GS): # #if stat.get()[i,1] == 0: continue # if not ITER in vars(): ITER = 0 # ary = out.get() # fn = "../test/test_%i_%i_%i.pdb"%(i,lh,lp) # dump_pdb(ary[i*len(ary)/GS:(i+1)*len(ary)/GS],"../test/.tmp") # os.system("echo MODEL %i >> %s"%(ITER,fn)) # os.system("cat ../test/.tmp >> "+fn) # xform_pdb(nparray_to_XFORMs(xout.get())[3*i+0],"../pdb/hyda1_hash_bb.pdb","../test/.tmp") # os.system("cat ../test/.tmp >> "+fn) # xform_pdb(nparray_to_XFORMs(xout.get())[3*i+1],"../pdb/PetF_hash_bb.pdb" ,"../test/.tmp") # os.system("cat ../test/.tmp >> "+fn) # # xform_pdb(nparray_to_XFORMs(xout.get())[3*i+2],"../pdb/petf_hash_bb.pdb" ,"../test/hyda_%i.pdb"%i) # dump_pdb(vout.get()[i,],"../test/.tmp","X") # os.system("cat ../test/.tmp >> "+fn) # os.system("echo ENDMDL >> %s"%(fn)) tag = str(random.random()) Ntrial = numpy.sum(stat.get()[:, 0]) Nhist = numpy.sum(stat.get()[:, 2]) h = hist.get() #numpy.apply_along_axis(numpy.sum, 0, hist.get()) print "DONE", lp, NC, lh, temperature, "mcmc steps/sec:", int( NOUT / (time.time() - t))