Here is an updated patch that is using only 'CXX', no more g++9.
From b38755e7b9690e37130a3096aa7a3a6d52fb80e8 Mon Sep 17 00:00:00 2001 From: Mihai M <mmi...@delajii.net> Date: Mon, 28 Sep 2020 23:59:47 -0700 Subject: [PATCH] Updated runtime to run under FreeBSD - for FreeBSD 12.0 setenv CXX g++9. --- python/tvm/_ffi/libinfo.py | 2 +- python/tvm/contrib/cc.py | 5 +++-- python/tvm/rpc/server.py | 7 +++++-- python/tvm/runtime/module.py | 9 +++++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/python/tvm/_ffi/libinfo.py b/python/tvm/_ffi/libinfo.py index b9fc8dc55..ae0f63ea4 100644 --- a/python/tvm/_ffi/libinfo.py +++ b/python/tvm/_ffi/libinfo.py @@ -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"): diff --git a/python/tvm/contrib/cc.py b/python/tvm/contrib/cc.py index 1b6a62fd9..add58137a 100644 --- a/python/tvm/contrib/cc.py +++ b/python/tvm/contrib/cc.py @@ -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 @@ -39,7 +40,7 @@ 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) @@ -103,7 +104,7 @@ def get_target_by_dump_machine(compiler): # 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["CXX"] if "CXX" in os.environ.keys() else "g++" if sys.platform == "darwin" or sys.platform.startswith("linux") else None ) diff --git a/python/tvm/rpc/server.py b/python/tvm/rpc/server.py index 03a124b46..bdca73e34 100644 --- a/python/tvm/rpc/server.py +++ b/python/tvm/rpc/server.py @@ -73,6 +73,9 @@ def _server_env(load_library, work_path=None): @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['CXX'] if 'CXX' in os.environ.keys() else "g++" + # pylint: disable=import-outside-toplevel path = temp.relpath(file_name) @@ -80,7 +83,7 @@ def _server_env(load_library, work_path=None): # 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. @@ -89,7 +92,7 @@ def _server_env(load_library, work_path=None): 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 diff --git a/python/tvm/runtime/module.py b/python/tvm/runtime/module.py index d9166b5f4..b133036fb 100644 --- a/python/tvm/runtime/module.py +++ b/python/tvm/runtime/module.py @@ -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 @@ -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["CXX"] if "CXX" in os.environ.keys() else "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. @@ -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"): -- 2.24.1 To summarize: * build (cmake) works w/o problems under FreeBSD (tried under 12.0) * runtime needs this patch to enable finding libs and proper g++ binary * I've tried both runtime and model conversion (relay.frontend.from_tflite). Both worked for me * target 'llvm' and 'opencl' are functional. Using opencl was slower ... but it might be my card (RX 560) * deploy_lib.tar made under Linux is loadable under FreeBSD - I assume as long it does not require external libs. Also linux will load deploy_lib.tar created under FreeBSD --- [Visit Topic](https://discuss.tvm.apache.org/t/running-tvm-on-freebsd/8009/4) to respond. You are receiving this because you enabled mailing list mode. To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/5fb8394b7c3d4a4b7661e583e73429aef58d9fcc12e074011c43b195520798ef).