samskalicky commented on a change in pull request #17270: Dynamic custom 
operator GPU support
URL: https://github.com/apache/incubator-mxnet/pull/17270#discussion_r369388924
 
 

 ##########
 File path: src/c_api/c_api.cc
 ##########
 @@ -685,28 +674,54 @@ int MXLoadLib(const char *path) {
       using namespace mxnet::op;
       regOp.set_num_inputs(DefaultSubgraphOpNumInputs);
       regOp.set_num_outputs(DefaultSubgraphOpNumOutputs);
-      regOp.set_attr<nnvm::FInferType>("FInferType",
-                                       DefaultSubgraphOpType, plevel);
-      regOp.set_attr<mxnet::FInferShape>("FInferShape",
-                                         DefaultSubgraphOpShape, plevel);
+      regOp.set_attr<nnvm::FInferType>("FInferType", DefaultSubgraphOpType, 
plevel);
+      regOp.set_attr<mxnet::FInferShape>("FInferShape", 
DefaultSubgraphOpShape, plevel);
       regOp.set_attr<FInferStorageType>("FInferStorageType",
                                         DefaultSubgraphOpStorageType, plevel);
       regOp.set_attr<FResourceRequest>("FResourceRequest",
                                        DefaultSubgraphOpResourceRequest, 
plevel);
       regOp.set_attr<nnvm::FMutateInputs>("FMutateInputs",
                                           DefaultSubgraphOpMutableInputs, 
plevel);
     }
-
     // optionally add stateful forward
-    if (create_opstate_fp != nullptr) {
+    if (createop_map.size() != 0) {
       regOp.set_attr<FCreateOpState>("FCreateOpState", create_opstate, plevel);
-      regOp.set_attr<FStatefulComputeEx>("FStatefulComputeEx<cpu>",
-                                        fstateful_forward, plevel);
+      auto fstate_forward = [=](const OpStatePtr& state_ptr,
+                                const OpContext& ctx,
+                                const std::vector<NDArray>& inputs,
+                                const std::vector<OpReqType>& req,
+                                const std::vector<NDArray>& outputs) {
+        CustomFComputeDispatcher(name_str, nullptr, nullptr, nullptr,
+                                 callFStatefulComp, 1, &state_ptr, ctx, 
inputs, req, outputs);
+      };
+      regOp.set_attr<FStatefulComputeEx>("FStatefulComputeEx<cpu>", 
fstate_forward, plevel);
+      regOp.set_attr<FStatefulComputeEx>("FStatefulComputeEx<gpu>", 
fstate_forward, plevel);
     } else {
-      regOp.set_attr<FComputeEx>("FComputeEx<cpu>", forward_lambda, plevel);
+      if (forward_ctx_map.count("cpu") > 0) {
+        auto forward_cpu_lambda = [=](const nnvm::NodeAttrs& attrs,
+                                      const OpContext& ctx,
+                                      const std::vector<NDArray>& inputs,
+                                      const std::vector<OpReqType>& req,
+                                      const std::vector<NDArray>& outputs) {
+          CustomFComputeDispatcher(name_str, callFComp, 
forward_ctx_map.at("cpu"), &attrs,
+                                   nullptr, 0, nullptr, ctx, inputs, req, 
outputs);
+        };
 
 Review comment:
   I think we should call `forward_ctx_map.at("cpu")` outside of the lambda and 
just use the `fcomp_t` otherwise it will capture the whole `forward_ctx_map` map

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to