Ejemplo n.º 1
0
        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)
Ejemplo n.º 2
0
        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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
        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)
Ejemplo n.º 6
0
        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)