Changeset cde11f0f in sasmodels


Ignore:
Timestamp:
Dec 23, 2015 10:07:37 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:
07e72e6
Parents:
e3a9733
Message:

make 'fast' a numeric type option as f32 with loose accuracy

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r5d316e9 rcde11f0f  
    6565    return True 
    6666 
    67 def load_model(model_definition, dtype="single", platform="ocl", fast=False): 
     67def load_model(model_definition, dtype="single", platform="ocl"): 
    6868    """ 
    6969    Prepare the model for the default execution platform. 
     
    8383    *platform* should be "dll" to force the dll to be used for C models, 
    8484    otherwise it uses the default "ocl". 
    85  
    86     *fast* is True if fast inaccurate math is acceptable (40% speed increase). 
    8785    """ 
    8886    if isstr(model_definition): 
     
    10199    # source = open(info['name']+'.cl','r').read() 
    102100 
    103     dtype = np.dtype(dtype) 
    104101    if (platform=="dll" 
    105102            or not HAVE_OPENCL 
     
    107104        return kerneldll.load_dll(source, info, dtype) 
    108105    else: 
    109         return kernelcl.GpuModel(source, info, dtype, fast) 
     106        return kernelcl.GpuModel(source, info, dtype) 
    110107 
    111108def make_kernel(model, q_vectors): 
  • sasmodels/kernelcl.py

    r5d316e9 rcde11f0f  
    183183 
    184184    def has_type(self, dtype): 
    185         dtype = np.dtype(dtype) 
     185        dtype = generate.F32 if dtype == 'fast' else np.dtype(dtype) 
    186186        return all(has_type(d, dtype) for d in self.context.devices) 
    187187 
     
    195195 
    196196    def compile_program(self, name, source, dtype, fast=False): 
    197         if name not in self.compiled: 
     197        key = "%s-%s-%s"%(name, dtype, fast) 
     198        if key not in self.compiled: 
    198199            #print("compiling",name) 
    199             self.compiled[name] = compile_model(self.context, source, dtype, 
    200                                                 fast) 
    201         return self.compiled[name] 
     200            dtype = np.dtype(dtype) 
     201            program = compile_model(self.context, source, dtype, fast) 
     202            self.compiled[key] = program 
     203        return self.compiled[key] 
    202204 
    203205    def release_program(self, name): 
     
    232234    for single and 'd', 'float64' or 'double' for double.  Double precision 
    233235    is an optional extension which may not be available on all devices. 
    234  
    235     *fast* is True if fast inaccurate math is acceptable (40% speed increase) 
    236     """ 
    237     def __init__(self, source, info, dtype=generate.F32, fast=False): 
     236    Half precision ('float16','half') may be available on some devices. 
     237    Fast precision ('fast') is a loose version of single precision, indicating 
     238    that the compiler is allowed to take shortcuts. 
     239    """ 
     240    def __init__(self, source, info, dtype=generate.F32): 
    238241        self.info = info 
    239242        self.source = source 
    240         self.dtype = np.dtype(dtype) 
    241         self.fast = fast 
     243        self.dtype = generate.F32 if dtype=='fast' else np.dtype(dtype) 
     244        self.fast = (dtype == 'fast') 
    242245        self.program = None # delay program creation 
    243246 
Note: See TracChangeset for help on using the changeset viewer.