XUtils

DCompute

[GPGPU with Native D for OpenCL and CUDA](https://dlang.org/blog/2017/07/17/dcompute-gpgpu-with-native-d-for-opencl-and-cuda/)


About

This project is a set of libraries designed to work with LDC to enable native execution of D on GPUs (and other more exotic targets of OpenCL such as FPGAs DSPs, hereafter just ‘GPUs’) on the OpenCL and CUDA runtimes. As DCompute depends on developments in LDC for the code generation, a relatively recent LDC is required, use 1.8.0 or newer.

There are four main parts:

  • std: A library containing standard functionality for targetting GPUs and abstractions over the intrinsics of OpenCL and CUDA.
  • driver: For handling all the compute API interactions and provide a friendly, easy-to-use, consistent interface. Of course you can always get down to a lower level of interaction if you need to. You can also use this to execute non-D kernels (e.g. OpenCL or CUDA).
  • kernels: A set of standard kernels and primitives to cover a large number of use cases and serve as documentation on how (and how not) to use this library.
  • tests: A framework for testing kernels. The suite is runnable with dub test (see dub.json for the configuration used).

Examples

Kernel:

@kernel void saxpy(GlobalPointer!(float) res,
                   float alpha,
                   GlobalPointer!(float) x,
                   GlobalPointer!(float) y, 
                   size_t N)
{
    auto i = GlobalIndex.x;
    if (i >= N) return;
    res[i] = alpha*x[i] + y[i];
}

Invoke with (CUDA):

q.enqueue!(saxpy)
    ([N,1,1],[1,1,1]) // Grid & block & optional shared memory
    (b_res,alpha,b_x,b_y, N); // kernel arguments

equivalent to the CUDA code

saxpy<<<1,N,0,q>>>(b_res,alpha,b_x,b_y, N);

For more examples and the full code see source/dcompute/tests.

Getting Started

Please see the documentation.

TODO

Generate OpenCL builtins from here

Our sponsors

&nbsp; &nbsp; &nbsp; &nbsp;


Articles

  • coming soon...