[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365091179
 
 

 ##
 File path: python/tvm/contrib/cc.py
 ##
 @@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 """Util to invoke C/C++ compilers in the system."""
-# pylint: disable=invalid-name
+# pylint: disable=invalid-name, raising-bad-type
 
 Review comment:
   do not disbale rising-bad-type


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365091130
 
 

 ##
 File path: python/tvm/contrib/cc.py
 ##
 @@ -51,10 +51,41 @@ def create_shared(output,
 else:
 raise ValueError("Unsupported platform")
 
+def get_target_by_dump_machine(compiler):
+""" Functor of get_target_triple that can get the target triple using 
compiler.
+
+Parameters
+--
+compiler : Optional[str]
+The compiler.
+
+Returns
+---
+out: Callable
+A function that can get target triple according to dumpmachine option 
of compiler.
+"""
+def get_target_triple():
+""" Get target triple according to dumpmachine option of compiler."""
+if compiler:
+cmd = [compiler, "-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 None
 
 Review comment:
   Raise None seems to be wrong, either raise an error or return None


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365069861
 
 

 ##
 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:
   ```python
   create_shared.get_target_triple = get_target_by_dump_machine(
"g++" if sys.platform == "darwin" or sys.platform.startswith("linux") 
else None)
   
   ndk.get_target_triple = get_target_by_dump_machine(NDK_CC)
   ```
   Note how ```get_target_by_dump_machine``` takes the compiler argument and 
returns a closure impl of get_target_triple


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365069930
 
 

 ##
 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:
   In the case of _fcompile, we can simply assign it to get_target_triple if 
user pass it in, or assign it to None


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365069861
 
 

 ##
 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:
   ```python
   create_shared.get_target_triple = get_target_by_dump_machine(
"g++" if sys.platform == "darwin" or sys.platform.startswith("linux") 
else None)
   
   ndk.get_target_triple = get_target_by_dump_machine(NDK_CC)
   
   ```


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365066925
 
 

 ##
 File path: python/tvm/contrib/ndk.py
 ##
 @@ -64,5 +64,28 @@ def create_shared(output,
 msg += py_str(out)
 raise RuntimeError(msg)
 
+def get_target_triple():
 
 Review comment:
   by having the functor, we can reuse get_target_triple function among ndk and 
cc


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365066395
 
 

 ##
 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:
   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


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365066395
 
 

 ##
 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


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r365066395
 
 

 ##
 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:
   I specificlaly mean add support here 
https://github.com/apache/incubator-tvm/blob/master/python/tvm/contrib/cc.py#L107


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364912655
 
 

 ##
 File path: python/tvm/contrib/ndk.py
 ##
 @@ -64,5 +64,28 @@ def create_shared(output,
 msg += py_str(out)
 raise RuntimeError(msg)
 
+def get_target_triple():
 
 Review comment:
   Let us create a functor that returns this function and reuse it in most 
places
   ```
   def get_target_by_dump_machine(compiler):
def get_target_triple():
...
return get_target_triple
   ```


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364913418
 
 

 ##
 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:
   please also add support for cross_compiler in this file


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364913289
 
 

 ##
 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":
 
 Review comment:
   Please also add wrapper for cross compiler


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364911422
 
 

 ##
 File path: include/tvm/codegen.h
 ##
 @@ -59,6 +59,21 @@ runtime::Module Build(const Array& funcs,
  * \return cstr The C string representation of the file.
  */
 std::string PackImportsToC(const runtime::Module& m, bool system_lib);
+
+/*!
+ * \brief Pack imported device library to a LLVM module.
+ *  Compile the LLVM module and link with the host library
+ *  will allow the DSO loader to automatically discover and import
+ *  the dependency from the shared library.
+ *
+ * \param m The host module with the imports.
+ * \param system_lib Whether expose as system library.
+ * \param target LLVM target
 
 Review comment:
   target-> target_triple


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364912249
 
 

 ##
 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:
   Let us do it lazily(otherwise user who import cc implicitly and does not 
have a proper compiler tool chain will get an error)
   
   create_shared.get_target_triple = get_target_triple


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364914242
 
 

 ##
 File path: src/codegen/llvm/llvm_module.cc
 ##
 @@ -62,6 +63,11 @@ class LLVMModuleNode final : public runtime::ModuleNode {
   return PackedFunc([flag](TVMArgs args, TVMRetValue *rv) {
   * rv = flag;
 });
+} else if (name == "get_target_triple") {
 
 Review comment:
   consider rename to _get_target_triple just to avoid potential user defined 
function. 


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364913154
 
 

 ##
 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:
   Let us create a functor that returns this function and reuse it in most 
places
   ```
   def get_target_by_dump_machine(compiler):
def get_target_triple():
...
return get_target_triple
   ```
   
   


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-09 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364911682
 
 

 ##
 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)
 
 Review comment:
   alignment 
   ```
   Returns
   ---
   out: Optional[str] 
   The result target triple
   ```


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-08 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364577848
 
 

 ##
 File path: src/codegen/codegen.cc
 ##
 @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, 
bool system_lib) {
  << "#endif\n";
   return os.str();
 }
+
+runtime::Module PackImportsToLLVM(const runtime::Module& mod,
+  bool system_lib,
+  const std::string& target) {
+  std::string bin = SerializeModule(mod);
+
+  std::ostringstream os;
+  uint64_t nbytes = bin.length();
+  os << std::hex;
+  for (size_t i = 0; i < sizeof(nbytes); ++i) {
+os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL);
+  }
+  for (size_t i = 0; i < bin.length(); ++i) {
+int c = bin[i];
+os << std::setfill('0') << std::setw(2) << (c & 0xff);
+  }
+
+  // Call codegen_blob to generate LLVM module
+  std::string codegen_f_name = "codegen.codegen_blob";
+  // the codegen function.
+  const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name);
+  CHECK(codegen_f != nullptr)  << "codegen.codegen_blob is not presented.";
+  return (*codegen_f)(os.str(), system_lib, target);
 
 Review comment:
   Sorry I forget to mention you cannot pass std string because that will be 
treated as null terminate c str. Pass a ByteArray instead 


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-08 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364550096
 
 

 ##
 File path: src/codegen/codegen.cc
 ##
 @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, 
bool system_lib) {
  << "#endif\n";
   return os.str();
 }
+
+runtime::Module PackImportsToLLVM(const runtime::Module& mod,
+  bool system_lib,
+  const std::string& target) {
+  std::string bin = SerializeModule(mod);
+
+  std::ostringstream os;
+  uint64_t nbytes = bin.length();
+  os << std::hex;
+  for (size_t i = 0; i < sizeof(nbytes); ++i) {
+os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL);
+  }
+  for (size_t i = 0; i < bin.length(); ++i) {
+int c = bin[i];
+os << std::setfill('0') << std::setw(2) << (c & 0xff);
+  }
+
+  // Call codegen_blob to generate LLVM module
+  std::string codegen_f_name = "codegen.codegen_blob";
+  // the codegen function.
+  const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name);
+  CHECK(codegen_f != nullptr)  << "codegen.codegen_blob is not presented.";
+  return (*codegen_f)(os.str(), system_lib, target);
 
 Review comment:
   std::string header;
   for (size_t i = 0; i < sizeof(nbytes); ++i) {
   header.push_back(((nbytes >> (i * 8)) & 0xffUL));
   }
   then pass header + content


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-08 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364549582
 
 

 ##
 File path: src/codegen/codegen.cc
 ##
 @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, 
bool system_lib) {
  << "#endif\n";
   return os.str();
 }
+
+runtime::Module PackImportsToLLVM(const runtime::Module& mod,
+  bool system_lib,
+  const std::string& target) {
+  std::string bin = SerializeModule(mod);
+
+  std::ostringstream os;
+  uint64_t nbytes = bin.length();
+  os << std::hex;
+  for (size_t i = 0; i < sizeof(nbytes); ++i) {
+os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL);
+  }
+  for (size_t i = 0; i < bin.length(); ++i) {
+int c = bin[i];
+os << std::setfill('0') << std::setw(2) << (c & 0xff);
+  }
+
+  // Call codegen_blob to generate LLVM module
+  std::string codegen_f_name = "codegen.codegen_blob";
+  // the codegen function.
+  const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name);
+  CHECK(codegen_f != nullptr)  << "codegen.codegen_blob is not presented.";
+  return (*codegen_f)(os.str(), system_lib, target);
 
 Review comment:
   This is only about the way to serialize the bytes in a fixed endian. We 
should be able to directly append it to binary string and put it in the 
beginning.


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-08 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364549582
 
 

 ##
 File path: src/codegen/codegen.cc
 ##
 @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, 
bool system_lib) {
  << "#endif\n";
   return os.str();
 }
+
+runtime::Module PackImportsToLLVM(const runtime::Module& mod,
+  bool system_lib,
+  const std::string& target) {
+  std::string bin = SerializeModule(mod);
+
+  std::ostringstream os;
+  uint64_t nbytes = bin.length();
+  os << std::hex;
+  for (size_t i = 0; i < sizeof(nbytes); ++i) {
+os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL);
+  }
+  for (size_t i = 0; i < bin.length(); ++i) {
+int c = bin[i];
+os << std::setfill('0') << std::setw(2) << (c & 0xff);
+  }
+
+  // Call codegen_blob to generate LLVM module
+  std::string codegen_f_name = "codegen.codegen_blob";
+  // the codegen function.
+  const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name);
+  CHECK(codegen_f != nullptr)  << "codegen.codegen_blob is not presented.";
+  return (*codegen_f)(os.str(), system_lib, target);
 
 Review comment:
   This is only  a way to serialize the nbytes in a fixed endian. We should be 
able to directly append it to binary string and put it in the beginning.


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-08 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364338087
 
 

 ##
 File path: src/codegen/codegen.cc
 ##
 @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, 
bool system_lib) {
  << "#endif\n";
   return os.str();
 }
+
+runtime::Module PackImportsToLLVM(const runtime::Module& mod,
+  bool system_lib,
+  const std::string& target) {
+  std::string bin = SerializeModule(mod);
+
+  std::ostringstream os;
+  uint64_t nbytes = bin.length();
+  os << std::hex;
+  for (size_t i = 0; i < sizeof(nbytes); ++i) {
+os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL);
+  }
+  for (size_t i = 0; i < bin.length(); ++i) {
+int c = bin[i];
+os << std::setfill('0') << std::setw(2) << (c & 0xff);
+  }
+
+  // Call codegen_blob to generate LLVM module
+  std::string codegen_f_name = "codegen.codegen_blob";
+  // the codegen function.
+  const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name);
+  CHECK(codegen_f != nullptr)  << "codegen.codegen_blob is not presented.";
+  return (*codegen_f)(os.str(), system_lib, target);
 
 Review comment:
   Do we need to pass hex here? can we directly pass the binary blob to LLVM?


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


[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly

2020-01-08 Thread GitBox
tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use 
LLVM directly
URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364338819
 
 

 ##
 File path: src/codegen/build_module.cc
 ##
 @@ -882,6 +887,16 @@ TVM_REGISTER_GLOBAL("_GetCurrentTarget")
   *ret = Target::Current(allow_not_defined);
   });
 
+TVM_REGISTER_GLOBAL("_GetLLVMTargetHost")
+.set_body([](TVMArgs args, TVMRetValue* ret) {
+  *ret = Target::GetLLVMTargetHost();
+});
+
+TVM_REGISTER_GLOBAL("_SetLLVMTargetHost")
 
 Review comment:
   It is a bit bad to use global state to pass this argument around. Would be 
great to pass this argument as an argument of PackToLLVM instead.
   
   
   I wonder if it is necessary to set the target to be the specific target, or 
can we directly use a somewhat generic target (this means LLVM won't perform 
any target specific optimization which is fine here)


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