def wrap_linker(fgraph, linkers, wrapper): lnk = WrapLinker(linkers, wrapper).accept(fgraph) return lnk
def __setstate__(self, state): linker, optimizer, message, profile_stats = state self.message = message self.profile_stats = profile_stats def profile_thunk(i, node, th): """ Profile only the execution time """ global run_cthunk if hasattr(th, 'cthunk'): t0 = time.time() failure = run_cthunk(th.cthunk) dt = time.time() - t0 if failure: raise RuntimeError( ('A C Op raised an exception. ProfileMode cannot' ' tell you what it was though. Use a standard mode' ' such as FAST_RUN to correct the problem.')) else: t0 = time.time() th() dt = time.time() - t0 # Some Op are so fast that the time.time() resolution is # insufficient to measure it. So we add an epsilon. self.apply_time[node] += max(dt, 1e-14) def profile_thunk2(i, node, th): """ Profile the execution time and the memory size. """ global run_cthunk if hasattr(th, 'cthunk'): t0 = time.time() failure = run_cthunk(th.cthunk) dt = time.time() - t0 if failure: raise RuntimeError( ('A C Op raised an exception. ProfileMode cannot' ' tell you what it was though. Use a standard mode' ' such as FAST_RUN to correct the problem.')) else: t0 = time.time() th() dt = time.time() - t0 for var, data in zip(node.outputs, th.outputs): sh = getattr(data[0], 'shape', 'input no shape') self.variable_shape[var] = sh self.apply_time[node] += max(dt, 1e-14) self.provided_linker = linker self.provided_optimizer = optimizer if isinstance(linker, basestring) or linker is None: linker = predefined_linkers[linker] if not config.ProfileMode.profile_memory: p_thunk = profile_thunk else: p_thunk = profile_thunk2 linker = WrapLinker([linker], p_thunk) self.linker = linker if isinstance(optimizer, basestring) or optimizer is None: optimizer = predefined_optimizers[optimizer] self._optimizer = optimizer self.call_time = 0 self.fn_time = 0
def __setstate__(self, state): linker, optimizer, message, profile_stats = state self.message = message self.profile_stats = profile_stats def profile_thunk(i, node, th): """ Profile only the execution time """ global run_cthunk if hasattr(th, 'cthunk'): t0 = time.time() failure = run_cthunk(th.cthunk) dt = time.time() - t0 if failure: raise RuntimeError( ('A C Op raised an exception. ProfileMode cannot' ' tell you what it was though. Use a standard mode' ' such as FAST_RUN to correct the problem.')) else: t0 = time.time() th() dt = time.time() - t0 # Some Op are so fast that the time.time() resolution is # insufficient to measure it. So we add an epsilon. self.apply_time[node] += max(dt, 1e-14) def profile_thunk2(i, node, th): """ Profile the execution time and the memory size. """ global run_cthunk if hasattr(th, 'cthunk'): t0 = time.time() failure = run_cthunk(th.cthunk) dt = time.time() - t0 if failure: raise RuntimeError( ('A C Op raised an exception. ProfileMode cannot' ' tell you what it was though. Use a standard mode' ' such as FAST_RUN to correct the problem.')) else: t0 = time.time() th() dt = time.time() - t0 size = [] for o in th.outputs: if not hasattr(o[0], 'size'): #if the output type don't have a size attribute, set -1 #to signify we can't evaluate it. #This happen at least for mtrand.RandomState type(in numpy) size.append(-1) continue s = o[0].size #can't use o[0].dtype.itemsize as dtype is a str for #CudaNdarray dtype = str(o[0].dtype) dtype2 = dtype[-2:] if dtype2 == '32': s *= 4 elif dtype2 == '64': s *= 8 elif dtype2 == '16': s *= 2 elif dtype[-1] == '8': s *= 1 elif dtype[-3:] == '128': s *= 16 else: raise Exception("Can't determine the memory size of dtype", o[0].dtype) size.append(s) self.outputs_size[node] = size self.apply_time[node] += max(dt, 1e-14) self.provided_linker = linker self.provided_optimizer = optimizer if isinstance(linker, basestring) or linker is None: linker = predefined_linkers[linker] if not config.ProfileMode.profile_memory: p_thunk = profile_thunk else: p_thunk = profile_thunk2 linker = WrapLinker([linker], p_thunk) self.linker = linker if isinstance(optimizer, basestring) or optimizer is None: optimizer = predefined_optimizers[optimizer] self._optimizer = optimizer self.call_time = 0 self.fn_time = 0 self.optimizer_time = 0 self.linker_time = 0