Esempio n. 1
0
def test_xyzhash_cl2():
	xh = xyzHash("../dat/psi.xyzHash")
	with open("xyzHash.cl") as o: KERN = o.read()
	
	ctx,queue = clutil.my_get_gpu_context()

	nxyz,xsize,ysize,zsize,grid_size = xh.num_point,xh.xsize,xh.ysize,xh.zsize,xh.grid_size
	
	prg = pyopencl.Program(ctx,KERN%vars())
	prg.build("-I/Users/sheffler/project/protoprot/ligh2t/lib "+clutil.MATHOPTS)
	knl = prg.test_xyzhash
		
	NL,NG = 64,12
	out = pyopencl.array.empty(queue, (1,), dtype=numpy.int32); out.fill(0)
	clpts = xh.get_coord_clarray(queue)
	clgrid = xh.get_grid_clarray(queue)
	kargs = (clpts.data,clgrid.data,out.data)

	t = time.time()
	knl(queue, (NL,NG), (NL,1) , *kargs ).wait()
	print (time.time()-t)
	
	print 64*NL*NG
	print 53949
	print out
Esempio n. 2
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))
Esempio n. 3
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))