def test_mapped_contextmanager(self):
        # Check that temporarily mapped memory is unregistered immediately,
        # such that it can be re-mapped at any time
        class MappedException(Exception):
            pass

        arr = np.zeros(1)
        ctx = cuda.current_context()
        ctx.deallocations.clear()
        with self.check_ignored_exception(ctx):
            with cuda.mapped(arr) as marr:
                pass
            with cuda.mapped(arr) as marr:
                pass
            # Should also work inside a `defer_cleanup` block
            with cuda.defer_cleanup():
                with cuda.mapped(arr) as marr:
                    pass
                with cuda.mapped(arr) as marr:
                    pass
            # Should also work when breaking out of the block due to an exception
            try:
                with cuda.mapped(arr) as marr:
                    raise MappedException
            except MappedException:
                with cuda.mapped(arr) as marr:
                    pass
Ejemplo n.º 2
0
    def test_mapped_contextmanager(self):
        # Check that temporarily mapped memory is unregistered immediately,
        # such that it can be re-mapped at any time
        class MappedException(Exception):
            pass

        arr = np.zeros(1)
        ctx = cuda.current_context()
        ctx.deallocations.clear()
        with self.check_ignored_exception(ctx):
            with cuda.mapped(arr) as marr:
                pass
            with cuda.mapped(arr) as marr:
                pass
            # Should also work inside a `defer_cleanup` block
            with cuda.defer_cleanup():
                with cuda.mapped(arr) as marr:
                    pass
                with cuda.mapped(arr) as marr:
                    pass
            # Should also work when breaking out of the block due to an exception
            try:
                with cuda.mapped(arr) as marr:
                    raise MappedException
            except MappedException:
                with cuda.mapped(arr) as marr:
                    pass