如何强制exe文件在Windows上的Nvidia GPU上运行
我有一个用 C++ 语言编写的程序。我的整个代码仅包含 3 个文件:我自己的类的头文件、包含该类的代码实现的 cpp 文件以及具有 main()
方法的第三个 cpp 文件。
我需要进行非常复杂的计算,在普通CPU上我的代码大约需要3个月才能完成执行。这就是为什么我尝试在我的 Nvidia GPU 上运行该程序。该代码是在 Visual Studio IDE 上开发的,我制作了一个 EXE 文件。
这就是我尝试做的:
- 转到图形设置 - >选择相关的Exe文件->设置该文件以获得 Nvidia 卡的高性能。这不起作用。
- 我打开 Nvidia 控制面板 ->应用程序设置->再次选择相关的Exe文件->选择 Nvidia GPU 以获得高性能。另外,这里没有运气。
两种方法都失败了,我的代码在我的 Intel GPU 上运行,而不是在我的 Nvidia 卡上运行。
如何强制执行Exe文件在Nvidia卡上运行?
三种方法是通过命令行(或任何其他方式)使我的 C++ 代码在我的 Nvidia GPU 上编译和运行吗?
I have a program written in C++
language. My whole code contains only 3 files: a header file for my own class, a cpp file with code implementation for the class and a 3rd cpp file where I have the main()
method.
I need to make very complicated calculations, and on a normal CPU my code takes about 3 months to complete the execution. That's why I tried to run the program on my Nvidia GPU. The code was developed on Visual Studio IDE and I made an EXE file.
This is what I tried to do:
- Went to graphics settings -> Choose the relevant Exe file -> set the file for high performance with Nvidia card. This did Not work.
- I open Nvidia Control Panel -> apps settings -> again, picked the relevant Exe file -> select Nvidia GPU for high performance. Also, no luck here.
Both ways failed, my code is running on my Intel GPU and not on my Nvidia card.
How can I force the execution of the Exe file to run on the Nvidia card?
Is three a way via the command line (or any other way) to make my C++ code to be compiled and run on my Nvidia GPU?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,没有简单和/或自动的方法来编译要在 GPU 中执行的通用 C++ 代码。您必须使用某些特定的 API 进行 GPU 计算,或者以某种工具能够自动生成 GPU 代码的方式实现代码。
我所知道的用于 GPU 编程的 C++ API 有:
CUDA:仅适用于 NVIDIA GPU,相对易于使用。这里有一个很好的介绍: https://developer.nvidia.com/博客/even-easier-introduction-cuda/
OpenCL:可以用于市场上大多数GPU,但不如CUDA那么容易使用。 OpenCL 的一个有趣的特性是生成的代码也可以在 CPU 中运行。示例如下: https://www.eriksmistad.no /开始使用-opencl-and-gpu-计算/
SYCL:一个相对较新的 API,用于构建在 OpenCL 之上的异构编程。 SYCL 高度简化了 GPU 编程,我发现这个有趣的教程展示了 SYCL 的易用性:https://tech.io/playgrounds/48226/introduction-to-sycl/introduction-to-sycl-2
不幸的是,如果您想使用一个,则需要重写代码的某些部分这些选项。我相信 SYCL 将是更容易的选择,并且需要对 C++ 代码进行更少的修改(我真的鼓励您看一下本教程,SYCL 非常容易使用)。另外,Visual Studio 似乎已经支持 SYCL: https ://developer.codeplay.com/products/computecpp/ce/guides/platform-support/targeting-windows
As far as I know, there is no easy and/or automatic way to compile general C++ code to be executed in a GPU. You have to use some specific API for GPU computing or implement the code in a way that some tool is able to automatically generate the code for a GPU.
The C++ APIs that I know for GPU programming are:
CUDA: intended for NVIDIA GPUs only, relatively easy to use. Here you have a good introduction: https://developer.nvidia.com/blog/even-easier-introduction-cuda/
OpenCL: can be used for most of the GPUs in the market, but is not as easy to use as CUDA. An interesting feature of OpenCL is that the generated code can also run in CPU. An example here: https://www.eriksmistad.no/getting-started-with-opencl-and-gpu-computing/
SYCL: a relatively recent API for heterogeneous programming built on top of OpenCL. SYCL highly simplifies the GPU programming, I found this interesting tutorial which shows how easy to use SYCL is: https://tech.io/playgrounds/48226/introduction-to-sycl/introduction-to-sycl-2
Unfortunately, you will need to rewrite some parts of your code if you want to use one of these options. I believe that SYCL will be the easier choice and the one that will require less modifications in the C++ code (I really encourage you to take a look at the tutorial, SYCL is pretty easy to use). Also, it seems that Visual Studio already supports SYCL: https://developer.codeplay.com/products/computecpp/ce/guides/platform-support/targeting-windows
NVIDIA 提供高性能 C++ 编译器,该编译器将生成代码,将部分工作负载转移到 GPU 上。
使用 C++17 并行算法效果最佳。
可能 - 您必须重新编写一些现有的 C++ 代码,然后使用 NVIDIA 的 C++ 编译器进行编译。
您的代码/算法必须支持某种形式的并行性。
以下是一些有关 NVIDIA HPC C++ 编译器信息的链接。
https://developer.nvidia.com/hpc-compilers
https://developer.nvidia.com/hpc-sdk
https://developer.nvidia.com/nvidia-hpc-sdk-downloads
NVIDIA offers a high performance C++ compiler that will generate code moving some of your workload onto the GPU.
This works best using C++17 parallel algorithm.
Likely - you have to re-write some your existing C++ code and then compile it using NVIDIA's C++ compiler.
Your code/algorithm must support some form of parallelism.
Here are some links with information about NVIDIA's HPC C++ compiler.
https://developer.nvidia.com/hpc-compilers
https://developer.nvidia.com/hpc-sdk
https://developer.nvidia.com/nvidia-hpc-sdk-downloads