Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

How to Build & Use OpenCL on Android Studio

7.671 visualizaciones

Publicado el

OpenCL source code is separated “host source code” as C Language file & “kernel(device) source code” as CL file.
But Android’s APK can NOT include “kernel(device) source code” as CL file in APK file.

In this case, I Introduce "OpenCL CL files header Generator". It generates Convert CL files to const char* in Single C header file.

Publicado en: Tecnología
  • Inicia sesión para ver los comentarios

How to Build & Use OpenCL on Android Studio

  1. 1. ©SIProp Project, 2006-2008 1 How to Build & Use OpenCL on Android Studio Noritsuna Imamura noritsuna@siprop.org
  2. 2. ©SIProp Project, 2006-2008 2 Goal Making OpenCL programming Environment on Android Studio Android Studio 1.3 or later C Language (Android NDK) OpenCL 1.1 (ARM-Mali)
  3. 3. ©SIProp Project, 2006-2008 3 Why? OpenCL source code is separated “host source code” as C Language file & “kernel(device) source code” as CL file. But Android’s APK can NOT include “kernel(device) source code” as CL file in APK file. Solution Convert CL file to const char* in Single C header file
  4. 4. ©SIProp Project, 2006-2008 4 Setup NDK on Android Studio1.3 Requited Gradle2.5 or later AS1.3’s Gradel is 2.4. MUST update 2.4 -> 2.5 . Setup NDK Settings->System Setting->Android SDK Modify “build.gradle” http://tools.android.com/tech-docs/new-build- system/gradle-experimental Informations Android NDK Support for Android Studio http://tools.android.com/tech-docs/android-ndk-preview NDK Samples https://github.com/googlesamples/android-ndk
  5. 5. ©SIProp Project, 2006-2008 5 Setup OpenCL on Android Studio1.3 Setup Header files of OpenCL Download from ARM-Mali’s OpenCL Dev Site http://malideveloper.arm.com/resources/sdks/mali-opencl- sdk/ Copy “[ARM-Mali dir]/include/CL/*.h” to “[your project dir]/app/main/src/jni/CL/” Load Shared Lib of OpenCL Copy “libOpenCL.so” from your Android Device to “[your Android Studio Dir]/sdk/ndk- bundle/platforms/android-[your target system]/arch- arm/usr/lib/”
  6. 6. ©SIProp Project, 2006-2008 6 Setup OpenCL on Android Studio1.3 Setup Header files & Shared Lib on Android Studio Add “Cflags” & “ldLibs” in “build.gradle” 1. build.gradle : app, android.ndk section 1. android.ndk { 2. moduleName = "openclsample-jni" 3. CFlags += "-I${file("src/main/jni/CL")}".toString() 4. ldLibs = ["android", "log", "OpenCL"] 5. (snip)
  7. 7. ©SIProp Project, 2006-2008 7 Setup Plugin “OpenCL CL Generator” Install Plugin to Android Studio Select “Setting->plugins” Click “Browse Repositories” Search Plugin by “OpenCL” as keyword Target Plugin URL https://plugins.jetbrains.com/plugin/7888?pr=androidstudio Click “Install Plugin” Restart Android Studio
  8. 8. ©SIProp Project, 2006-2008 8 Use Plugin “OpenCL CL Generator” Click “Tools->Generate OpenCL’s CL files header”
  9. 9. ©SIProp Project, 2006-2008 9 How to Use Plugin: Host Side Host side programming: standard OpenCL CL file(kernel side source code) is loaded as “file”. 1. #include “opencl_cl_files.h” 2. (snip) 3. /* Create Kernel Program from the source */ 4. program = clCreateProgramWithSource(context, 1, (const char **)&CLCL_HELLO, (const size_t *)&strlen(CLCL_HELLO), &ret); 1. FILE *fp; 2. char fileName[] = "./hello.cl"; 3. char *source_str; 4. size_t source_size; 5. fp = fopen(fileName, "r"); 6. source_str = (char*)malloc(MAX_SOURCE_SIZE); 7. source_size = fread( source_str, 1, MAX_SOURCE_SIZE, fp); 8. fclose( fp ); 9. (snip) 10. /* Create Kernel Program from the source */ 11. program = clCreateProgramWithSource(context, 1, (const char **)&source_str, (const size_t *)&source_size, &ret); Host side programming: with Android Plugin CL file is loaded as “const char*”.
  10. 10. ©SIProp Project, 2006-2008 10 How to Use Plugin: Kernel Side 1. Converted Original File: opencl_cl_files.h 1. const char *CLCL_HELLO = 2. "#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enablen" 3. "n" 4. "__kernel void hello(__global char* string)n" 5. "{n" 6. " string[0] = 'H';n" 7. " string[1] = 'e';n" 8. " string[2] = 'l';n" 9. " string[3] = 'l';n" 10. " string[4] = 'o';n" 11. " string[5] = '0';n" 12. "}n" 13. ""; 1. Kernel Source Code File: hello.cl 1. #pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable 2. __kernel void hello(__global char* string) 3. { 4. string[0] = 'H'; 5. string[1] = 'e'; 6. string[2] = 'l'; 7. string[3] = 'l'; 8. string[4] = 'o'; 9. string[5] = '0'; 10. } Kernel side programming 1. Write Source Code as CL file(Kernel Source Code) 2. Convert CL file(Kernel Source Code) to Original Header File as “opencl_cl_files.h”
  11. 11. ©SIProp Project, 2006-2008 11 Setup libOpenCL.so on Android If you(or your Android Device) don’t have libOpenCL.so in “/system/lib” or “/system/vendor/lib”, you can download libOpenCL.so. Support GPUs adreno-3xx: Qualcomm's Adreno 3xx GPUs mali-t6xx: ARM's Mali-T6xx GPUs Download from: https://github.com/madeye/opencl-android-proprietary Setup Copy All SO files to “/system/lib” or “/system/vendor/lib” on your Android Device.
  12. 12. ©SIProp Project, 2006-2008 12 Appendix
  13. 13. ©SIProp Project, 2006-2008 13 Download the Sample Project for AS The Sample Project for AS that I use in this slide. https://github.com/noritsuna/OpenCLCLGenerator_ Sample Features “build.gradle” for NDK Support Setup Plugin OpenCL Headers & SO lib The Sample Source Code for OpenCL

×