You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/11/12 11:17:18 UTC

[GitHub] [tvm] Mousius opened a new pull request #9501: [3/3][AOT][DeviceAPI] Wire up cpacked Device API context

Mousius opened a new pull request #9501:
URL: https://github.com/apache/tvm/pull/9501


   Adding the same functionality for the Device API to the cpacked calling convention. The MakePackedAPI pass now implicitly uses any variable named `kDeviceContextVar` as the `resource_handle` and this is then used in the `cpacked` calling convention which always expects some form of resource_handle to be passed.
   
   This is stacked on top of #9500 and #9395


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] manupa-arm merged pull request #9501: [3/3][AOT][DeviceAPI] Wire up cpacked Device API context

Posted by GitBox <gi...@apache.org>.
manupa-arm merged pull request #9501:
URL: https://github.com/apache/tvm/pull/9501


   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mbs-octoml commented on a change in pull request #9501: [3/3][AOT][DeviceAPI] Wire up cpacked Device API context

Posted by GitBox <gi...@apache.org>.
mbs-octoml commented on a change in pull request #9501:
URL: https://github.com/apache/tvm/pull/9501#discussion_r750492272



##########
File path: src/relay/backend/aot_executor_codegen.cc
##########
@@ -347,18 +347,30 @@ class AOTExecutorCodegen : public MixedModeVisitor {
     }
 
     GlobalVar global_var = call_lowered_props.lowered_func;
+    tir::Var empty_var("no_device_context", DataType::Handle());
     bool has_c_device_api_context = device_contexts_.count(global_var) != 0;
+    bool use_cpacked_api = !use_unpacked_api_;
+
     if (has_c_device_api_context) {

Review comment:
       Let's comment these three semi-implicit calling conventions here, including a one-sentence summary of where the extra args show up in the runtime.




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] manupa-arm commented on pull request #9501: [3/3][AOT][DeviceAPI] Wire up cpacked Device API context

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #9501:
URL: https://github.com/apache/tvm/pull/9501#issuecomment-976230360


   Thanks @mbs-octoml @Mousius . This is merged now!


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] manupa-arm commented on a change in pull request #9501: [3/3][AOT][DeviceAPI] Wire up cpacked Device API context

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on a change in pull request #9501:
URL: https://github.com/apache/tvm/pull/9501#discussion_r754020019



##########
File path: src/relay/backend/aot_executor_codegen.cc
##########
@@ -347,18 +347,41 @@ class AOTExecutorCodegen : public MixedModeVisitor {
     }
 
     GlobalVar global_var = call_lowered_props.lowered_func;
+    tir::Var empty_var("no_device_context", DataType::Handle());
     bool has_c_device_api_context = device_contexts_.count(global_var) != 0;
+    bool use_cpacked_api = !use_unpacked_api_;
+
+    // The device context is passed to the operator in one of the following calling patterns:
+    //  * Unpacked / direct function call with context:
+    //      operator(arg0, arg1, device_context);
+    //  * Unpacked / direct function call without context:
+    //      operator(arg0, arg1);
+    //  * Type-erased packed function call with context:
+    //      operator(args, type_codes, int num_args, out_ret_value, out_ret_tcode,
+    //      device_context_my_device)
+    //  * Type-erased packed function call without context (we create an empty var for codegen):
+    //      operator(args, type_codes, int num_args, out_ret_value, out_ret_tcode,
+    //      no_device_context)
     if (has_c_device_api_context) {
+      // call_extern calling convention with context
       tir::Var context = device_contexts_.Get(global_var).value();
-      args.push_back(device_contexts_[global_var]);
+      args.push_back(context);
 
       tir::Evaluate func_call(tvm::tir::Call(DataType::Int(32), calling_pattern, args));
       create_func_call_stmts.push_back(tir::SeqStmt({
           GenerateDeviceHook(context, "Open"),
           func_call,
           GenerateDeviceHook(context, "Close"),
       }));
+    } else if (use_cpacked_api) {
+      // call_cpacked calling convention needs a blank context
+      args.push_back(empty_var);
+
+      tir::Evaluate func_call(tvm::tir::Call(DataType::Int(32), calling_pattern, args));
+      tir::LetStmt set_zero(empty_var, tir::make_zero(DataType::Handle()), func_call);

Review comment:
       Any reason why we cant just pass the call without let binding it to an empty var?
   i.e.
   args.push_back(tir::make_zero(DataType::Handle()))




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Mousius commented on a change in pull request #9501: [3/3][AOT][DeviceAPI] Wire up cpacked Device API context

Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #9501:
URL: https://github.com/apache/tvm/pull/9501#discussion_r754161482



##########
File path: src/relay/backend/aot_executor_codegen.cc
##########
@@ -347,18 +347,41 @@ class AOTExecutorCodegen : public MixedModeVisitor {
     }
 
     GlobalVar global_var = call_lowered_props.lowered_func;
+    tir::Var empty_var("no_device_context", DataType::Handle());
     bool has_c_device_api_context = device_contexts_.count(global_var) != 0;
+    bool use_cpacked_api = !use_unpacked_api_;
+
+    // The device context is passed to the operator in one of the following calling patterns:
+    //  * Unpacked / direct function call with context:
+    //      operator(arg0, arg1, device_context);
+    //  * Unpacked / direct function call without context:
+    //      operator(arg0, arg1);
+    //  * Type-erased packed function call with context:
+    //      operator(args, type_codes, int num_args, out_ret_value, out_ret_tcode,
+    //      device_context_my_device)
+    //  * Type-erased packed function call without context (we create an empty var for codegen):
+    //      operator(args, type_codes, int num_args, out_ret_value, out_ret_tcode,
+    //      no_device_context)
     if (has_c_device_api_context) {
+      // call_extern calling convention with context
       tir::Var context = device_contexts_.Get(global_var).value();
-      args.push_back(device_contexts_[global_var]);
+      args.push_back(context);
 
       tir::Evaluate func_call(tvm::tir::Call(DataType::Int(32), calling_pattern, args));
       create_func_call_stmts.push_back(tir::SeqStmt({
           GenerateDeviceHook(context, "Open"),
           func_call,
           GenerateDeviceHook(context, "Close"),
       }));
+    } else if (use_cpacked_api) {
+      // call_cpacked calling convention needs a blank context
+      args.push_back(empty_var);
+
+      tir::Evaluate func_call(tvm::tir::Call(DataType::Int(32), calling_pattern, args));
+      tir::LetStmt set_zero(empty_var, tir::make_zero(DataType::Handle()), func_call);

Review comment:
       Good point @manupa-arm, I've removed it :smile_cat: 




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org