简体   繁体   English

检查CUDA存在需要CUDA的程序?

[英]Program to check CUDA presence needs CUDA?

I wrote a simple application that checks if NVIDIA CUDA is available on the computer. 我写了一个简单的应用程序来检查计算机上是否有NVIDIA CUDA。 It simply displays true if a CUDA-capable device is found. 如果找到支持CUDA的设备,它只显示true

I send the app to a second PC, and the application didn't run - a dialog box showed up that cudart.dll was not found. 我将应用程序发送到第二台PC,并且应用程序没有运行 - 出现了一个对话框,显示找不到cudart.dll I want to check if CUDA is present and it requires CUDA to do that :) 我想检查CUDA是否存在,它需要CUDA来做:)

I am using CUDA 5.0, VS2012, VC++11, Windows 7. 我正在使用CUDA 5.0,VS2012,VC ++ 11,Windows 7。

Can I compile the application in a way, that all CUDA libraries are inside the executable? 我可以用一种方式编译应用程序,所有CUDA库都在可执行文件中吗?


So the scenario is: 所以场景是:

  1. My app is compiled & sent to a computer 我的应用程序已编译并发送到计算机
  2. The computer can: 电脑可以:
    1. be running windows, linux (my app is compatible with the system) 运行Windows,Linux(我的应用程序与系统兼容)
    2. have a gpu or not 有没有gpu
    3. have an nvidia gpu or not 有没有nvidia gpu
    4. have CUDA installed or not 是否安装了CUDA
  3. My app should return true only if 2.3 and 2.4 are positive (GPU with CUDA) 只有当2.3和2.4为正时,我的应用才会返回true (带CUDA的GPU)

As an opening comment, I think the order and number of steps in your edit is incorrect. 作为开场评论,我认为编辑中的步骤顺序和数量不正确。 It should be: 它应该是:

  1. Programs starts and attempts to load the runtime API library 程序启动并尝试加载运行时API库
  2. If the runtime library is present, attempt to use it to enumerate devices. 如果存在运行时库,请尝试使用它来枚举设备。

If step 1 fails, you do not have the necessary runtime support, and CUDA cannot be used. 如果步骤1失败,则您没有必要的运行时支持,并且无法使用CUDA。 If 2 fails, there is not a compatible driver and GPU present in the system and CUDA cannot be used. 如果2失败,则系统中不存在兼容的驱动程序和GPU,并且无法使用CUDA。 If they both pass, you are good to go. 如果他们都过去了,你很高兴。

In step 1 you want to use something like dlopen on Linux and handle the return status. 在步骤1中,您希望在Linux上使用类似dlopen东西并处理返回状态。 On Windows, you probably want to use the DLL delay loading mechanism (Sorry, not a Windows programmer, can't tell you more than that). 在Windows上,您可能希望使用DLL延迟加载机制 (对不起,不是Windows程序员,不能告诉您更多)。

In both cases, if the library loads, then fetch the address of cudaGetDeviceCount via the appropriate host OS API and call it. 在这两种情况下,如果库加载,则通过适当的主机OS API获取cudaGetDeviceCount的地址并调用它。 That tells you whether there are compatible GPUs which can be enumerated. 这告诉您是否有可以枚举的兼容GPU。 What you do after you find an apparently usable GPU is up to you. 在找到明显可用的GPU后,您所做的就由您决定。 I would check for compute status and try establishing a context on it. 我会检查计算状态并尝试在其上建立一个上下文。 That will ensure that a fully functional runtime/driver combination is present and everything works. 这将确保存在功能齐全的运行时/驱动程序组合并且一切正常。

I think that using only the software there is no reliable way to ensure that a GPU is Cuda-capable or not, especially if we consider that Cuda is a driver-based technology and for the OS Cuda doesn't exist if the driver says that Cuda doesn't exist. 我认为仅使用软件没有可靠的方法来确保GPU是否具有Cuda功能,特别是如果我们认为Cuda是基于驱动程序的技术而且如果驱动程序说那么操作系统Cuda不存在Cuda不存在。

I think that the best way to do this is the old fashion way, consider checking this simple web page and you will get a much more reliable answer. 我认为最好的方法是采用旧时尚的方式,考虑检查这个简单的网页 ,你会得到一个更可靠的答案。

create a plugin for your application that dynamically links to the relevant CUDA-libraries and performs the check. 为您的应用程序创建一个动态链接到相关CUDA库并执行检查的插件。

then try loading the plugin and run it's check. 然后尝试加载插件并运行它的检查。

  • if the plugin fails to load, then you don't have the CUDA-libraries installed, so you can assume False 如果插件无法加载,那么您没有安装CUDA库,因此您可以假设为False

  • if the plugin succeeds to load, then you have CUDA-libs installed and can perform the check, whether the hardware supports CUDA as well. 如果插件成功加载,那么你安装了CUDA-libs并且可以执行检查,硬件是否也支持CUDA。

链接到stackoverflow上的不同帖子: detection-nvidia-gpus-without-cuda这显示了检查cuda api是否可用且可访问的整个序列。

As a late andditional answer: 作为一个迟到的回答:

I am struggling with the same problem (detecting cuda installation without using it) and my solution so far is 我正在努力解决同样的问题(检测cuda安装而不使用它),到目前为止我的解决方案是

  • ensuring LoadLibraryA("nvcuda.dll") != nullptr (tells you pretty much only if there is an nvidia card installed, though) 确保LoadLibraryA("nvcuda.dll") != nullptr (仅在安装了nvidia卡的情况下告诉你)
  • checking for environment variable CUDA_PATH (or in my case, CUDA_PATH_V8_0), since that seems to be set by the cuda installation: const char * szCuda8Path = std::getenv("CUDA_PATH_V8_0"); 检查环境变量CUDA_PATH(或者在我的情况下,CUDA_PATH_V8_0),因为这似乎是由cuda安装设置的: const char * szCuda8Path = std::getenv("CUDA_PATH_V8_0"); (must be != nullptr) (必须是!= nullptr)

Use cudaGetDeviceCount() to know if the computer is CUDA-capable. 使用cudaGetDeviceCount()来了解计算机是否具有CUDA功能。

According to this thread , you cannot statically link cudart.dll . 根据这个帖子 ,你不能静态链接cudart.dll

There are workarounds: embed the CUDA runtime as a resource in your executable, then extract it when your program runs, then dynamically link. 有一些解决方法:将CUDA运行时作为资源嵌入可执行文件中,然后在程序运行时将其解压缩,然后动态链接。

You can also use nvidia-smi to see if CUDA is installed on a machine. 您还可以使用nvidia-smi查看是否在计算机上安装了CUDA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM