Changeset f734e7d in sasmodels for sasmodels/kerneldll.py
- Timestamp:
- Feb 22, 2015 1:44:54 AM (9 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:
- 6137124
- Parents:
- 711d8e2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kerneldll.py
r68d3c1b rf734e7d 11 11 12 12 from . import generate 13 from .kernelpy import PyInput, Py Kernel13 from .kernelpy import PyInput, PyModel 14 14 15 15 from .generate import F32, F64 … … 22 22 if "VCINSTALLDIR" in os.environ: 23 23 # MSVC compiler is available, so use it. 24 # TODO: remove intermediate OBJ file created in the directory 25 # TODO: maybe don't use randomized name for the c file 24 26 COMPILE = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG /Tp%(source)s /openmp /link /DLL /INCREMENTAL:NO /MANIFEST /OUT:%(output)s" 25 27 # Can't find VCOMP90.DLL (don't know why), so remove openmp support from windows compiler build … … 54 56 be defined without using too many resources. 55 57 """ 56 import tempfile57 58 58 source, info = generate.make(kernel_module) 59 if callable(info.get('Iq',None)): 60 return PyModel(info) 59 61 source_files = generate.sources(info) + [info['filename']] 60 62 newest = max(os.path.getmtime(f) for f in source_files) … … 68 70 status = os.system(command) 69 71 if status != 0: 70 print "compile failed. File is in %r"%filename72 raise RuntimeError("compile failed. File is in %r"%filename) 71 73 else: 72 74 ## uncomment the following to keep the generated c file … … 76 78 77 79 78 IQ_ARGS = [c_void_p, c_void_p, c_int , c_void_p, c_double]79 IQXY_ARGS = [c_void_p, c_void_p, c_void_p, c_int , c_void_p, c_double]80 IQ_ARGS = [c_void_p, c_void_p, c_int] 81 IQXY_ARGS = [c_void_p, c_void_p, c_void_p, c_int] 80 82 81 83 class DllModel(object): … … 107 109 self.dll = ct.CDLL(self.dllpath) 108 110 111 pd_args_1d = [c_void_p, c_double] + [c_int]*Npd1d if Npd1d else [] 112 pd_args_2d= [c_void_p, c_double] + [c_int]*Npd2d if Npd2d else [] 109 113 self.Iq = self.dll[generate.kernel_name(self.info, False)] 110 self.Iq.argtypes = IQ_ARGS + [c_double]*Nfixed1d + [c_int]*Npd1d114 self.Iq.argtypes = IQ_ARGS + pd_args_1d + [c_double]*Nfixed1d 111 115 112 116 self.Iqxy = self.dll[generate.kernel_name(self.info, True)] 113 self.Iqxy.argtypes = IQXY_ARGS + [c_double]*Nfixed2d + [c_int]*Npd2d117 self.Iqxy.argtypes = IQXY_ARGS + pd_args_2d + [c_double]*Nfixed2d 114 118 115 119 def __getstate__(self): … … 120 124 121 125 def __call__(self, input): 122 # Support pure python kernel call123 if input.is_2D and callable(self.info['Iqxy']):124 return PyKernel(self.info['Iqxy'], self.info, input)125 elif not input.is_2D and callable(self.info['Iq']):126 return PyKernel(self.info['Iq'], self.info, input)127 128 126 if self.dll is None: self._load_dll() 129 127 kernel = self.Iqxy if input.is_2D else self.Iq … … 175 173 self.p_res = self.res.ctypes.data 176 174 177 def __call__(self, pars, pd_pars, cutoff):175 def __call__(self, fixed_pars, pd_pars, cutoff): 178 176 real = np.float32 if self.input.dtype == F32 else np.float64 179 fixed = [real(p) for p in pars]180 cutoff = real(cutoff)181 loops = np.hstack(pd_pars)182 loops = np.ascontiguousarray(loops.T, self.input.dtype).flatten()183 loops_N = [np.uint32(len(p[0])) for p in pd_pars]184 177 185 178 nq = c_int(self.input.nq) 186 p_loops = loops.ctypes.data 187 args = self.input.q_pointers + [self.p_res, nq, p_loops, cutoff] + fixed + loops_N 179 if pd_pars: 180 cutoff = real(cutoff) 181 loops_N = [np.uint32(len(p[0])) for p in pd_pars] 182 loops = np.hstack(pd_pars) 183 loops = np.ascontiguousarray(loops.T, self.input.dtype).flatten() 184 p_loops = loops.ctypes.data 185 dispersed = [p_loops, cutoff] + loops_N 186 else: 187 dispersed = [] 188 fixed = [real(p) for p in fixed_pars] 189 args = self.input.q_pointers + [self.p_res, nq] + dispersed + fixed 188 190 #print pars 189 191 self.kernel(*args)
Note: See TracChangeset
for help on using the changeset viewer.