Monday, July 29, 2013

Android Application Bluetooth Low Energy Scanner

After installing the Android 4.3 on Nexus-4, one can write the Bluetooth Low Energy (BLE) programs on Android platform. As still no official samples are available from LG/Google on the SDK samples, I tried to dig through available the Java-docs for new SDK and write  an Android-App for scanning all BLE devices available in vicinity.

To use this application, we need following:

  • Any Android with 4.3 installed and have BLE HW support ( that means the mobile phone should support Bluetooth 4.0)
  • For getting list of scanned devices, we have two options:
    • Have real BLE devices (like BLE dongles, chips, SoC, etc)
      • We need to have a firmware image that allows us to start the discoverability on the device.
    • Have another Android 4.3 phone with BLE enabled and discovery enabled

I have TI's CC2540DK-MINI development kit  and NordicSemi's   nRF51822 Development kit. TI's kit comes with a KeyFrob and USB-based-BLE-devices and USB-based firmware loader.  For current project, I am using TI's kit's KeyFrob as my BLE device (that I am scanning from Android phone).

I have loaded the project code to the  project site.
You can try the same application using the Android application download link

Here is screen shot



Sunday, July 28, 2013

New Android 4.3 Manual Update on Nexus-4 does not contain OpenCL support

After successful update of Android 4.3 on Nexus-4 phone, I have found that my OpenCL Android applications are not running in system. After some initial lookup/debug of problem using:

  • adb logcat  is indicating that libOpenCL is not loaded
  • abd shell ls -l /system/lib/libOpenCL.so is not returning any entries
So it seems that google/LG will take some more time to make the OpenCL work on Android 4.3

Update of Nexus 4 with Android 4.3

As official OTA update for Android 4.3  from google is not still available on Nexus-4 (4.3 is released on 24-Jul-2013), I thought that let me try manual (risky approach & could brick phone) uploading using various following links:
Disclaimer: Please note that normally one should wait for OTA updates from Google. This manual approach is risk prone and may brick your device. If you try this approach, please keep in mind that you may brick your device & I am not responsible if any thing happens to your device :)

BTW using this procedure, all old information/application in phone will be still intact (unless otherwise something extra things were done).

Prerequisites
  • You have non rooted Nexus 4 and it is in Android version 4.2.2 and you have PC/Laptop with Windows-XP-SP3 (it may work with other latest window versions, but I have not worked with them for this operation)
  • You have latest Android SDK tools.
    • Your adb should have following version:
      • adb version  : Android Debug Bridge version 1.0.31
      • Note: adb help will not show sideload command while issuing adb help. So please ensure that we have above adb version. The adb sideload command will work when the phone is in recovery mode
  • You have properly installed windows drivers on computer so that you can see devices from 'adb devices'
  • You have downloaded the Android 4.3.3 release zip file for Nexus-4 (stock with no ROM modiifcations)  from following link . If you other devices other than Nexus-4, please check for the update zip at that site.
    • After download rename the file to update.zip
    • Length of file:  177,524,837 , MD5: a62d34fef0fda5a512ffdc87b59ed9d4
  • While doing update, you may need to add extra USB device drivers for adb sideload
    • Add following entries in your Drive:\opt\Android\android-sdk\extras\google\usb_driver\android_winusb.inf
      • In section  [Google.NTx86]
        • %CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_D001
      • In Section [Google.NTamd64]
        • %CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_D001
    • You need to do this in case when your adb sideload says no devices found. Above USB VID(Vendor ID) and PID( Product ID) are for Nexus 4. 
    • If your device is not Nexus-4, the VID & PID might change and you get them via (please ensure that you are connected to PC via USB cable and the phone is in recovery mode -- go to that mode by: adb  reboot bootloader & procedure below):
      • My Computer -- Manage -- Device Manager -- Other Devices -- Nexus 4 -- Properties -- USB VID & PID from Combox over there
Update procedure
  • Goto boot recovery mode:
    • Without SDK tools:
      • Stop Android phone
      • Press Volume-UP and Volume-Down and Power buttons simultaneously
    • With ADB
      • adb  reboot bootloader
  • Use Volume buttons to select 'Recovery Mode'
    • Use power button to select the operation
  • Phone should show Android Icon with Exclamation mark. Press Volume-UP and Power buttons 
  • Use Volume buttons to select 'Update from ADB'
    • Use power button to select the operation
  • Then it will show load using adb sideload
    • Ensure that you have configured Nexus 4 Recovery mode USB drivers as mentioned above for your Nexus 4 device
  • Then from PC issue following command
    • adb sideload c:\update.zip
    • It will take few minutes for doing updates (if everything is went fine). 
Hope this helps who wants to get 4.3.3 updates and can't wait till google OTA update comes officially and want to take risk :)

Tuesday, June 18, 2013

Got working Arduino Pro Mini for Home Automation work - 1

For my home automation projects, I have been doing lots of R&D on various factors like:

  • Low cost MCU and MCU related board (commercially available)
  • Low power consumption in deep sleep (may not be the best , but reasonable low current consumption, so that MCU can withstand power outages)
    • Lots of cheap boards are there. For the time being I have chosen following Arduino boards
  • Cheap availability of wireless connectivity solutions
    • Bluetooth 4.0
      • In coming future, I would be using BLE-Soc chips likeNordic nrf51822 and TI's cc2540 & cc2541 -- as we have cheap assembled boards at various internet shops (like alibaba, dealsextreme, ebay, etc) .These boards typically come for 6 to 12$ 
    • Zigbee
      • I tried initially, but their board's cost is high very high  even at above shops and difficult solder because of QFN-soldering, wireless antenna's design, etc.
    • Proprietary wireless protocol
      • I found Nordic radio transceiver NRF24L01+ at 2.4GHz spectrum at following site for around 1$ per board
  • Free compiler, open source libraries & knowledge base in net.  If not free some trial based compiler for doing R&D (like cc254x chips).
Arduino fits the bill, but their overall solution costs more than 15 to 20$ before an year back (with my research at that point of time). So I dropped Arduino idea and looking for other solutions. Recently I casually browsed Alibaba site and found that I can get a reasonably powered Ardunio for less than 5$ and wireless connectivity for another 1$. So brought these items and finally started doing first helloworld on this boards. 

Here are pictures for  this board
This is for connecting this board with typically USB-to-Serial-Dongle(Prolific based) and correpsonding RS232 TTL convertor



This is showing minimal connections needed for powering and burning the program to Arduino. These yellow wires do connect to above USB-RS232-Dongle (RX & TX appropriately)


Board view from top view with an empty board on side


Connections from Arduino Board to RS232

Please ensure that you connect serial port cross-connection like following:

  • Board-Longer-Side RXI to RS232 TX
  • Board-Longer-Side TXD to RS232 RX

Arduino IDE Options

  • Select proper Serial port
  • Select  board as either of these boards. For my both voltages have worked out
    • 'Arduino Prop or Pro Mini (5V, 16MHz) w/ Atmega328'
    • 'Arduino Prop or Pro Mini (3.3 V, 8MHz) w/ Atmega328'
  • Select Programmer as 'Arduino as ISP'

Actions need to be taken while pressing Upload from IDE

  • As current setup does not use DTR/RTS on RS232 and only uses RX/TX (from USB to Rs232 converter), we need to press reset button just before the flashing (i.e., when console logs shows lines something like following in verbose-burning-mode-preferences) 
 Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 

Problems/Issues faced

Serial Port not detected in Linux

Run as root, then the Arduino IDE recognizes the Serial port . Select appropriate serial port from output of 'dmesg' command in linux.

Flashing Issues

  • After selecting the board as 'Arduino Prop or Pro Mini (5V, 16MHz) w/ Atmega328' and correct serial port. After trying to flash image to board has given following error messages.

Binary sketch size: 2,654 bytes (of a 30,720 byte maximum)avrdude: stk500_recv(): programmer is not responding

  • Now enable the verbose upload option via File -- Preference --'Show verbose output during'  = 'burning' .
    • After this step , I got following messages
Binary sketch size: 2,654 bytes (of a 30,720 byte maximum)
**/arduino-1.0.5/hardware/tools/avrdude -C/opt/arduino-1.0.5/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/build5308589158935848821.tmp/ASCIITable.cpp.hex:i 

avrdude: Version 5.11, compiled on Sep  9 2011 at 16:00:41
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "**/arduino-1.0.5/hardware/tools/avrdude.conf"
         User configuration file is "***/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

avrdude done.  Thank you.
    • Another error which slightly different at end
         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [00] 
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.
  • As this not typical USB based driver (which is available in little costlier Arduino boards) and I am using hard coded RS232 wiring, I tried to flash the image by pressing the reset button on the board. This made the flashing to occur successfully. Actually if we reset the board, MCU waits for flashing-data from RX/TX pins few seconds. If no  recognized flashing data comes to RX/TX pins, MCU will boot with previous programm that is there in flash. One has to find appropriate time to press reset button -- this timing can be assisted by putting verbose-burning-option.
  • So successful flash sequence is shown as:
Binary sketch size: 2,654 bytes (of a 30,720 byte maximum)
***/arduino-1.0.5/hardware/tools/avrdude -C***/arduino-1.0.5/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/build5308589158935848821.tmp/ASCIITable.cpp.hex:i 

avrdude: Version 5.11, compiled on Sep  9 2011 at 16:00:41
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "***/arduino-1.0.5/hardware/tools/avrdude.conf"
         User configuration file is "***/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
avrdude: Send: A [41] . [80]   [20] 
.....
         Hardware Version: 2
         Firmware Version: 1.16
avrdude: Send: A [41] . [84]   [20] 
..............
avrdude: Recv: . [10] 
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20] 
.......
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: AVR device initialized and ready to accept instructions

Reading | avrdude: Send: u [75]   [20] 
avrdude: Recv: . [14] . [1e] . [95] . [0f] . [10] 
################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
.................
.................
avrdude: Recv: . [10] 
###avrdude: Send: U [55] . [00] . [05]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: t [74] . [00] ^ [5e] F [46]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [ee] . [0f] . [ff] . [1f] . [05] . [90] . [f4] . [91] . [e0] - [2d] . [09] . [94] . [f8] . [94] . [ff] . [cf] A [41] S [53] C [43] I [49] I [49]   [20] T [54] a [61] b [62] l [6c] e [65]   [20] ~ [7e]   [20] C [43] h [68] a [61] r [72] a [61] c [63] t [74] e [65] r [72]   [20] M [4d] a [61] p [70] . [00] , [2c]   [20] d [64] e [65] c [63] : [3a]   [20] . [00] , [2c]   [20] h [68] e [65] x [78] : [3a]   [20] . [00] , [2c]   [20] o [6f] c [63] t [74] : [3a]   [20] . [00] , [2c]   [20] b [62] i [69] n [6e] : [3a]   [20] . [00] ! [21] . [00] . [00] . [00] . [00] . [00] . [95] . [03] . [c8] . [00] + [2b] . [03] \ [5c] . [03] < [3c] . [03] . [85] . [03] 
avrdude: Recv: . [10] 
## | 100% 0.59s

avrdude: verifying ...
avrdude: 2654 bytes of flash verified
avrdude: Send: Q [51]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 

avrdude done.  Thank you.




So with minimal booting is done with this board, next step is to connect Nordic Wireless chips and try wireless connectivity.


Thursday, March 14, 2013

Nexus 4 is running with OpenCL programs using aparapi

After the initial OpenCL programs
  clinfo
  helloworld
  helloworld2

on my Nexus 4 phone, I am trying to use some existing Java-OpenCL frameworks (like JOCL, JavCL, OpenCL4Java  and aparapi) for the Android based OpenCL developement.

So aftersome initial studies, fixed on AMD's aparapi and started porting the X86/X86_64 OpenCL-Java framework to any Android-based phone with OpenCL implementation (on GPU).

As part of helloworld2, I have mapped all OpenCL API methods using generic way irrespective of the underlying OpenCL SDK vendor.

Now I ventured to port aparapi from X86/X86_64 to ARM (on android ). To simplify the porting exercise, I took svn release version 68 as starting point for aparapi project.

Need to hack following of the code to accommodate Qualcomm OpenCL SDK on the Android on ARM:
  • Need to use reflection to get sun.misc.Unsafe.
    • Not all Unsafe methods are available on Android version
      • So no float, double, boolean and their corresponding array versions
    • Apache Unsafe internal field names are different than Sun's Unsafe
  • Removed some hard codings on JNI code, so that it works for QUALCOMM SDK also
  • QualComm SDK crashes the Dalvik-VM, if the OpenCL-Kernel is in inner class (and field names contains '$')
  • Current AMD OpenCL code generation depends on class-files availability on classpath. In Android it is dex-file, so need to package the original classpath also into apk file and access it via raw resource

So after all these major changes, the OpenCL program totally written in java worked on my Nexus 4. Once I get time, I will cleanup code and submit my code to my site

Here is the log from my Nexus 4 for this whole exercise (with generated OpenCL in logs):

I/System.out( 2379): getClassBytes Needed for :org/aopencl/aparapi/MyKernel.class , res-id:7f040000
I/System.out( 2379): getClassBytes:java.util.zip.ZipEntry, getting bytes for:org/aopencl/aparapi/MyKernel.class
D/dalvikvm( 2379): GC_CONCURRENT freed 394K, 5% free 9008K/9444K, paused 2ms+3ms, total 16ms
I/System.out( 2379): Got :org/aopencl/aparapi/MyKernel.class, size:-1
I/System.out( 2379): extractBytes:710
D/aopencl ( 2379): Trying shared libraries at following locations:
D/aopencl ( 2379): /system/lib/libOpenCL.so
D/aopencl ( 2379): /system/vendor/lib/egl/libGLES_mali.so
D/aopencl ( 2379): /system/lib/libllvm-a3xx.so
D/aopencl ( 2379): Using the Shared library:/system/lib/libOpenCL.so
E/aparapi ( 2379): platform 0 QUALCOMM
E/aparapi ( 2379): CL_DEVICE_MAX_COMPUTE_UNITS 4
E/aparapi ( 2379): CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 3
E/aparapi ( 2379): CL_DEVICE_MAX_WORK_GROUP_SIZE 256
E/aparapi ( 2379): CL_DEVICE_GLOBAL_MEM_SIZE 1910623136
E/aparapi ( 2379): CL_DEVICE_LOCAL_MEM_SIZE 1910623168
E/aparapi ( 2379): device[0x722d6d50]: Type:
E/aparapi ( 2379): GPU
E/aparapi ( 2379):
E/aparapi ( 2379):
E/aparapi ( 2379): JNIContext 7289b008
E/aparapi ( 2379): JNIContext valid:1
W/aparapi ( 2379): getExtensions JNIContext :7289b008
W/aparapi ( 2379): getExtensions2 JNIContext :cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_qcom_default_relaxed_math cl_qcom_perf_monitor
D/KernelRunner( 2379): Capabilities initialized to :[cl_qcom_perf_monitor, cl_khr_byte_addressable_store, cl_qcom_default_relaxed_math, cl_khr_local_int32_extended_atomics, cl_khr_local_int32_base_atomics, cl_khr_global_int32_base_atomics, cl_khr_gl_sharing, cl_khr_global_int32_extended_atomics, cl_khr_fp16]
D/KernelRunner( 2379): passed requiresDoublePragma
D/KernelRunner( 2379): passed requiresByteAddressableStorePragma
D/KernelRunner( 2379): passed requiresAtomic32Pragma
D/KernelRunner( 2379): Gen-OpenCL:typedef struct This_s{
D/KernelRunner( 2379): __global int *squares;
D/KernelRunner( 2379): __global int *values;
D/KernelRunner( 2379): int passid;
D/KernelRunner( 2379): }This;
D/KernelRunner( 2379): int get_pass_id(This *this){
D/KernelRunner( 2379): return this->passid;
D/KernelRunner( 2379): }
D/KernelRunner( 2379): __kernel void run(
D/KernelRunner( 2379): __global int *squares,
D/KernelRunner( 2379): __global int *values,
D/KernelRunner( 2379): int passid
D/KernelRunner( 2379): ){
D/KernelRunner( 2379): This thisStruct;
D/KernelRunner( 2379): This* this=&thisStruct;
D/KernelRunner( 2379): this->squares = squares;
D/KernelRunner( 2379): this->values = values;
D/KernelRunner( 2379): this->passid = passid;
D/KernelRunner( 2379): {
D/KernelRunner( 2379): int gid = get_global_id(0);
D/KernelRunner( 2379): this->squares[gid] = this->values[gid] + (this->values[gid] / 2);
D/KernelRunner( 2379): return;
D/KernelRunner( 2379): }
D/KernelRunner( 2379): }
E/aparapi ( 2379): clBuildProgram start clBuildProgram-ptr:722c533d, cl-prgm-ptr:735e4b38, dev-idc:1, devs:735d6ac8
E/aparapi ( 2379): clBuildProgram end:0
D/KernelRunner( 2379): passed buildProgramJNI
D/KernelRunner( 2379): arg 0, squares, type=1688, primitiveSize=4
D/KernelRunner( 2379): arg 1, values, type=1288, primitiveSize=4
E/aparapi ( 2379): in setArgs arg 0 squares type 00001688
E/aparapi ( 2379): in setArgs arg 1 values type 00001288
D/KernelRunner( 2379): saw newArrayRef for squares = [I@4248aa40, newArrayLen = 32
D/KernelRunner( 2379): saw newArrayRef for values = [I@4248a9a8, newArrayLen = 32
E/aparapi ( 2379): for globalSize=32, stepping localSize from 32, returning localSize=32
D/KernelRunner( 2379): Need to resync arrays on org.aopencl.aparapi.MyKernel
E/aparapi ( 2379): got type for squares: 00001688
E/aparapi ( 2379): testing for Resync javaArray squares: old=0x0, new=0x2e900005
E/aparapi ( 2379): Resync javaArray for squares: 0x2e900005 0x0
E/aparapi ( 2379): NewWeakGlobalRef for squares, set to 0x1d600003
E/aparapi ( 2379): updateKernel, args[0].sizeInBytes=128
E/aparapi ( 2379): got type for values: 00001288
E/aparapi ( 2379): testing for Resync javaArray values: old=0x0, new=0x1e300009
E/aparapi ( 2379): Resync javaArray for values: 0x1e300009 0x0
E/aparapi ( 2379): NewWeakGlobalRef for values, set to 0x1d600007
E/aparapi ( 2379): updateKernel, args[1].sizeInBytes=128
E/aparapi ( 2379): back from updateKernel
E/aparapi ( 2379): got type for arg 0, squares, type=00001688
E/aparapi ( 2379): runKernel: arrayOrBuf ref 0x1d600003, oldAddr=0x0, newAddr=0x4248aa50, ref.mem=0x0, isArray=1
E/aparapi ( 2379): at memory addr 0x4248aa50, contents:
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379):
D/aparapi ( 2379): squares 0 clCreateBuffer(context, CL_MEM_USE_HOST_PTR|CL_MEM_READ_WRITE, size=00000080 bytes, address=4248aa50, &status)
E/aparapi ( 2379): writing buffer 0 squares
E/aparapi ( 2379): got type for arg 1, values, type=00001288
E/aparapi ( 2379): runKernel: arrayOrBuf ref 0x1d600007, oldAddr=0x0, newAddr=0x4248a9b8, ref.mem=0x0, isArray=1
E/aparapi ( 2379): at memory addr 0x4248a9b8, contents:
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 01
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379): 00
E/aparapi ( 2379):
D/aparapi ( 2379): values 1 clCreateBuffer(context, CL_MEM_USE_HOST_PTR|CL_MEM_READ_ONLY, size=00000080 bytes, address=4248a9b8, &status)
E/aparapi ( 2379): writing buffer 1 values
E/aparapi ( 2379): reading buffer 0 squares
D/KernelRunner( 2379): executeOpenCL completed. _globalSize=32
I/System.out( 2379): Execution mode=GPU

Friday, March 8, 2013

OpenCL Helloworld program on Nexus 4 device

After getting the CLInfo for Nexus Devices, I tried to map all OpenCL symbols for writing full fledged OpenCL applications on Nexu 4 devices.

As part of this exercise, created mappings to all OpenCL exported functions and wrote one helloword example. With this mapping it is fully possible to write any OpenCL 1.1 specification based programs on C/C++ on Nexus-4 phones.

Code is hosted at aopencl project .

For a change this time used program to create command line executable at Nexus 4 phone. So to execute, one needs Android-NDK needs to be installed along with Android-SDK. More instructions are in README.

BTW, output from the Devices comes likes this:


shell@android:/data/local/tmp $ ./helloworld                                   
Loaded library name:/system/lib/libOpenCL.so
input string: GdkknVnqkc
output string: HelloWorld
shell@android:/data/local/tmp $


As we can see from output, .so file mapped is: /system/lib/libOpenCL.so


Tuesday, March 5, 2013

CLInfo for Nexus 4

Finally I submitted the changed code at  google-code.

All Nexus-4 (possibly Nexus 10) users can try the application in download section at the same place

In future, I will add more programs for Nexus 4 at same location.

Happy coding :)

Monday, March 4, 2013

CLInfo on Nexus 4 phone

Recently bought Nexus 4 phone for the 4 cores and OpenCL support.

So wanted to do something on this phone & found Rahul Garg is doing some R&D on the Nexus devices.

So take the code from there and modified it include more information for getting extra details from Nexus phone.

Here are screen snapshots for CLInfo for Nexus 4:




Here is the extra information that I got from 'adb logcat'.

I/ActivityManager( 510): Start proc org.codedivine.testcln10 for activity org.codedivine.testcln10/.MainActivity: pid=15181 uid=10101 gids={50101, 1028}
D/dalvikvm(15181): Trying to load lib /data/app-lib/org.codedivine.testcln10-1/libhelloCL.so 0x4215d220
D/dalvikvm(15181): Added shared lib /data/app-lib/org.codedivine.testcln10-1/libhelloCL.so 0x4215d220
D/dalvikvm(15181): No JNI_OnLoad found in /data/app-lib/org.codedivine.testcln10-1/libhelloCL.so 0x4215d220, skipping init
D/overlay ( 159): Set pipe=VG1 dpy=0;
D/overlay ( 159): Unset pipe=VG0 dpy=0; Unset pipe=VG1 dpy=0; Unset pipe=RGB1 dpy=0;
D/libEGL (15181): loaded /system/lib/egl/libEGL_adreno200.so
I/CLInfo (15181): CLInfo:QUALCOMM Snapdragon(TM)
I/CLInfo (15181):
I/CLInfo (15181): 0:QUALCOMM Adreno(TM)
I/CLInfo (15181): Max Compute Units: 4
I/CLInfo (15181): Max work group size: 256
I/CLInfo (15181): Max Work Item Dimensions: 3
I/CLInfo (15181): Max work item dimensions: 3
I/CLInfo (15181): Max work items: (256,256,256)
I/CLInfo (15181): Preferred vector width char: 1
I/CLInfo (15181): Preferred vector width short: 1
I/CLInfo (15181): Preferred vector width int: 1
I/CLInfo (15181): Preferred vector width long: 1
I/CLInfo (15181): Preferred vector width float: 1
I/CLInfo (15181): Preferred vector width double: 0
I/CLInfo (15181): Max clock frequency: 325MHz
I/CLInfo (15181): Address bits: 32bits
I/CLInfo (15181): Max memory allocation: 981506048 bytes
I/CLInfo (15181): Image support: True
I/CLInfo (15181): Max size of kernel argument: 256
I/CLInfo (15181): Alignment of base addres: 512 bits
I/CLInfo (15181): Minimum alignment for any datatype: 64 bytes
I/CLInfo (15181): Denorms: False
I/CLInfo (15181): Quiet NaNs: False
I/CLInfo (15181): Round to nearest even: False
I/CLInfo (15181): Round to zero: False
I/CLInfo (15181): Round to +ve and infinity: False
I/CLInfo (15181): IEEE754-2008 fused multiply-add: False
I/CLInfo (15181): Cache type err:0
I/CLInfo (15181): Cache line size: 16 bytes
I/CLInfo (15181): Cache size: 32768 bytes
I/CLInfo (15181): Global memory size: 1963012096 bytes
I/CLInfo (15181): Constant buffer size: 4096 bytes
I/CLInfo (15181): Max number of constant args: 8
I/CLInfo (15181): Local memory type err:0
I/CLInfo (15181): Local memory size: 8192 bytes
I/CLInfo (15181): Profiling timer resolution: 1000
I/CLInfo (15181): Device endianess: True
I/CLInfo (15181): Available: True
I/CLInfo (15181): Compiler available: False
I/CLInfo (15181): Execution capabilities:
I/CLInfo (15181): Execute OpenCL kernels: True
I/CLInfo (15181): Execute native kernels: True
I/CLInfo (15181): Queue properties:
I/CLInfo (15181): Out-of-Order: False
I/CLInfo (15181): Profiling: False
I/CLInfo (15181): Name: QUALCOMM Adreno(TM)
I/CLInfo (15181): Vendor: QUALCOMM
I/CLInfo (15181): Error:CL_DRIVER_VERSION:-30
I/CLInfo (15181): Profile: EMBEDDED_PROFILE
I/CLInfo (15181): Version: OpenCL 1.1 Adreno(TM) 320
I/CLInfo (15181): Extensions: cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_qcom_default_relaxed_math cl_qcom_perf_monitor
I/CLInfo (15181):
I/CLInfo (15181): 1:QUALCOMM Krait(TM)
I/CLInfo (15181): Max Compute Units: 4
I/CLInfo (15181): Max work group size: 1
I/CLInfo (15181): Max Work Item Dimensions: 3
I/CLInfo (15181): Max work item dimensions: 3
I/CLInfo (15181): Max work items: (1,1,1)
I/CLInfo (15181): Preferred vector width char: 16
I/CLInfo (15181): Preferred vector width short: 16
I/CLInfo (15181): Preferred vector width int: 16
I/CLInfo (15181): Preferred vector width long: 1
I/CLInfo (15181): Preferred vector width float: 16
I/CLInfo (15181): Preferred vector width double: 0
I/CLInfo (15181): Max clock frequency: 1500MHz
I/CLInfo (15181): Address bits: 32bits
I/CLInfo (15181): Max memory allocation: 981506048 bytes
I/CLInfo (15181): Image support: True
I/CLInfo (15181): Max size of kernel argument: 256
I/CLInfo (15181): Alignment of base addres: 1024 bits
I/CLInfo (15181): Minimum alignment for any datatype: 128 bytes
I/CLInfo (15181): Denorms: False
I/CLInfo (15181): Quiet NaNs: False
I/CLInfo (15181): Round to nearest even: False
I/CLInfo (15181): Round to zero: False
I/CLInfo (15181): Round to +ve and infinity: False
I/CLInfo (15181): IEEE754-2008 fused multiply-add: False
I/CLInfo (15181): Cache type err:0
I/CLInfo (15181): Cache line size: 64 bytes
I/CLInfo (15181): Cache size: 1048576 bytes
I/CLInfo (15181): Global memory size: 981506048 bytes
I/CLInfo (15181): Constant buffer size: 65536 bytes
I/CLInfo (15181): Max number of constant args: 8
I/CLInfo (15181): Local memory type err:0
I/CLInfo (15181): Local memory size: 32768 bytes
I/CLInfo (15181): Profiling timer resolution: 0
I/CLInfo (15181): Device endianess: True
I/CLInfo (15181): Available: True
I/CLInfo (15181): Compiler available: True
I/CLInfo (15181): Execution capabilities:
I/CLInfo (15181): Execute OpenCL kernels: False
I/CLInfo (15181): Execute native kernels: False
I/CLInfo (15181): Queue properties:
I/CLInfo (15181): Out-of-Order: False
I/CLInfo (15181): Profiling: False
I/CLInfo (15181): Name: QUALCOMM Krait(TM)
I/CLInfo (15181): Vendor: QUALCOMM
I/CLInfo (15181): Error:CL_DRIVER_VERSION:-30
I/CLInfo (15181): Profile: EMBEDDED_PROFILE
I/CLInfo (15181): Version: OpenCL 1.1 Krait(TM)
I/CLInfo (15181): Extensions: cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cles_khr_int64 cl_khr_fp16




I will post the code for the above shortly.

Special Thanks: