how to run a function on PyCUDA
You need to run a function written in python in the GPU using PyCUDA.
When I work with arrays, I allocate memory for them on the video card and can continue to work with them.
How to do this only with a function, for example, what would be so
0
1 answers
If the function performs simple operations, you can use the abstraction pycuda. gpuarray. gpuArray:
import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
a_gpu = gpuarray.to_gpu(np.random.randn(4,4).astype(np.float32))
a_doubled = (2*a_gpu).get()
print(a_doubled)
print(a_gpu)
More complex functions will need to be implemented with inserts in the language C
, as in the example with the function doublify(...)
1
Author: MaxU, 2018-05-17 15:11:42