DCompute: GPGPU with Native D for OpenCL and CUDA
dlang.org
dlang.org
Autovectorization alone is difficult in C and C++ because the languages provide almost no useful information about aliasing. Precise aliasing info is just the tip of the iceberg regarding what you would need for GPU-based autovectorization.
a[] = c * b[];
The idea of them is they are parallelizable, and do not require an auto-vectoring loop optimizer. Auto-vectorizing is fraught with problems, like the user not being aware if the auto-vectorizing succeeded or not.Another aspect of D that enables parallization is the use of ranges + algorithms. Although currently unexploited, it has the potential to be able to express parallel algorithms, and then take advantage of that.
It also does not help with problems that are not as embarrassingly parallel, but could still benefit from vectorisation, such as summations (or reductions in general), or things that contain their own inner control flow (think a Mandelbrot set, where you have a larger outer parallel loop with an inner serial while-loop).
It'll be interesting to see what sort of context-switch performance comes out of the Zen APU devices when they are released (next year I believe).
I'd be somewhat surprised if Intel and NVidia aren't working on similar things.
Shared memory by itself will not have a significant performance impact here (although it simplifies the data movement substantially). For a scalar-vector multiplication, you are strongly memory bound, and so you still have to wait for all the memory to be retrieved over the bus. You are correct if both CPU and GPU are behind the same bus (such as if the GPU is on the same die), but modern GPUs support shared virtual memory even for non-integrated GPUs.
Is that similar to the C++ std::algorithm execution policy features introduced in C++17?
Foo[] foo = ...;
foreach(f; foo) { f.bar.baz.quux; }
and the computation is parallelisable then you can write
import std.parallelism; foreach(f; parallel(foo)) { f.bar.baz.quux; }
and it will parallelised across threads.
I guess std.parallelism's parallel might be more analogous to an "instance" of an executor.
std::sort(par,a.begin(),a.end());
to call a parallel implementation of sort on `a`.
probably won't get on the front page of HN :|
[0] https://github.com/ddemidov/vexcl
[1] http://numba.pydata.org/numba-doc/latest/cuda/kernels.html [2] http://numba.pydata.org/numba-doc/latest/cuda/reduction.html...
It's not at all like you write python and it translates it to CUDA or anything.
However numba's 'vectorize' and 'guvectorize' decorators can also run code on the GPU. The current documentation doesn't show good GPU examples, but here's examples from the documentation for the deprecated numbapro (the CUDA things from numbapro were later added into numba): https://docs.continuum.io/numbapro/CUDAufunc
@vectorize(['float32(float32, float32, float32)',
'float64(float64, float64, float64)'],
target='gpu')
def cu_discriminant(a, b, c):
return math.sqrt(b ** 2 - 4 * a * c)
The 'float32/64' type signatures are not strictly necessary, unless you want to define the output type (so if the inputs are 32-bit floats and you don't want it to return 64-bit floats); if given no signature numba will automatically compile a new kernel each time the function is called with a new type signature. So that function would become (but in current numba 'gpu' should be replaced with 'cuda'): @vectorize(target='gpu')
def cu_discriminant(a, b, c):
return math.sqrt(b ** 2 - 4 * a * c)
Vectorize is a little limited in that it only operates on scalars and broadcasts those scalar operations over arrays.guvectorize is more powerful and can operate on arrays directly so something like convolution or a moving average are possible, but is slightly more complicated to use than vectorize.
Update: fixed code formatting
https://github.com/Syncleus/aparapi/
"Aparapi allows developers to write native Java code capable of being executed directly on a graphics card GPU by converting Java byte code to an OpenCL kernel dynamically at runtime. Because it is backed by OpenCL Aparapi is compatible with all OpenCL compatible Graphics Cards."