1

I have a routine that is designed to be called under any of three processing modes; SingleCpuThread, ParallelCpuThreads and ParallelGpuThreads.

Within the routine, the math is performed using Alea.DeviceFunction in order to be compliant with Alea when the routine is called under the ParallelGpuProcessing mode.

Question: When the same routine is called under the other two modes, and the math is being performed using DeviceFunction, is that using the Gpu and incurring the overhead and marshaling, etc.? And if so (which would be bad), what's the best way to let the same routine use dot net's .Math functions instead of .DeviceFunction, without having duplicate the whole routine for separate Cpu-happy and a Gpu-happy versions of the routine?

cayman
  • 11
  • 1

1 Answers1

1

As the term device functions says, the functions run on the GPU, assuming all the data there. Hence there is no marshaling overhead.

To simplify CPU / GPU code reuse most device functions are implemented to run also on the CPU. Some device functions however just don't make sense on the CPU, like for instance the ballot function. That means you can just use device functions and then you will know that Alea GPU will fastest on GPU. The compiler is also mapping some of the .NET math functions automatically to GPU device functions.

Daniel
  • 1,522
  • 1
  • 12
  • 25
  • Thanks for your reply. If I understand you correctly, then.... When the application is running under processing mode ParallelGpuThreads (my enum), then my data is on the Gpu and the DeviceFunctions are executing on the Gpu, and there is no problem. However, when the application is running under processing modes SingleCpuThread, ParallelCpuThreads (my enums), then my data is on the Cpu and the DeviceFunctions may or may not be executing on the Gpu, which may or may not be a problem, because that would require the data to be marshalled to Gpu unnecessarily (a performance hit). – cayman Aug 20 '17 at 15:01
  • Since the determination of whether DeviceFunctions are able to on Cpu is function-by-function, is there any documentation of this or is there any other way to know for certain? The DeviceFunctions that my routines are using are... - DeviceFunction.IsNaN - DeviceFunction.Log10 - DeviceFunction.Sqrt - DeviceFunction.Abs – cayman Aug 20 '17 at 15:01