Changeset 886fa25 in sasmodels for sasmodels/kerneldll.py


Ignore:
Timestamp:
Oct 6, 2016 12:24:32 PM (8 years ago)
Author:
ajj
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
5b37fd6
Parents:
4a2e1e5
git-author:
Wojciech Potrzebowski <Wojciech.Potrzebowski@…> (10/06/16 12:24:32)
git-committer:
Andrew Jackson <andrew.jackson@…> (10/06/16 12:24:32)
Message:

Ticket576 - updated custom models not being recompiled (#10)

  • OpenCL drivers installation has been added
  • Moved compilation.rst to gpu_computations.rst (more propreiate name)
  • Check-ups for 576
  • Unloading lib from ctypes by triggering release function in kerneldll ref #576
  • Import clean-ups in kerneldll
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kerneldll.py

    r3764ec1 r886fa25  
    7373import tempfile 
    7474import ctypes as ct  # type: ignore 
    75 from ctypes import c_void_p, c_int32, c_longdouble, c_double, c_float  # type: ignore 
     75import _ctypes as _ct 
    7676import logging 
    7777 
     
    111111    compiler = "unix" 
    112112 
    113 ARCH = "" if ct.sizeof(c_void_p) > 4 else "x86"  # 4 byte pointers on x86 
     113ARCH = "" if ct.sizeof(ct.c_void_p) > 4 else "x86"  # 4 byte pointers on x86 
    114114if compiler == "unix": 
    115115    # Generic unix compile 
     
    241241    if not os.path.exists(dll): 
    242242        need_recompile = True 
    243     elif getattr(sys, 'frozen', None) is not None: 
    244         # TODO: don't suppress time stamp 
    245         # Currently suppressing recompile when running in a frozen environment 
    246         need_recompile = False 
    247243    else: 
    248244        dll_time = os.path.getmtime(dll) 
     
    301297    def _load_dll(self): 
    302298        # type: () -> None 
    303         #print("dll", self.dllpath) 
    304299        try: 
    305300            self._dll = ct.CDLL(self.dllpath) 
     
    308303            raise 
    309304 
    310         float_type = (c_float if self.dtype == generate.F32 
    311                       else c_double if self.dtype == generate.F64 
    312                       else c_longdouble) 
     305        float_type = (ct.c_float if self.dtype == generate.F32 
     306                      else ct.c_double if self.dtype == generate.F64 
     307                      else ct.c_longdouble) 
    313308 
    314309        # int, int, int, int*, double*, double*, double*, double*, double 
    315         argtypes = [c_int32]*3 + [c_void_p]*4 + [float_type] 
     310        argtypes = [ct.c_int32]*3 + [ct.c_void_p]*4 + [float_type] 
    316311        names = [generate.kernel_name(self.info, variant) 
    317312                 for variant in ("Iq", "Iqxy", "Imagnetic")] 
     
    344339        Release any resources associated with the model. 
    345340        """ 
     341        dll_handle = self._dll._handle 
    346342        if os.name == 'nt': 
    347             #dll = ct.cdll.LoadLibrary(self.dllpath) 
    348             dll = ct.CDLL(self.dllpath) 
    349             dll_handle = dll._handle 
    350             #dll_handle = ct.c_void_p(dll._handle) 
    351             del dll, self._dll 
    352             self._dll = None 
    353343            ct.windll.kernel32.FreeLibrary(dll_handle) 
    354344        else: 
    355             pass 
    356  
     345            _ct.dlclose(dll_handle) 
     346        del self._dll 
     347        self._dll = None 
    357348 
    358349class DllKernel(Kernel): 
     
    411402        #print("returned",self.q_input.q, self.result) 
    412403        pd_norm = self.result[self.q_input.nq] 
    413         scale = values[0]/(pd_norm if pd_norm!=0.0 else 1.0) 
     404        scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0) 
    414405        background = values[1] 
    415406        #print("scale",scale,background) 
Note: See TracChangeset for help on using the changeset viewer.