ENCP / CNNdroid

Open Source Library for GPU-Accelerated Execution of Trained Deep Convolutional Neural Networks on Android
MIT License
539 stars 181 forks source link

High CPU usage #7

Open jay2002 opened 7 years ago

jay2002 commented 7 years ago

I noticed that when I test renderscript in my phone (Samsung S4), cpu usage is very high. It seems that the code is running on the CPU. Is it reasonable?

latifisalar commented 7 years ago

CPU is also utilized by the CNNdroid, it's used for acceleration of Pooling and LRN layers and for some preprocessing stuff, so it's reasonable to have high cpu usage in those time slots.

jay2002 commented 7 years ago

I only use conv layer, the cpu usage is still very high. Is it possible that the codes in renderscript also use CPU?

latifisalar commented 7 years ago

Yes it can, Renderscript can automatically decide to accelerate the code on the CPU if using GPU would not offer a noticeable performance gain or if the GPU itself is not supported (which should not be your case) By the way, I should note that if you have ReLU layers, they are applied to the conv output over CPU, so you'll still observe some activity in cpu.

jay2002 commented 7 years ago

I have kill all the Relu layer and only test the performance of the conv-rs codes. My code is very simple:

for(int i = 0; i < 99999; i++)
     conv.myScript44.forEach_root(outputAllocation.get(i));

The CPU usage is still very high (over 70%). That's weird. @latifisalar Have you test the cpu usage and gpu usage before?

droidarehere commented 7 years ago

@jay2002 do you have an exynos or snapdragon S4?

Also see this issue: https://github.com/ENCP/CNNdroid/issues/5

jay2002 commented 7 years ago

Hi @droidarehere I have add '#pragma rs_fp_relaxed' for the RS code. My test device is OPPO r7 with Snapdragon MSM8939, OPPO r9 with MT6755/Malit-860 MP2, and Samsung S4 with Exynos 5410.

In my test, after add '#pragma rs_fp_relaxed', the cpu usage of OPPO r7 dropped to 20%, but the speed of convolution also dropped. So I'm not sure whether it is run on GPU. But for OPPO r9 and Samsung S4, after add '#pragma rs_fp_relaxed', the cpu usage is still very high.

Any idea?

droidarehere commented 7 years ago

@jay2002 Sounds like you have discovered which device has a GPU-enabled implementation.

Some tips for timing:

jay2002 commented 7 years ago

@droidarehere Thanks for your advertise. Have you test the cpu and gpu uasge before? What's the usual cpu usage when you test?

droidarehere commented 7 years ago

@jay2002 I just looked, around the same as yours. I wouldn't worry about the exact number though it will vary depending on how many cores the device has, how many background processes are running, how busy the scheduler on your specific device wants to clock the cores, etc.

akbarxie commented 7 years ago

I have chang the code in my project ,just reomve some four dimension array and using one dimension will make the app running faster.You can have a try.