Created
July 20, 2013 20:54
-
-
Save JerzySpendel/6046415 to your computer and use it in GitHub Desktop.
Takie tam dodawanie.
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
import numpy as np | |
import pyopencl | |
host_vec_1 = np.array([37.0,50.0,54.0], dtype=np.float32) | |
host_vec_2 = np.array([35.0, 51.0, 54.0], dtype=np.float32) | |
host_vec_out = np.array(host_vec_1.shape, dtype=np.float32) | |
opencl_source = """ | |
__kernel void vector_add(__global float* c,__global float* a,__global float* b){ | |
unsigned int n = get_global_id(0); | |
float de = 0.2; | |
de = sin(de); | |
c[n] = sin(de); | |
} | |
""" | |
ctx = pyopencl.create_some_context() | |
queue = pyopencl.CommandQueue(ctx) | |
prog = pyopencl.Program(ctx, opencl_source).build() | |
buf1in = pyopencl.Buffer(ctx, pyopencl.mem_flags.READ_ONLY | pyopencl.mem_flags.COPY_HOST_PTR, hostbuf=host_vec_1) | |
buf2in = pyopencl.Buffer(ctx, pyopencl.mem_flags.READ_ONLY | pyopencl.mem_flags.COPY_HOST_PTR, hostbuf=host_vec_2) | |
outArray = np.empty_like(host_vec_1) | |
bufOut = pyopencl.Buffer(ctx, pyopencl.mem_flags.WRITE_ONLY | pyopencl.mem_flags.COPY_HOST_PTR, hostbuf = outArray) | |
prog.vector_add(queue, outArray.shape, None, bufOut, buf1in, buf2in) | |
pyopencl.enqueue_copy(queue, outArray, bufOut) | |
print(outArray) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment