Page 1 of 2

OpenCL/C++ hybrid rendering

Posted: Sat Feb 10, 2018 2:45 pm
by Dade
Introduction

LuxCore supports GPU+CPU rendering since the first days thanks to OpenCL CPU device. However the performance of OpenCL CPU devices (from AMD and Intel) are very disappointing. They are a lot slower than C++ code and they can even slow down the GPU performance. So GPU+CPU rendering is often slower than GPU-only rendering.

OpenCL/C++ hybrid rendering

OpenCL/C++ hybrid rendering is the solution to this problem. OpenCL is used to run the rendering on GPUs while native C++ code is used for the CPU rendering. This solution has 3 major advantages:

1) there is no need to install an OpenCL CPU device driver. NVIDA doens't include one in their drivers and it is complex and cumbersome to have to install another driver from AMD/Intel.

2) there is no slowdown of GPU rendering so using GPU+CPU rendering is always faster. I have worked to have maximum GPU performance even with a 100% load on CPU.

3) C++ written code is a LOT faster than OpenCL running on CPU device. It is usually 4-6 times faster in my tests.

A test

This is a rendering with a OpenCL GPU (AMD R290X) and OpenCL CPU (i7 3630k, 6 cores + hyper-threading):
hotel-ocl.jpg
and this is with a OpenCL GPU (AMD R290X) and C++ code (i7 3630k, 6 cores + hyper-threading):
hotel-hybrid.jpg
The 12 threads runs at about 2,750K rays/sec with C++ while at a miserable 762K rays/sec with the OpenCL CPU device. The GPU runs slightly faster with the hybrid rendering too.
The result is that hybrid rendering runs at 3.03M samples/sec while OpenCL GPU+CPU at 2.52M samples/sec. Now the contribute of CPU can be significative (and more complex is the scene and more significative is going to be).

Metropolis sampler

A word of caution for Metropolis sampler: the OpenCL implementation is different from the C++ one so there may be differences in the output and mixing the results may not be a good idea.

LuxCore API

Hybrid rendering is now enabled by default with PATHOCL and TILEPATHOCL. It is disabled and not usable with RTPATHOCL for obvious reasons. The number of hybrid rendering threads lunched is the same of cores+hyper-threading and can be controlled by this property:

Code: Select all

opencl.native.threads.count = 12

Re: OpenCL/C++ hybrid rendering

Posted: Sat Feb 10, 2018 3:19 pm
by Sharlybg
Luxcore The way it's mean to be Rendered :twisted: . impressive

Re: OpenCL/C++ hybrid rendering

Posted: Tue Feb 13, 2018 4:19 am
by david57
Yes, I did notice that rendering with CPU + GPU did not boost speed much so I just left it with only GPU.
I already think, its a very fast renderer even without the help of the CPU.
LuxCore should bring thousands of Architects and Artist to using it.

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 10:42 am
by B.Y.O.B.
Is it a good idea to hide the OpenCL CPU devices in BlendLuxCore now? (Remove them from UI)

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 10:51 am
by Dade
B.Y.O.B. wrote: Thu Feb 15, 2018 10:42 am Is it a good idea to hide the OpenCL CPU devices in BlendLuxCore now? (Remove them from UI)
It should be never used but you can never know, we could have a checkbox "Hide CPU devices", enabled by default :idea:

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 11:30 am
by B.Y.O.B.
The "Use CPUs" toggle button is already disabled by default.
I could add an info label explaining that CPUs are already used even with "Use CPUs" disabled but I think this will be very confusing.
Is it really important to keep this option? I can also add it again if we later notice that some users need the OpenCL CPU device.

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 11:42 am
by Dade
B.Y.O.B. wrote: Thu Feb 15, 2018 11:30 am The "Use CPUs" toggle button is already disabled by default.
I could add an info label explaining that CPUs are already used even with "Use CPUs" disabled but I think this will be very confusing.
Is it really important to keep this option? I can also add it again if we later notice that some users need the OpenCL CPU device.
Ok, let's remove it (but is the management of opencl.native.threads.account available ?)

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 12:07 pm
by B.Y.O.B.
Dade wrote: Thu Feb 15, 2018 11:42 am but is the management of opencl.native.threads.account available ?
I'll rework the whole thing and make it available.

By the way can the user disable hybrid rendering?
E.g. by setting opencl.native.threads.count = 0?

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 12:10 pm
by Dade
B.Y.O.B. wrote: Thu Feb 15, 2018 12:07 pm
Dade wrote: Thu Feb 15, 2018 11:42 am but is the management of opencl.native.threads.account available ?
I'll rework the whole thing and make it available.

By the way can the user disable hybrid rendering?
E.g. by setting opencl.native.threads.count = 0?
Yes, the 0 value is intended exactly for that purpose.

Re: OpenCL/C++ hybrid rendering

Posted: Thu Feb 15, 2018 12:26 pm
by B.Y.O.B.
This is the new menu.
If "Use CPUs" is disabled, native thread count will be set to 0.
If all OpenCL devices are disabled, a warning label is shown.
Unbenannt2.PNG
Unbenannt2.PNG (7.91 KiB) Viewed 14183 times
I'll also add a warning in case of hybrid + Metropolis sampler.
edit: with warning: