[RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions

Robinson, Paul via cfe-dev
Hi,

OpenCL spec requires that a pointer should be aligned to at least the pointee type. Therefore, if a device-side enqueued kernel has a local int* argument, it should be aligned to 4 bytes.

Since these buffers in local addr space are allocated by __enqueue_kernel, it needs to know the alignment of these buffers, not just their sizes.

Although such information is not passed to the original OpenCL builtin function enqueue_kernel, it can be obtained by checking the prototype of the block invoke function at compile time.

I would like to create a patch to pass this information to  __enqueue_kernel. Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates local buffer with extra alignment therefore wasted memory space.

Any comments?

Thanks.

Sam

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

winmail.dat (18K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions

Robinson, Paul via cfe-dev


> OpenCL spec requires that a pointer should be aligned to at least the pointee type.


So a pointer to int16 would be 64 byte aligned? Seems strange though. Can you give me the spec reference?

> Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates local buffer with extra alignment therefore wasted memory space.

Can you explain in more details here, please.

Cheer,
Anastasia

From: Liu, Yaxun (Sam) <[hidden email]>
Sent: 01 December 2017 19:45
To: Anastasia Stulova; cfe-dev ([hidden email]); Bader, Alexey ([hidden email])
Cc: Sumner, Brian
Subject: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions
 

Hi,

 

OpenCL spec requires that a pointer should be aligned to at least the pointee type. Therefore, if a device-side enqueued kernel has a local int* argument, it should be aligned to 4 bytes.

 

Since these buffers in local addr space are allocated by __enqueue_kernel, it needs to know the alignment of these buffers, not just their sizes.

 

Although such information is not passed to the original OpenCL builtin function enqueue_kernel, it can be obtained by checking the prototype of the block invoke function at compile time.

 

I would like to create a patch to pass this information to  __enqueue_kernel. Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates local buffer with extra alignment therefore wasted memory space.

 

Any comments?

 

Thanks.

 

Sam


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions

Robinson, Paul via cfe-dev

Spec reference:

 

OpenCL v2.0 s6.1.5

The OpenCL compiler is responsible for aligning data items to the appropriate alignment as required by the data type. For arguments to a __kernel function declared to be a pointer to a data type, the OpenCL compiler can assume that the pointee is always appropriately aligned as required by the data type. The behavior of an unaligned load or store is undefined, except for the vloadn, vload_halfn, vstoren, and vstore_halfn functions defined in section 6.13.7.

 

s6.2.5

Casting a pointer to a new type represents an unchecked assertion that the address is correctly aligned.

 

The C Standard, 6.3.2.3, paragraph 7 [ISO/IEC 9899:2011], states

 

A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the referenced type, the behavior is undefined.

 

For example, if a block kernel has argument local int4*. Its alignment should be 16 bytes. Passing a pointer aligned to 1 byte may result in undefined behavior. Most hardware can still load from the unaligned memory but will a performance hit. If runtime wants to avoid the performance hit, it has to allocate the buffer at maximum possible alignment e.g. 32 bytes, which will result in wasted memory.

 

Sam

 

From: Anastasia Stulova [mailto:[hidden email]]
Sent: Friday, December 15, 2017 10:40 AM
To: Liu, Yaxun (Sam) <[hidden email]>; cfe-dev ([hidden email]) <[hidden email]>; Bader, Alexey ([hidden email]) <[hidden email]>
Cc: Sumner, Brian <[hidden email]>; nd <[hidden email]>
Subject: Re: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions

 

 

> OpenCL spec requires that a pointer should be aligned to at least the pointee type.

 

So a pointer to int16 would be 64 byte aligned? Seems strange though. Can you give me the spec reference?

> Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates local buffer with extra alignment therefore wasted memory space.

Can you explain in more details here, please.

Cheer,
Anastasia


From: Liu, Yaxun (Sam) <[hidden email]>
Sent: 01 December 2017 19:45
To: Anastasia Stulova; cfe-dev ([hidden email]); Bader, Alexey ([hidden email])
Cc: Sumner, Brian
Subject: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions

 

Hi,

 

OpenCL spec requires that a pointer should be aligned to at least the pointee type. Therefore, if a device-side enqueued kernel has a local int* argument, it should be aligned to 4 bytes.

 

Since these buffers in local addr space are allocated by __enqueue_kernel, it needs to know the alignment of these buffers, not just their sizes.

 

Although such information is not passed to the original OpenCL builtin function enqueue_kernel, it can be obtained by checking the prototype of the block invoke function at compile time.

 

I would like to create a patch to pass this information to  __enqueue_kernel. Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates local buffer with extra alignment therefore wasted memory space.

 

Any comments?

 

Thanks.

 

Sam


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev