wkcn opened a new pull request #14363: Support multi-threading for Custom 
Operator
URL: https://github.com/apache/incubator-mxnet/pull/14363
 
 
   ## Description ##
   Hi! I found that there was single-thread to execute custom operator. It 
drops the performance.
   Is it a better way to support custom operator in multi-thread?
   
   Test Case:
   ```python
   import mxnet as mx
   import time
   
   def task(ti):
       print(ti, "py_task_start")
       a = 0
       N = 100000000
       for i in range(N):
           a *= i
       print(ti, "py_task_end")
   
   class TestOP(mx.operator.CustomOp):
       def __init__(self):
           super(TestOP, self).__init__()
       def forward(self, is_train, req, in_data, out_data, aux):
           print("sleep 5s")
           time.sleep(5)
           print("sleep finished")
           out_data[0][:] = in_data[0]
       def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
           pass
   
   @mx.operator.register("test_op")
   class TestOPProp(mx.operator.CustomOpProp):
       def __init__(self):
           super(TestOPProp, self).__init__()
       def list_arguments(self):
           return ['x']
       def list_outputs(self):
           return ['y']
       def infer_shape(self, in_shape):
           return in_shape, in_shape
       def create_operator(self, ctx, shapes, dtypes):
           return TestOP()
   
   a = mx.nd.array([1,2,3])
   tic = time.time()
   b = mx.nd.Custom(a, op_type='test_op')
   c = mx.nd.Custom(a, op_type='test_op')
   d = mx.nd.Custom(a, op_type='test_op')
   mx.nd.waitall()
   print(time.time() - tic)
   ```
   
   Cost Time:
   Before: 15s
   After: 5s
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to 
the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) 
created (except PRs with tiny changes)
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [x] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding 
a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing 
distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a 
new build option with NCCL)
   - [x] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments 
are documented. 
   - For new examples, README.md is added to explain the what the example does, 
the source of the dataset, expected performance on test set and reference to 
the original paper if applicable
   - Check the API doc at 
http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [x] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [x] Support multi-threading for Custom Operator
   - [x] Add environmental variable `MXNET_CUSTOM_OP_NUM_THREADS`
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be 
made.
   - Interesting edge cases to note 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

Reply via email to