[{"data":1,"prerenderedAt":361},["ShallowReactive",2],{"content-query-AQlumfIscH":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":355,"_id":356,"_source":357,"_file":358,"_stem":359,"_extension":360},"/technology-blogs/en/2591","en",false,"","MindSpore Made Easy | Compiling the GPU Version of MindSpore in Windows","To try out the new MindSpore GPU version on Windows, follow the steps described in this blog.","2023-02-15","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/03/e4c01dc566b041018409bf5ab7f7bbac.png","technology-blogs","Practices",{"type":15,"children":16,"toc":352},"root",[17,25,31,40,45,50,55,63,68,100,105,115,122,127,132,137,168,175,183,204,214,233,241,249,261,269,274,286,297,308,319,330,341],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"mindspore-made-easy-compiling-the-gpu-version-of-mindspore-in-windows",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":24,"value":30},"MindSpore has not offered a GPU version for Windows for quite some time, despite high demand from user surveys and customer feedback. This is due to the fact that the CUDA compilation tool relies on the Microsoft MSVC compiler, cl.exe, in Windows, preventing the use of the MinGw GCC toolchain for compilation. However, after overcoming numerous engineering challenges, a MSVC-based MindSpore GPU version is now available and can be used to compile the code in the current master branch. To try out the new MindSpore GPU version on Windows, follow the following steps.",{"type":18,"tag":26,"props":32,"children":33},{},[34],{"type":18,"tag":35,"props":36,"children":37},"strong",{},[38],{"type":24,"value":39},"1. Compilation Preparations",{"type":18,"tag":26,"props":41,"children":42},{},[43],{"type":24,"value":44},"Prepare the following tools and libraries for compiling the MindSpore GPU version on Windows.",{"type":18,"tag":26,"props":46,"children":47},{},[48],{"type":24,"value":49},"(1) Install Microsoft Visual Studio Community 2019[1].",{"type":18,"tag":26,"props":51,"children":52},{},[53],{"type":24,"value":54},"Download the community edition, and install the components shown in the figure. You can also switch to a non-C drive for installation.",{"type":18,"tag":26,"props":56,"children":57},{},[58],{"type":18,"tag":59,"props":60,"children":62},"img",{"alt":7,"src":61},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/03/766cb7e7bf27489dbaf4ae0a4a160075.png",[],{"type":18,"tag":26,"props":64,"children":65},{},[66],{"type":24,"value":67},"(2) Install Git for Windows[2].",{"type":18,"tag":26,"props":69,"children":70},{},[71,73,78,80,85,87,92,94,98],{"type":24,"value":72},"Add the Git directory to the ",{"type":18,"tag":35,"props":74,"children":75},{},[76],{"type":24,"value":77},"Path",{"type":24,"value":79}," environment variable. If Git is installed in ",{"type":18,"tag":35,"props":81,"children":82},{},[83],{"type":24,"value":84},"D:\\Program Files\\Git",{"type":24,"value":86},", add ",{"type":18,"tag":35,"props":88,"children":89},{},[90],{"type":24,"value":91},"D:\\Git\\usr\\bin",{"type":24,"value":93}," to the ",{"type":18,"tag":35,"props":95,"children":96},{},[97],{"type":24,"value":77},{"type":24,"value":99}," environment variable.",{"type":18,"tag":26,"props":101,"children":102},{},[103],{"type":24,"value":104},"(3) Install CMake 3.18.3[3].",{"type":18,"tag":26,"props":106,"children":107},{},[108,110,114],{"type":24,"value":109},"The installation path cannot contain Chinese or Japanese characters. After the installation is complete, add the CMake path to the ",{"type":18,"tag":35,"props":111,"children":112},{},[113],{"type":24,"value":77},{"type":24,"value":99},{"type":18,"tag":26,"props":116,"children":117},{},[118],{"type":18,"tag":59,"props":119,"children":121},{"alt":7,"src":120},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/03/239d688cbf084019ae165ee1e8561d0a.png",[],{"type":18,"tag":26,"props":123,"children":124},{},[125],{"type":24,"value":126},"(4) Install Python[4].",{"type":18,"tag":26,"props":128,"children":129},{},[130],{"type":24,"value":131},"The Python version must be 3.7.5 or higher. You can select a proper version from Huawei Cloud and install it.",{"type":18,"tag":26,"props":133,"children":134},{},[135],{"type":24,"value":136},"(5) Install CUDA and cuDNN.",{"type":18,"tag":26,"props":138,"children":139},{},[140,142,147,149,154,156,161,163,167],{"type":24,"value":141},"Download CUDA[5] and cuDNN[6] from the NVIDIA official website. Select CUDA 11.1 or 11.6. CUDA is an executable installation package, so simply click ",{"type":18,"tag":35,"props":143,"children":144},{},[145],{"type":24,"value":146},"Install",{"type":24,"value":148}," to begin the installation process. Select cuDNN 11.1 or 11.6. After downloading and decompressing the package, add the cuDNN installation directory to the ",{"type":18,"tag":35,"props":150,"children":151},{},[152],{"type":24,"value":153},"CUDNN_HOME",{"type":24,"value":155}," environment variable. In addition, to use cuDNN, you need to download an additional zlib dynamic link library ",{"type":18,"tag":35,"props":157,"children":158},{},[159],{"type":24,"value":160},"zlibwapi.dll",{"type":24,"value":162}," and add the path to the ",{"type":18,"tag":35,"props":164,"children":165},{},[166],{"type":24,"value":77},{"type":24,"value":99},{"type":18,"tag":26,"props":169,"children":170},{},[171],{"type":18,"tag":59,"props":172,"children":174},{"alt":7,"src":173},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/03/4c77bda18d4d470484742cdd03ecf031.png",[],{"type":18,"tag":26,"props":176,"children":177},{},[178],{"type":18,"tag":35,"props":179,"children":180},{},[181],{"type":24,"value":182},"2. MindSpore GPU Compilation",{"type":18,"tag":26,"props":184,"children":185},{},[186,188,202],{"type":24,"value":187},"Open the CLI, run g",{"type":18,"tag":35,"props":189,"children":190},{},[191,193,200],{"type":24,"value":192},"it clone ",{"type":18,"tag":194,"props":195,"children":197},"a",{"href":196},"mailto:git@gitee.com",[198],{"type":24,"value":199},"git@gitee.com",{"type":24,"value":201},":mindspore/mindspore.git",{"type":24,"value":203}," to download the MindSpore master code repository, go to the MindSpore code directory from the CLI, and run the following compilation commands:",{"type":18,"tag":205,"props":206,"children":208},"pre",{"code":207},"set FROM_GITEE=1\ncall build.bat ms_vs_gpu\n",[209],{"type":18,"tag":210,"props":211,"children":212},"code",{"__ignoreMap":7},[213],{"type":24,"value":207},{"type":18,"tag":26,"props":215,"children":216},{},[217,219,224,226,231],{"type":24,"value":218},"Wait for about two hours (depending on the computer performance) to complete the version compilation. The compiled GPU version is stored in ",{"type":18,"tag":35,"props":220,"children":221},{},[222],{"type":24,"value":223},"build/package",{"type":24,"value":225}," in the code repository. You can run ",{"type":18,"tag":35,"props":227,"children":228},{},[229],{"type":24,"value":230},"pip install mindspore_gpu-2.0.0-cp39-cp39-win_amd64.whl",{"type":24,"value":232}," to install the GPU version.",{"type":18,"tag":205,"props":234,"children":236},{"code":235},"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",[237],{"type":18,"tag":210,"props":238,"children":239},{"__ignoreMap":7},[240],{"type":24,"value":235},{"type":18,"tag":26,"props":242,"children":243},{},[244],{"type":18,"tag":35,"props":245,"children":246},{},[247],{"type":24,"value":248},"3. Running the MindSpore GPU Version",{"type":18,"tag":26,"props":250,"children":251},{},[252,254,259],{"type":24,"value":253},"Download the MindSpore handwritten digit tutorial code[7], install pip install mindvision (MindSpore Vision suit), and run ",{"type":18,"tag":35,"props":255,"children":256},{},[257],{"type":24,"value":258},"python mindspore_quick_start.py --device_target=GPU",{"type":24,"value":260},". We can see training jobs are executed successfully, indicating that the compiled version functions properly.",{"type":18,"tag":205,"props":262,"children":264},{"code":263},"(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",[265],{"type":18,"tag":210,"props":266,"children":267},{"__ignoreMap":7},[268],{"type":24,"value":263},{"type":18,"tag":26,"props":270,"children":271},{},[272],{"type":24,"value":273},"Download Links",{"type":18,"tag":26,"props":275,"children":276},{},[277,279],{"type":24,"value":278},"[1]",{"type":18,"tag":194,"props":280,"children":284},{"href":281,"rel":282},"https://learn.microsoft.com/zh-cn/visualstudio/releases/2019/release-notes",[283],"nofollow",[285],{"type":24,"value":281},{"type":18,"tag":26,"props":287,"children":288},{},[289,291],{"type":24,"value":290},"[2]",{"type":18,"tag":194,"props":292,"children":295},{"href":293,"rel":294},"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",[283],[296],{"type":24,"value":293},{"type":18,"tag":26,"props":298,"children":299},{},[300,302],{"type":24,"value":301},"[3]",{"type":18,"tag":194,"props":303,"children":306},{"href":304,"rel":305},"https://github.com/Kitware/Cmake/releases/tag/v3.18.3",[283],[307],{"type":24,"value":304},{"type":18,"tag":26,"props":309,"children":310},{},[311,313],{"type":24,"value":312},"[4]",{"type":18,"tag":194,"props":314,"children":317},{"href":315,"rel":316},"https://repo.huaweicloud.com/python/",[283],[318],{"type":24,"value":315},{"type":18,"tag":26,"props":320,"children":321},{},[322,324],{"type":24,"value":323},"[5]",{"type":18,"tag":194,"props":325,"children":328},{"href":326,"rel":327},"https://developer.nvidia.com/cuda-11.1.1-download-archive",[283],[329],{"type":24,"value":326},{"type":18,"tag":26,"props":331,"children":332},{},[333,335],{"type":24,"value":334},"[6]",{"type":18,"tag":194,"props":336,"children":339},{"href":337,"rel":338},"https://developer.nvidia.com/cudnn",[283],[340],{"type":24,"value":337},{"type":18,"tag":26,"props":342,"children":343},{},[344,346],{"type":24,"value":345},"[7]",{"type":18,"tag":194,"props":347,"children":350},{"href":348,"rel":349},"https://obs.dualstack.cn-north-4.myhuaweicloud.com/mindspore-website/notebook/r1.8/tutorials/zh_cn/beginner/mindspore_quick_start.py",[283],[351],{"type":24,"value":348},{"title":7,"searchDepth":353,"depth":353,"links":354},4,[],"markdown","content:technology-blogs:en:2591.md","content","technology-blogs/en/2591.md","technology-blogs/en/2591","md",1776506106655]