Monday, May 28, 2012

The first GPU programming in Paraiso

Now let's move on to the GPU. We need only a few modifications to turn the code generator that uses C++ into that that uses CUDA.
$ diff HelloWorld/Generator.hs HelloGPU/Generator.hs
40c40,42
<   { Native.directory = "./dist/"
---
>   { Native.directory = "./dist/" ,
>     Native.language  = Native.CUDA,
>     Native.cudaGridSize = (32,1)
The following Setup specifies that we want to generate CUDA code, and also specifies the CUDA grid dimensions. (The following code will be executed with dimensions <<<32,1>>>.)
mySetup :: Native.Setup Vec2 Int
mySetup =
  (Native.defaultSetup $ Vec :~ 10 :~ 20)
  { Native.directory = "./dist/" ,
    Native.language  = Native.CUDA,
    Native.cudaGridSize = (32,1)
  }
The generated code has been tested to produce the same result as the C++ version using nvcc 4.1 (with its built-in thrust) on TSUBAME 2.0 at Tokyo Institute of Technology.

No comments:

Post a Comment