예제 #1
0
    def check_minrpc():
        if tvm.get_global_func("rpc.CreatePipeClient",
                               allow_missing=True) is None:
            return
        # export to minrpc
        temp = utils.tempdir()
        f = tvm.build(s, [A, B], "llvm --system-lib", name="myadd")
        path_minrpc = temp.relpath("dev_lib.minrpc")
        f.export_library(path_minrpc, rpc.with_minrpc(cc.create_executable))

        with pytest.raises(RuntimeError):
            rpc.PopenSession("filenotexist")

        # statrt the minrpc session.
        remote = tvm.rpc.PopenSession(path_minrpc)
        dev = remote.cpu(0)
        f1 = remote.system_lib()

        a = tvm.nd.array(np.random.uniform(size=102).astype(A.dtype), dev)
        b = tvm.nd.array(np.zeros(102, dtype=A.dtype), dev)
        time_f = f1.time_evaluator("myadd", remote.cpu(0), number=1)
        cost = time_f(a, b).mean
        np.testing.assert_equal(b.asnumpy(), a.asnumpy() + 1)

        # change to not executable
        os.chmod(path_minrpc, stat.S_IRUSR)
        with pytest.raises(RuntimeError):
            rpc.PopenSession(path_minrpc)
예제 #2
0
def test_rpc_echo():
    def check(remote):
        fecho = remote.get_function("testing.echo")
        assert (fecho(1, 2, 3) == 1)
        assert (fecho(100, 2, 3) == 100)
        assert (fecho("xyz") == "xyz")
        assert (bytes(fecho(bytearray(b"123"))) == b"123")

        with pytest.raises(RuntimeError):
            raise_err = remote.get_function(
                "testing.test_raise_error_callback")("RuntimeError")
            raise_err()

    temp = rpc.server._server_env([])
    server = rpc.Server("localhost")
    client = rpc.connect(server.host, server.port)
    check(rpc.LocalSession())

    check(client)
    # Test minrpc server.
    temp = util.tempdir()
    minrpc_exec = temp.relpath("minrpc")
    tvm.rpc.with_minrpc("g++")(minrpc_exec, [])
    check(rpc.PopenSession(minrpc_exec))
    # minrpc on the remote
    server = rpc.Server("localhost")
    client = rpc.connect(server.host,
                         server.port,
                         session_constructor_args=[
                             "rpc.PopenSession",
                             open(minrpc_exec, "rb").read()
                         ])
    check(client)
예제 #3
0
 def check_minrpc():
     if tvm.get_global_func("rpc.CreatePipeClient", allow_missing=True) is None:
         return
     # Test minrpc server.
     temp = utils.tempdir()
     minrpc_exec = temp.relpath("minrpc")
     tvm.rpc.with_minrpc(cc.create_executable)(minrpc_exec, [])
     check(rpc.PopenSession(minrpc_exec))
     # minrpc on the remote
     server = rpc.Server("localhost")
     client = rpc.connect(
         server.host,
         server.port,
         session_constructor_args=["rpc.PopenSession", open(minrpc_exec, "rb").read()],
     )
     check(client)
def test_rpc_echo():
    def check(remote):
        fecho = remote.get_function("testing.echo")
        assert fecho(1, 2, 3) == 1
        assert fecho(100, 2, 3) == 100
        assert fecho("xyz") == "xyz"
        assert bytes(fecho(bytearray(b"123"))) == b"123"

        with pytest.raises(RuntimeError):
            raise_err = remote.get_function(
                "testing.test_raise_error_callback")("RuntimeError")
            raise_err()

        remote.cpu().sync()
        with pytest.raises(AttributeError):
            f3 = remote.system_lib()["notexist"]

    temp = rpc.server._server_env([])
    server = rpc.Server("localhost")
    client = rpc.connect(server.host, server.port)
    check(rpc.LocalSession())

    check(client)
    # Test minrpc server.
    temp = util.tempdir()
    minrpc_exec = temp.relpath("minrpc")
    tvm.rpc.with_minrpc(cc.create_executable)(minrpc_exec, [])
    check(rpc.PopenSession(minrpc_exec))
    # minrpc on the remote
    server = rpc.Server("localhost")
    client = rpc.connect(
        server.host,
        server.port,
        session_constructor_args=[
            "rpc.PopenSession",
            open(minrpc_exec, "rb").read()
        ],
    )
    check(client)