Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example that profiles parallel sum #774

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

FattiMei
Copy link

Description

This program profiles the parallel sum kernel when summing two arrays of increasing size, interpreting the data as char, int, float... the results are plotted with matplotlib, it's an external dependency but it's a common one.

Rationale

When experimenting with GPU computing is useful to estimate an upper bound on performance, this PR offers an example of how you could use pyopencl events to profile a kernel (I suppose we are profiling only the execution time without the data transfers).
The results show a powerful idea in parallel computing: using shorter types improves throughput

Possible corners

  • I assumed that the profiling times were in nanoseconds
  • I wanted to work with fp16, but not all devices support it so I commented it out. Maybe we could query at runtime if fp16 arithmetic is supported

Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this. Some comments below.

Comment on lines 50 to 53
FLOPS = 1e9 * sums / (event.profile.end - event.profile.start)
GFLOPS = FLOPS / 1e6

data[row, col] = GFLOPS
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, this workload will be bandwidth-bound, so GB/s will be the more appropriate measure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This decision was made because it's common to evaluate gpu performance based on TFLOPS (and this number is computed with similar workloads) and especially highlights the fact that of course the flops go up when working with smaller types

examples/demo_flops.py Outdated Show resolved Hide resolved
header = f'#define T {literal}\n'
kernel = cl.Program(ctx, header + src).build().sum

event = kernel(queue, (sums,), None, x, y, z)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally good practice to do a few "warmup" rounds before timing, to better measure the steady-state rate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are problem with caches however. In cpu runs I get crazy GFLOPS for medium size arrays because they already live in the cache, gpu doesn't seem to suffer from this problem.
But with the new commits one could decide to do no warmup runs and only one hot run so it's ok

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you look over the CI failures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants