Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions Exercises/Exercise01/Python/DeviceInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,45 @@
# History: C++ version written by Tom Deakin, 2012
# Ported to Python by Tom Deakin, July 2013
#
from __future__ import print_function

# Import the Python OpenCL API
import pyopencl as cl

# Create a list of all the platform IDs
platforms = cl.get_platforms()

print "\nNumber of OpenCL platforms:", len(platforms)
print("\nNumber of OpenCL platforms:", len(platforms))

print "\n-------------------------"
print("\n-------------------------")

# Investigate each platform
for p in platforms:
# Print out some information about the platforms
print "Platform:", p.name
print "Vendor:", p.vendor
print "Version:", p.version
# print out some information about the platforms
print("Platform:", p.name)
print("Vendor:", p.vendor)
print("Version:", p.version)

# Discover all devices
devices = p.get_devices()
print "Number of devices:", len(devices)
print("Number of devices:", len(devices))

# Investigate each device
for d in devices:
print "\t-------------------------"
# Print out some information about the devices
print "\t\tName:", d.name
print "\t\tVersion:", d.opencl_c_version
print "\t\tMax. Compute Units:", d.max_compute_units
print "\t\tLocal Memory Size:", d.local_mem_size/1024, "KB"
print "\t\tGlobal Memory Size:", d.global_mem_size/(1024*1024), "MB"
print "\t\tMax Alloc Size:", d.max_mem_alloc_size/(1024*1024), "MB"
print "\t\tMax Work-group Total Size:", d.max_work_group_size
print("\t-------------------------")
# print out some information about the devices
print("\t\tName:", d.name)
print("\t\tVersion:", d.opencl_c_version)
print("\t\tMax. Compute Units:", d.max_compute_units)
print("\t\tLocal Memory Size:", d.local_mem_size/1024, "KB")
print("\t\tGlobal Memory Size:", d.global_mem_size/(1024*1024), "MB")
print("\t\tMax Alloc Size:", d.max_mem_alloc_size/(1024*1024), "MB")
print("\t\tMax Work-group Total Size:", d.max_work_group_size)

# Find the maximum dimensions of the work-groups
dim = d.max_work_item_sizes
print "\t\tMax Work-group Dims:(", dim[0], " ".join(map(str, dim[1:])), ")"
print("\t\tMax Work-group Dims:(", dim[0], " ".join(map(str, dim[1:])), ")")

print "\t-------------------------"
print("\t-------------------------")

print "\n-------------------------"
print("\n-------------------------")
7 changes: 4 additions & 3 deletions Exercises/Exercise03/Python/vadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# C version Updated by Tom Deakin and Simon McIntosh-Smith, October 2012
# Ported to Python by Tom Deakin, July 2013
#
from __future__ import print_function

# Import the Python OpenCL API
import pyopencl as cl
Expand Down Expand Up @@ -90,7 +91,7 @@
# Wait for the commands to finish before reading back
queue.finish()
rtime = time() - rtime
print "The kernel ran in", rtime, "seconds"
print("The kernel ran in", rtime, "seconds")

# Read back the results from the compute device
cl.enqueue_copy(queue, h_c, d_c)
Expand All @@ -106,7 +107,7 @@
if tmp*tmp < TOL*TOL:
correct += 1
else:
print "tmp", tmp, "h_a", a, "h_b", b, "h_c", c
print("tmp", tmp, "h_a", a, "h_b", b, "h_c", c)

# Summarize results
print "C = A+B:", correct, "out of", LENGTH, "results were correct."
print("C = A+B:", correct, "out of", LENGTH, "results were correct.")
7 changes: 4 additions & 3 deletions Exercises/Exercise04/Python/vadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# C version Updated by Tom Deakin and Simon McIntosh-Smith, October 2012
# Ported to Python by Tom Deakin, July 2013
#
from __future__ import print_function

# Import the Python OpenCL API
import pyopencl as cl
Expand Down Expand Up @@ -90,7 +91,7 @@
# Wait for the commands to finish before reading back
queue.finish()
rtime = time() - rtime
print "The kernel ran in", rtime, "seconds"
print("The kernel ran in", rtime, "seconds")

# Read back the results from the compute device
cl.enqueue_copy(queue, h_c, d_c)
Expand All @@ -106,7 +107,7 @@
if tmp*tmp < TOL*TOL:
correct += 1
else:
print "tmp", tmp, "h_a", a, "h_b", b, "h_c", c
print("tmp", tmp, "h_a", a, "h_b", b, "h_c", c)

# Summarize results
print "C = A+B:", correct, "out of", LENGTH, "results were correct."
print("C = A+B:", correct, "out of", LENGTH, "results were correct.")
7 changes: 4 additions & 3 deletions Exercises/Exercise05/Python/vadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# C version Updated by Tom Deakin and Simon McIntosh-Smith, October 2012
# Ported to Python by Tom Deakin, July 2013
#
from __future__ import print_function

# Import the Python OpenCL API
import pyopencl as cl
Expand Down Expand Up @@ -90,7 +91,7 @@
# Wait for the commands to finish before reading back
queue.finish()
rtime = time() - rtime
print "The kernel ran in", rtime, "seconds"
print("The kernel ran in", rtime, "seconds")

# Read back the results from the compute device
cl.enqueue_copy(queue, h_c, d_c)
Expand All @@ -106,7 +107,7 @@
if tmp*tmp < TOL*TOL:
correct += 1
else:
print "tmp", tmp, "h_a", a, "h_b", b, "h_c", c
print("tmp", tmp, "h_a", a, "h_b", b, "h_c", c)

# Summarize results
print "C = A+B:", correct, "out of", LENGTH, "results were correct."
print("C = A+B:", correct, "out of", LENGTH, "results were correct.")
5 changes: 3 additions & 2 deletions Exercises/Exercise06/Python/helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function

from definitions import *
import numpy
Expand Down Expand Up @@ -25,7 +26,7 @@ def error(N, C):
# Function to analyze and output results
def results(N, C, run_time):
mflops = 2.0 * N * N * N/(1000000.0* run_time)
print run_time, "seconds at", mflops, "MFLOPS"
print(run_time, "seconds at", mflops, "MFLOPS")
errsq = error(N, C)
if numpy.isnan(errsq) or errsq > TOL:
print "Errors in multiplication:", errsq
print("Errors in multiplication:", errsq)
7 changes: 4 additions & 3 deletions Exercises/Exercise06/Python/matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Ported to Python by Tom Deakin, July 2013
# Modified to assume square matrices by Simon McIntosh-Smith, Sep 2014
#
from __future__ import print_function

from helper import *
from definitions import *
Expand Down Expand Up @@ -51,13 +52,13 @@
# C matrix
h_C = numpy.empty(size).astype(numpy.float32)

print "\n===== Sequential, matrix mult (dot prod), order", ORDER, "on host CPU ======\n"
print("\n===== Sequential, matrix mult (dot prod), order", ORDER, "on host CPU ======\n")

for i in range(COUNT):
h_C.fill(0.0)
start_time = time()

print "Skipping as this takes a long time to run!"
print("Skipping as this takes a long time to run!")
#seq_mat_mul_sdot(N, h_A, h_B, h_C)

run_time = time() - start_time
Expand All @@ -84,7 +85,7 @@
mmul = program.mmul
mmul.set_scalar_arg_dtypes([numpy.int32, None, None, None])

print "\n===== OpenCL, matrix mult, C(i,j) per work item, order", N, "======\n"
print("\n===== OpenCL, matrix mult, C(i,j) per work item, order", N, "======\n")

# Do the multiplication COUNT times
for i in range(COUNT):
Expand Down
8 changes: 4 additions & 4 deletions Exercises/Exercise09/Python/pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
# History: Written in C by Tim Mattson, 11/99
# Ported to Python by Tom Deakin, July 2013
#

from __future__ import print_function
from time import time

num_steps = 100000000

print "\nNote: Wanted to do", num_steps, "steps, but this is very slow in Python."
print("\nNote: Wanted to do", num_steps, "steps, but this is very slow in Python.")

num_steps = 1000000

print "Doing", num_steps, "steps instead."
print("Doing", num_steps, "steps instead.")

integral_sum = 0.0

Expand All @@ -36,5 +36,5 @@

run_time = time() - start_time;

print "\npi with", num_steps, "steps is", pi, "in", run_time, "seconds\n"
print("\npi with", num_steps, "steps is", pi, "in", run_time, "seconds\n")