NVPTX: __iAtomicCAS support ?

Dear colleagues,

I'm looking if we can replace nvopencc with LLVM NVPTX in our project.
It turns NVPTX won't work with the code nvopencc can handle (please
see the log below). So are atomic intrinsics not supported or am I
doing call in a wrong way?

Thanks,
- Dima.

SOURCE

From: Dmitry N. Mikushin [mailto:maemarcus@gmail.com]
Sent: Wednesday, May 16, 2012 5:44 AM
To: LLVM-Dev
Cc: Justin Holewinski
Subject: NVPTX: __iAtomicCAS support ?

Dear colleagues,

I'm looking if we can replace nvopencc with LLVM NVPTX in our project.
It turns NVPTX won't work with the code nvopencc can handle (please
see the log below). So are atomic intrinsics not supported or am I
doing call in a wrong way?

There are really two issues here.

First, the error you are seeing is because calls are disabled in the back-end until an outstanding LLVM core patch is committed. Hopefully, we'll be able to push that in soon.

Second, __iAtomicCAS() is a CUDA-C built-in function; the implementation is provided by a library linked with the LLVM IR before the NVPTX back-end sees it. You will need to provide your own implementations for such functions.

Thanks, Justin!

Clang does not implement atomic intrinsics, but fortunately supports inline asm:

__inline__ __attribute__((always_inline)) __attribute__((device)) int
__iAtomicCAS(int *p, int compare, int val)
{
        int *global, result;
        asm(
                "cvta.to.global.u64 %0, %1;\n\t"
                "atom.global.cas.b32 %2, [%0], %3, %4;"
                :: "l"(global), "l"(p), "r"(result), "r"(compare), "r"(val));
        return result;
}

It helped to workaround this particular problem.

- D.