[{"data":1,"prerenderedAt":293},["ShallowReactive",2],{"content-query-XPyyeQCss5":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":287,"_id":288,"_source":289,"_file":290,"_stem":291,"_extension":292},"/technology-blogs/zh/2168","zh",false,"","昇思易点通 | 在Windows下编译昇思MindSpore的GPU版本","想要尝鲜的朋友可以通过如下的步骤完成昇思MindSpore Windows GPU版本的编译。","2023-02-15","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/02/17/79f90e83c0d145699875b3a7a37ef64b.png","technology-blogs","基础知识",{"type":15,"children":16,"toc":284},"root",[17,25,37,42,46,54,62,67,72,81,86,91,98,103,108,115,123,131,145,155,160,168,176,184,189,197,205,217,228,239,250,261,272],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"昇思易点通-在windows下编译昇思mindspore的gpu版本",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29,31],{"type":24,"value":30},"**作者：**王磊 ｜",{"type":18,"tag":32,"props":33,"children":34},"strong",{},[35],{"type":24,"value":36},"来源：知乎",{"type":18,"tag":26,"props":38,"children":39},{},[40],{"type":24,"value":41},"昇思MindSpore在Windows下长期缺失GPU版本，多次的用户调研以及客户反馈都期望能提供Windows GPU版本。这个问题的核心原因在于CUDA的编译工具，在Windows下依赖cl.exe，这是微软的MSVC的编译器，因此无法使用Mingw的Gcc工具链完成编译。在解决了海量的工程问题后，当前master分支代码已可以基于MSVC完成Windows GPU版本编译，并在2.0版本中进行正式的发布。",{"type":18,"tag":26,"props":43,"children":44},{},[45],{"type":24,"value":9},{"type":18,"tag":26,"props":47,"children":48},{},[49],{"type":18,"tag":32,"props":50,"children":51},{},[52],{"type":24,"value":53},"01",{"type":18,"tag":26,"props":55,"children":56},{},[57],{"type":18,"tag":32,"props":58,"children":59},{},[60],{"type":24,"value":61},"编译前准备",{"type":18,"tag":26,"props":63,"children":64},{},[65],{"type":24,"value":66},"Windows GPU版本的编译依赖如下工具和库，需要在编译前完成准备：",{"type":18,"tag":26,"props":68,"children":69},{},[70],{"type":24,"value":71},"1、安装Microsoft Visual Studio Community 2019[1]，选择社区版下载，安装时按照下图选择相应的组件，同时也可以切换到非C盘进行安装。",{"type":18,"tag":26,"props":73,"children":74},{},[75],{"type":18,"tag":76,"props":77,"children":80},"img",{"alt":78,"src":79},"image.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20230216083837.74863398650226325095557069489523:50540216011335:2400:5AB91CFF61AE63F212AA1721908779A55358B37D9FB7E10580E6065CB2E49B25.png",[],{"type":18,"tag":26,"props":82,"children":83},{},[84],{"type":24,"value":85},"2、 安装git for windows[2]。同时将Git目录加到Path环境变量中，如果git安装在D:\\Program Files\\Git时，那么需要把D:\\Git\\usr\\bin加入到Path环境变量中。",{"type":18,"tag":26,"props":87,"children":88},{},[89],{"type":24,"value":90},"3、 安装CMake 3.18.3版本[3]。安装路径中不能出现中文和日文，安装完成后将cmake的路径添加到系统环境变量Path中，2，3设置如下图。",{"type":18,"tag":26,"props":92,"children":93},{},[94],{"type":18,"tag":76,"props":95,"children":97},{"alt":78,"src":96},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20230216083851.40774780528313633684643449470409:50540216011335:2400:6AE4AC248F41A3ED4DE5E7818C2F0761A4A3CEA6F056FB7F6BFE69E2DAF741F7.png",[],{"type":18,"tag":26,"props":99,"children":100},{},[101],{"type":24,"value":102},"4、安装Python[4]（>=3.7.5）。可以从华为云选择合适的版本进行安装。",{"type":18,"tag":26,"props":104,"children":105},{},[106],{"type":24,"value":107},"5、安装Cuda和Cudnn：从Nvida官方网站，分别下载Cuda[5]和CUDNN[6]。Cuda的版本可以选择11.1或者11.6，其中Cuda是可执行的安装包，点击安装即可。CUDNN需要选择11.1或者11.6对应的版本，下载解压缩之后把CUDNN的安装目录加到CUDNN_HOME的环境变量中。此外，使用CUDNN需要下载一个额外的zlib动态链接库zlibwapi.dll，并将路径其加入到Path环境变量中。如下图：",{"type":18,"tag":26,"props":109,"children":110},{},[111],{"type":18,"tag":76,"props":112,"children":114},{"alt":78,"src":113},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20230216083904.17924448821933820567626570305832:50540216011335:2400:27AF7F5270FAF20FB7EB977597A3D8C14249718B7AF271713662ED03D6CA063B.png",[],{"type":18,"tag":26,"props":116,"children":117},{},[118],{"type":18,"tag":32,"props":119,"children":120},{},[121],{"type":24,"value":122},"02",{"type":18,"tag":26,"props":124,"children":125},{},[126],{"type":18,"tag":32,"props":127,"children":128},{},[129],{"type":24,"value":130},"编译昇思MindSpore GPU版本",{"type":18,"tag":26,"props":132,"children":133},{},[134,136,143],{"type":24,"value":135},"打开cmd命令行，使用git clone ",{"type":18,"tag":137,"props":138,"children":140},"a",{"href":139},"mailto:git@gitee.com",[141],{"type":24,"value":142},"git@gitee.com",{"type":24,"value":144},":mindspore/mindspore.git下载昇思MindSpore主干代码仓，然后从命令行进入到昇思MindSpore代码目录，执行编译命令：",{"type":18,"tag":146,"props":147,"children":149},"pre",{"code":148},"set FROM_GITEE=1\ncall build.bat ms_vs_gpu\n",[150],{"type":18,"tag":151,"props":152,"children":153},"code",{"__ignoreMap":7},[154],{"type":24,"value":148},{"type":18,"tag":26,"props":156,"children":157},{},[158],{"type":24,"value":159},"后续等待约2小时左右（和计算机性能有关），就可以完成版本的编译。编译好的GPU版本在代码仓的build/package中，如下，使用pip install mindspore_gpu-2.0.0-cp39-cp39-win_amd64.whl即可完成GPU版本的安装。",{"type":18,"tag":146,"props":161,"children":163},{"code":162},"Mode                 LastWriteTime         Length Name\n----                 -------------         ------ ----\nd-----         2022/8/31     11:09                build\nd-----         2022/8/31     20:06                dist\nd-----         2022/8/31     20:06                mindspore\nd-----         2022/8/31     20:06                mindspore_gpu.egg-info\n-a----         2022/8/31     20:06       93617923 mindspore_gpu-2.0.0-cp39-cp39-win_amd64.whl\n",[164],{"type":18,"tag":151,"props":165,"children":166},{"__ignoreMap":7},[167],{"type":24,"value":162},{"type":18,"tag":26,"props":169,"children":170},{},[171],{"type":18,"tag":32,"props":172,"children":173},{},[174],{"type":24,"value":175},"03",{"type":18,"tag":26,"props":177,"children":178},{},[179],{"type":18,"tag":32,"props":180,"children":181},{},[182],{"type":24,"value":183},"运行昇思MindSpore GPU版本",{"type":18,"tag":26,"props":185,"children":186},{},[187],{"type":24,"value":188},"下载昇思MindSpore的手写数字教程代码[7]，安装MindSpore Vision套件pip install mindvision，然后执行python mindspore_quick_start.py --device_target=GPU。可以看到训练任务可以顺利执行，证明编译出的版本功能正常。",{"type":18,"tag":146,"props":190,"children":192},{"code":191},"(py39) PS C:\\Users\\iambowen\\Downloads> python .\\mindspore_quick_start.py --device_target=GPU\n……\nepoch: 1 step: 125, loss is 2.284395456314087\nepoch: 1 step: 250, loss is 2.2882909774780273\nepoch: 1 step: 375, loss is 2.294778823852539\nepoch: 1 step: 500, loss is 2.3158369064331055\nepoch: 1 step: 625, loss is 2.3036279678344727\nepoch: 1 step: 750, loss is 1.9158216714859009\nepoch: 1 step: 875, loss is 0.3985179364681244\nepoch: 1 step: 1000, loss is 0.14882513880729675\nepoch: 1 step: 1125, loss is 0.21342350542545319\nepoch: 1 step: 1250, loss is 0.07935728877782822\nepoch: 1 step: 1375, loss is 0.14339512586593628\nepoch: 1 step: 1500, loss is 0.08406876772642136\nepoch: 1 step: 1625, loss is 0.013466060161590576\nepoch: 1 step: 1750, loss is 0.07948829233646393\n……\n",[193],{"type":18,"tag":151,"props":194,"children":195},{"__ignoreMap":7},[196],{"type":24,"value":191},{"type":18,"tag":26,"props":198,"children":199},{},[200],{"type":18,"tag":32,"props":201,"children":202},{},[203],{"type":24,"value":204},"下载链接",{"type":18,"tag":26,"props":206,"children":207},{},[208,210],{"type":24,"value":209},"[1]",{"type":18,"tag":137,"props":211,"children":215},{"href":212,"rel":213},"https://learn.microsoft.com/zh-cn/visualstudio/releases/2019/release-notes",[214],"nofollow",[216],{"type":24,"value":212},{"type":18,"tag":26,"props":218,"children":219},{},[220,222],{"type":24,"value":221},"[2]",{"type":18,"tag":137,"props":223,"children":226},{"href":224,"rel":225},"https://link.zhihu.com/?target=https%3A//github.com/git-for-windows/git/releases/download/v2.29.2.windows.2/Git-2.29.2.2-64-bit.exe",[214],[227],{"type":24,"value":224},{"type":18,"tag":26,"props":229,"children":230},{},[231,233],{"type":24,"value":232},"[3]",{"type":18,"tag":137,"props":234,"children":237},{"href":235,"rel":236},"https://github.com/Kitware/Cmake/releases/tag/v3.18.3",[214],[238],{"type":24,"value":235},{"type":18,"tag":26,"props":240,"children":241},{},[242,244],{"type":24,"value":243},"[4]",{"type":18,"tag":137,"props":245,"children":248},{"href":246,"rel":247},"https://repo.huaweicloud.com/python/",[214],[249],{"type":24,"value":246},{"type":18,"tag":26,"props":251,"children":252},{},[253,255],{"type":24,"value":254},"[5]",{"type":18,"tag":137,"props":256,"children":259},{"href":257,"rel":258},"https://developer.nvidia.com/cuda-11.1.1-download-archive",[214],[260],{"type":24,"value":257},{"type":18,"tag":26,"props":262,"children":263},{},[264,266],{"type":24,"value":265},"[6]",{"type":18,"tag":137,"props":267,"children":270},{"href":268,"rel":269},"https://developer.nvidia.com/cudnn",[214],[271],{"type":24,"value":268},{"type":18,"tag":26,"props":273,"children":274},{},[275,277],{"type":24,"value":276},"[7]",{"type":18,"tag":137,"props":278,"children":281},{"href":279,"rel":280},"https://obs.dualstack.cn-north-4.myhuaweicloud.com/mindspore-website/notebook/r1.8/tutorials/zh%5C_cn/beginner/mindspore%5C_quick%5C_start.py",[214],[282],{"type":24,"value":283},"https://obs.dualstack.cn-north-4.myhuaweicloud.com/mindspore-website/notebook/r1.8/tutorials/zh\\_cn/beginner/mindspore\\_quick\\_start.py",{"title":7,"searchDepth":285,"depth":285,"links":286},4,[],"markdown","content:technology-blogs:zh:2168.md","content","technology-blogs/zh/2168.md","technology-blogs/zh/2168","md",1776506120378]