Created
November 13, 2021 20:39
-
-
Save 4OH4/1e881372a3b6b5dd468f5ded99633357 to your computer and use it in GitHub Desktop.
Allocating memory on the GPU and copying data with PyCUDA (pt. 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create Python variables | |
a = np.random.randn(100).astype(np.float32) | |
b = np.random.randn(100).astype(np.float32) | |
result = np.random.randn(100).astype(np.float32) | |
# allocate memory on GPU | |
a_gpu = cuda.mem_alloc(a.nbytes) | |
b_gpu = cuda.mem_alloc(b.nbytes) | |
result_gpu = cuda.mem_alloc(b.nbytes) | |
# copy data to GPU | |
cuda.memcpy_htod(a_gpu, a) | |
cuda.memcpy_htod(b_gpu, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment