[Openmp-dev] [EXT] Re: 32-bit target device support

Finkel, Hal J. via Openmp-dev openmp-dev at lists.llvm.org
Wed Aug 14 17:07:07 PDT 2019


On 8/14/19 4:37 AM, Andreas Hommel via Openmp-dev wrote:
In embedded environments it is not uncommon to pair a 64-bit ARM with 32-bit accelerator devices (as in my case).
I have just started this, so maybe I am just naïve here, but I can run a lot of examples on our device using this ugly hack:

  CharUnits TySz = Ctx.getTypeSizeInChars(Ty);
  CharUnits PtrSz = CharUnits::fromQuantity(4); // our device pointers are 32-bits wide
  if (!IsByRef &&
      (TySz > PtrSz ||
       Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) {
    IsByRef = true;
  }

Is it really that hard to support this (I could imagine that things could become messy with mixed host/device endianness))?


One issue in this kind of configuration is that, if the host and accelerator have different data layouts, then sharing any kind of aggregate, in general, will cause problems. Simple cases will work (e.g., you have an array of floats), but it will be fragile even if no pointers are involved. Do you work in an environment where you can force the accelerator's structure layout rules (etc.) to match the host's rules?

 -Hal


The much harder 32-bit <-> 64-bit pointer translation problem already seems to work flawlessly in my setup.

-Andreas

From: Alexey Bataev <a.bataev at hotmail.com><mailto:a.bataev at hotmail.com>
Sent: Wednesday, 14 August, 2019 11:00
To: Andreas Hommel <andreas.hommel at nxp.com><mailto:andreas.hommel at nxp.com>
Subject: [EXT] Re: [Openmp-dev] 32-bit target device support

It is not a big, it is by design. There is an agreement that the basic types must have the same sizes on both the host and the device. Otherwise, the results are unpredictable.
Best regards,
Alexey Bataev

14 авг. 2019 г., в 4:36, Andreas Hommel via Openmp-dev <openmp-dev at lists.llvm.org<mailto:openmp-dev at lists.llvm.org>> написал(а):
Hi,

I am currently adding support for an experimental 32-bit OpenMP target device using x86_64 as a host. There seems to be a bug in

bool Sema::Sema::isOpenMPCapturedByRef(…,) {
…
  if (!IsByRef &&
      (Ctx.getTypeSizeInChars(Ty) >
           Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) ||
       Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) {
    IsByRef = true;
  }
  return IsByRef;
}

The above code assumes that the target device’s UIntPtr size is the same as the host’s UIntPtr which is not true in my case. So, if you pass a 64-bit double to a 32-bit device the host compilation pass uses by-value argument passing, because the value fits into the 64-bit pointers. However, if you build for the target (-fopenmp-is-device), the 64-bit float does not fit into the 32-bit pointer, so the target assumes that the value is passed by-reference and the device does not pick up the correct argument value.

A possible fix would to use something like this

  if (!IsByRef &&
      (Ctx.getTypeSizeInChars(Ty) >
           DCtx.getTypeSizeInChars(DCtx.getUIntPtrType()) ||
       Ctx.getDeclAlign(D) > DCtx.getTypeAlignInChars(DCtx.getUIntPtrType()))) {
    IsByRef = true;
  }

where DCtx is the context of the target device. But that context does not seem to be available in the host’s Sema.

Sema.LangOpts.OMPTargetTriples seems to be the only available starting point to get to a device’s context, or am I missing something?

Thanks,
Andreas
_______________________________________________
Openmp-dev mailing list
Openmp-dev at lists.llvm.org<mailto:Openmp-dev at lists.llvm.org>
https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fopenmp-dev&data=02%7C01%7Candreas.hommel%40nxp.com%7C32dd8f14c6554381322708d72095c718%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C637013699969308643&sdata=xfb0mOT%2B%2Bd18w3atQK2mMLhIWJJPGCUDDeADjD0x7Eo%3D&reserved=0>



_______________________________________________
Openmp-dev mailing list
Openmp-dev at lists.llvm.org<mailto:Openmp-dev at lists.llvm.org>
https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev


--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20190815/4dd058ec/attachment.html>


More information about the Openmp-dev mailing list