Skip to content

Commit d2f080f

Browse files
authored
[flang][cuda][openacc] Enable CUDA interop for use_device by default (#193058)
1 parent ca6f65a commit d2f080f

3 files changed

Lines changed: 20 additions & 24 deletions

File tree

flang/lib/Lower/OpenACC.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,8 @@ void AccDataMap::remapDataOperandSymbols(
18801880
llvm::cast<hlfir::DeclareOp>(*computeDef).setSkipRebox(true);
18811881

18821882
symbolMap.addVariableDefinition(
1883-
symbol, llvm::cast<fir::FortranVariableOpInterface>(computeDef));
1883+
symbol, llvm::cast<fir::FortranVariableOpInterface>(computeDef),
1884+
/*force=*/true);
18841885
}
18851886

18861887
for (const auto &comp : components) {
@@ -2966,10 +2967,10 @@ genACCHostDataOp(Fortran::lower::AbstractConverter &converter,
29662967

29672968
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
29682969

2969-
// When CUDA Fortran is enabled, extra symbols are created in the host_data
2970-
// scope for use_device objects. Bind them to the outer scope's symbols before
2971-
// processing any clauses, since the if clause may reference these symbols.
2972-
if (semanticsContext.IsEnabled(Fortran::common::LanguageFeature::CUDA)) {
2970+
// Extra symbols are created in the host_data scope for use_device objects.
2971+
// Bind them to the outer scope's symbols before processing any clauses,
2972+
// since the if clause may reference these symbols.
2973+
{
29732974
for (const Fortran::parser::AccClause &clause : accClauseList.v) {
29742975
if (const auto *useDevice =
29752976
std::get_if<Fortran::parser::AccClause::UseDevice>(&clause.u)) {
@@ -2981,13 +2982,7 @@ genACCHostDataOp(Fortran::lower::AbstractConverter &converter,
29812982
if (const auto *name =
29822983
Fortran::parser::GetDesignatorNameIfDataRef(*designator)) {
29832984
newSym = name->symbol;
2984-
} else if (const auto *arrayElement = Fortran::parser::Unwrap<
2985-
Fortran::parser::ArrayElement>(*designator)) {
2986-
const Fortran::parser::Name &name =
2987-
Fortran::parser::GetLastName(arrayElement->Base());
2988-
newSym = name.symbol;
2989-
} else if (Fortran::parser::Unwrap<
2990-
Fortran::parser::StructureComponent>(*designator)) {
2985+
} else {
29912986
newSym = Fortran::parser::GetFirstName(*designator).symbol;
29922987
}
29932988
} else if (const auto *name =

flang/lib/Semantics/resolve-names.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,25 +1612,26 @@ bool AccVisitor::Pre(const parser::OpenACCBlockConstruct &x) {
16121612
}
16131613

16141614
void AccVisitor::CopySymbolWithDevice(const parser::Name *name) {
1615-
// When CUDA Fortran is enabled together with OpenACC, new
1616-
// symbols are created for the one appearing in the use_device
1617-
// clause. These new symbols have the CUDA Fortran device
1618-
// attribute.
1619-
if (context_.languageFeatures().IsEnabled(common::LanguageFeature::CUDA) &&
1620-
name && name->symbol) {
1621-
if (Symbol * copy{currScope().CopySymbol(name->symbol->GetUltimate())}) {
1622-
name->symbol = copy;
1615+
// New symbols are created for those appearing in the use_device clause.
1616+
// These new symbols get the CUDA device attribute.
1617+
if (name && name->symbol) {
1618+
Symbol *copy{currScope().CopySymbol(name->symbol->GetUltimate())};
1619+
if (copy) {
16231620
if (auto *object{copy->GetUltimate().detailsIf<ObjectEntityDetails>()}) {
16241621
object->set_cudaDataAttr(common::CUDADataAttr::Device);
16251622
}
1623+
} else {
1624+
copy = FindInScope(currScope(), name->symbol->GetUltimate().name());
1625+
}
1626+
if (copy) {
1627+
name->symbol = copy;
16261628
}
16271629
}
16281630
}
16291631

16301632
void AccVisitor::CopySymbolWithDeviceStructurePath(const parser::Name *baseName,
16311633
llvm::ArrayRef<SourceName> componentPath, parser::Designator &designator) {
1632-
if (!context_.languageFeatures().IsEnabled(common::LanguageFeature::CUDA) ||
1633-
!baseName || !baseName->symbol || componentPath.empty()) {
1634+
if (!baseName || !baseName->symbol || componentPath.empty()) {
16341635
return;
16351636
}
16361637
const Symbol &orig{*baseName->symbol};

flang/test/Semantics/OpenACC/bug1583.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ subroutine sub (v)
1515
type(t) :: v
1616
!$acc host_data use_device(v%c)
1717
!DEF: /foo EXTERNAL (Subroutine) ProcEntity
18-
!REF: /m/sub/v
19-
!REF: /m/t/c
18+
!DEF:/m/sub/OpenACCConstruct1/vObjectEntityTYPE(t)
19+
!DEF:/m/sub/OpenACCConstruct1/DerivedType1/cALLOCATABLEObjectEntityREAL(4)
2020
call foo(v%c)
2121
!$acc end host_data
2222
end subroutine

0 commit comments

Comments
 (0)