如何包含 OpenCL 库来生成独立的应用程序?

发布于 2024-10-31 10:53:32 字数 217 浏览 0 评论 0原文

我试图向一位同事展示我可以使用 OpenCL 做的奇特的事情,但执行程序无法在她的计算机上运行。一些libopencl.so(或类似)文件丢失(即她没有安装OpenCL)。所以我可能相当基本的(Linux)问题是,如何包含我的小C + OpenCL程序也将包含的所有必需的so文件在没有 OpenCL 的机器上运行?

I tried to show a colleague the fancy stuff I can do with OpenCL, but the exec would not run on her computer. Some libopencl.so (or similar) files were missing (i.e. she did not have OpenCL installed). So my probably rather basic (Linux) question is, How do I include all the necessary so files that my little C + OpenCL program will also run on machines without OpenCL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花落人离去 2024-11-07 10:53:32

正如 Damon 的评论已经指出的那样,这是不可能以通用方式做到的,因为每种设备都有自己的供应商,并且该供应商有自己的 OpenCL 实现。但是,如果您只想拥有可在大多数 Linux 计算机上运行的 OpenCL 应用程序的“可移植”副本,则有一种方法可以实现这一目标。

  1. 下载AMD APP SDK(当前版本2.4)。我假设它是 64 位版本,但它对于 32 位或其他版本号应该几乎相同,只需更改相应的字符串即可。

  2. 将 SDK 解压到应用程序可执行文件的子目录中。因此,例如,如果应用程序位于 $HOME/myapp 中,则 SDK 文件应位于 $HOME/myapp/AMD-APP-SDK-v2.4-lnx64 中。

  3. 将 ICD 文件从 icd-registration.tgz 存档中提取到名为 icd 的文件夹中。因此,我们应该有 $HOME/myapp/AMD-APP-SDK-v2.4-lnx64/icd/amdocl32.icd (和 amdocl64.icd)。

现在我们已经可以便携式安装 AMD APP SDK 了,它应该可以在大多数 x86 处理器上运行。我们只需要在启动应用程序之前设置适当的环境变量即可。由于我不是 GNU/Linux 人员并且不太了解 bash,因此我已将路径硬编码到我们的可移植目录。据推测,可以以某种方式自动获取当前位置,这显然会好得多。

#!/bin/bash
DIRECTORY=$HOME/myapp
export OPENCL_VENDOR_PATH=$DIRECTORY/AMD-APP-SDK-v2.4-lnx64/icd
export AMDAPPSDKROOT=$DIRECTORY/AMD-APP-SDK-v2.4-lnx64
export LD_LIBRARY_PATH=$AMDAPPSDKROOT/lib/x86_64:$LD_LIBRARY_PATH
./myapp

上面的脚本应该放在应用程序的根目录中,即$HOME/myapp/scriptname。因此,我们可以通过执行 ./scriptname 来启动便携式应用程序。正如我所说,由于我不太了解 bash,上面的脚本当然可以更好,处理程序的参数并自动找出脚本位置。但它应该显示如何做到这一点的总体思路。

As Damon's comment already states, this is not possible to do in a general way, since each kind of device has its own vendor and that vendor has its own implementation of OpenCL. However, if what you want to do is simply to have a "portable" copy of your OpenCL application that will run on most Linux computers, there is a way to achieve that.

  1. Download the AMD APP SDK (currently version 2.4). I'll be assuming its the 64-bit version but it should be pretty much identical for 32-bit or other version numbers, just change the corresponding strings.

  2. Extract the SDK to a subdirectory of your applications executable. So for instance if the application is in $HOME/myapp, then the SDK files should be in $HOME/myapp/AMD-APP-SDK-v2.4-lnx64.

  3. Extract the ICD files from the icd-registration.tgz archive into a folder named icd. So we should have $HOME/myapp/AMD-APP-SDK-v2.4-lnx64/icd/amdocl32.icd (and amdocl64.icd).

Now we have the workings of a portable installation of the AMD APP SDK, which should work on most x86-processors. We just need to set the appropriate environment variables before launching the application. Since I am not a GNU/Linux person and don't know bash very well I have hardcoded the path to our portable directory. Presumably it is somehow possible to get the current location automatically, which would obviously be much nicer.

#!/bin/bash
DIRECTORY=$HOME/myapp
export OPENCL_VENDOR_PATH=$DIRECTORY/AMD-APP-SDK-v2.4-lnx64/icd
export AMDAPPSDKROOT=$DIRECTORY/AMD-APP-SDK-v2.4-lnx64
export LD_LIBRARY_PATH=$AMDAPPSDKROOT/lib/x86_64:$LD_LIBRARY_PATH
./myapp

The above script should be placed in the root directory of your application, i.e. $HOME/myapp/scriptname. Thus we can launch the portable application by doing ./scriptname. As I said since I don't know bash very well the above script could certainly be much nicer, handling arguments to the program and automatically figuring out the scripts location. But it should show the general idea of how to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文