如何在Android上使用OpenCL?

发布于 2024-12-29 07:37:36 字数 176 浏览 8 评论 0原文

对于平台独立性(桌面、云、移动……),当速度很重要时,使用 OpenCL 进行 GPGPU 开发会很棒。我知道 Google 正在推动 RenderScript 作为替代方案,但它似乎仅适用于 Android,不太可能包含在 iOS 中。

因此,我寻求一种在 Android 应用程序中执行 OpenCL 代码的解决方案。

For plattform independence (desktop, cloud, mobile, ...) it would be great to use OpenCL for GPGPU development when speed does matter. I know Google pushes RenderScript as an alternative, but it seems to be only be available for Android and is unlikely to be ever included in iOS.

Therefore I seek for a solution to execute OpenCL code within Android Apps.

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

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

发布评论

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

评论(8

独行侠 2025-01-05 07:37:36

尽管距离提出最初的问题已经过去了很多年,但我认为这仍然是很多开发人员的问题。

答案有两个方面。
首先,不幸的是,Google 并不正式支持 OpenCL。

其次,幸运的是,许多芯片供应商提供了他们的库来支持 OpenCL。目前,大多数旗舰和中端智能手机(配备 Qualcomm Adreno GPU、ARM Mali GPU 或 Imagination PowerVR GPU)都包含 OpenCL 库。

要在Android上使用OpenCL,有几个步骤:

  1. 检查设备上是否有OpenCL库。这可以通过使用 OpenCL-Z Android。这是检查 Android 设备上 OpenCL 可用性的绝佳工具,它还提供原始计算性能指标,这可能非常有帮助。

主要芯片供应商的 OpenCL 库可以在设备中找到:
以下是 OpenCL 库的位置:

Qualcomm Adreno:

/system/vendor/lib/libOpenCL.so
or /system/lib/libOpenCL.so (older devices)

ARM Mali:

/system/vendor/lib/egl/libGLES_mali.so
or /system/lib/egl/libGLES_mali.so

PowerVR:

/system/vendor/lib/libPVROCL.so
  1. 使用 C 或 C++ 编写 OpenCL 程序

  2. 创建 NDK 项目来编译您的C/C++ 代码,并在设备上测试它们作为可执行文件。

  3. 为您的 NDK 程序函数创建 JNI 接口。

  4. 创建Android项目,使用JAVA代码中的JNI函数调用涉及OpenCL的原生函数。

    创建Android

索尼教程是一个很好的参考来源。该教程中介绍的技术可应用于任何 Qualcomm Adreno GPU。只需很少的修改,该代码和 makefile 也可以在其他支持 OpenCL 的设备(例如 Mali 和 PowerVR)上运行。

希望这有帮助。

Although time has passed since the original question was asked, I think this is still a question for a lot of developers.

There are two aspects in the answer.
First, unfortunately, Google doesn't support OpenCL officially.

Second, fortunately, many chip vendors provide their libraries to support OpenCL. As the time for now, most of the flagship and middle-tier smartphones (with Qualcomm Adreno GPU, ARM Mali GPU, or Imagination PowerVR GPU) include the OpenCL libraries.

To use OpenCL on Android, there are several steps:

  1. check if there is OpenCL library on the device. This can be done by using OpenCL-Z Android. This is a great tool to check the OpenCL availability on Android devices, and it also provides raw compute performance metrics, which could be very helpful.

The OpenCL libraries for the major chip vendors can be found in the devices:
The followings are the location of the OpenCL library:

Qualcomm Adreno:

/system/vendor/lib/libOpenCL.so
or /system/lib/libOpenCL.so (older devices)

ARM Mali:

/system/vendor/lib/egl/libGLES_mali.so
or /system/lib/egl/libGLES_mali.so

PowerVR:

/system/vendor/lib/libPVROCL.so
  1. Write your OpenCL program using C or C++

  2. Create NDK project to compile your C/C++ code, and test them on the device as executable.

  3. Create JNI interface for your NDK program functions.

  4. Create Android project, using JNI functions in the JAVA code to call native functions involving with OpenCL.

The sony tutorial is a good source to refer. The techniques presented in that tutorial can be applied to any Qualcomm Adreno GPU. With very minimal modification, that code and makefiles can also run on other OpenCL-capable devices (such as Mali and PowerVR).

Hope this helps.

中性美 2025-01-05 07:37:36

据我所知,唯一支持 OpenCL 的 Android 设备是基于 Mali T600 系列芯片的设备(文章 此处)。他们有一个 OpenCL SDK。显然它也是 OpenCL 1.1 完整配置文件。

Nexus 10 就是使用此类芯片的设备。三星 Exynos 5 双 SoC 使用 Mali T604,因此任何使用它的东西都可以与 Mali T600 OpenCL SDK 一起使用(我自己还没有尝试过)。

OpenCL 博客的作者正在尝试尝试一下有了这个,所以可能值得关注他的系列文章。

但是,Android 上的 OpenCL 支持是全新的(截至 2013 年 2 月 16 日),因此,虽然非常适合实验,但在提供更多支持之前可能值得谨慎(谁说 OpenCL 1.1 的初始支持有多么错误)

The only Android devices I know that support OpenCL are the ones based on the Mali T600 family of chips (article here). They have an OpenCL SDK. Apparently it is OpenCL 1.1 full profile as well.

The Nexus 10 is a device that uses such a chip. The Samsung Exynos 5 dual SoC uses a Mali T604, so anything using this supposedly could be used with the Mali T600 OpenCL SDK (havne't tried any of this myself).

The author of the OpenCL blog is trying to have a go with this, so it might be worth following his series of articles.

But, OpenCL support on Android is brand new (as of 16/2/2013) so, while great for experimentation, it might be worth being cautious until there is more support (who says how buggy the intitial support of OpenCL 1.1 is)

指尖微凉心微凉 2025-01-05 07:37:36

在索尼开发者世界查看 Android OpenCL 演示,完整的项目及其源代码,其中图像的双边过滤是在 OpenCL 中完成的,并与单线程 C 实现进行比较。有关索尼设备等预计支持何种类型的一些信息也可以在本文中找到。

文章:

提升使用 OpenCL 的 Android 应用程序的性能

文章来源:

来源至OpenCl Android 项目

免责声明:我是索尼移动的顾问

Checkout an Android OpenCL demo over at Sony developer world, complete project with source, where a bilateral filtering of an image is done in OpenCL and compared to a single threaded C implementation. Some information on what kind of support is expected in Sony devices etc can be found in the article as well.

Article:

Boost the performance of your Android app with OpenCL

Source for article:

Source to OpenCl Android project

Disclaimer: I'm a consultant at Sony Mobile

原来分手还会想你 2025-01-05 07:37:36

2018年,您可以使用openCL通过Android Studio开发Android应用程序。

为了将 openCL 与 Android Studio 结合使用,您需要做几件事。

  1. 检查您的设备是否支持 openCL 以及使用 OpenCL-Z Android 的版本,然后将预构建的库复制到您的计算机中,就像 Robert Wang 所说的那样。
  2. 下载Android Studio。
  3. 创建一个 C/C++ 支持的项目。
  4. 将 libOpenCL.so 复制到文件夹 //app/src/main/jniLibs//(您必须自己创建该文件夹)。
  5. 创建您的本机 C/C++ 文件(如果尚未创建)并将其与 Cmake 中的预构建库链接。另外,将您的本机 C/C++ 文件添加为 android 项目的库。 https://developer.android.com/studio/projects/configure-cmake
  6. 配置您的模块(应用程序)build.gradle 文件。

    <前><代码>安卓{
    ...
    默认配置{
    外部本地构建{
    cmake {
    // 根据您的设备架构进行过滤
    abiFilters 'armeabi-v7a'
    }
    }
    ...
    }
    源集{
    主要的 {
    jniLibs.srcDirs = ['src/main/jniLibs']
    }
    }
    ...
    }

In 2018, you can use openCL to develop Android app with Android Studio.

In order to use openCL with Android Studio, you will need to do several things.

  1. Check to see if your device supports openCL and what version using the OpenCL-Z Android and copy the prebuilt library into your computer like Robert Wang said.
  2. Download Android Studio.
  3. Create a project C/C++ support.
  4. Copy your libOpenCL.so to the folder /<your_project>/app/src/main/jniLibs/<architecture>/(You will have to create the folder yourself).
  5. Create your native C/C++ file if it is not created yet and link it with the prebuilt library in Cmake. Also, add your native C/C++ file as a library for the android project. https://developer.android.com/studio/projects/configure-cmake.
  6. Config your module(app) build.gradle file.

    android{
       ...
       default_config{
           externalNativeBuild{
              cmake {
                 // Filter based on your device architecture
                 abiFilters 'armeabi-v7a'
              }
            }
            ...
       }
       sourceSets {
          main {
             jniLibs.srcDirs = ['src/main/jniLibs']
          }
       }
       ...
    }
    
时间你老了 2025-01-05 07:37:36

您应该使用 RenderScript 计算来代替:
http://developer.android.com/guide/topics/renderscript/compute.html

使用 OpenCL 不是很安全,因为库(或功能)可能在目标设备上不可用。老实说,我什至不知道是否有任何 Android 设备真正支持它。如果设备上的 GPU 无法执行您想要运行的任何程序,RenderScript 将回退到 CPU 计算。

但是,如果您仍然想使用 OpenCL,这里的一些内容可能会对您有所帮助
http://www.pgroup.com/lit/articles/insider/v4n2a3.htm

您可能需要/需要特定于设备的 SDK(例如 nVidia Tegra SDK)才能进行适当的控制。

You should use RenderScript Compute instead:
http://developer.android.com/guide/topics/renderscript/compute.html

Using OpenCL is not very safe because the library (or capability) may not be available on the target device. To be honest, I don't even know if any Android device out there actually supports it. RenderScript will fall back to CPU computation if the GPU on the device is not capable of executing whatever program you want to run.

However, if you still want to use OpenCL, heres something that may help you
http://www.pgroup.com/lit/articles/insider/v4n2a3.htm

You might want/need the device-specific SDK (like the nVidia Tegra SDK) in order to have proper control.

娇纵 2025-01-05 07:37:36

所有 Qualcomm Adreno 300 系列均支持 OpenCL 1.1 嵌入式配置文件。要使用OpenCL,您需要开发NDK代码,因为Google在Java层不支持OpenCL。如果您知道如何开发 NDK 代码,那么编写 OpenCL 代码会非常简单。您需要有可用的 libOpenCL.so,它可以从支持 OpenCL 的设备获取,例如使用 Snapdragon 的 HTC one、Moto X 和 Samsung Note/Galaxy 版本。

All Qualcomm Adreno 300 serials support OpenCL 1.1 embedded profile. To use OpenCL, you need to develop NDK code as OpenCL is not supported by google at Java layer. It is pretty straighforward to write OpenCL code if you know how to develop NDK code. You need to have the libOpenCL.so available, which can be fetched from the OpenCL capable device, such as HTC one, Moto X, and Samsung Note/Galaxy versions that use Snapdragon.

像你 2025-01-05 07:37:36

Khronos 发布了 OpenCL 2.0,包括对 Android 的官方支持:
https://www.khronos.org/news/press/khronos-releases -opencl-2.0

Khronos released OpenCL 2.0 including official support for Android:
https://www.khronos.org/news/press/khronos-releases-opencl-2.0

俯瞰星空 2025-01-05 07:37:36

只要看看开源的arm计算库(ACL),它包含OpenCL内核:
https://developer.arm.com/technologies/compute-library

它有一个文档站点:
https://arm-software.github.io/ComputeLibrary/latest/

和一个 github 站点:
https://github.com/ARM-software/ComputeLibrary

另请查找 Qualcomm SNPE SDK (它使用 OpenCL:https://developer.qualcomm.com/论坛/qdn-forums/software/snapdragon-neural-processing-engine-sdk/34526):https://developer.qualcomm.com/docs/snpe/overview.html

< a href="https://www.youtube.com/watch?v=h3T1ekJ_iXM" rel="nofollow noreferrer">https://www.youtube.com/watch?v=h3T1ekJ_iXM

您还可以查看适用于移动应用的 Tensorflow Lite:https://www.tensorflow.org/lite/

也许以后会以ACL的方式支持OpenCL(现在是Android 8.1 NNAPI解决方案 - https://www.slideshare.net/kstan2/open-source- nn-frameworks-on-cellphones):

https://github.com/tensorflow/tensorflow/issues/18324

Tensorflow Lite GPU 加速 - 它适用于所有操作系统版本还是仅适用于 8.1?

http://jevois.org/ qa/index.php?qa=2057&qa_1=can-tensorflow-lite-use-the-gpu

一个很好的例子科特林在这里:
https://github.com/eddywm/KTFLITE

对于也使用 NNAPI 或 OpenGL 的 caffe2,有一些对 OpenCL 未来的希望:
https://github.com/laMia482/caffe2_android

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