Changeset 40a87fa in sasmodels for sasmodels/kerneldll.py
- Timestamp:
- Aug 8, 2016 9:24:11 AM (8 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:
- 2472141
- Parents:
- 2d65d51
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kerneldll.py
r739aad4 r40a87fa 48 48 import sys 49 49 import os 50 from os.path import join as joinpath, split as splitpath, splitext50 from os.path import join as joinpath, splitext 51 51 import subprocess 52 52 import tempfile … … 100 100 CC.append("-fopenmp") 101 101 def compile_command(source, output): 102 """unix compiler command""" 102 103 return CC + [source, "-o", output, "-lm"] 103 104 elif compiler == "msvc": … … 115 116 LN = "/link /DLL /INCREMENTAL:NO /MANIFEST".split() 116 117 def compile_command(source, output): 118 """MSVC compiler command""" 117 119 return CC + ["/Tp%s"%source] + LN + ["/OUT:%s"%output] 118 120 elif compiler == "tinycc": … … 120 122 CC = [tinycc.TCC] + "-shared -rdynamic -Wall".split() 121 123 def compile_command(source, output): 124 """tinycc compiler command""" 122 125 return CC + [source, "-o", output] 123 126 elif compiler == "mingw": … … 127 130 CC.append("-fopenmp") 128 131 def compile_command(source, output): 132 """mingw compiler command""" 129 133 return CC + [source, "-o", output, "-lm"] 130 134 … … 142 146 143 147 def compile(source, output): 148 # type: (str, str) -> None 149 """ 150 Compile *source* producing *output*. 151 152 Raises RuntimeError if the compile failed or the output wasn't produced. 153 """ 144 154 command = compile_command(source=source, output=output) 145 155 command_str = " ".join('"%s"'%p if ' ' in p else p for p in command) … … 219 229 need_recompile = dll_time < newest_source 220 230 if need_recompile: 221 basename = os.path.splitext(os.path.basename(dll))[0] + "_"222 fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename)231 basename = splitext(os.path.basename(dll))[0] + "_" 232 system_fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) 223 233 source = generate.convert_type(source, dtype) 224 with os.fdopen( fd, "w") as file:225 file .write(source)234 with os.fdopen(system_fd, "w") as file_handle: 235 file_handle.write(source) 226 236 compile(source=filename, output=dll) 227 237 # comment the following to keep the generated c file … … 260 270 Call :meth:`release` when done with the kernel. 261 271 """ 262 263 272 def __init__(self, dllpath, model_info, dtype=generate.F32): 264 273 # type: (str, ModelInfo, np.dtype) -> None … … 266 275 self.dllpath = dllpath 267 276 self._dll = None # type: ct.CDLL 277 self._kernels = None # type: List[Callable, Callable] 268 278 self.dtype = np.dtype(dtype) 269 279 … … 277 287 raise 278 288 279 f p= (c_float if self.dtype == generate.F32280 else c_double if self.dtype == generate.F64281 else c_longdouble)289 float_type = (c_float if self.dtype == generate.F32 290 else c_double if self.dtype == generate.F64 291 else c_longdouble) 282 292 283 293 # int, int, int, int*, double*, double*, double*, double*, double 284 argtypes = [c_int32]*3 + [c_void_p]*4 + [f p]294 argtypes = [c_int32]*3 + [c_void_p]*4 + [float_type] 285 295 names = [generate.kernel_name(self.info, variant) 286 296 for variant in ("Iq", "Iqxy", "Imagnetic")] … … 316 326 #dll = ct.cdll.LoadLibrary(self.dllpath) 317 327 dll = ct.CDLL(self.dllpath) 318 libHandle = dll._handle319 # libHandle = ct.c_void_p(dll._handle)328 dll_handle = dll._handle 329 #dll_handle = ct.c_void_p(dll._handle) 320 330 del dll, self._dll 321 331 self._dll = None 322 ct.windll.kernel32.FreeLibrary( libHandle)323 else: 324 pass 332 ct.windll.kernel32.FreeLibrary(dll_handle) 333 else: 334 pass 325 335 326 336
Note: See TracChangeset
for help on using the changeset viewer.