This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Fix integer parameters of enqueue_kernel
ClosedPublic

Authored by Anastasia on Nov 10 2016, 8:52 AM.

Details

Reviewers
yaxunl
Summary

Parameters representing number of events as well as sizes of enqueued block arguments in enqueue_kernel function are specified as uint type. This prevents passing sizeof(int) type expressions on the 64 bit architectures because they return size_t which is a 64 bit wide in contrast to uint that is always 32 bits.

The suggestion is:

  • For the number of events argument allow to pass larger integers than 32 bits as soon as compiler can prove that the range fits in 32 bits. If not, the diagnostic will be given.
  • Change type of the arguments specifying sizes of the corresponding block arguments to be size_t.

The proposed enqueue_kernel signature would be:

int enqueue_kernel (queue_t queue, kernel_enqueue_flags_t flags, const ndrange_t ndrange, uint num_events_in_wait_list, const clk_event_t *event_wait_list, clk_event_t *event_ret, void (^block)(local void *, ...), size_t size0, ...)

and therefore compiler should allow the call:

enqueue_kernel(default_queue, flags, ndrange, sizeof(event_wait_list)/sizeof(event_wait_list[0]), event_wait_list2, &clk_event,
               ^(local void *p) {
                 return;
               },
               sizeof(int[2]));

See tests for more examples.

Diff Detail

Event Timeline

Anastasia updated this revision to Diff 77496.Nov 10 2016, 8:52 AM
Anastasia retitled this revision from to [OpenCL] Fix integer parameters of enqueue_kernel.
Anastasia updated this object.
Anastasia added a reviewer: yaxunl.
Anastasia updated this object.
Anastasia added a subscriber: cfe-commits.
yaxunl edited edge metadata.Nov 11 2016, 8:23 AM

My main concern is that by making the number of event be of type size_t instead of uint we are not conforming to the spec, although I agree it is better for the user.

lib/CodeGen/CGBuiltin.cpp
2547

should Int32Ty be SizeTy?

lib/Sema/SemaChecking.cpp
453

This comment does not match what this function does. The function checks if the argument is integer type but does not check if it fits into 32 bit. Also the diagnostic msg says it is not an integer type and does not mention the size requirement.

test/CodeGenOpenCL/cl20-device-side-enqueue.cl
1

It seems the command is changed by replacing all CHECK with COMMON.

Anastasia added inline comments.Nov 11 2016, 10:55 AM
lib/CodeGen/CGBuiltin.cpp
2547

I am not changing the width of the event number argument actually because I think 32 bit width is sufficient. I just want us to accept objects with the larger width types to be passed in case compiler can prove that they fit in 32 bits. This will allow passing sizeof expression for example (even in 64 bit architectures) but it will create diagnostic only in case the value returned doesn't fit in 32 bits.

See CheckImplicitConversion in SemaChecking.cpp.

lib/Sema/SemaChecking.cpp
453

As per above comment I intended to keep the 32 bit width type for the number of events, but the object passed can have large type as soon as the actual value in it fits in 32 bits (if compiler can deduce that). If the value doesn't fit in 32 bits or the value range is not known at compile time, a diagnostic will be generated.

test/CodeGenOpenCL/cl20-device-side-enqueue.cl
1

Indeed, I've done something wrong with the string replacement. Will correct that! Thanks!

I thought the number of events was also changed to size_t type. Now I understand. Probably I was misled by the summary:

"Parameters representing number of events as well as sizes of enqueued block arguments in enqueue_kernel function are specified as uint type. This prevents passing sizeof(int) type expressions on the 64 bit architectures because they return size_t which is a 64 bit wide in contrast to uint that is always 32 bits."

It sounds like number of events should also be changed. Maybe drop 'number of events as well as' from the above sentence?

I see. If I say something like:

  • For the number of event argument allow to pass larger integers than 32 bits as soon as compiler can prove that the range fits in 32 bits. If not, the diagnostic will be given.
  • Change type of the arguments specifying sizes of the corresponding block arguments to be size_t.
yaxunl accepted this revision.Nov 14 2016, 7:03 AM
yaxunl edited edge metadata.

LGTM with the change for the summary. Thanks!

This revision is now accepted and ready to land.Nov 14 2016, 7:03 AM
Anastasia updated this revision to Diff 77825.Nov 14 2016, 9:21 AM
Anastasia updated this object.
Anastasia edited edge metadata.
  1. Corrected typos in CodeGen test.
  2. Improved description.
Anastasia closed this revision.Nov 14 2016, 9:50 AM

Committed in r286849.