Changeset e6a5556 in sasmodels


Ignore:
Timestamp:
Feb 4, 2016 10:13:22 PM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
eeb8bac
Parents:
caf768d
Message:

prefer certain devices for opencl gpu/cpu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernelcl.py

    r199d40d re6a5556  
    252252    gpu, cpu = None, None 
    253253    for platform in cl.get_platforms(): 
     254        # AMD provides a much weaker CPU driver than Intel/Apple, so avoid it. 
     255        # If someone has bothered to install the AMD/NVIDIA drivers, prefer them over the integrated 
     256        # graphics driver that may have been supplied with the CPU chipset. 
     257        preferred_cpu = platform.vendor.startswith('Intel') or platform.vendor.startswith('Apple') 
     258        preferred_gpu = platform.vendor.startswith('Advanced') or platform.vendor.startswith('NVIDIA') 
    254259        for device in platform.get_devices(): 
    255260            if device.type == cl.device_type.GPU: 
     261                # If the existing type is not GPU then it will be CUSTOM or ACCELERATOR, 
     262                # so don't override it. 
     263                if gpu is None or (preferred_gpu and gpu.type == cl.device_type.GPU): 
     264                    gpu = device 
     265            elif device.type == cl.device_type.CPU: 
     266                if cpu is None or preferred_cpu: 
     267                    cpu = device 
     268            else: 
     269                # System has cl.device_type.ACCELERATOR or cl.device_type.CUSTOM 
     270                # Intel Phi for example registers as an accelerator 
     271                # Since the user installed a custom device on their system and went through the 
     272                # pain of sorting out OpenCL drivers for it, lets assume they really do want to 
     273                # use it as their primary compute device. 
    256274                gpu = device 
    257             else: 
    258                 cpu = device 
    259     single = gpu if gpu is not None else cpu 
    260     double = gpu if gpu is not None and has_type(gpu, np.dtype('double')) else cpu 
    261  
    262     if single == double: 
    263         return [cl.Context([single])] 
    264     else: 
    265         return [cl.Context([single]), cl.Context([double])] 
     275 
     276    # order the devices by gpu then by cpu; when searching for an available device by data type they 
     277    # will be checked in this order, which means that if the gpu supports double then the cpu will never 
     278    # be used (though we may make it possible to explicitly request the cpu at some point). 
     279    devices = [] 
     280    if gpu is not None: 
     281        devices.append(gpu) 
     282    if cpu is not None: 
     283        devices.append(cpu) 
     284    return [cl.Context([d]) for d in devices] 
    266285 
    267286 
Note: See TracChangeset for help on using the changeset viewer.