Exemple #1
0
 def check_ir_dump(self, pyfunc):
     interp = self.get_ir(pyfunc)
     out = StringIO()
     interp.dump(file=out)
     expected = textwrap.dedent(pyfunc.__doc__).strip().splitlines()
     got = out.getvalue().strip().splitlines()
     self.assertEqual(got, expected,
                      "dump might need to be refreshed; here is the "
                      "actual dump:\n%s\n" % (out.getvalue()))
Exemple #2
0
 def check_ir_dump(self, pyfunc):
     interp = self.get_ir(pyfunc)
     out = StringIO()
     interp.dump(file=out)
     expected = textwrap.dedent(pyfunc.__doc__).strip().splitlines()
     got = out.getvalue().strip().splitlines()
     self.assertEqual(got, expected,
                      "dump might need to be refreshed; here is the "
                      "actual dump:\n%s\n" % (out.getvalue()))
Exemple #3
0
def _multiruntest(suite):
    stream = StringIO()
    with contextlib.closing(stream):
        runner = unittest.TextTestRunner(descriptions=False, verbosity=3,
                                         buffer=True, stream=stream)
        result = runner.run(suite)
        return result.wasSuccessful(), stream.getvalue()
Exemple #4
0
    def test_polytyped(self):
        @cuda.jit
        def foo(x, y):
            pass

        foo(1, 1)
        foo(1.2, 2.4)

        file = StringIO()
        foo.inspect_types(file=file)
        typeanno = file.getvalue()
        file.close()
        # Signature in annotation
        self.assertIn("({0}, {0})".format(intp), typeanno)
        self.assertIn("(float64, float64)", typeanno)

        # Signature in LLVM dict
        llvmirs = foo.inspect_llvm()
        self.assertEqual(
            2,
            len(llvmirs),
        )
        self.assertIn((intp, intp), llvmirs)
        self.assertIn((float64, float64), llvmirs)

        # Function name in LLVM
        self.assertIn("foo", llvmirs[intp, intp])
        self.assertIn("foo", llvmirs[float64, float64])

        asmdict = foo.inspect_asm()

        # Signature in LLVM dict
        self.assertEqual(
            2,
            len(asmdict),
        )
        self.assertIn((intp, intp), asmdict)
        self.assertIn((float64, float64), asmdict)

        # NNVM inserted in PTX
        self.assertIn("foo", asmdict[intp, intp])
        self.assertIn("foo", asmdict[float64, float64])
Exemple #5
0
class CapturedTrace:
    """Capture the trace temporarily for validation."""

    def __init__(self):
        self.buffer = StringIO()
        self.handler = logging.StreamHandler(self.buffer)
    def __enter__(self):
        self._handlers = logger.handlers
        self.buffer = StringIO()
        logger.handlers = [logging.StreamHandler(self.buffer)]
    def __exit__(self, type, value, traceback):
        logger.handlers = self._handlers
    def getvalue(self):

        # Depending on how the tests are run, object names may be
        # qualified by their containing module.
        # Remove that to make the trace output independent from the testing mode.
        log = self.buffer.getvalue()
        log = log.replace(__name__ + '.','')
        return log
Exemple #6
0
    def test_monotyped(self):
        @cuda.jit("(float32, int32)")
        def foo(x, y):
            pass

        file = StringIO()
        foo.inspect_types(file=file)
        typeanno = file.getvalue()
        # Function name in annotation
        self.assertIn("foo", typeanno)
        # Signature in annotation
        self.assertIn("(float32, int32)", typeanno)
        file.close()
        # Function name in LLVM
        self.assertIn("foo", foo.inspect_llvm())

        asm = foo.inspect_asm()

        # Function name in PTX
        self.assertIn("foo", asm)
        # NVVM inserted comments in PTX
        self.assertIn("Generated by NVIDIA NVVM Compiler", asm)
Exemple #7
0
    def test_monotyped(self):
        @cuda.jit("(float32, int32)")
        def foo(x, y):
            pass

        file = StringIO()
        foo.inspect_types(file=file)
        typeanno = file.getvalue()
        # Function name in annotation
        self.assertIn("foo", typeanno)
        # Signature in annotation
        self.assertIn("(float32, int32)", typeanno)
        file.close()
        # Function name in LLVM
        self.assertIn("foo", foo.inspect_llvm())

        asm = foo.inspect_asm()

        # Function name in PTX
        self.assertIn("foo", asm)
        # NVVM inserted comments in PTX
        self.assertIn("Generated by NVIDIA NVVM Compiler", asm)
Exemple #8
0
    def test_polytyped(self):
        @cuda.jit
        def foo(x, y):
            pass

        foo(1, 1)
        foo(1.2, 2.4)

        file = StringIO()
        foo.inspect_types(file=file)
        typeanno = file.getvalue()
        file.close()
        # Signature in annotation
        self.assertIn("({0}, {0})".format(intp), typeanno)
        self.assertIn("(float64, float64)", typeanno)

        # Signature in LLVM dict
        llvmirs = foo.inspect_llvm()
        self.assertEqual(2, len(llvmirs), )
        self.assertIn((intp, intp), llvmirs)
        self.assertIn((float64, float64), llvmirs)

        # Function name in LLVM
        self.assertIn("foo", llvmirs[intp, intp])
        self.assertIn("foo", llvmirs[float64, float64])

        asmdict = foo.inspect_asm()

        # Signature in LLVM dict
        self.assertEqual(2, len(asmdict), )
        self.assertIn((intp, intp), asmdict)
        self.assertIn((float64, float64), asmdict)

        # NNVM inserted in PTX
        self.assertIn("foo", asmdict[intp, intp])
        self.assertIn("foo", asmdict[float64, float64])