1 //===-- runtime/CUDA/allocatable.cpp --------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "flang/Runtime/CUDA/allocatable.h"
11 #include "../terminator.h"
12 #include "flang/Runtime/CUDA/common.h"
13 #include "flang/Runtime/CUDA/descriptor.h"
14 #include "flang/Runtime/allocatable.h"
16 #include "cuda_runtime.h"
18 namespace Fortran::runtime::cuda
{
21 RT_EXT_API_GROUP_BEGIN
23 int RTDEF(CUFAllocatableAllocate
)(Descriptor
&desc
, bool hasStat
,
24 const Descriptor
*errMsg
, const char *sourceFile
, int sourceLine
) {
25 if (desc
.HasAddendum()) {
26 Terminator terminator
{sourceFile
, sourceLine
};
27 // TODO: This require a bit more work to set the correct type descriptor
30 "not yet implemented: CUDA descriptor allocation with addendum");
32 // Perform the standard allocation.
33 int stat
{RTNAME(AllocatableAllocate
)(
34 desc
, hasStat
, errMsg
, sourceFile
, sourceLine
)};
35 #ifndef RT_DEVICE_COMPILATION
36 // Descriptor synchronization is only done when the allocation is done
40 RTNAME(CUFGetDeviceAddress
)((void *)&desc
, sourceFile
, sourceLine
)};
41 RTNAME(CUFDescriptorSync
)
42 ((Descriptor
*)deviceAddr
, &desc
, sourceFile
, sourceLine
);
48 int RTDEF(CUFAllocatableDeallocate
)(Descriptor
&desc
, bool hasStat
,
49 const Descriptor
*errMsg
, const char *sourceFile
, int sourceLine
) {
50 // Perform the standard allocation.
51 int stat
{RTNAME(AllocatableDeallocate
)(
52 desc
, hasStat
, errMsg
, sourceFile
, sourceLine
)};
53 #ifndef RT_DEVICE_COMPILATION
54 // Descriptor synchronization is only done when the deallocation is done
58 RTNAME(CUFGetDeviceAddress
)((void *)&desc
, sourceFile
, sourceLine
)};
59 RTNAME(CUFDescriptorSync
)
60 ((Descriptor
*)deviceAddr
, &desc
, sourceFile
, sourceLine
);
70 } // namespace Fortran::runtime::cuda