How to use OpenCL on iMX8 with Android

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use OpenCL on iMX8 with Android

Jump to solution
4,806 Views
dmitry_yunitski
Contributor II

We try to use OpenCL on the board using MACE library. It seems OpenCL library is not accessible on the board, we're getting the following errors : 

E/linker: library "/system/vendor/lib64/libOpenCL.so" ("/vendor/lib64/libOpenCL.so") needed or dlopened by "/data/app/com.mapbox.vision.teaser-Z24w2xgzilGUCXbduDriKg==/base.apk!/lib/arm64-v8a/libvision-sdk-wrapper.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="/data/app/com.mapbox.vision.teaser-Z24w2xgzilGUCXbduDriKg==/lib/arm64:/data/app/com.mapbox.vision.teaser-Z24w2xgzilGUCXbduDriKg==/base.apk!/lib/arm64-v8a", permitted_paths="/data:/mnt/expand:/data/data/com.mapbox.vision.teaser"]

Internet suggests to add libOpenCL.so to the /system/etc/public.libraries.txt (1, 2, 3), but that hadn't worked for us. Seems entries in the /system/etc/public.libraries.txt only list libraries at the /system/lib and not /system/vendor/lib64. So when we've added libOpenCL.so to this list device just wasn't able to boot after the reboot, complaining unable to load the libOpenCL.so

We've tried to copy libOpenCL.so to /system/lib, which produced another error since libOpenCL depends on another library, that is also not in the /system/lib, that depend on another library and so on. 

How could we correctly expose libOpenCL? Seems that there should be another public.libraries.txt listing exposed vendor libraries, but we were unable to locate one.

1 Solution
4,616 Views
jesse_edwards
Contributor I

Dzmitry found the solution. It was to place a file here /vendor/etc/public.libraries.txt and to put libOpenCL.so inside the txt file.

In order to place that file there you might have to remount the filesystem as rw instead of ro. The filesystem was initial read only which we followed this post to unlock. How to remount /system - 8.1 imx8m Copied from the that post to here incase the link changes.

1. Unlock the device.

  a. Boot up the device.

  b. Choose Settings -> Developer Options -> OEM Unlocking to enable OEM unlocking.

  c. Enter Fastboot mode on the device. Execute the following command on the target side:

      reboot bootloader

  d. Unlock the device. Execute the following command on the host side:
      fastboot oem unlock

  e. Wait until the unlock process is complete.

 

2. Disable DM-verity.

  a. Boot up the device.

  b. Disable the DM-verity feature. Execute the following command on the host side:
      adb root

      adb disable-verity

      adb reboot

View solution in original post

8 Replies
1,839 Views
Aerotic
Contributor I

There's information for those who fail with the above method.

There is another `public.libraries.txt`, whose full path is `/etc/public.libraries.txt`.

Add `libOpenCL.so`  to both `public.libraries.txt` works. Only adding to ` /vendor/etc/public.libraries.txt` does not work. Only adding to `/etc/public.libraries.txt` is not verified.

0 Kudos
2,996 Views
jan4coffee
Contributor I

Hi,

I was able to resolve this issue, with this change a normal third party Android application can load OpenCL and use it.
Included in NXP AOSP 12 for imx8mp is OpenCL 1.2, not OpenCL 3.0

Good information on how to use OpenCL 1.2 can be found in "IMX_GRAPHICS_USERS_GUIDE.pdf"

In the Android applications AndroidManifest.xml use the "uses-native-library" tag

 <application
        android:testOnly="false"
....
        android:theme="@style/AppTheme" >

        <uses-native-library
            android:name="libOpenCL.so"
            android:required="false" />

        <activity android:name=".MainActivity"
....
        </activity>

 

Change to AOSP

project device/nxp/
diff --git a/imx8m/evk_8mp/BoardConfig.mk b/imx8m/evk_8mp/BoardConfig.mk
index eb3030a2..400f39a8 100644
--- a/imx8m/evk_8mp/BoardConfig.mk
+++ b/imx8m/evk_8mp/BoardConfig.mk
@@ -199,5 +199,7 @@ SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += \
 
 BOARD_SEPOLICY_DIRS := \
        $(CONFIG_REPO_PATH)/imx8m/sepolicy \
-       $(IMX_DEVICE_PATH)/sepolicy
+       $(IMX_DEVICE_PATH)/sepolicy \
+       device/nxp/imx8m/evk_8mp/sepolicy/vendor
 
+#BOARD_VENDOR_SEPOLICY_DIRS+= device/nxp/imx8m/evk_8mp/sepolicy/vendor
diff --git a/imx8m/evk_8mp/evk_8mp.mk b/imx8m/evk_8mp/evk_8mp.mk
index 34cd374f..50545da7 100644
--- a/imx8m/evk_8mp/evk_8mp.mk
+++ b/imx8m/evk_8mp/evk_8mp.mk
@@ -348,7 +348,8 @@ PRODUCT_PACKAGES += \
 
 # GPU openCL g2d
 PRODUCT_COPY_FILES += \
-    $(IMX_PATH)/imx/opencl-2d/cl_g2d.cl:$(TARGET_COPY_OUT_VENDOR)/etc/cl_g2d.cl
+    $(IMX_PATH)/imx/opencl-2d/cl_g2d.cl:$(TARGET_COPY_OUT_VENDOR)/etc/cl_g2d.cl \
+    vendor/etc/public.libraries.txt:$(TARGET_COPY_OUT_VENDOR)/etc/public.libraries.txt
 
 # -------@block_wifi-------

Append the "<aosp-build-source>/vendor/etc/public.libraries.txt" with "libOpenCL.so"

eg: "cat vendor/etc/public.libraries.txt"
libOpenCL.so

Ensure that "adb shell ldd /vendor/lib64/libOpenCL.so" works as expected, libOpenCL.so and all it's ("/vendor/lib64/") dependencies has to be exposed as "same_process_hal_file" in the SE-linux file found in the "./imx8m/sepolicy/file_contexts" e.g "/vendor/lib(64)?/libOpenCL\.so u:object_r:same_process_hal_file:s0" 

Good luck!

0 Kudos
4,617 Views
jesse_edwards
Contributor I

Dzmitry found the solution. It was to place a file here /vendor/etc/public.libraries.txt and to put libOpenCL.so inside the txt file.

In order to place that file there you might have to remount the filesystem as rw instead of ro. The filesystem was initial read only which we followed this post to unlock. How to remount /system - 8.1 imx8m Copied from the that post to here incase the link changes.

1. Unlock the device.

  a. Boot up the device.

  b. Choose Settings -> Developer Options -> OEM Unlocking to enable OEM unlocking.

  c. Enter Fastboot mode on the device. Execute the following command on the target side:

      reboot bootloader

  d. Unlock the device. Execute the following command on the host side:
      fastboot oem unlock

  e. Wait until the unlock process is complete.

 

2. Disable DM-verity.

  a. Boot up the device.

  b. Disable the DM-verity feature. Execute the following command on the host side:
      adb root

      adb disable-verity

      adb reboot

4,616 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello Dzmitry,

OpenCL is available on yocto, the software you are using is not supported by NXP.

Regards

0 Kudos
4,616 Views
jesse_edwards
Contributor I

@Bio_TICFSL what are you referring to when you say "the software you are using is not supported by NXP". The software that was used should be supported as it was downloaded directly off the NXP website in the Embedded Software section. 

i.MX 8QuadMax/QuadPlus Multisensory Enablement Kit | NXP 

Software: Q10.0.0_1.0.0_ANDROID_SOURCE

0 Kudos
4,616 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hi,

I refer to MACE is not supported.

Regards

0 Kudos
4,616 Views
dmitry_yunitski
Contributor II

Hello, 

our question here is more about OpenCL, not MACE itself, MACE just fails to dlopen opencl. From Android docs it seems there should be additional public.libraries.txt file containing list of exposed vendor libraries, but it's not there on the board. 

0 Kudos
4,616 Views
dmitry_yunitski
Contributor II

Hi, thanks for the response, however it's not really clear - does it mean there is absolutely no way to use OpenCL library with Android? Despite it's actually present on the device under /system/vendor/lib64/ and the only missing part is it's not exposed?

0 Kudos