ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

L2NormalizeLayer much slower on GPU than on CPU

Open Rares14324 opened this issue 7 years ago • 12 comments

Output of 'strings libarm_compute.so | grep arm_compute_version': arm_compute_version=v19.02 Build options: {'embed_kernels': '1', 'onpencl': '1', 'arch': 'arm64-v8a', 'neon': '1', 'benchmark_tests': '1', 'build': 'cross_compile', 'debug': '0', 'os': 'android', 'Werror': '0'} Git hash=514be65ad8d3340f53fd9591035352ed285811ba Platform: aarch64 Operating System: Android

Problem description: While debugging the slowness of my network when running using OpenCL I found that the CLL2NormalizeLayer is the one making the network overall slower than it's NEON counterpart. I've attached some results of the arm_compute_benchmark application to showcase this on S7 and on S8 results-L2-s7.log results-L2-s8.log

The difference is quite concerning (up to 10 times slower on OpenCL). Is this expected or a known issue ? Is there a patch somewhere, maybe, that resolves this ? Thank-you, Rares

Rares14324 avatar Mar 07 '19 07:03 Rares14324

Hi @Rares14324, From your logs I noticed that you are using a tuner file: --tuner-file=/data/local/tmp/tuner-file-winograd.csv

From the name it seems the tuning file refers to something else. Could you try without it?

Thanks, Manuel

ManubARM avatar Mar 07 '19 10:03 ManubARM

Hi @ManubARM , thank-you for looking into this. That was because I used the history to get the full command. I made sure to run it twice (once for adjustment and a second time for tuned). I've attached a log without it on the S7, the S8 is in use right now. The big difference still persists. results-L2-s7.log

Rares14324 avatar Mar 07 '19 11:03 Rares14324

Hi @Rares14324

How do you run your benchmarks? Do you set a constant GPU frequency? Is the governor set to performance?

mpekatsoula avatar Mar 11 '19 15:03 mpekatsoula

Hi @mpekatsoula I don't know how to set the a constant GPU frequency on an un-rooted S7 device. I believe the CPU governor is set to interactive(from Aida64), don't know how to change that one either on an un-rooted S7. Is there such a way ?

Rares14324 avatar Mar 11 '19 15:03 Rares14324

Hi @Rares14324

I've just run the benchmark tests for L2NormalizeLayer and the measurements look good to me. Try enabling the following instruments: --instruments=OPENCL_TIMER_MS,SCHEDULER_TIMER_MS

morgolock avatar Mar 18 '19 13:03 morgolock

Hi @morgolock I've done as you requested. Though I currently do not understand what they mean, here they are: results-L2-s7-instruments.log

Rares14324 avatar Mar 19 '19 13:03 Rares14324

Hi @Rares14324

When you enable the instrument=SCHEDULER_TIMER_MS, the benchmark test will show you how much time each individual CL kernel is taking up to run. I suggested this as a way to explore more in detail the performance of the function.

I think that for some very small shapes like 11x11 the Neon implementation is simply faster than the OpenCL equivalent and that is because in the CL backend there are some extra costs involved in setting up the kernels and scheduling the work. You could expect the OpenCL implementation to be faster than the neon one for bigger shapes as 1921x1083, 641x485x2x3 and 799x595x1x4.

You could try running the benchmark test with the following options to check this: --iterations=5 --mode=NIGHTLY and compare the execution times.

Hope this helps. I'll close this, if you need additional help please reopen.

morgolock avatar Mar 19 '19 17:03 morgolock

Hi @morgolock I ran the nightliy benchmarks as per your recommendation and upon looking

You could expect the OpenCL implementation to be faster than the neon one for bigger shapes as 1921x1083, 641x485x2x3 and 799x595x1x4.

doesn't seem to hold according to these results. results-L2-s7-nightly.log I also made a simple addition for the "results-L2-s7-instruments.log" in my last post for the biggest data in there (31x27x17x2) with an average of 0.0055 for "l2_normalize_x GWS" and 0.02 for "reduction_operation_x GWS", the end result being 6.5 ms for OpenCL as oposed to 1.8 ms (manual addition) for NEON. Also you mention that the results from your testing showed expected results. Could you maybe detail the platform or just post these here ? I would like to know on which platform this works better for OpenCL. I have some other phones with Adreno but the end-result is the same. I haven't put the results here because it's not made from ARM.

Rares14324 avatar Mar 20 '19 07:03 Rares14324

Hi @Rares14324

I was using a hikey board. I can now reproduce some of your results, I'll take a look at this and see what I can find out.

morgolock avatar Mar 20 '19 10:03 morgolock

Hi @Rares14324

A fix has been merged to the main development branch, please take a look at the code review and patch: https://review.mlplatform.org/#/c/ml/ComputeLibrary/+/906/

I'll close the ticket, please reopen if needed.

morgolock avatar May 24 '19 10:05 morgolock

Hi @morgolock I've checked out the 19_05 branch from the development repository this morning and ran the benchmarks on with --mode=ALL on an S7 and S8. On bigger data it is faster than neon. On some cases where the input is size is small it seems NEON is still faster. Because I don't understand OpenCL at a good enough level i can't say if the overhead of moving the data to the gpu is causing this or not or if there are some tweaks that can be made when the input size is small. I'm attaching the logs for reference. results-L2-s7-ALL-AfterFix.log results-L2-s8-ALL-AfterFix.log

Rares14324 avatar May 28 '19 11:05 Rares14324

Hi @Rares14324 I took a quick look at the s7 output and it looks okay to me.

For very small workloads like Shape=11x11 the overhead of setting up the job for the CL backend is not neglectable and the size of the workload is too small to keep the GPU busy; makes sense that the Neon backend would be faster in these cases.

Please reopen if you still need support.

morgolock avatar May 29 '19 12:05 morgolock