Changeset aa4946b in sasmodels for sasmodels/kerneldll.py


Ignore:
Timestamp:
Mar 11, 2015 9:15:40 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:
af1d68c
Parents:
49d1d42f
Message:

refactor so kernels are loaded via core.load_model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kerneldll.py

    r63b32bb raa4946b  
    5454 
    5555 
    56 def load_model(kernel_module, dtype="double"): 
     56def make_dll(source, info, dtype="double"): 
    5757    """ 
    5858    Load the compiled model defined by *kernel_module*. 
     
    6060    Recompile if any files are newer than the model file. 
    6161 
    62     *dtype* is ignored.  Compiled files are always double. 
    63  
    64     The DLL is not loaded until the kernel is called so models an 
     62    *dtype* is a numpy floating point precision specifier indicating whether 
     63    the model should be single or double precision.  The default is double 
     64    precision. 
     65 
     66    The DLL is not loaded until the kernel is called so models can 
    6567    be defined without using too many resources. 
     68 
     69    Set *sasmodels.kerneldll.DLL_PATH* to the compiled dll output path. 
     70    The default is the system temporary directory. 
     71 
     72    Set *sasmodels.ALLOW_SINGLE_PRECISION_DLLS* to True if single precision 
     73    models are allowed as DLLs. 
    6674    """ 
    6775    if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double"   # Force 64-bit dll 
    6876    dtype = np.dtype(dtype) 
    6977 
    70     source, info = generate.make(kernel_module) 
    7178    if callable(info.get('Iq',None)): 
    7279        return PyModel(info) 
     
    7986 
    8087    source_files = generate.sources(info) + [info['filename']] 
    81     dllpath = dll_path(info, dtype) 
     88    dll= dll_path(info, dtype) 
    8289    newest = max(os.path.getmtime(f) for f in source_files) 
    83     if not os.path.exists(dllpath) or os.path.getmtime(dllpath)<newest: 
     90    if not os.path.exists(dll) or os.path.getmtime(dll)<newest: 
    8491        # Replace with a proper temp file 
    8592        fid, filename = tempfile.mkstemp(suffix=".c",prefix=tempfile_prefix) 
    8693        os.fdopen(fid,"w").write(source) 
    87         command = COMPILE%{"source":filename, "output":dllpath} 
     94        command = COMPILE%{"source":filename, "output":dll} 
    8895        print "Compile command:",command 
    8996        status = os.system(command) 
    90         if status != 0: 
     97        if status != 0 or not os.path.exists(dll): 
    9198            raise RuntimeError("compile failed.  File is in %r"%filename) 
    9299        else: 
    93100            ## uncomment the following to keep the generated c file 
    94             #os.unlink(filename); print "saving compiled file in %r"%filename 
    95             pass 
    96     return DllModel(dllpath, info, dtype=dtype) 
     101            os.unlink(filename); print "saving compiled file in %r"%filename 
     102    return dll 
     103 
     104 
     105def load_dll(source, info, dtype="double"): 
     106    """ 
     107    Create and load a dll corresponding to the source,info pair returned 
     108    from :func:`sasmodels.generate.make` compiled for the target precision. 
     109 
     110    See :func:`make_dll` for details on controlling the dll path and the 
     111    allowed floating point precision. 
     112    """ 
     113    filename = make_dll(source, info, dtype=dtype) 
     114    return DllModel(filename, info, dtype=dtype) 
    97115 
    98116 
Note: See TracChangeset for help on using the changeset viewer.