7.2 CPU Backends

Sh can be used to generate programs for the CPU. At the time of writing this is supported by the gcc backend, which can execute stream programs by compiling them into C code which is passed on to the GCC compiler and linked into the program dynamically. The backend is particularily useful if you intend to run a stream program that uses features not supported by any GPU backends, e.g. data-dependent conditional control flow.

While the GCC backend is the only available CPU backend at the time of writing, we are considering implementing several other CPU backends, including an interpreter, a dynamic code generation backend for x86 CPUs and a libtcc (Tiny C Compiler library [?]) backend.

To use the GCC backend exclusively, simply run shSetBackend("gcc"). This will set the GCC backend as the only backend. / E  Alternatively, you can use a gcc:stream or cpu:stream target in your program declaration, which will cause the program to execute on the GCC backend (or, in the latter case, any CPU backend) regardless of what backend is set as the default.

The GCC backend does not consider any particular metadata at this time.


Note: This manual is available as a bound book from AK Peters, including better formatting, in-depth examples, and about 200 pages not available on-line.