SlideShare a Scribd company logo
1 of 13
©SIProp Project, 2006-2008 1
How to Build & Use OpenCL on Android
Studio
Noritsuna Imamura
noritsuna@siprop.org
©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)
©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
©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
©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/”
©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)
©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
©SIProp Project, 2006-2008 8
Use Plugin “OpenCL CL Generator”
Click “Tools->Generate OpenCL’s CL files
header”
©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*”.
©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”
©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.
©SIProp Project, 2006-2008 12
Appendix
©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

More Related Content

What's hot

Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Yocto project and open embedded training
Yocto project and open embedded trainingYocto project and open embedded training
Yocto project and open embedded trainingH Ming
 
Android OS Porting: Introduction
Android OS Porting: IntroductionAndroid OS Porting: Introduction
Android OS Porting: IntroductionJollen Chen
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show fileSaurabh Tripathi
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driverVandana Salve
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoScyllaDB
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of AndroidTetsuyuki Kobayashi
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Egor Elizarov
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
 

What's hot (20)

Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Yocto project and open embedded training
Yocto project and open embedded trainingYocto project and open embedded training
Yocto project and open embedded training
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Android OS Porting: Introduction
Android OS Porting: IntroductionAndroid OS Porting: Introduction
Android OS Porting: Introduction
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driver
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of Android
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 

Viewers also liked (8)

Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-
 
Protocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in KitchenProtocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in Kitchen
 
將DNA在廚房抽出的程序
將DNA在廚房抽出的程序將DNA在廚房抽出的程序
將DNA在廚房抽出的程序
 
How to setup mastodon in chinese
How to setup mastodon in chineseHow to setup mastodon in chinese
How to setup mastodon in chinese
 
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
 
5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局
 
All list of the measuring machines for microwave
All list of the measuring machines for microwaveAll list of the measuring machines for microwave
All list of the measuring machines for microwave
 
衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記
 

Similar to How to Build & Use OpenCL on Android Studio

Wonho Park_20151209
Wonho Park_20151209Wonho Park_20151209
Wonho Park_20151209Wonho Park
 
EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18Xiaoli Liang
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made EasyAlon Fliess
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneDeepti Singh
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneDeepti Singh
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
The Ring programming language version 1.5.2 book - Part 15 of 181
The Ring programming language version 1.5.2 book - Part 15 of 181The Ring programming language version 1.5.2 book - Part 15 of 181
The Ring programming language version 1.5.2 book - Part 15 of 181Mahmoud Samir Fayed
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011pundiramit
 
OpenCL Programming 101
OpenCL Programming 101OpenCL Programming 101
OpenCL Programming 101Yoss Cohen
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxgopikahari7
 
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018Somkiat Khitwongwattana
 
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud RunDesigning flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Runwesley chun
 

Similar to How to Build & Use OpenCL on Android Studio (20)

Getting Started With Android
Getting Started With AndroidGetting Started With Android
Getting Started With Android
 
Wonho Park_20151209
Wonho Park_20151209Wonho Park_20151209
Wonho Park_20151209
 
Lec05 buffers basic_examples
Lec05 buffers basic_examplesLec05 buffers basic_examples
Lec05 buffers basic_examples
 
EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18
 
How to Use OpenMP on Native Activity
How to Use OpenMP on Native ActivityHow to Use OpenMP on Native Activity
How to Use OpenMP on Native Activity
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid clone
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Android
Android Android
Android
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid clone
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
ColdBox i18N
ColdBox i18N ColdBox i18N
ColdBox i18N
 
The Ring programming language version 1.5.2 book - Part 15 of 181
The Ring programming language version 1.5.2 book - Part 15 of 181The Ring programming language version 1.5.2 book - Part 15 of 181
The Ring programming language version 1.5.2 book - Part 15 of 181
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
 
OpenCL Programming 101
OpenCL Programming 101OpenCL Programming 101
OpenCL Programming 101
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
Toolchain
ToolchainToolchain
Toolchain
 
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
 
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud RunDesigning flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
 

More from Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院)

More from Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院) (20)

What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?
 
半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!
 
Introduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPWIntroduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPW
 
Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会
 
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPiPrinciple Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
 
Microwaveguquantum
MicrowaveguquantumMicrowaveguquantum
Microwaveguquantum
 
The easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on WindowsThe easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on Windows
 
GNU Radio Study for Super beginner
GNU Radio Study for Super beginnerGNU Radio Study for Super beginner
GNU Radio Study for Super beginner
 
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
 
Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3
 
Zedroid - Android (5.0 and later) on Zedboard
Zedroid - Android (5.0 and later) on ZedboardZedroid - Android (5.0 and later) on Zedboard
Zedroid - Android (5.0 and later) on Zedboard
 
3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop
 
計算機(物理)
計算機(物理)計算機(物理)
計算機(物理)
 
Resume
ResumeResume
Resume
 
How to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in ChineseHow to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in Chinese
 
How to Use OpenGL/ES on Native Activity
How to Use OpenGL/ES on Native ActivityHow to Use OpenGL/ES on Native Activity
How to Use OpenGL/ES on Native Activity
 
How to Make Hand Detector on Native Activity with OpenCV
How to Make Hand Detector on Native Activity with OpenCVHow to Make Hand Detector on Native Activity with OpenCV
How to Make Hand Detector on Native Activity with OpenCV
 
How to Make Android Native Application
How to Make Android Native ApplicationHow to Make Android Native Application
How to Make Android Native Application
 
How to Add Original Library to Android NDK
How to Add Original Library to Android NDKHow to Add Original Library to Android NDK
How to Add Original Library to Android NDK
 
How to Customize Android Framework&System
How to Customize Android Framework&SystemHow to Customize Android Framework&System
How to Customize Android Framework&System
 

Recently uploaded

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

How to Build & Use OpenCL on Android Studio

  • 1. ©SIProp Project, 2006-2008 1 How to Build & Use OpenCL on Android Studio Noritsuna Imamura noritsuna@siprop.org
  • 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. ©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. ©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. ©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. ©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. ©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. ©SIProp Project, 2006-2008 8 Use Plugin “OpenCL CL Generator” Click “Tools->Generate OpenCL’s CL files header”
  • 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. ©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. ©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.
  • 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