Skip to content

Commit 1b9d6e9

Browse files
Add examples
1 parent 986d37b commit 1b9d6e9

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,40 @@
1010
This project is a set of libraries designed to work with [ldc][1] to
1111
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.
1212

13-
There are three main parts
13+
There are four main parts
1414
* A standard library '[std](https://github.com/libmir/dcompute/tree/master/source/dcompute/std)' containing standard functionality for targetting GPUs, an abstraction layer over the intrinsics.
1515
* A [driver](https://github.com/libmir/dcompute/tree/master/source/dcompute/driver) library to handle 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.
1616
* A set of standard [kernels](https://github.com/libmir/dcompute/tree/master/source/dcompute/kernels) and primitives to cover a large number of use cases and serve as documentation on how (and how not) to use this library.
17+
* A testing framework [tests](https://github.com/libmir/dcompute/tree/master/source/dcompute/tests) for testing kernels. The suite is runnable with `dub test`.
1718

19+
## Examples
20+
21+
Kernel:
22+
```
23+
@kernel void saxpy(GlobalPointer!(float) res,
24+
float alpha,
25+
GlobalPointer!(float) x,
26+
GlobalPointer!(float) y,
27+
size_t N)
28+
{
29+
auto i = GlobalIndex.x;
30+
if (i >= N) return;
31+
res[i] = alpha*x[i] + y[i];
32+
}
33+
```
34+
35+
Invoke with (CUDA):
36+
```
37+
q.enqueue!(saxpy)
38+
([N,1,1],[1,1,1]) // Block & grid & optional shared memory
39+
(b_res,alpha,b_x,b_y, N); // kernel arguments
40+
```
41+
equivalent to the CUDA code
42+
```
43+
saxpy<<<N,1,0,q>>>(b_res,alpha,b_x,b_y, N);
44+
```
45+
46+
For more examples and the full code see `source/dcompute/tests`.
1847
## Build Instructions
1948

2049
To build DCompute you will need:
@@ -34,8 +63,4 @@ Please see the [wiki](https://github.com/libmir/dcompute/wiki).
3463

3564
Generate OpenCL builtins from [here](https://github.com/KhronosGroup/SPIR-Tools/wiki/SPIR-2.0-built-in-functions)
3665

37-
Get D versions of the OpenCL and CUDA APIs so that work can begin on a unified D driver API.
38-
39-
Add code examples to the readme.
40-
4166
[1]: https://github.com/ldc-developers/ldc

0 commit comments

Comments
 (0)