ispc/ispc — pull request #749 by egaburov (2014-02-21 15:00:34+00:00)
Title: Experimental support for PTX with examples

#### Overview:
* This pull request allows ISPC to emit PTX-ready LLVM IR. This IR can later be compiled into PTX either with libNVVM or LLVM PTX backend, and PTX can be executed by standard means. Workable examples with corresponding makefiles for CPU, KNC, and PTX, can be found in examples/portable/

* Currently, ISPC is unable to emit PTX directly, although LLVM PTX compilation backend is already in place. This is due to possible license issues with libdevice.compute_35.10.bc (a part of libNVVM), which contains IR for common math functions (sqrt/rsqrt/rcp/sin/cos/exp etc..).

* There is also ptxtools folder which contains source code with makefile for the two executables: ptxgen and ptxcc. ptxgen uses libNVVM to compile LLVM IR to PTX, and ptxcc compiles the resulting PTX into an object file linkable with nvcc. Both require CUDA Toolkit.

* The run_tests.py is adapted to run tests on nvptx target.

* Currently, this functionality is in experimental phase. It works on many .ispc files, but there could be some which won't compile, or do compile but crash during runtime. Usually, a "simple patch" of the .ispc file can fix the problem, and may even improve performance.

* This is the first attempt to merge the changes, and to seek feedback, comments, suggestions for improvements. It may take a while for changes to be merged.

* Documentation and tutorial is being written, and will be committed to this branch once ready.

#### Requirements:
* NVIDIA Kepler GPU with dynamic parallelism (sm_35 architecture)
* CUDA Toolkit 6.0rc or above
* llvm-dis from LLVM-3.2 (or ISPC must be compiled with LLVM 3.2 because NVVM is based on LLVM 3.2 IR)
* Patience, but examples in examples/portable demonstrate how to use PTX (as well how to run the same code on CPU and KNC).

#### Limitations & known issues:
1. Must use ISPC tasking functionality to run efficiently on GPU
2. Must use new/delete and/or ispc_malloc/ispc_free/ispc_memset/ispc_memcpy to allocate/free/set/copy memory that is visible to GPU
3. Export function must have void return type.
4. Task/export functions do not accept varying data-types
5. new/delete currently only works with uniform data-types
6. aossoa/soaaos is not yet supported
7. sizeof(varying data type) is not yet unsupported
8. Function pointers do not work yet (may or may not generate compilation fail)
9. memset/memcpy/memmove is not yet supported
10. "uniform" arrays in global scope are mapped to global memory
11. "varying" arrays in global scope are not yet supported
12. "uniform" arrays in local scope are mapped to shared memory
13. "varying" arrays in local scope are mapped to local memory
14. "const uniform/varying" arrays are mapped to local memory
15. "const static uniform" arrays are mapped to constant memory
16. "const static varying" arrays are mapped to global memory
17. "static" data types in local scope are not allowed; compilation will fail
18. Best performance is obtained with libNVVM (LLVM PTX backend can also be used but it requires libdevice.compute_35.10.bc that comes with libNVVM)
19. But some things may not compile yet with libNVVM (e.g. tests/switch-{8-12}.ispc)
20. Likely there are more... which, together with some of the above-mentioned issues, will be fixed in due time