windows10下cuda9.2升级到cuda10.2

原创
2020/09/09 13:02
阅读数 5.6W

一、文章主要内容

    1、Windows10下从cuda9.2升级到cuda10.2

    2、Windows10下cudnn安装

    3、cuda9.2、cuda10.2、cudnn7.2.1、cudnn7.6.5在DeepLearning4j中性能对比

二、安装过程

    1、机器环境说明:

     CPU:i7 8700 6核12线程

     GPU:GTX 1070Ti

     内存:16G

    备注:机器中曾经安装过cuda和cudnn,版本为:cuda9.2.148、cudnn7.2.1

     

    2、安装包准备

    (1)、cuda下载

    cuda下载地址:https://developer.nvidia.com/cuda-toolkit-archive,这里下载版本为:10.2,由于dl4j最高只支持到10.2

    

    安装机器为windows10  64位,选择cuda win10的64位版本,安装模式选择local,把安装包下载到本地安装

    (2)、cuDNN下载

    下载地址:https://developer.nvidia.com/rdp/cudnn-archive,这里选择与cuda10.2匹配的最新cudnn版本:7.6.5,这里不选8.0.2的原因是dl4j-beta6不支持8.x版本。

    

    下载到的安装包如下:

    

    3、安装cuda10.2

    直接按照默认安装路径,下一步,同意并继续 -> 精简安装

    

    进入安装阶段

    

    安装结束之后,在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA目录之下,出现了v10.2的文件夹,如下图:

    

    备注:这里有个v9.2,是之前安装的cuda版本,设置环境变量,也可以切换到9.2的版本

    打开cmd控制台,输入nvcc --version命令回车,如下图所示,说明10.2版本安装成功

    

    同时用dl4j最新的example测试,验证cuad10.2是否可用,example地址:https://github.com/eclipse/deeplearning4j-examples/tree/master/mvn-project-template

   将maven依赖修改成如下配置,其中将dl4j-master.version修改为:1.0.0-beta6,加入nd4j-cuda-10.2-platform和deeplearning4j-cuda-10.2依赖

<properties>
        <dl4j-master.version>1.0.0-beta6</dl4j-master.version>
        <logback.version>1.2.3</logback.version>
        <java.version>1.8</java.version>
        <maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
    </properties>


    <dependencies>
        <!-- deeplearning4j-core: contains main functionality and neural networks -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-core</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>

        <!--
        ND4J backend: every project needs one of these. The backend defines the hardware on which network training
        will occur. "nd4j-native-platform" is for CPUs only (for running on all operating systems).
        -->
        <!-- <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-native</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency> 
        -->
        <!-- CUDA: to use GPU for training (CUDA) instead of CPU, uncomment this, and remove nd4j-native-platform -->
        <!-- Requires CUDA to be installed to use. Change the version (8.0, 9.0, 9.1) to change the CUDA version -->
        
         <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-cuda-10.2-platform</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency> 
       

        <!-- Optional, but recommended: if you use CUDA, also use CuDNN. To use this, CuDNN must also be installed -->
        <!-- See: https://deeplearning4j.konduit.ai/config/backends/config-cudnn#using-deeplearning-4-j-with-cudnn -->
        
         <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-cuda-10.2</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency> 
       

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
    </dependencies>

     Run as 一下main方法,打印日志如下, ND4J CUDA build version: 10.2.89,说明cuda10.2已经生效。

o.d.e.s.LeNetMNIST - Load data....
o.d.e.s.LeNetMNIST - Build model....
o.n.l.f.Nd4jBackend - Loaded [JCublasBackend] backend
o.n.n.NativeOpsHolder - Number of threads used for linear algebra: 32
o.n.n.Nd4jBlas - Number of threads used for OpenMP BLAS: 0
o.n.l.a.o.e.DefaultOpExecutioner - Backend used: [CUDA]; OS: [Windows 10]
o.n.l.a.o.e.DefaultOpExecutioner - Cores: [12]; Memory: [3.5GB];
o.n.l.a.o.e.DefaultOpExecutioner - Blas vendor: [CUBLAS]
o.n.l.j.JCublasBackend - ND4J CUDA build version: 10.2.89
o.n.l.j.JCublasBackend - CUDA device 0: [GeForce GTX 1070 Ti]; cc: [6.1]; Total memory: [8589934592]
o.d.n.m.MultiLayerNetwork - Starting MultiLayerNetwork with WorkspaceModes set to [training: ENABLED; inference: ENABLED], cacheMode set to [NONE]
o.d.n.l.c.ConvolutionLayer - Could not initialize CudnnConvolutionHelper
java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.deeplearning4j.nn.layers.convolution.ConvolutionLayer.initializeHelper(ConvolutionLayer.java:78)
Caused by: java.lang.UnsatisfiedLinkError: no jnicudnn in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1543)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1192)

    上面的日志中,出现一个异常,cudnn无法被初始化,是因为cudnn还没有安装,接下来就可以安装cudnn了。

    4、cuDNN安装

    解压 cudnn-10.2-windows10-x64-v7.6.5.32.zip,出现下图所示的三个文件夹

    

    将这三个文件夹复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2目录下即可。cudnn的文件便加入到了cuda安装目录下

    

    再次运行测试程序,异常消失,且CudnnSubsamplingHelper和CudnnConvolutionHelper初始化成功

o.d.e.s.LeNetMNIST - Load data....
o.d.e.s.LeNetMNIST - Build model....
o.n.l.f.Nd4jBackend - Loaded [JCublasBackend] backend
o.n.n.NativeOpsHolder - Number of threads used for linear algebra: 32
o.n.n.Nd4jBlas - Number of threads used for OpenMP BLAS: 0
o.n.l.a.o.e.DefaultOpExecutioner - Backend used: [CUDA]; OS: [Windows 10]
o.n.l.a.o.e.DefaultOpExecutioner - Cores: [12]; Memory: [3.5GB];
o.n.l.a.o.e.DefaultOpExecutioner - Blas vendor: [CUBLAS]
o.n.l.j.JCublasBackend - ND4J CUDA build version: 10.2.89
o.n.l.j.JCublasBackend - CUDA device 0: [GeForce GTX 1070 Ti]; cc: [6.1]; Total memory: [8589934592]
o.d.n.m.MultiLayerNetwork - Starting MultiLayerNetwork with WorkspaceModes set to [training: ENABLED; inference: ENABLED], cacheMode set to [NONE]
o.d.n.l.c.ConvolutionLayer - CudnnConvolutionHelper successfully initialized
o.n.j.h.i.CudaZeroHandler - Creating bucketID: 5
o.d.n.l.c.s.SubsamplingLayer - CudnnSubsamplingHelper successfully initialized
o.d.n.l.c.ConvolutionLayer - CudnnConvolutionHelper successfully initialized
o.d.n.l.c.s.SubsamplingLayer - CudnnSubsamplingHelper successfully initialized

    至此,cuda10.2和cudnn7.6.5安装成功,且可以dl4j beta6可以正常运行。

三、性能对比

    测试程序地址:https://github.com/eclipse/deeplearning4j-examples/tree/master/mvn-project-template,网络结构为LeNet

    环境说明:

       操作系统:Windows10

       CPU:i7 8700   3.2GHz   6核12线程

       GPU:GTX 1070Ti

       内存:16G

       dl4j:beta6

     对比结果:

                   运行环境                                    耗时(ms)                       
                     CPU             26566
                    cuda9.2             20725
         cuda9.2+cudnn7.2.1             12575
                    cuda10.2             19953
           cuda10.2+cudnn7.6.5             12574

     结果说明:

     1、cuda9.2和cuda10.2运行结果相差不大

     2、cuda9.2+cudnn7.2.1 和  cuda10.2+cudnn7.6.5运行结果也相差不大

     3、cudnn运行效率有显著提升

     4、GPU配合cudnn比CPU效率提升2倍

   特殊说明:dl4j基于cudnn对如下结构进行了优化,如下图所示:

    

 

快乐源于分享。

   此博客乃作者原创, 转载请注明出处。

 

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部