haojin2 opened a new pull request #14359: Speedup _contrib_index_copy
URL: https://github.com/apache/incubator-mxnet/pull/14359
 
 
   ## Description ##
   Re-writing the Map kernel of contrib.index_copy to speed up index_copy 
operator for DGL usage.
   Plus a small fix to operator registration to fix problem with symbolic API.
   
   ## 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)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] 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)
   - [ ] 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
   - [ ] 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] Custom CPU kernel for best performance on CPU
   - [x] Custom GPU kernel for best performance on GPU
   
   ## Comments ##
   benchmark results:
   CPU
   - forward only (ms): 26.154723167419434->25.8462176322937  ~1x speedup
   - forward+backward (ms): 63094.7536945343->57.216822385787964 ~1103x speedup
   GPU:
   - forward only (ms): 52.20915079116821->4.262630462646484 ~12.25x speedup
   - forward+backward (ms): 36445.19102573395->14.284788131713867 ~2551x speedup
   ```Python
   import mxnet as mx
   
   # uncomment line to use corresponding ctx
   # ctx = mx.cpu()
   # ctx = mx.gpu(0)
   
   orig_row = 40000
   new_row = 20000
   col = 512
   
   import random
   
   indices = [i for i in range(orig_row)]
   random.shuffle(indices)
   indices = mx.nd.array(indices[0:new_row], ctx=ctx, dtype='int32')
   
   from mxnet.test_utils import check_speed, rand_ndarray
   
   mx_orig = rand_ndarray((orig_row, col)).as_in_context(ctx)
   mx_new = rand_ndarray((new_row, col)).as_in_context(ctx)
   
   orig = mx.sym.Variable("orig")
   idx = mx.sym.Variable("idx")
   new = mx.sym.Variable("new")
   mx_sym = mx.sym.contrib.index_copy(old_tensor=orig, index_vector=idx, 
new_tensor=new)
   
   print(check_speed(mx_sym, typ='forward', location={"orig": mx_orig, "idx": 
indices, "new": mx_new}, ctx=ctx, N=1000) * 1000)
   print(check_speed(mx_sym, typ='whole', location={"orig": mx_orig, "idx": 
indices, "new": mx_new}, ctx=ctx, N=10) * 1000)
   ```
   

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