From bf7a96ff9005b3a5a21398da40442bf72822a8c0 Mon Sep 17 00:00:00 2001 From: Elena Date: Thu, 2 Jul 2020 10:10:38 -0400 Subject: [PATCH 1/5] fix order in enqueue_copy --- 021_array_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/021_array_sum.py b/021_array_sum.py index e9b35e1..c70f7b0 100644 --- a/021_array_sum.py +++ b/021_array_sum.py @@ -36,10 +36,10 @@ cl_arrays = [cl_a, cl_b, cl_c] for x in range(3): - cl.enqueue_copy(queue, cl_arrays[x], np_arrays[x]) + cl.enqueue_copy(queue, np_arrays[x], cl_arrays[x]) queue.finish() # Copy the data for array c back to the host for x in np_arrays: print(x) -# Print all three host arrays, to show sum() worked \ No newline at end of file +# Print all three host arrays, to show sum() worked From 1ca1e407ac568f83443b92c605f9151b3d69649c Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 3 Jul 2020 09:36:15 -0400 Subject: [PATCH 2/5] enqueue_read_buffer is deprecated, replaced with enqueue-copy --- 030_timing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/030_timing.py b/030_timing.py index 19c361d..f628854 100644 --- a/030_timing.py +++ b/030_timing.py @@ -39,10 +39,10 @@ def gpu_array_sum(a, b): elapsed = 1e-9*(event.profile.end - event.profile.start) # Calculate the time it took to execute the kernel print("GPU Kernel Time: {0} s".format(elapsed)) # Print the time it took to execute the kernel c_gpu = np.empty_like(a) # Create an empty array the same size as array a - cl.enqueue_read_buffer(queue, c_buffer, c_gpu).wait() # Read back the data from GPU memory into array c_gpu + cl.enqueue_copy(queue, c_buffer, c_gpu).wait() # Read back the data from GPU memory into array c_gpu gpu_end_time = time() # Get the GPU end time print("GPU Time: {0} s".format(gpu_end_time - gpu_start_time)) # Print the time the GPU program took, including both memory copies return c_gpu # Return the sum of the two arrays cpu_array_sum(a, b) # Call the function that sums two arrays on the CPU -gpu_array_sum(a, b) # Call the function that sums two arrays on the GPU \ No newline at end of file +gpu_array_sum(a, b) # Call the function that sums two arrays on the GPU From acda0df350517e79686f14e4d13d9d656f0e8735 Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 3 Jul 2020 09:37:00 -0400 Subject: [PATCH 3/5] make arrays large --- 040_elementwise.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/040_elementwise.py b/040_elementwise.py index 358051c..5f6124d 100644 --- a/040_elementwise.py +++ b/040_elementwise.py @@ -7,14 +7,14 @@ context = cl.create_some_context() # Initialize the Context queue = cl.CommandQueue(context) # Instantiate a Queue -a = cl_array.to_device(queue, numpy.random.randn(10).astype(numpy.float32)) # Create a random pyopencl array -b = cl_array.to_device(queue, numpy.random.randn(10).astype(numpy.float32)) # Create a random pyopencl array +a = cl_array.to_device(queue, numpy.random.randn(50000).astype(numpy.float32)) # Create a random pyopencl array +b = cl_array.to_device(queue, numpy.random.randn(50000).astype(numpy.float32)) # Create a random pyopencl array c = cl_array.empty_like(a) # Create an empty pyopencl destination array sum = cl.elementwise.ElementwiseKernel(context, "float *a, float *b, float *c", "c[i] = a[i] + b[i]", "sum") # Create an elementwise kernel object # - Arguments: a string formatted as a C argument list -# - Operation: a snippet of C that carries out the desired map operatino +# - Operation: a snippet of C that carries out the desired map operation # - Name: the fuction name as which the kernel is compiled sum(a, b, c) # Call the elementwise kernel @@ -22,4 +22,4 @@ print("a: {}".format(a)) print("b: {}".format(b)) print("c: {}".format(c)) -# Print all three arrays, to show sum() worked \ No newline at end of file +# Print all three arrays, to show sum() worked From 136182a95847af64b62613f4477f668f4e9e67e7 Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 3 Jul 2020 09:37:48 -0400 Subject: [PATCH 4/5] added info on last two programs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5345fb7..5be2ebb 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,5 @@ PyOpenCL is a tool that is worth learning. Python allows exceptional clarity-of - 010 Introspection - Find out about your computer's OpenCL situation - 020 Array Sum - Use OpenCL To Add Two Large Random Arrays - Hiding Details - 021 Array Sum - Use OpenCL To Add Two Large Random Arrays - Showing Details +- 030 Timing - Compare performance of a loop in pure Python versus OpenCL +- 040 Elementwise - Use PyOpenCL arrays and elementwise to add two large randon arrays From 5135e622fe827defd91f18d149d451ec74b19190 Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 3 Jul 2020 09:40:48 -0400 Subject: [PATCH 5/5] spelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5be2ebb..6c985e8 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ PyOpenCL is a tool that is worth learning. Python allows exceptional clarity-of - 020 Array Sum - Use OpenCL To Add Two Large Random Arrays - Hiding Details - 021 Array Sum - Use OpenCL To Add Two Large Random Arrays - Showing Details - 030 Timing - Compare performance of a loop in pure Python versus OpenCL -- 040 Elementwise - Use PyOpenCL arrays and elementwise to add two large randon arrays +- 040 Elementwise - Use PyOpenCL arrays and elementwise to add two large random arrays