Search code examples
unit-testingcudaopenclgpuemulation

Is it possible to emulate a GPU for CUDA/OpenCL unit testing purposes?


I would like to develop a library with an algorithm that can run on the CPU or the GPU. The GPU can be Nvidia (then the algorithm will use CUDA) or not (then the algorithm will use OpenCL).

I would like to emulate a GPU in this project because maybe:

  • I will use different computer to develop the software and some of them don't have a GPU.

  • The software will be finally executed in servers that can have a GPU or not and the unit test must be executed and passed.

Is there a way to emulate a GPU for unit testing purposes?

In the following link:

GPU Emulator for CUDA programming without the hardware

They show a solution but only for CUDA, not for OpenCL and the software they propose "GPUOcelot" is no longer actively maintained.


Solution

  • It depends on what you mean on emulation. You cannot emulate the speed of GPUs.

    The GPU is architecturally very different from the CPU, with a lot of working threads (1000s, 10000s, ...), that's why we use it. The CPU can have only a few threads, even when you parallelize the code. They also have different instruction sets.

    You can however emulate the execution using special softwares, like NVEmulate for NVIDIA GPUs and OpenCL Emulator-Debugger for AMD.

    A related question: GPU Emulator for CUDA programming without the hardware, where the accepted answer recommends gpuocelot for CUDA emulation.