[cfe-dev] [OpenCL] RFC: let Clang generate llvm atomic instructions for OpenCL atomic builtin functions

Anastasia Stulova via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 8 01:46:29 PST 2016


Hi Sam,

Could you implement CL2.0 atomics by calling the C11 ones, i.e. doing something like:

  C atomic_exchange( volatile A* obj, C desired ){
    return  __c11_atomic_exchange(obj, desired);
  }

There is still one issue we have though with an absence of memory_scope in Clang/LLVM.

So for the following declaration, we don't have anything available in Clang to represent the last parameter:

C atomic_exchange_explicit(volatile A *object, C desired, memory_order order, memory_scope scope);

We also don't have anything in IR to map it to.

One approach here could be to just ignore it and perhaps call a regular C11 atomic passing all other parameters except memory scope.
Alternatively we could extend the Clang atomic builtins with CL2.0 style builtins for those that require memory scope.

Btw @Alexey, we did add some CL builtins recently i.e for Pipes (see clang at r258782) and will probably need more - enqueue_kernel.

Cheers,
Anastasia

From: Liu, Yaxun (Sam) [mailto:Yaxun.Liu at amd.com]
Sent: 04 March 2016 18:04
To: Bader, Alexey; Anastasia Stulova; Pan, Xiuli; cfe-dev at lists.llvm.org
Cc: Sumner, Brian; Stellard, Thomas; Zhang, Guansong
Subject: RE: [OpenCL] RFC: let Clang generate llvm atomic instructions for OpenCL atomic builtin functions

Hi Alexey,

To clarify,  when I said OpenCL atomic builtin functions, the 'builtin' was in the sense of OpenCL spec. In Clang they are just treated as ordinary functions.

Let's take an example of OpenCL atomic builtin function:

uint y;
volatile __global atomic_uint *x;
atomic_store(x, y);

Currently we clang generates a function call

  call spir_func void @_Z12atomic_storePVU3AS1U7_Atomicjj(i32 addrspace(1)* %x, i32 %y)

However, it can simply be represented as an LLVM instruction

  store atomic volatile i32 %y, i32 addrspace(1)* %x seq_cst, align 4

So I am wondering why not let Clang just generating the instruction directly, since Clang already did the same thing for some libm functions.

Sam

From: Bader, Alexey [mailto:alexey.bader at intel.com]
Sent: Friday, March 4, 2016 11:22 AM
To: Liu, Yaxun (Sam) <Yaxun.Liu at amd.com<mailto:Yaxun.Liu at amd.com>>; 'anastasia.stulova at arm.com' <anastasia.stulova at arm.com<mailto:anastasia.stulova at arm.com>>; Pan, Xiuli <xiuli.pan at intel.com<mailto:xiuli.pan at intel.com>>; cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
Cc: Sumner, Brian <Brian.Sumner at amd.com<mailto:Brian.Sumner at amd.com>>
Subject: RE: [OpenCL] RFC: let Clang generate llvm atomic instructions for OpenCL atomic builtin functions

Hi Sam,

Could you clarify your idea?
At the moment clang doesn't provide any OpenCL built-in functions - they are provided by OpenCL implementation.
Clang provides C11 atomic built-ins<http://clang.llvm.org/docs/LanguageExtensions.html#c11-atomic-builtins> which should produce desired llvm atomic instructions.
This should work for OpenCL v2.0 atomics since they are taken from C11.

Thanks,
Alexey

From: Liu, Yaxun (Sam) [mailto:Yaxun.Liu at amd.com]
Sent: Thursday, March 3, 2016 11:37 PM
To: Bader, Alexey; 'anastasia.stulova at arm.com'; Pan, Xiuli; cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
Cc: Sumner, Brian
Subject: RE: [OpenCL] RFC: let Clang generate llvm atomic instructions for OpenCL atomic builtin functions

Hi,

OpenCL atomic builtin functions are similar to llvm atomic instructions. It seems natural to represent OpenCL atomic builtin functions by LLVM atomic instructions.

Doing this can simplify implementation of OpenCL builtin library and have a unified representation for OpenCL atomic builtin functions.

Any feedback? Thanks.

Sam

--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160308/ccf6d002/attachment.html>


More information about the cfe-dev mailing list