Changeset 300a2f7 in sasmodels


Ignore:
Timestamp:
Aug 18, 2016 11:30:23 AM (8 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:
4f3dd42
Parents:
6dc78e4
Message:

Force programs to be recompiled on OpenCL when they are changed. Ref #576

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernelcl.py

    rbde38b5 r300a2f7  
    281281            warnings.warn("the environment variable 'PYOPENCL_CTX' might not be set correctly") 
    282282 
    283     def compile_program(self, name, source, dtype, fast=False): 
    284         # type: (str, str, np.dtype, bool) -> cl.Program 
     283    def compile_program(self, name, source, dtype, fast, timestamp): 
     284        # type: (str, str, np.dtype, bool, float) -> cl.Program 
    285285        """ 
    286286        Compile the program for the device in the given context. 
    287287        """ 
     288        # Note: PyOpenCL caches based on md5 hash of source, options and device 
     289        # so we don't really need to cache things for ourselves.  I'll do so 
     290        # anyway just to save some data munging time. 
    288291        key = "%s-%s%s"%(name, dtype, ("-fast" if fast else "")) 
     292        # Check timestamp on program 
     293        program, program_timestamp = self.compiled.get(key, (None, np.inf)) 
     294        if program_timestamp < timestamp: 
     295            del self.compiled[key] 
    289296        if key not in self.compiled: 
    290297            context = self.get_context(dtype) 
     
    293300            program = compile_model(self.get_context(dtype), 
    294301                                    str(source), dtype, fast) 
    295             self.compiled[key] = program 
    296         return self.compiled[key] 
    297  
    298     def release_program(self, name): 
    299         # type: (str) -> None 
    300         """ 
    301         Free memory associated with the program on the device. 
    302         """ 
    303         if name in self.compiled: 
    304             self.compiled[name].release() 
    305             del self.compiled[name] 
     302            self.compiled[key] = (program, timestamp) 
     303        return program 
    306304 
    307305def _get_default_context(): 
     
    399397        if self.program is None: 
    400398            compile_program = environment().compile_program 
     399            timestamp = generate.timestamp(self.info) 
    401400            self.program = compile_program( 
    402401                self.info.name, 
    403402                self.source['opencl'], 
    404403                self.dtype, 
    405                 self.fast) 
     404                self.fast, 
     405                timestamp) 
    406406            variants = ['Iq', 'Iqxy', 'Imagnetic'] 
    407407            names = [generate.kernel_name(self.info, k) for k in variants] 
     
    421421        """ 
    422422        if self.program is not None: 
    423             environment().release_program(self.info.name) 
    424423            self.program = None 
    425424 
  • sasmodels/sasview_model.py

    rbde38b5 r300a2f7  
    115115    Load a custom model given the model path. 
    116116    """ 
     117    #print("load custom", path) 
    117118    kernel_module = custom.load_custom_kernel_module(path) 
    118119    try: 
Note: See TracChangeset for help on using the changeset viewer.