1 //===-- runtime/CUDA/pointer.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/pointer.h"
10 #include "../assign-impl.h"
12 #include "../terminator.h"
13 #include "flang/Runtime/CUDA/descriptor.h"
14 #include "flang/Runtime/CUDA/memmove-function.h"
15 #include "flang/Runtime/pointer.h"
17 #include "cuda_runtime.h"
19 namespace Fortran::runtime::cuda
{
22 RT_EXT_API_GROUP_BEGIN
24 int RTDEF(CUFPointerAllocate
)(Descriptor
&desc
, int64_t stream
, bool hasStat
,
25 const Descriptor
*errMsg
, const char *sourceFile
, int sourceLine
) {
26 if (desc
.HasAddendum()) {
27 Terminator terminator
{sourceFile
, sourceLine
};
28 // TODO: This require a bit more work to set the correct type descriptor
31 "not yet implemented: CUDA descriptor allocation with addendum");
33 // Perform the standard allocation.
35 RTNAME(PointerAllocate
)(desc
, hasStat
, errMsg
, sourceFile
, sourceLine
)};
39 int RTDEF(CUFPointerAllocateSync
)(Descriptor
&desc
, int64_t stream
,
40 bool hasStat
, const Descriptor
*errMsg
, const char *sourceFile
,
42 int stat
{RTNAME(CUFPointerAllocate
)(
43 desc
, stream
, hasStat
, errMsg
, sourceFile
, sourceLine
)};
44 #ifndef RT_DEVICE_COMPILATION
45 // Descriptor synchronization is only done when the allocation is done
49 RTNAME(CUFGetDeviceAddress
)((void *)&desc
, sourceFile
, sourceLine
)};
50 RTNAME(CUFDescriptorSync
)
51 ((Descriptor
*)deviceAddr
, &desc
, sourceFile
, sourceLine
);
57 int RTDEF(CUFPointerAllocateSource
)(Descriptor
&pointer
,
58 const Descriptor
&source
, int64_t stream
, bool hasStat
,
59 const Descriptor
*errMsg
, const char *sourceFile
, int sourceLine
) {
60 int stat
{RTNAME(CUFPointerAllocate
)(
61 pointer
, stream
, hasStat
, errMsg
, sourceFile
, sourceLine
)};
63 Terminator terminator
{sourceFile
, sourceLine
};
64 Fortran::runtime::DoFromSourceAssign(
65 pointer
, source
, terminator
, &MemmoveHostToDevice
);
70 int RTDEF(CUFPointerAllocateSourceSync
)(Descriptor
&pointer
,
71 const Descriptor
&source
, int64_t stream
, bool hasStat
,
72 const Descriptor
*errMsg
, const char *sourceFile
, int sourceLine
) {
73 int stat
{RTNAME(CUFPointerAllocateSync
)(
74 pointer
, stream
, hasStat
, errMsg
, sourceFile
, sourceLine
)};
76 Terminator terminator
{sourceFile
, sourceLine
};
77 Fortran::runtime::DoFromSourceAssign(
78 pointer
, source
, terminator
, &MemmoveHostToDevice
);
87 } // namespace Fortran::runtime::cuda