Changeset 7bf4757 in sasmodels


Ignore:
Timestamp:
May 6, 2016 3:08:14 AM (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:
3a45c2c, e9d10a6
Parents:
306e354
Message:

move precompile all models functionality into core; default dll models to double precision

Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r4d76711 r7bf4757  
    77    ] 
    88 
     9import os 
    910from os.path import basename, dirname, join as joinpath, splitext 
    1011from glob import glob 
     
    139140    # open(model_info['name']+'.c','w').write(source) 
    140141    # source = open(model_info['name']+'.cl','r').read() 
    141     source = generate.make_source(model_info) 
    142     if dtype is None: 
    143         dtype = 'single' if model_info['single'] else 'double' 
    144142    if callable(model_info.get('Iq', None)): 
    145143        return kernelpy.PyModel(model_info) 
     144    source = generate.make_source(model_info) 
     145    default_dtype = 'single' if model_info['single'] else 'double' 
     146    ocl_dtype = default_dtype if dtype is None else dtype 
     147    dll_dtype = 'double' if dtype is None else dtype 
    146148    if (platform == "dll" 
    147149            or not HAVE_OPENCL 
    148             or not kernelcl.environment().has_type(dtype)): 
    149         return kerneldll.load_dll(source, model_info, dtype) 
    150     else: 
    151         return kernelcl.GpuModel(source, model_info, dtype) 
    152  
    153 def precompile_dll(model_name, dtype="double"): 
    154     """ 
    155     Precompile the dll for a model. 
    156  
    157     Returns the path to the compiled model, or None if the model is a pure 
    158     python model. 
     150            or not kernelcl.environment().has_type(ocl_dtype)): 
     151        return kerneldll.load_dll(source, model_info, dll_dtype) 
     152    else: 
     153        return kernelcl.GpuModel(source, model_info, ocl_dtype) 
     154 
     155def precompile_dlls(path, dtype="double"): 
     156    """ 
     157    Precompile the dlls for all builtin models, returning a list of dll paths. 
     158 
     159    *path* is the directory in which to save the dlls.  It will be created if 
     160    it does not already exist. 
    159161 
    160162    This can be used when build the windows distribution of sasmodels 
    161     (which may be missing the OpenCL driver and the dll compiler), or 
    162     otherwise sharing models with windows users who do not have a compiler. 
    163  
    164     See :func:`sasmodels.kerneldll.make_dll` for details on controlling the 
    165     dll path and the allowed floating point precision. 
    166     """ 
    167     model_info = load_model_info(model_name) 
    168     source = generate.make_source(model_info) 
    169     return kerneldll.make_dll(source, model_info, dtype=dtype) if source else None 
    170  
     163    which may be missing the OpenCL driver and the dll compiler. 
     164    """ 
     165    if not os.path.exists(path): 
     166        os.makedirs(path) 
     167    compiled_dlls = [] 
     168    for model_name in list_models(): 
     169        model_info = load_model_info(model_name) 
     170        source = generate.make_source(model_info) 
     171        if source: 
     172            old_path = kerneldll.DLL_PATH 
     173            try: 
     174                kerneldll.DLL_PATH = path 
     175                dll = kerneldll.make_dll(source, model_info, dtype=dtype) 
     176            finally: 
     177                kerneldll.DLL_PATH = old_path 
     178            compiled_dlls.append(dll) 
     179    return compiled_dlls 
    171180 
    172181def get_weights(model_info, pars, name): 
Note: See TracChangeset for help on using the changeset viewer.