Changeset 20317b3 in sasmodels
- Timestamp:
- Jul 28, 2016 8:16:31 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:
- 2547694
- Parents:
- d2d6100
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernelcl.py
ra4280bd r20317b3 65 65 raise RuntimeError("OpenCL not available") 66 66 67 from pyopencl import mem_flags as mf # type: ignore68 from pyopencl.characterize import get_fast_inaccurate_build_options # type: ignore69 # CRUFT: pyopencl < 2017.1 (as of June 2016 needs quotes around include path)70 def _quote_path(v):71 """72 Quote the path if it is not already quoted.73 74 If v starts with '-', then assume that it is a -I option or similar75 and do not quote it. This is fragile: -Ipath with space needs to76 be quoted.77 """78 return '"'+v+'"' if v and ' ' in v and not v[0] in "\"'-" else v79 80 if hasattr(cl, '_DEFAULT_INCLUDE_OPTIONS'):81 cl._DEFAULT_INCLUDE_OPTIONS = [_quote_path(v) for v in cl._DEFAULT_INCLUDE_OPTIONS]82 83 67 from pyopencl import mem_flags as mf 84 68 from pyopencl.characterize import get_fast_inaccurate_build_options … … 93 77 except ImportError: 94 78 pass 79 80 # CRUFT: pyopencl < 2017.1 (as of June 2016 needs quotes around include path) 81 def quote_path(v): 82 """ 83 Quote the path if it is not already quoted. 84 85 If v starts with '-', then assume that it is a -I option or similar 86 and do not quote it. This is fragile: -Ipath with space needs to 87 be quoted. 88 """ 89 return '"'+v+'"' if v and ' ' in v and not v[0] in "\"'-" else v 90 91 def fix_pyopencl_include(): 92 import pyopencl as cl 93 if hasattr(cl, '_DEFAULT_INCLUDE_OPTIONS'): 94 cl._DEFAULT_INCLUDE_OPTIONS = [quote_path(v) for v in cl._DEFAULT_INCLUDE_OPTIONS] 95 96 fix_pyopencl_include() 97 95 98 96 99 # The max loops number is limited by the amount of local memory available … … 256 259 Return a OpenCL context for the kernels of type dtype. 257 260 """ 258 for context , queue in zip(self.context, self.queues):261 for context in self.context: 259 262 if all(has_type(d, dtype) for d in context.devices): 260 263 return context … … 282 285 if key not in self.compiled: 283 286 context = self.get_context(dtype) 284 logging.info("building %s for OpenCL %s" 285 % (key, context.devices[0].name.strip()))287 logging.info("building %s for OpenCL %s", key, 288 context.devices[0].name.strip()) 286 289 program = compile_model(self.get_context(dtype), 287 290 str(source), dtype, fast) … … 299 302 300 303 def _get_default_context(): 301 # type: () -> cl.Context304 # type: () -> List[cl.Context] 302 305 """ 303 306 Get an OpenCL context, preferring GPU over CPU, and preferring Intel … … 318 321 for platform in cl.get_platforms(): 319 322 # AMD provides a much weaker CPU driver than Intel/Apple, so avoid it. 320 # If someone has bothered to install the AMD/NVIDIA drivers, prefer them over the integrated 321 # graphics driver that may have been supplied with the CPU chipset. 322 preferred_cpu = platform.vendor.startswith('Intel') or platform.vendor.startswith('Apple') 323 preferred_gpu = platform.vendor.startswith('Advanced') or platform.vendor.startswith('NVIDIA') 323 # If someone has bothered to install the AMD/NVIDIA drivers, prefer 324 # them over the integrated graphics driver that may have been supplied 325 # with the CPU chipset. 326 preferred_cpu = (platform.vendor.startswith('Intel') 327 or platform.vendor.startswith('Apple')) 328 preferred_gpu = (platform.vendor.startswith('Advanced') 329 or platform.vendor.startswith('NVIDIA')) 324 330 for device in platform.get_devices(): 325 331 if device.type == cl.device_type.GPU: 326 # If the existing type is not GPU then it will be CUSTOM or ACCELERATOR,327 # so don't override it.332 # If the existing type is not GPU then it will be CUSTOM 333 # or ACCELERATOR so don't override it. 328 334 if gpu is None or (preferred_gpu and gpu.type == cl.device_type.GPU): 329 335 gpu = device … … 334 340 # System has cl.device_type.ACCELERATOR or cl.device_type.CUSTOM 335 341 # Intel Phi for example registers as an accelerator 336 # Since the user installed a custom device on their system and went through the 337 # pain of sorting out OpenCL drivers for it, lets assume they really do want to 338 # use it as their primary compute device. 342 # Since the user installed a custom device on their system 343 # and went through the pain of sorting out OpenCL drivers for 344 # it, lets assume they really do want to use it as their 345 # primary compute device. 339 346 gpu = device 340 347 341 # order the devices by gpu then by cpu; when searching for an available device by data type they 342 # will be checked in this order, which means that if the gpu supports double then the cpu will never 343 # be used (though we may make it possible to explicitly request the cpu at some point). 348 # order the devices by gpu then by cpu; when searching for an available 349 # device by data type they will be checked in this order, which means 350 # that if the gpu supports double then the cpu will never be used (though 351 # we may make it possible to explicitly request the cpu at some point). 344 352 devices = [] 345 353 if gpu is not None: … … 372 380 self.fast = fast 373 381 self.program = None # delay program creation 382 self._kernels = None 374 383 375 384 def __getstate__(self): … … 394 403 names = [generate.kernel_name(self.info, k) for k in variants] 395 404 kernels = [getattr(self.program, k) for k in names] 396 self._kernels = dict((k, v) for k,v in zip(variants, kernels))405 self._kernels = dict((k, v) for k, v in zip(variants, kernels)) 397 406 is_2d = len(q_vectors) == 2 398 407 if is_2d: … … 500 509 def __init__(self, kernel, dtype, model_info, q_vectors): 501 510 # type: (cl.Kernel, np.dtype, ModelInfo, List[np.ndarray]) -> None 502 max_pd = model_info.parameters.max_pd503 npars = len(model_info.parameters.kernel_parameters)-2504 511 q_input = GpuInput(q_vectors, dtype) 505 512 self.kernel = kernel … … 516 523 517 524 self.result_b = cl.Buffer(self.queue.context, mf.READ_WRITE, 518 q_input.global_size[0] * dtype.itemsize)525 q_input.global_size[0] * dtype.itemsize) 519 526 self.q_input = q_input # allocated by GpuInput above 520 527 521 self._need_release = [ self.result_b, self.q_input]528 self._need_release = [self.result_b, self.q_input] 522 529 self.real = (np.float32 if dtype == generate.F32 523 530 else np.float64 if dtype == generate.F64
Note: See TracChangeset
for help on using the changeset viewer.