Paper acknowledges positively D's approach to purity
Robert Jacques
sandford at jhu.edu
Mon Sep 15 19:31:59 PDT 2008
On Mon, 15 Sep 2008 20:33:58 -0400, bearophile <bearophileHUGS at lycos.com>
wrote:
> How have you used D with CUDA? I'd like to know a bit more technical
> details.
Let's see. There's a couple of parts.
1) Created stub omf files to load the DLL correctly (CUDA doesn't support
dynamic linking yet). The main issue here was there was a mangling change
between what D expected and what NVIDIA provided.
2) Converted the CUDA device header over to D (done with htod with some
manual clean up)
3) Made use of a template and mixin combo to simplify declaring all the
methods of the CUDA types: i.e. float3, etc. I should refactor this to a
template and aliases.
4) Made a high level api to simplify using CUDA. (Heavy use of templates
again to type check, etc. everything). Here's an example:
Device gpu = Device(); // Find
the first CUDA compatible device
writefln(gpu); // Print
out its slot and type
auto kernel = new Module("kernel.cubin"); // Load a
compiled CUDA module from a file
float[] data = ...; // Load
some data
auto image = new Texture!(float)(kernel,"image",640,480,data); // Place
it into a texture
auto ouput = new cu1D!(float)(640*480); //
Allocate an output array
auto func = new Kernel!(float*)(kernel,"func",image); // Get the
function you want
func[[40,30],[16,16]](output); // Launch
the function
gpu.wait; // Wait
for the GPU to finish
write_output(output.dup); // Get the
results
I still write all the kernels in C and compile with nvcc though. Recently,
PTX (aka CUDA assembly) support came to the driver, so writing D code that
generates CUDA directly is theoretically possible.
> And do you know about BSGP (that I think is a step toward the future of
> such things)?
> http://www.kunzhou.net/
I hadn't heard about BSGP, so thanks. The general concept of BSGP has been
around for a few years now, Microsoft's Accelerator
(research.microsoft.com/act/) comes to mind (And apparently Microsoft is
the licensor for BSGP too), though the implementation looks more modern
(at first glance).
More information about the Digitalmars-d-announce
mailing list