Skip to content

[flang][cuda] Support corner case of data transfer #132451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions flang-rt/lib/cuda/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "flang/Runtime/CUDA/memory.h"
#include "flang-rt/runtime/assign-impl.h"
#include "flang-rt/runtime/descriptor.h"
#include "flang-rt/runtime/terminator.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/CUDA/descriptor.h"
Expand Down Expand Up @@ -98,8 +99,21 @@ void RTDECL(CUFDataTransferDescDesc)(Descriptor *dstDesc, Descriptor *srcDesc,
} else {
terminator.Crash("host to host copy not supported");
}
Fortran::runtime::Assign(
*dstDesc, *srcDesc, terminator, MaybeReallocate, memmoveFct);
if ((srcDesc->rank() > 0) && (dstDesc->Elements() < srcDesc->Elements())) {
// Special case when rhs is bigger than lhs and both are contiguous arrays.
// In this case we do a simple ptr to ptr transfer with the size of lhs.
// This is be allowed in the reference compiler and it avoids error
// triggered in the Assign runtime function used for the main case below.
if (!srcDesc->IsContiguous() || !dstDesc->IsContiguous())
terminator.Crash("Unsupported data transfer: mismatching element counts "
"with non-contiguous arrays");
RTNAME(CUFDataTransferPtrPtr)(dstDesc->raw().base_addr,
srcDesc->raw().base_addr, dstDesc->Elements() * dstDesc->ElementBytes(),
mode, sourceFile, sourceLine);
} else {
Fortran::runtime::Assign(
*dstDesc, *srcDesc, terminator, MaybeReallocate, memmoveFct);
}
}

void RTDECL(CUFDataTransferCstDesc)(Descriptor *dstDesc, Descriptor *srcDesc,
Expand Down