Skip to content

Commit

Permalink
Updated runtime to run under FreeBSD. (#6600)
Browse files Browse the repository at this point in the history
* Updated runtime to run under FreeBSD.
setenv CXX to proper binary - c++ or g++9 for FreeBSD 12.0.

* Update python/tvm/runtime/module.py

Co-authored-by: Junru Shao <[email protected]>

* Update python/tvm/rpc/server.py

Co-authored-by: Junru Shao <[email protected]>

* Changed to use os.environ.get

* Fixed format.

* Yet another lint fix.

Co-authored-by: Junru Shao <[email protected]>
  • Loading branch information
iiahim and junrushao authored Oct 2, 2020
1 parent 7e671cb commit f9abf56
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/tvm/_ffi/libinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def find_lib_path(name=None, search_path=None, optional=False):
if os.environ.get("TVM_LIBRARY_PATH", None):
dll_path.append(os.environ["TVM_LIBRARY_PATH"])

if sys.platform.startswith("linux"):
if sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
dll_path.extend(split_env_var("LD_LIBRARY_PATH", ":"))
dll_path.extend(split_env_var("PATH", ":"))
elif sys.platform.startswith("darwin"):
Expand Down
11 changes: 9 additions & 2 deletions python/tvm/contrib/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""Util to invoke C/C++ compilers in the system."""
# pylint: disable=invalid-name
import sys
import os
import subprocess

from .._ffi.base import py_str
Expand All @@ -39,7 +40,11 @@ def create_shared(output, objects, options=None, cc="g++"):
cc : Optional[str]
The compiler command.
"""
if sys.platform == "darwin" or sys.platform.startswith("linux"):
if (
sys.platform == "darwin"
or sys.platform.startswith("linux")
or sys.platform.startswith("freebsd")
):
_linux_compile(output, objects, options, cc, compile_shared=True)
elif sys.platform == "win32":
_windows_shared(output, objects, options)
Expand Down Expand Up @@ -103,7 +108,9 @@ def get_target_triple():
# assign so as default output format
create_shared.output_format = "so" if sys.platform != "win32" else "dll"
create_shared.get_target_triple = get_target_by_dump_machine(
"g++" if sys.platform == "darwin" or sys.platform.startswith("linux") else None
os.environ.get(
"CXX", "g++" if sys.platform == "darwin" or sys.platform.startswith("linux") else None
)
)


Expand Down
7 changes: 5 additions & 2 deletions python/tvm/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ def load_module(file_name):
@tvm._ffi.register_func("tvm.rpc.server.download_linked_module", override=True)
def download_linked_module(file_name):
"""Load module from remote side."""
# c++ compiler/linker
cc = os.environ.get("CXX", "g++")

# pylint: disable=import-outside-toplevel
path = temp.relpath(file_name)

if path.endswith(".o"):
# Extra dependencies during runtime.
from tvm.contrib import cc as _cc

_cc.create_shared(path + ".so", path)
_cc.create_shared(path + ".so", path, cc=cc)
path += ".so"
elif path.endswith(".tar"):
# Extra dependencies during runtime.
Expand All @@ -89,7 +92,7 @@ def download_linked_module(file_name):
tar_temp = util.tempdir(custom_path=path.replace(".tar", ""))
_tar.untar(path, tar_temp.temp_dir)
files = [tar_temp.relpath(x) for x in tar_temp.listdir()]
_cc.create_shared(path + ".so", files)
_cc.create_shared(path + ".so", files, cc=cc)
path += ".so"
elif path.endswith(".dylib") or path.endswith(".so"):
pass
Expand Down
9 changes: 7 additions & 2 deletions python/tvm/runtime/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# pylint: disable=invalid-name, unused-import, import-outside-toplevel
"""Runtime Module namespace."""
import os
import ctypes
import struct
from collections import namedtuple
Expand Down Expand Up @@ -393,13 +394,17 @@ def load_module(path, fmt=""):
This function will automatically call
cc.create_shared if the path is in format .o or .tar
"""

# c++ compiler/linker
cc = os.environ.get("CXX", "g++")

# High level handling for .o and .tar file.
# We support this to be consistent with RPC module load.
if path.endswith(".o"):
# Extra dependencies during runtime.
from tvm.contrib import cc as _cc

_cc.create_shared(path + ".so", path)
_cc.create_shared(path + ".so", path, cc=cc)
path += ".so"
elif path.endswith(".tar"):
# Extra dependencies during runtime.
Expand All @@ -408,7 +413,7 @@ def load_module(path, fmt=""):
tar_temp = _util.tempdir(custom_path=path.replace(".tar", ""))
_tar.untar(path, tar_temp.temp_dir)
files = [tar_temp.relpath(x) for x in tar_temp.listdir()]
_cc.create_shared(path + ".so", files)
_cc.create_shared(path + ".so", files, cc=cc)
path += ".so"
# TODO(weberlo): we should probably use a more distinctive suffix for uTVM object files
elif path.endswith(".obj"):
Expand Down

0 comments on commit f9abf56

Please sign in to comment.