Problem with standard headers in single source programming models


In single source programming models (like CUDA, OpenMP) there are both “host” and “device” code in the same source file/translation unit. This causes some issues with system headers and standard library headers when compilation is performed for device target. Reason is that even when compiling for the device, host code must be semantically analyzable.

For example, in case of compilation to ‘spir’ target with -std=gnu++11 flag we will get an error:

error: __float128 is not supported on this target

Also, in headers there could be other things like inline asm, intrinsics not lowerable in device.

Since the problem is not new, my question is about the possible solutions of this problem.

I tried to look into the approach currently implemented in clang for single source programming models.

As far as I understood: