Skip to content

Commit

Permalink
Replace 0.0.0.0 with 127.0.0.1 for client connections (apache#7766)
Browse files Browse the repository at this point in the history
* Rename references to 0.0.0.0 to localhost. Also change references to 127.0.0.1 to localhost so that all references are consistent. 0.0.0.0 is not the same as localhost.
  • Loading branch information
rkimball authored and Trevor Morris committed May 6, 2021
1 parent 804b764 commit b924a6d
Show file tree
Hide file tree
Showing 42 changed files with 114 additions and 111 deletions.
2 changes: 1 addition & 1 deletion apps/benchmark/arm_cpu_imagenet_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def evaluate_network(network, target, target_host, repeat):
help="The model of the test device. If your device is not listed in "
"the choices list, pick the most similar one as argument.",
)
parser.add_argument("--host", type=str, default="localhost")
parser.add_argument("--host", type=str, default="127.0.0.1")
parser.add_argument("--port", type=int, default=9190)
parser.add_argument("--rpc-key", type=str, required=True)
parser.add_argument("--repeat", type=int, default=10)
Expand Down
2 changes: 1 addition & 1 deletion apps/benchmark/mobile_gpu_imagenet_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def evaluate_network(network, target, target_host, dtype, repeat):
help="The model of the test device. If your device is not listed in "
"the choices list, pick the most similar one as argument.",
)
parser.add_argument("--host", type=str, default="localhost")
parser.add_argument("--host", type=str, default="127.0.0.1")
parser.add_argument("--port", type=int, default=9190)
parser.add_argument("--rpc-key", type=str, required=True)
parser.add_argument("--repeat", type=int, default=30)
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy/arm_compute_lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ An example configuration for `test_config.json`:
{
"connection_type": "local",
"host": "localhost",
"host": "127.0.0.1",
"port": 9090,
"target": "llvm -mtriple=aarch64-linux-gnu -mattr=+neon",
"device_key": "",
Expand Down
2 changes: 1 addition & 1 deletion jvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ server.start();
This will open a socket and wait for remote requests. You can use Java, Python, or any other frontend to make an RPC call. Here's an example for calling remote function `test.rpc.strcat` in Java.

```java
RPCSession client = Client.connect("localhost", port.value);
RPCSession client = Client.connect("127.0.0.1", port.value);
Function func = client.getFunction("test.rpc.strcat");
String result = func.call("abc", 11L).asString();
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void test_add_one_remote() throws IOException {
Server server = null;
try {
server = TestUtils.startServer(port);
RPCSession remote = Client.connect("localhost", port.value);
RPCSession remote = Client.connect("127.0.0.1", port.value);
Device dev = remote.cpu();

remote.upload(new File(libPath));
Expand Down
4 changes: 2 additions & 2 deletions jvm/core/src/test/java/org/apache/tvm/rpc/RPCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void test_addone() {
Server server = null;
try {
server = TestUtils.startServer(port);
RPCSession client = Client.connect("localhost", port.value);
RPCSession client = Client.connect("127.0.0.1", port.value);
Function func = client.getFunction("test.rpc.addone");
assertEquals(11L, func.call(10).asLong());
} finally {
Expand All @@ -73,7 +73,7 @@ public void test_strcat() {
Server server = null;
try {
server = TestUtils.startServer(port);
RPCSession client = Client.connect("localhost", port.value);
RPCSession client = Client.connect("127.0.0.1", port.value);
Function func = client.getFunction("test.rpc.strcat");
assertEquals("abc:11", func.call("abc", 11L).asString());
} finally {
Expand Down
2 changes: 1 addition & 1 deletion jvm/core/src/test/scripts/test_rpc_proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def start_proxy_server(port, timeout):
prox = proxy.Proxy("localhost", port=port, port_end=port + 1)
prox = proxy.Proxy("127.0.0.1", port=port, port_end=port + 1)
if timeout > 0:
import time

Expand Down
8 changes: 3 additions & 5 deletions python/tvm/auto_scheduler/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,20 +552,18 @@ def __init__(
if dev.exist:
cuda_arch = "sm_" + "".join(dev.compute_version.split("."))
set_cuda_target_arch(cuda_arch)
host = "0.0.0.0"
self.tracker = Tracker(host, port=9000, port_end=10000, silent=True)
self.tracker = Tracker(port=9000, port_end=10000, silent=True)
device_key = "$local$device$%d" % self.tracker.port
self.server = Server(
host,
port=self.tracker.port,
port_end=10000,
key=device_key,
silent=True,
tracker_addr=(self.tracker.host, self.tracker.port),
tracker_addr=("127.0.0.1", self.tracker.port),
)
self.runner = RPCRunner(
device_key,
host,
"127.0.0.1",
self.tracker.port,
priority,
n_parallel,
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, db_index=REDIS_PROD):
import redis

if db_index == RedisDatabase.REDIS_TEST:
host = "localhost"
host = "127.0.0.1"
else:
host = os.environ.get("TVM_FLEET_HOST")
self.db = redis.StrictRedis(host=host, port=6379, db=db_index)
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/graph_tuner/base_graph_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def benchmark_layout_transform(
timeout=10,
use_rpc=False,
device_key=None,
host="localhost",
host="127.0.0.1",
port=9190,
n_parallel=1,
build_func="default",
Expand Down
7 changes: 3 additions & 4 deletions python/tvm/autotvm/measure/measure_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,18 +399,17 @@ def set_task(self, task):
from ...rpc.server import Server

self.task = task
tracker = Tracker("0.0.0.0", port=9000, port_end=10000, silent=True)
tracker = Tracker(port=9000, port_end=10000, silent=True)
device_key = "$local$device$%d" % tracker.port
server = Server(
"0.0.0.0",
port=9000,
port_end=10000,
key=device_key,
silent=True,
tracker_addr=(tracker.host, tracker.port),
tracker_addr=("127.0.0.1", tracker.port),
)
self.key = device_key
self.host = tracker.host
self.host = "127.0.0.1"
self.port = tracker.port

super(LocalRunner, self).set_task(task)
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, msg):


@register_error
class RPCError(RuntimeError):
class RPCError(TVMError):
"""Error thrown by the remote server handling the RPC call."""


Expand Down
6 changes: 3 additions & 3 deletions python/tvm/exec/measure_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""measure bandwidth and compute peak
e.g.
python3 -m tvm.exec.measure_peak --target cuda --rpc-host 0.0.0.0 --rpc-port 9090
python3 -m tvm.exec.measure_peak --target cuda --rpc-host 127.0.0.1 --rpc-port 9090
python3 -m tvm.exec.measure_peak --target opencl --target-host "llvm -mtriple=aarch64-linux-gnu" \
--rpc-host $TVM_OPENCL_DEVICE_HOST --rpc-port 9090
"""
Expand All @@ -30,14 +30,14 @@


def main():
"""Main funciton"""
"""Main function"""
parser = argparse.ArgumentParser()
parser.add_argument("--target", type=str, default="llvm", help="The build target")
parser.add_argument(
"--target-host", type=str, default=None, help="The host code compilation target"
)
parser.add_argument(
"--rpc-host", type=str, default="0.0.0.0", help="the hostname of the server"
"--rpc-host", type=str, default="127.0.0.1", help="the hostname of the server"
)
parser.add_argument("--rpc-port", type=int, default=9090, help="The port of the RPC")

Expand Down
2 changes: 1 addition & 1 deletion python/tvm/exec/query_rpc_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():

# default to local host or environment variable
if not args.host:
args.host = os.environ.get("TVM_TRACKER_HOST", "localhost")
args.host = os.environ.get("TVM_TRACKER_HOST", "127.0.0.1")

if not args.port:
args.port = int(os.environ.get("TVM_TRACKER_PORT", "9190"))
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/exec/rpc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main(args):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--host", type=str, default="localhost", help="the hostname of the server")
parser.add_argument("--host", type=str, default="127.0.0.1", help="the hostname of the server")
parser.add_argument("--port", type=int, default=9090, help="The port of the RPC")
parser.add_argument(
"--web-port", type=int, default=8888, help="The port of the http/websocket server"
Expand Down
4 changes: 3 additions & 1 deletion python/tvm/exec/rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def main(args):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--host", type=str, default="0.0.0.0", help="the hostname of the server")
parser.add_argument(
"--host", type=str, default="0.0.0.0", help="The host IP address the tracker binds to"
)
parser.add_argument("--port", type=int, default=9090, help="The port of the RPC")
parser.add_argument("--port-end", type=int, default=9199, help="The end search port of the RPC")
parser.add_argument(
Expand Down
4 changes: 3 additions & 1 deletion python/tvm/exec/rpc_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def main(args):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--host", type=str, default="0.0.0.0", help="the hostname of the tracker")
parser.add_argument(
"--host", type=str, default="0.0.0.0", help="The host IP address the tracker binds to"
)
parser.add_argument("--port", type=int, default=9190, help="The port of the RPC")
parser.add_argument("--port-end", type=int, default=9199, help="The end search port of the RPC")
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/rpc/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def __init__(
self.port = my_port
break
except socket.error as sock_err:
if sock_err.errno in [98, 48]:
if sock_err.errno in [errno.EADDRINUSE]:
continue
raise sock_err
if not self.port:
Expand Down
5 changes: 3 additions & 2 deletions python/tvm/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import threading
import multiprocessing
import time
import errno
import tvm._ffi

from tvm._ffi.base import py_str
Expand Down Expand Up @@ -333,7 +334,7 @@ def __init__(
self.port = my_port
break
except socket.error as sock_err:
if sock_err.errno in [98, 48]:
if sock_err.errno in [errno.EADDRINUSE]:
continue
raise sock_err
if not self.port:
Expand Down Expand Up @@ -423,7 +424,7 @@ class Server(object):

def __init__(
self,
host,
host="0.0.0.0",
port=9091,
port_end=9199,
is_proxy=False,
Expand Down
8 changes: 4 additions & 4 deletions python/tvm/rpc/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _tracker_server(listen_sock, stop_key):


class Tracker(object):
"""Start RPC tracker on a seperate process.
"""Start RPC tracker on a separate process.
Python implementation based on multi-processing.
Expand All @@ -386,7 +386,7 @@ class Tracker(object):
Whether run in silent mode
"""

def __init__(self, host, port=9190, port_end=9199, silent=False):
def __init__(self, host="0.0.0.0", port=9190, port_end=9199, silent=False):
if silent:
logger.setLevel(logging.WARN)

Expand All @@ -399,7 +399,7 @@ def __init__(self, host, port=9190, port_end=9199, silent=False):
self.port = my_port
break
except socket.error as sock_err:
if sock_err.errno in [98, 48]:
if sock_err.errno in [errno.EADDRINUSE]:
continue
raise sock_err
if not self.port:
Expand All @@ -414,7 +414,7 @@ def __init__(self, host, port=9190, port_end=9199, silent=False):

def _stop_tracker(self):
sock = socket.socket(base.get_addr_family((self.host, self.port)), socket.SOCK_STREAM)
sock.connect((self.host, self.port))
sock.connect(("127.0.0.1", self.port))
sock.sendall(struct.pack("<i", base.RPC_TRACKER_MAGIC))
magic = struct.unpack("<i", base.recvall(sock, 4))[0]
assert magic == base.RPC_TRACKER_MAGIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Device:
"""

connection_type = "local"
host = "localhost"
host = "127.0.0.1"
port = 9090
target = "llvm -mtriple=aarch64-linux-gnu -mattr=+neon"
device_key = ""
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_arm_compute_lib/test_config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"connection_type": "local",
"host": "localhost",
"host": "127.0.0.1",
"port": 9090,
"target": "llvm -mtriple=aarch64-linux-gnu -mattr=+neon",
"device_key": "",
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_bnns/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Device:
"""

connection_type = "local"
host = "localhost"
host = "127.0.0.1"
port = 9090
target = "llvm"
device_key = ""
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_coreml_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import pytest
import os

proxy_host = os.environ.get("TVM_IOS_RPC_PROXY_HOST", "localhost")
proxy_host = os.environ.get("TVM_IOS_RPC_PROXY_HOST", "127.0.0.1")
proxy_port = os.environ.get("TVM_IOS_RPC_PROXY_PORT", 9090)
destination = os.environ.get("TVM_IOS_RPC_DESTINATION", "")
key = "iphone"
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_edgetpu_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def check_remote(target_edgetpu=False):
tflite_output = interpreter.get_tensor(output_details[0]["index"])

# inference via remote tvm tflite runtime
server = rpc.Server("localhost")
server = rpc.Server("127.0.0.1")
remote = rpc.connect(server.host, server.port)
dev = remote.cpu(0)

Expand Down
4 changes: 3 additions & 1 deletion tests/python/contrib/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def test_rpc(dtype):
return
if not tvm.testing.device_enabled("rpc") or not tvm.runtime.enabled("llvm"):
return
server = rpc.Server("localhost")

np_ones = np.ones((512, 512), dtype=dtype)
server = rpc.Server("127.0.0.1")
remote = rpc.connect(server.host, server.port)
value = tvm.nd.empty((512, 512), dtype, remote.cpu())
random_fill = remote.get_function("tvm.contrib.random.random_fill")
Expand Down
14 changes: 7 additions & 7 deletions tests/python/contrib/test_rpc_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ def _put(tclient, value):
base.sendjson(tclient._sock, value)
base.recvjson(tclient._sock)

tserver = tracker.Tracker("localhost", 8888)
tproxy = proxy.Proxy("localhost", 8881, tracker_addr=("localhost", tserver.port))
tclient = rpc.connect_tracker("localhost", tserver.port)
tserver = tracker.Tracker("127.0.0.1", 8888)
tproxy = proxy.Proxy("127.0.0.1", 8881, tracker_addr=("127.0.0.1", tserver.port))
tclient = rpc.connect_tracker("127.0.0.1", tserver.port)

server0 = rpc.Server(
"localhost", port=9099, tracker_addr=("localhost", tserver.port), key="abc"
"127.0.0.1", port=9099, tracker_addr=("127.0.0.1", tserver.port), key="abc"
)
server1 = rpc.Server(
"localhost", port=9099, tracker_addr=("localhost", tserver.port), key="xyz"
"127.0.0.1", port=9099, tracker_addr=("127.0.0.1", tserver.port), key="xyz"
)
server2 = rpc.Server("localhost", tproxy.port, is_proxy=True, key="xyz")
server3 = rpc.Server("localhost", tproxy.port, is_proxy=True, key="xyz1")
server2 = rpc.Server("127.0.0.1", tproxy.port, is_proxy=True, key="xyz")
server3 = rpc.Server("127.0.0.1", tproxy.port, is_proxy=True, key="xyz1")

# Fault tolerence to un-handled requested value
_put(tclient, [TrackerCode.REQUEST, "abc", "", 1])
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_tflite_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_remote():
tflite_output = interpreter.get_tensor(output_details[0]["index"])

# inference via remote tvm tflite runtime
server = rpc.Server("localhost")
server = rpc.Server("127.0.0.1")
remote = rpc.connect(server.host, server.port)
a = remote.upload(tflite_model_path)

Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_runtime_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def check_verify():

def check_remote():
mlib = tvm.build(s, [A, B], "llvm", name="myadd")
server = rpc.Server("localhost")
server = rpc.Server("127.0.0.1")
remote = rpc.connect(server.host, server.port)
temp = utils.tempdir()
dev = remote.cpu(0)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_runtime_graph_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def split_debug_line(i):

def check_remote():
mlib = tvm.build(s, [A, B], "llvm", name="myadd")
server = rpc.Server("localhost")
server = rpc.Server("127.0.0.1")
remote = rpc.connect(server.host, server.port)
temp = utils.tempdir()
dev = remote.cpu(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def verify_rpc_gpu_export(obj_format):

from tvm import rpc

server = rpc.Server("localhost", port=9094)
server = rpc.Server("127.0.0.1", port=9094)
remote = rpc.connect(server.host, server.port)
remote.upload(path_lib)
loaded_lib = remote.load_module(path_lib)
Expand Down
Loading

0 comments on commit b924a6d

Please sign in to comment.