I don't know the full state of the art but I can provide a very limited set of things to look at which may be useful.
The accepted answer for this question is now out of date.
The question of compiling and runnning GPU code for CUDA or OpenCL on a machine that does not natively support it has come up on here several times (but sadly its often taken as off-topic). This answer is for those questions too.
Many of the answers refer to software solutions that have not been maintained. There seem to be only two answers which stand the test of time which treat this as a mu question.
- Use a real GPU - i.e. buy a cheap cuda card if you don't already have one.
- Rent someone elses GPU in the cloud
However emulators do exist.
Also GPU virtualization is well covered by the wikipedia page. There is strong support for getting virtual machines to use the hosts hardware.
Docker and virtualbox both for example support GPU passthough.
Reasons to emulate
- To learn and keep up to date with changes to CUDA and OpenCL
- To estimate the effect of the various APIs on performance.
- To test that your code works on a variety of different platforms.
- As a proxy for hardware you don't have access to (as per this question)
Kind of emulation
For testing you might accept a slow implementation as long as it is compliant and reliable.
For production running on different hardware you would more likely accept similar, but not 100% equivalent constructs but (e.g. different warp size, different high-level libraries for FFT, ...) and much more complicated performance-optimized implementations of primitives. You would probaly demand at least 80% of the Cuda speed for comparable hardware.
(Thanks to https://stackoverflow.com/users/13130048/sebastian for those two points)
For the second case you would likely need not just GPU virtualisation but additional optimisation passes.
Why are there less emulators and why don't they survive the test of time?
- GPUs are affordable. It is only high performance that costs.
- GPUs (not to mention TPUs and FPGAs) are developing rapidly.
- Some hardware tricks are kept secret from competitors so emulating actual hardware is difficult.
- The CUDA and openCL standards are changing too but less quickly.
There is arguably a need for more programmers that understand them. Compiling your code without running and testing it would simply be unprofessional. There would seem to be an obvious need for emulation where you don't have all the possible or interesting hardware combinations physical available.
That being the case its surprising that so many of these emulation projects have not stood the test of time or been endorsed/provided by GPU manufacturers.
There are some active emulation projects however.
Active GPU EMulation Projects
There are at least two active emulation projects maintained as of October 2022:
I cannot speak to how good these are and how commonly they are used compared to using real GPUs (either your own or rented).
Honorable mentions
Cuda to OpenCL source to source transpilers.
These appear to be maintained but are not themselves emulators.
Why is this not a solved problem?
There are a number of challenges to overcome. My take on these would be something like:
- provide a runtime emulating a particular version of the CUDA or openCL standard
- provide a compiler targeting this runtime (ideally gcc or clang)
- get the backing of a vendor (e.g. Nvidia or the kronos group)
- get the backing of a community (i.e. a decent userbase and set of contributors)
- build support into a popular emulation environment (e.g. virtualbox)
You could also argue the case that almost all people working in this area have access to real GPUs so this is not necessary at all.
The vendors of point 3 are doing well with points 1 and 2 and 4.
An emulator has to both build on that and take some mindshare of its own.
This is an uphill struggle. I hope and believe there will be success in the future.
Looking at virtualbox the last discussion I can find is from 2011.
Seemingly retired projects
These have been mentioned in answers to previous attempts to ask and answer this kind of question.
- gpuocelot - no longer maintained
- mcuda - looks unmaintained
- cuda-waste - on google code which was frozen long ago
- nvemulate - cude emulator Nvidia - retired a while back
Other seemingly retired projects of interest:
Earlier (out of date) questions: