Here is a patch to make tvm runtime working under FreeBSD. Compiling works ok 
(including OpenCL) but runtime .py needs little adjustments to get the compiler 
name and library search path. As a note simple .so (i.e. CPU only) compiled on 
Linux work on FreeBSD ... 

    From 69850f072e2ca2d4d11f49f2acb8eca93f5ac00a Mon Sep 17 00:00:00 2001
    From: Mihai M <mmi...@delajii.net>
    Date: Sun, 27 Sep 2020 16:18:46 -0700
    Subject: [PATCH] Updated runtime to run under FreeBSD - tested w/ 12.0, 
g++9.

    ---
     python/tvm/_ffi/libinfo.py   |  2 +-
     python/tvm/contrib/cc.py     |  4 ++--
     python/tvm/rpc/server.py     |  7 +++++++
     python/tvm/runtime/module.py | 13 +++++++++++--
     4 files changed, 21 insertions(+), 5 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..61ccf48a8 100644
    --- a/python/tvm/contrib/cc.py
    +++ b/python/tvm/contrib/cc.py
    @@ -39,7 +39,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 +103,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
    +    "g++" if sys.platform == "darwin" or sys.platform.startswith("linux") 
else "g++9" if sys.platform.startswith("freebsd") else None
     )
     
     
    diff --git a/python/tvm/rpc/server.py b/python/tvm/rpc/server.py
    index 03a124b46..eef917773 100644
    --- a/python/tvm/rpc/server.py
    +++ b/python/tvm/rpc/server.py
    @@ -73,6 +73,13 @@ 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."""
    +
    +        # Guess C compiler[?]
    +        if  'CXX' in os.environ.keys():
    +            cc=os.environ['CXX']
    +        else:
    +            cc="g++9" if sys.platform.startswith("freebsd") else "g++"
    +    
             # pylint: disable=import-outside-toplevel
             path = temp.relpath(file_name)
     
    diff --git a/python/tvm/runtime/module.py b/python/tvm/runtime/module.py
    index d9166b5f4..5c86c7bd9 100644
    --- a/python/tvm/runtime/module.py
    +++ b/python/tvm/runtime/module.py
    @@ -17,6 +17,8 @@
     
     # pylint: disable=invalid-name, unused-import, import-outside-toplevel
     """Runtime Module namespace."""
    +import sys
    +import os
     import ctypes
     import struct
     from collections import namedtuple
    @@ -393,13 +395,20 @@ def load_module(path, fmt=""):
         This function will automatically call
         cc.create_shared if the path is in format .o or .tar
         """
    +
    +    # Guess C compiler[?]
    +    if  'CXX' in os.environ.keys():
    +        cc=os.environ['CXX']
    +    else:
    +        cc="g++9" if sys.platform.startswith("freebsd") 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 +417,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.17.1

g++ is hardcoded in the current .py files. May be having the option to pass it 
via environment or a different mechanism would be a good idea.





---
[Visit Topic](https://discuss.tvm.apache.org/t/running-tvm-on-freebsd/8009/1) 
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/00d827cd6a7629ec37b36cd49acdb9a6e1c0899b263d1a555eb6ff71f135ee11).

Reply via email to