Install mxnet and install minpy

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DarrenXf/article/details/86099499

make sure the things below.

1.your machine has a nvidia gpu.
2.installed gpu cuda and cudnn.

how to install mxnet?

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple     --upgrade mxnet-cu90

use cu90 because my cuda version is 9.0

then install minpy

pip install minpy

then is a demo to test minpy gpu acceleration.

import time    
import numpy as np    
import numpy.random as random    
import minpy.numpy as mnp    
    
    
def main():    
    random.seed(0)    
    X = random.randn(10000, 16000)    
    A = np.array(X,dtype=np.float32)    
    Y = random.randn(16000, 5000)    
    B = np.array(Y,dtype=np.float32)    
    
    print("A.shape:%s" ,A.shape)    
    print("B.shape:%s" ,B.shape)    
    
    start = time.time()    
    C = mnp.dot(A,B)    
    d1 = time.time() - start    
    print('minpy numpy:', d1)    
    print(C)    
    
    start = time.time()    
    C = np.dot(A,B)    
    d2 = time.time() - start    
    print('numpy:', d2)    
    print(C)    
    print("%s" , d2/d1)    
    
    
if __name__ == '__main__':    
    main()    

output

A.shape:%s (10000, 16000)
B.shape:%s (16000, 5000)
minpy numpy: 0.3046295642852783
[[-129.23964     34.24473    205.77763   ...   64.57458   -134.04288
  -282.5226   ]
 [  56.055874   151.66455      4.534541  ...  -59.855354    77.807755
   102.97847  ]
 [  53.7853    -133.20685   -114.16803   ...  -78.15841    -22.429447
  -100.71634  ]
 ...
 [  18.944311  -179.30074   -114.42271   ...  -22.20309    -29.131681
    16.166618 ]
 [  -5.1453457  -11.761197   -28.63139   ... -236.34016    -67.44423
   -50.811813 ]
 [ 137.46251    -77.67743    -74.262535  ...  -25.249132    83.94517
   -14.008699 ]]
numpy: 3.323066234588623
[[-129.23964     34.24473    205.77763   ...   64.57458   -134.04288
  -282.5226   ]
 [  56.055874   151.66455      4.534541  ...  -59.855354    77.807755
   102.97847  ]
 [  53.7853    -133.20685   -114.16803   ...  -78.15841    -22.429447
  -100.71634  ]
 ...
 [  18.944311  -179.30074   -114.42271   ...  -22.20309    -29.131681
    16.166618 ]
 [  -5.1453457  -11.761197   -28.63139   ... -236.34016    -67.44423
   -50.811813 ]
 [ 137.46251    -77.67743    -74.262535  ...  -25.249132    83.94517
   -14.008699 ]]
%s 10.908548034020265

猜你喜欢

转载自blog.csdn.net/DarrenXf/article/details/86099499
今日推荐