You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/27 08:29:17 UTC

[GitHub] TX2012LH opened a new issue #9209: Speed between Ndarry and Numpy

TX2012LH opened a new issue #9209: Speed between Ndarry and Numpy
URL: https://github.com/apache/incubator-mxnet/issues/9209
 
 
   ## Description
   I write one demo to compare speed between Ndarray and Numpy and I find that cpu-Ndarray is not as fast as Numpy?
   
   ## Environment info
   ubunut 14.04
   gpu titan x
   
   ## Code
   ``` python
   def argmax_nd():
       gpu_device = mx.gpu()
       for i in xrange(100):
           with mx.Context(gpu_device):
               nd_a = mx.nd.array(np.random.randint(10, size=(176, 176, 100)))
               t = time.time()
               nd_a -= mx.nd.min(nd_a, axis=(0, 1))
               nd_a /= (mx.nd.sum(nd_a, axis=(0, 1)) + 1e-8)
               b = 0.38 * nd_a + mx.nd.ones(nd_a.shape) * (1 - 0.38)
               c = b.reshape((-1, nd_a.shape[2]))
               d = mx.nd.argmax(c, axis=0)
               y = d / 176 - 176/2.
               x = d % 176 - 176/2.
               m = x.asnumpy()
               n = y.asnumpy()
               print 'argmax time: ', time.time() - t
   
   def argmax_np():
       for i in xrange(100):
           np_a = np.random.randint(10, size=(176, 176, 100)).astype(float)
           t = time.time()
           np_a -= np.min(np_a, axis=(0, 1))
           np_a /= (np.sum(np_a, axis=(0, 1)) + 1e-8)
           b = 0.38 * np_a + np.ones(np_a.shape) * (1 - 0.38)
           c = b.reshape((-1, np_a.shape[2]))
           d = np.argmax(c, axis=0)
           y = d / 176 - 176/2.
           x = d % 176 - 176/2.
           print 'argmax time: ', time.time() - t
   ```
   ## Time Cost
   GPU-Ndarray: 23ms
   CPU-Ndarray: 82ms
   Numpy: 45 ms

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services