Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| pycuda [2015/04/27 11:56] – [Installed version] admin | pycuda [2015/04/27 11:59] (Version actuelle) – [Links] admin | ||
|---|---|---|---|
| Ligne 7: | Ligne 7: | ||
| * Version 2014.1 on lumière cluster. | * Version 2014.1 on lumière cluster. | ||
| - | * use <code bash>$ module load python</ | + | |
| + | use <code bash>$ module load python</ | ||
| | | ||
| ===== How to ? ===== | ===== How to ? ===== | ||
| + | <code python vectadd.py> | ||
| - | + | import pycuda.autoinit | |
| + | import pycuda.driver as drv | ||
| + | import numpy | ||
| + | |||
| + | from pycuda.compiler import SourceModule | ||
| + | mod = SourceModule(""" | ||
| + | __global__ void multiply_them(float *dest, float *a, float *b) | ||
| + | { | ||
| + | const int i = threadIdx.x; | ||
| + | dest[i] = a[i] * b[i]; | ||
| + | } | ||
| + | """ | ||
| + | |||
| + | multiply_them = mod.get_function(" | ||
| + | |||
| + | a = numpy.random.randn(400).astype(numpy.float32) | ||
| + | b = numpy.random.randn(400).astype(numpy.float32) | ||
| + | |||
| + | dest = numpy.zeros_like(a) | ||
| + | multiply_them( | ||
| + | drv.Out(dest), | ||
| + | block=(400, | ||
| + | |||
| + | print dest-a*b | ||
| + | </ | ||
| + | ===== Links ===== | ||
| + | |||
| + | * http:// | ||