FrozenGene commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365069096
########## File path: python/tvm/contrib/cc.py ########## @@ -51,9 +51,32 @@ def create_shared(output, else: raise ValueError("Unsupported platform") +def get_target_triple(): + """ Get the target triple using compiler. + + Returns + ------- + out: str (Linux / Mac) or None (Win32) + """ + if sys.platform == "darwin" or sys.platform.startswith("linux"): + cmd = ["g++", "-dumpmachine"] + proc = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (out, _) = proc.communicate() + if proc.returncode != 0: + msg = "dumpmachine error:\n" + msg += py_str(out) + raise RuntimeError(msg) + return py_str(out) + elif sys.platform == "win32": + return None + else: + raise ValueError("Unsupported platform") + # assign so as default output format create_shared.output_format = "so" if sys.platform != "win32" else "dll" +create_shared.get_target_triple = get_target_triple() Review comment: > Sorry I specificlaly mean add support here https://github.com/apache/incubator-tvm/blob/master/python/tvm/contrib/cc.py#L107 > > By allowing passing in an optional get_target_triple function Sorry I just saw your recent change of `By allowing passing in an optional get_target_triple function`. I understood previous that we should only expose `get_target_by_dump_machine` and `get_target_triple` should only accept `compiler` parameter. Seems that you want we could accept one functor of `get_target_triple` in cross_compiler so that we could get this information, i.e. ```python def get_target_by_dump_machine(compiler="g++"): # default value be g++. could be specified by other api def get_target_triple(): if sys.platform == "darwin" or sys.platform.startswith("linux"): cmd = [compiler, "-dumpmachine"] # change to compiler proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out, _) = proc.communicate() if proc.returncode != 0: msg = "dumpmachine error:\n" msg += py_str(out) raise RuntimeError(msg) return py_str(out) elif sys.platform == "win32": return None else: raise ValueError("Unsupported platform") def cross_compiler(compile_func, base_options=None, output_format="so", get_target_triple=None): ... _fcompile.get_target_by_dump_machine = get_target_triple if get_target_triple else get_target_by_dump_machine ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services