halide/Halide — pull request #267 by dsharlet-intel (2014-03-17 23:25:06+00:00)
Title: Enable 'vectorize' for OpenCL C target w/ vload+vstore optimization

This pull request is beginning to enable the vectorize schedule for the OpenCL C target. @jrprice, I think this is what you wanted in your message on the mailing list on 2-25 (re: Interleaved Function Evaluation). Sorry I've been sitting on this for a while! I'd be curious to hear if it meets your needs. I've tested it on some simple functions with good results.

While it doesn't actually do anything related to SIMD on any GPU I'm familiar with, the primary motivation is to help GPUs efficiently utilize their memory bandwidth when accessing small types (< 4 bytes for most GPUs). This disproportionately affects GPUs because their caches generally aren't able as good. A secondary benefit is this also reduces index/address calculation overhead. Instead of computing indices for every element, they're only computed for every N elements, where N is the vector width.

As pointed out on the mailing list, while GPU compilers should theoretically be able to do this with 'unroll', they generally don't. This has also been my experience.

Currently, this is only useful in fairly limited circumstances. It will only use vector loads/store optimizations when the indices to a load/store are a simple ramp. Any border clamping/handling will disable the vector loads/stores and it generates some gather/scatter code instead. I think the only way around this is to generate different kernels for the edges...

Also included in this pull request:

- Fixed problem where CodeGen_C was generating stack allocations of zero elements for scalar variables. This fixes arg_max test for OpenCL C target. It *might* be correct to fix this in the constant_allocation_size function, but that looks like a very high impact change so I only fixed it for the C target for now. The other targets don't seem to have a problem with this.
- Fixed (unnecessary?) header not found issue on windows in the three debug_* tests.
- Fixed error I was getting regarding missing PNaCl math initmod.