[J3] [EXTERNAL] Re: Custom Memory Allocator
Van Snyder
van.snyder at jpl.nasa.gov
Mon Nov 18 13:45:39 EST 2019
On Mon, 2019-11-18 at 18:35 +0000, Steidel, Jon L via J3 wrote:
> Hi Reuben,
>
> In the 5.0 spec on page 158 in section 2.11.13 allocate Directive at lines 1-2 is a Fortran restriction
>
> List items specified in the allocate directive must not have the ALLOCATABLE attribute unless the directive is associated with an allocate statement.
>
> So, I think if the allocate directive appears immediately before an ALLOCATE statement, list items may be allocatable. So, I think the following is
> permitted:
>
> real, allocatable :: x(:), y(:)
> ! declare and initialize omp_allocator and omp_alloctraits
>
> !$omp allocate (x, y) allocator (xy_alloc)
> allocate (x(n), y(n))
I hope it's also permitted before a DEALLOCATE statement.
> In this case the allocate statement would use the allocator specified by xy_alloc. A complete example can be found starting on page 342 of the OpenMP 5.0
> Examples document that is now available at http://www.openmp.org/specifications.
>
> -jon
>
>
>
> -----Original Message-----
> From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Reuben D. Budiardja via J3
> Sent: Friday, November 15, 2019 7:31 PM
> To: Steidel, Jon L via J3 <j3 at mailman.j3-fortran.org>
> Cc: Reuben D. Budiardja <reubendb at ornl.gov>
> Subject: Re: [J3] [EXTERNAL] Re: Custom Memory Allocator
>
> Hi Jon,
>
> Interesting. I was not aware of this (but then again I am not yet fully familiar with OpenMP 5). However, in the spec it says for Fortran the list item "must not have the ALLOCATABLE attribute" unless associated with "allocate statement".
>
> So I am not sure how this would solve my issue (provided I could find such compiler). Or am I misunderstanding thing?
>
> Thanks,
> Reuben
>
> On 11/15/2019 05:18 PM, Steidel, Jon L via J3 wrote:
> > OpenMP 5.0 has the ALLOCATE directive, with the ALLOCATOR clause. I don't know if you have access to an OpenMP 5.0 compiler (or if there is yet one available), or if this would work for you if you can find such a compiler.
> >
> > -jon
> >
> > -----Original Message-----
> > From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Reuben D.
> > Budiardja via J3
> > Sent: Friday, November 15, 2019 2:30 PM
> > To: j3 at mailman.j3-fortran.org
> > Cc: Reuben D. Budiardja <reubendb at ornl.gov>
> > Subject: [J3] Custom Memory Allocator
> >
> > Hello,
> >
> > I am wondering if there is a standard-conformance way to allocate allocatable array with a custom memory allocator, e.g. via third-party provided C-library.
> >
> > At first I looked into passing the allocatable into a bind(c) subroutine and use the C descriptor from the C side. But sec 18.6 and 18.7 prevent using any custom allocator other than using CFI_allocate().
> >
> > Real-world use case examples: we need to use CUDA memory allocator
> > cudaMallocManaged() to use CUDA Unified Memory, and cudaHostAlloc() to use page-locked memory on the system.
> >
> > I suppose the hack-ish way is to swap the base_address member of C descriptor to the address given cudaMallocManaged() (and free-up the original address from CFI_allocate()).
> >
> > I wondered if for further enhancement on C interoperability we may consider allowing custom allocator into the standard.
> >
> > I'd be interested in any feedback.
> >
> > Best,
> > Reuben
> >
>
> --
> Reuben D. Budiardja
> reubendb at ornl.gov | (865) 576-9519
> National Center for Computational Sciences Oak Ridge National Laboratory
More information about the J3
mailing list