Multi-core Android

I performed a simple parallel algorithm by drawing a mandelbrot set for testing parallel computing on Nexus 7 (Tegra 3, 4 + 1 kernels). After starting several times, I get 1.5 seconds for serial and 1.0 for parallel, but parallel and serial come very close to each other after 1.3 seconds.

The square is 700x700 pixels, and the mandelbrot code I use is

http://rosettacode.org/wiki/Mandelbrot_set#Java

Parallel implementation performs two half-mandelbrot similar to this

public void mandelbrotParallel() { Thread t1 = new Thread(new Runnable() { public void run() { mandelbrotOne(); } }); Thread t2 = new Thread(new Runnable() { public void run() { mandelbrotTwo(); } }); t1.start(); t2.start(); try { t1.join(); t2.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } mHandler.post(new Runnable() { public void run() { v.setBmp(bmp); v.invalidate(); } }); } 

I skipped a simple vector add-on before and found similar anecdotal results (without scientific rigor). So I'm wondering if there is anything special to get Android to run multiple cores to complete the task.

Based on quick conversations with Google, it is possible that the kernels are inactive and wait for the calculation to be really long (a few seconds) before the kernels are turned on ... Is this true? If so, are there Java API calls (no JNI) that you can execute to pre-wake the kernels?

+4
source share
2 answers

It sounds like a candidate for RenderScript . In a nutshell, it allows you to perform expensive calculations that use all available acceleration resources (multiple cores, GPU computing, dsp, etc.). From the docs:

Renderscript provides your applications with the ability to run operations by automatically parallelizing all available processor cores. It also supports various types of processors, such as CPU, GPU or DSP. Renderscript is useful for applications that perform image processing, mathematical modeling, or any operations that require a lot of mathematical calculation.

You will need to rewrite your Mandelbrot code in C, but you will not have to break it into pieces, since you will take care of parallelization.

Using RenderScript from Android code is simple as described here .

+2
source

A regular Android system is trying to be conservative. Therefore, if you create a new thread and start some heavy calculations, the Linux kernel first runs on one core and increases its base speed. As soon as the kernel is “busy” over a certain threshold for a while, only then does the kernel launch another kernel.

The same is true in a different direction: as soon as the system calms down, it will slowly turn off the cores and reduce the frequency.

From a developer's point of view, you cannot influence this on “normal” Android. Android does not have an API to wake up a certain number of cores or set a specific core frequency.


If you can switch to an embedded Android, you will have more options, as a regular Linux kernel has options for influencing the main frequencies and the number of active kernels. This is done through the "governors." There are several options in a regular Linux kernel. On this issue, you are interested in tuning a performance controller that will keep you awake at the highest frequency.

The Linux kernel interface is located in the / sys file system. I am going to show the adb shell commands here and leave it to you to turn it into Java, read and write commands.

 cd /sys/devices/system/cpu 

In this directory you will find virtual files indicating how many cores are present in the system:

 cat possible 

should give the answer 0-3 in your Tegra 3 case. The kernel does not know that if only one core works, it secretly goes to the spare low-power core. There are also directories cpu0 cpu1 cpu2 cpu3. Depending on the kernel version, they can only appear if the kernel is activated. Each of the cpu directories contains a cpufreq directory, where you can interact with the cpufreq subsystem . It should contain a scaling_available_governors file that shows which cpu controllers are available. You can only do this on the root system:

 echo "performance" >cpu0/cpufreq/scaling_governor 

Set a regulator that will maintain the core at the highest frequency. On an undisturbed system, you will receive a "resolved" error message.


To show the impact of this behavior, Vector Fabrics created a test application that runs the inpainting algorithm on OpenCV in parallel. The application measures both serial and parallel performance up to 4 cores. Even with the parallel operation of the version twice, the measurements change due to the launch of the cores. See for yourself (download the form in the application store): http://www.vectorfabrics.com/products/case-study/opencv_inpaint

+2
source

All Articles