[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479572929



##
File path: src/target/llvm/codegen_amdgpu.cc
##
@@ -228,23 +233,50 @@ inline int DetectROCMApiVersion() {
   return 305;
 }
 
-runtime::Module BuildAMDGPU(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,

Review comment:
   Thanks! Updated!





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479480327



##
File path: src/target/llvm/codegen_amdgpu.cc
##
@@ -228,23 +233,50 @@ inline int DetectROCMApiVersion() {
   return 305;
 }
 
-runtime::Module BuildAMDGPU(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,

Review comment:
   Or `SetKeyValueEntry`?





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479479672



##
File path: src/target/llvm/codegen_amdgpu.cc
##
@@ -228,23 +233,50 @@ inline int DetectROCMApiVersion() {
   return 305;
 }
 
-runtime::Module BuildAMDGPU(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,

Review comment:
   `ProcessTarget` sounds a little bit vague, because it doesn't mention in 
which way we process it...
   
   We are dealing with a dictionary `Map`, which I call "target 
config", because it is a configuration used to generate a target, not the 
target class itself. This method aims to update one of its key-value entry. So 
what about `UpdateTargetConfigKeyValueEntry`? 





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479471092



##
File path: src/target/llvm/codegen_amdgpu.cc
##
@@ -228,23 +233,50 @@ inline int DetectROCMApiVersion() {
   return 305;
 }
 
-runtime::Module BuildAMDGPU(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,

Review comment:
   I feel like the word "canonicalize" is too strong, because it doesn't 
really have a canonical form. Maybe "update" is appropriate here, because what 
it does is to just update the key-value in the config. What do you think?





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479471812



##
File path: src/target/llvm/llvm_module.cc
##
@@ -252,18 +251,21 @@ class LLVMModuleNode final : public runtime::ModuleNode {
   LOG(FATAL) << "Fail to load module: " << msg;
 }
 std::string target_;

Review comment:
   I changed it to "target_metadata" because it is something from metadata 
section of a llvm module





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479471092



##
File path: src/target/llvm/codegen_amdgpu.cc
##
@@ -228,23 +233,50 @@ inline int DetectROCMApiVersion() {
   return 305;
 }
 
-runtime::Module BuildAMDGPU(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,

Review comment:
   I feel like the work "canonicalize" is too strong, because it doesn't 
really have a canonical form. Maybe "update" is appropriate here, because what 
it does is to just update the key-value in the config. What do you think?





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479470329



##
File path: src/target/llvm/codegen_nvptx.cc
##
@@ -254,14 +254,35 @@ inline int DetectCUDAComputeVersion() {
   }
 }
 
-runtime::Module BuildNVPTX(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,

Review comment:
   Good idea. I moved it to `build_common.h`





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479468506



##
File path: src/target/llvm/codegen_nvptx.cc
##
@@ -254,14 +254,35 @@ inline int DetectCUDAComputeVersion() {
   }
 }
 
-runtime::Module BuildNVPTX(IRModule mod, std::string target) {
+static void UpdateTargetConfig(const String& key, const String& value,
+   Map* target_config, bool 
error_if_inconsistent) {
+  if (target_config->count(key)) {
+const ObjectRef& obj = (*target_config)[key];
+CHECK(obj->IsInstance())
+<< "TypeError: In code generation for AMDGPU, expect key \"" << key

Review comment:
   Oooops





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479468055



##
File path: src/target/llvm/llvm_common.cc
##
@@ -140,16 +132,43 @@ std::unique_ptr 
GetLLVMTargetMachine(const std::string& tar
   }
 
   std::string err;
-  const llvm::Target* target = 
llvm::TargetRegistry::lookupTarget(target_triple, err);
-  if (target == nullptr) {
+  const llvm::Target* llvm_target = 
llvm::TargetRegistry::lookupTarget(target_triple, err);
+  if (llvm_target == nullptr) {
 CHECK(allow_null) << err << " target_triple=" << target_triple;
 return nullptr;
   }
   llvm::TargetMachine* tm =
-  target->createTargetMachine(target_triple, mcpu, mattr, opt, 
llvm::Reloc::PIC_);
+  llvm_target->createTargetMachine(target_triple, mcpu, mattr, opt, 
llvm::Reloc::PIC_);
   return std::unique_ptr(tm);
 }
 
+std::string LLVMTargetToString(const Target& target) {
+  std::ostringstream os;
+  os << "llvm";
+  if (Optional mtriple = target->GetAttr("mtriple")) {
+os << " -mtriple=" << mtriple.value();
+  }
+  if (Optional mcpu = target->GetAttr("mcpu")) {
+os << " -mcpu=" << mcpu.value();
+  }
+  if (Optional> mattr = target->GetAttr>("mattr")) 
{
+bool is_first;
+os << " -mattr=";
+for (const String& attr : mattr.value()) {
+  if (is_first) {
+is_first = false;
+  } else {
+os << ",";
+  }

Review comment:
   





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




[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #6347: [Target][Codegen] Use target class in all codegens

2020-08-28 Thread GitBox


junrushao1994 commented on a change in pull request #6347:
URL: https://github.com/apache/incubator-tvm/pull/6347#discussion_r479466091



##
File path: src/target/llvm/llvm_module.cc
##
@@ -252,18 +251,21 @@ class LLVMModuleNode final : public runtime::ModuleNode {
   LOG(FATAL) << "Fail to load module: " << msg;
 }
 std::string target_;

Review comment:
   This is something confused me as well...I didn't understand why here is 
a local variable whose name ends with underscore...





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