https://github.com/libmir/dcompute
DCompute: Native execution of D on GPUs and other Accelerators
https://github.com/libmir/dcompute
cuda d fpga gpgpu gpu ldc opencl
Last synced: 4 months ago
JSON representation
DCompute: Native execution of D on GPUs and other Accelerators
- Host: GitHub
- URL: https://github.com/libmir/dcompute
- Owner: libmir
- License: bsl-1.0
- Created: 2016-07-17T05:54:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-23T18:34:18.000Z (over 2 years ago)
- Last Synced: 2024-12-10T02:20:34.877Z (4 months ago)
- Topics: cuda, d, fpga, gpgpu, gpu, ldc, opencl
- Language: D
- Homepage:
- Size: 158 KB
- Stars: 138
- Watchers: 14
- Forks: 27
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-d - 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/) (Parallel computing / XML)
README
# dcompute
[](http://code.dlang.org/packages/dcompute)
[](http://code.dlang.org/packages/dcompute)
[](http://code.dlang.org/packages/dcompute)
[](https://gitter.im/libmir/public)## About
This project is a set of libraries designed to work with [LDC][1] 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](https://github.com/ldc-developers/ldc/releases/tag/v1.8.0) or newer.There are four main parts:
* [std](https://github.com/libmir/dcompute/tree/master/source/dcompute/std): A library containing standard functionality for targetting GPUs and abstractions over the intrinsics of OpenCL and CUDA.
* [driver](https://github.com/libmir/dcompute/tree/master/source/dcompute/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](https://github.com/libmir/dcompute/tree/master/source/dcompute/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](https://github.com/libmir/dcompute/tree/master/source/dcompute/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`.
## Build InstructionsTo build DCompute you will need:
* [ldc][1] as the D dcompiler.
* a SPIRV capable LLVM (available [here](https://github.com/thewilsonator/llvm/tree/compute) to build ldc to to support SPIRV (required for OpenCL)).
* or LDC built with any LLVM 3.9.1 or greater that has the NVPTX backend enabled, to support CUDA.
* [dub](https://github.com/dlang/dub)
and then just run `$dub build` or add `"dcompute": "~>0.1.0"` to your `dub.json` or `dependency "dcompute" version="~>0.1.0"` to your `dub.sdl`.If you get an error like `Error: unrecognized switch '-mdcompute-targets=cuda-210`, make sure you are using LDC and not DMD: passing `--compiler=/path/to/ldc2` to dub will force it to use `/path/to/ldc2` as the D compiler.
A dmd compatible d compiler,[dmd](https://github.com/dlang/dmd), ldmd or gdmd (available as part of [ldc][1] and [gdc](https://github.com/D-Programming-GDC/GDC) respectively), and cmake for building ldc is also required if you need to build ldc yourself.
## Getting StartedPlease see the [documentation](https://github.com/libmir/dcompute/blob/master/docs/README.md).
## TODO
Generate OpenCL builtins from [here](https://github.com/KhronosGroup/SPIR-Tools/wiki/SPIR-2.0-built-in-functions)
[1]: https://github.com/ldc-developers/ldc
### Our sponsors
[
](http://symmetryinvestments.com/)
[](https://github.com/kaleidicassociates)