Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pycuda.driver as cuda
- import pycuda.autoinit
- from pycuda.compiler import SourceModule
- import numpy
- a = numpy.random.randn(4,4)
- a = a.astype(numpy.float32)
- a_gpu = cuda.mem_alloc(a.nbytes)
- cuda.memcpy_htod(a_gpu,a)
- mod = SourceModule("""
- __global__ void doublify(float *a)
- {
- int idx = threadIdx.x + threadIdx.y * 4;
- a[idx] *= 2;
- }
- """)
- import os
- os.system("vcvarsamd64.bat")
- import pycuda.gpuarray as gpuarray
- import pycuda.driver as cuda
- import pycuda.autoinit
- import numpy
- a_gpu = gpuarray.to_gpu(numpy.random.randn(4, 4))
- print "a_gpu ="
- print a_gpu
- a_doubled = (2*a_gpu).get()
- print
- print "a_doubled ="
- print a_doubled
- COMPILER-BINDIR = C:Program Files (x86)Microsoft Visual Studio 10.0VCbinamd64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement