rpc_tracker.py 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
17
# pylint: disable=redefined-outer-name, invalid-name
18
"""Tool to start RPC tracker"""
19 20 21 22
from __future__ import absolute_import

import logging
import argparse
23 24
import multiprocessing
import sys
25
from ..rpc.tracker import Tracker
26 27

def main(args):
28
    """Main funciton"""
29 30
    tracker = Tracker(args.host, port=args.port, port_end=args.port_end,
                      silent=args.silent)
31 32 33 34
    tracker.proc.join()


if __name__ == "__main__":
35 36
    parser = argparse.ArgumentParser()
    parser.add_argument('--host', type=str, default="0.0.0.0",
37
                        help='the hostname of the tracker')
38
    parser.add_argument('--port', type=int, default=9190,
39
                        help='The port of the RPC')
40
    parser.add_argument('--port-end', type=int, default=9199,
41
                        help='The end search port of the RPC')
42 43 44 45
    parser.add_argument('--no-fork', dest='fork', action='store_false',
                        help="Use spawn mode to avoid fork. This option \
                         is able to avoid potential fork problems with Metal, OpenCL \
                         and ROCM compilers.")
46 47 48
    parser.add_argument('--silent', action='store_true',
                        help="Whether run in silent mode.")

49
    parser.set_defaults(fork=True)
50 51
    args = parser.parse_args()
    logging.basicConfig(level=logging.INFO)
52 53 54 55 56 57 58
    if args.fork is False:
        if sys.version_info[0] < 3:
            raise RuntimeError(
                "Python3 is required for spawn mode."
            )
        multiprocessing.set_start_method('spawn')
    else:
59 60 61
        if not args.silent:
            logging.info("If you are running ROCM/Metal, fork will cause "
                         "compiler internal error. Try to launch with arg ```--no-fork```")
62
    main(args)