[Openmp-commits] [PATCH] D45528: [OpenMP] Remove compilation warning when using clang to compile bc files.

George Rokos via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Apr 16 07:46:53 PDT 2018


grokos added a comment.

In https://reviews.llvm.org/D45528#1068356, @guansong wrote:

> In https://reviews.llvm.org/D45528#1067671, @grokos wrote:
>
> > In https://reviews.llvm.org/D45528#1067615, @guansong wrote:
> >
> > > In https://reviews.llvm.org/D45528#1067520, @grokos wrote:
> > >
> > > > In https://reviews.llvm.org/D45528#1067487, @guansong wrote:
> > > >
> > > > > update as suggested (except PRId64)
> > > >
> > > >
> > > > Isn't `PRId64` working?
> > >
> > >
> > > I did not find any usage of it on the device side. Not confident on using it. We can remove the warning first, and improve the format later?
> >
> >
> > It's not giving a warning because in CUDA `long long int` happens to be 64 bits long, so you can use `%lld` to print an `int64_t`. This is not guaranteed to be true on every platform, therefore the portable way to print an `int64_t` is using the `PRId64` macro. That's what we do in the base library.
>
>
> My understanding of PRId64 is just a pretty format for lld, which I did not master yet, maybe you can help me to understand those two macros better.
>
> But not sure why %lld can be wrong with long long int, this is standard c/c++ which cuda is based on?


`long long int` is printed via `%lld`, but the value you are printing here is not a `long long int`, it's an `int64_t`. `int64_t` is printed via `PRId64`. `int64_t` is not necessarily equal to `long long int`.

`PRId64` is not a pretty format for `long long int`, it's a macro that expands to the correct modifier for `int64_t`. `long long int` just happens to be 64 bits long in CUDA, but it's not guaranteed to be 64 bits everywhere. You don't get any compiler warnings here because in CUDA `int64_t` is typedef-ed as `long long int` and, consequently, `PRId64` expands to `lld`. That doesn't mean that `int64_t` can be treated as a `long long int` everywhere.

E.g. some day we may reuse this code for another GPU architecture (we had a discussion a while ago about creating a GPU-agnostic RTL which then nvptx/amdgcn/some_other_gpu will specialize). If `int64_t` is defined on that other architecture as `long int` for instance, then `%lld` will trigger a warning. If, instead, we use the `PRId64` macro, it will expand to the correct `ld` automatically.


https://reviews.llvm.org/D45528





More information about the Openmp-commits mailing list