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

Andreas Hommel via Openmp-dev openmp-dev at lists.llvm.org
Thu Aug 15 07:22:38 PDT 2019


You can make structure layouts compatible by using <stdint> types, e.g., int32_t in the common definitions and (worst case) add some alignment attributes. But that would have to be done even if you are not usingOpenMP.

 

Structure with embedded pointers will need special attention, but they will not work anyway unless you have a host/device unified shared memory model.

 

I have just started this internal experiment, but I was able to resolve all issues (except for that byval/byref capture issue in clang) in my omptarget plugin and I am able to run some simple examples that target our 32-bit device from an x86_64 host.

 

-Andreas

 

From: Finkel, Hal J. <hfinkel at anl.gov> 
Sent: Thursday, 15 August, 2019 2:07
To: Andreas Hommel <andreas.hommel at nxp.com>; openmp-dev at lists.llvm.org
Subject: Re: [Openmp-dev] [EXT] Re: 32-bit target device support

 

Caution: EXT Email 

 

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  <mailto:a.bataev at hotmail.com> <a.bataev at hotmail.com> 
Sent: Wednesday, 14 August, 2019 11:00
To: Andreas Hommel  <mailto:andreas.hommel at nxp.com> <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%7C977179e68f5243428bd008d721148470%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637014244335712888&sdata=19zJr9SXBHeZ5%2ByZkL1T4DbesbRhq%2F0i2UQCaQtFfvo%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 <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%7C977179e68f5243428bd008d721148470%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637014244335722882&sdata=M6JiDMMl6vpda93I14Cj5Fc%2BDLsKqJYzn3NZTGTYJ24%3D&reserved=0> 

-- 
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/55df6b99/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 9859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20190815/55df6b99/attachment-0001.bin>


More information about the Openmp-dev mailing list