Changeset 8faffcd in sasmodels for capcylcope.py
- Timestamp:
- Jul 10, 2014 4:06:29 PM (10 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 2de9a5e
- Parents:
- 8a20be5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
capcylcope.py
r8a20be5 r8faffcd 6 6 import pyopencl as cl 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 def set_precision(src, qx, qy, dtype): 11 qx = np.ascontiguousarray(qx, dtype=dtype) 12 qy = np.ascontiguousarray(qy, dtype=dtype) 13 if np.dtype(dtype) == np.dtype('float32'): 14 header = """\ 15 #define real float 16 """ 17 else: 18 header = """\ 19 #pragma OPENCL EXTENSION cl_khr_fp64: enable 20 #define real double 21 """ 22 return header+src, qx, qy 8 23 9 24 class GpuCapCylinder(object): … … 13 28 PD_PARS = ['rad_cyl', 'length', 'rad_cap', 'theta', 'phi'] 14 29 15 def __init__(self, qx, qy ):30 def __init__(self, qx, qy, dtype='float32'): 16 31 17 self.qx = np.asarray(qx, np.float32)18 self.qy = np.asarray(qy, np.float32)19 32 #create context, queue, and build program 20 self.ctx = cl.create_some_context() 21 self.queue = cl.CommandQueue(self.ctx) 33 ctx,_queue = card() 34 trala = open('NR_BessJ1.cpp').read()+"\n"+open('Capcyl_Kfun.cpp').read()+"\n"+open('Kernel-Cylinder.cpp').read() 35 src, qx, qy = set_precision(trala, qx, qy, dtype=dtype) 22 36 23 self.prg = cl.Program( self.ctx, open('Kernel-CapCyl.cpp').read()).build()37 self.prg = cl.Program(ctx, open('Kernel-CapCyl.cpp').read()).build() 24 38 25 39 #buffers 26 40 mf = cl.mem_flags 27 self.qx_b = cl.Buffer( self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx)28 self.qy_b = cl.Buffer( self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy)29 self.res_b = cl.Buffer( self.ctx, mf.WRITE_ONLY, qx.nbytes)41 self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) 42 self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) 43 self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes) 30 44 self.res = np.empty_like(self.qx) 31 45 self.vol_i = float(0.0) 32 self.vol_b = cl.Buffer( self.ctx, mf.WRITE_ONLY, self.vol_i.nbytes)46 self.vol_b = cl.Buffer(ctx, mf.WRITE_ONLY, self.vol_i.nbytes) 33 47 34 48 def eval(self, pars): 35 49 50 _ctx,queue = card() 36 51 rad_cyl,length,rad_cap,theta,phi = \ 37 52 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 54 69 for l in xrange(len(phi.weight)): 55 70 56 self.prg.CapCylinderKernel( self.queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b,71 self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, 57 72 self.vol_b, np.float32(rad_cyl.value[i]), np.float32(rad_cap.value[m]), np.float32(length.value[j]), 58 73 np.float32(theta.value[k]), np.float32(phi.value[l]), np.float32(sub), np.float32(pars['scale']), … … 60 75 np.float32(rad_cyl.weight[i]), np.float32(length.weight[j]), np.uint32(self.qx.size), np.uint32(size)) 61 76 62 cl.enqueue_copy( self.queue, self.res, self.res_b)63 cl.enqueue_copy( self.queue, self.vol_i, self.vol_b)77 cl.enqueue_copy(queue, self.res, self.res_b) 78 cl.enqueue_copy(queue, self.vol_i, self.vol_b) 64 79 65 80 sum += self.res
Note: See TracChangeset
for help on using the changeset viewer.