[flang] [llvm] [flang][cuda] Add support for allocate with device source (PR #171743)

Zhen Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 10 16:52:41 PST 2025


================
@@ -57,26 +57,35 @@ int RTDEF(CUFAllocatableAllocate)(Descriptor &desc, int64_t *stream,
 
 int RTDEF(CUFAllocatableAllocateSource)(Descriptor &alloc,
     const Descriptor &source, int64_t *stream, bool *pinned, bool hasStat,
-    const Descriptor *errMsg, const char *sourceFile, int sourceLine) {
+    const Descriptor *errMsg, const char *sourceFile, int sourceLine,
+    bool sourceIsDevice) {
   int stat{RTNAME(CUFAllocatableAllocate)(
       alloc, stream, pinned, hasStat, errMsg, sourceFile, sourceLine)};
   if (stat == StatOk) {
     Terminator terminator{sourceFile, sourceLine};
-    Fortran::runtime::DoFromSourceAssign(
-        alloc, source, terminator, &MemmoveHostToDevice);
+    Fortran::runtime::DoFromSourceAssign(alloc, source, terminator,
+        sourceIsDevice ? &MemmoveDeviceToHost : &MemmoveHostToDevice);
   }
   return stat;
 }
 
 int RTDEF(CUFAllocatableAllocateSourceSync)(Descriptor &alloc,
     const Descriptor &source, int64_t *stream, bool *pinned, bool hasStat,
-    const Descriptor *errMsg, const char *sourceFile, int sourceLine) {
-  int stat{RTNAME(CUFAllocatableAllocateSync)(
-      alloc, stream, pinned, hasStat, errMsg, sourceFile, sourceLine)};
+    const Descriptor *errMsg, const char *sourceFile, int sourceLine,
+    bool sourceIsDevice) {
+  int stat;
+  printf("%d\n", sourceIsDevice);
----------------
wangzpgi wrote:

Do we need this printf?

https://github.com/llvm/llvm-project/pull/171743


More information about the llvm-commits mailing list