Skip to content

Commit ac4f701

Browse files
committed
WIP: attempting to add an atomicadd intrinsinc
1 parent fec503d commit ac4f701

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ struct IntrinsicLibrary {
185185
mlir::Value genAnint(mlir::Type, llvm::ArrayRef<mlir::Value>);
186186
fir::ExtendedValue genAny(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
187187
mlir::Value genAtanpi(mlir::Type, llvm::ArrayRef<mlir::Value>);
188+
mlir::Value genAtomicAdd(mlir::Type, llvm::ArrayRef<mlir::Value>);
188189
fir::ExtendedValue
189190
genCommandArgumentCount(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
190191
mlir::Value genAsind(mlir::Type, llvm::ArrayRef<mlir::Value>);

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static constexpr IntrinsicHandler handlers[]{
147147
{"atan2pi", &I::genAtanpi},
148148
{"atand", &I::genAtand},
149149
{"atanpi", &I::genAtanpi},
150+
{"atomicaddd", &I::genAtomicAdd, {}, /*isElemental=*/false},
150151
{"bessel_jn",
151152
&I::genBesselJn,
152153
{{{"n1", asValue}, {"n2", asValue}, {"x", asValue}}},
@@ -2574,6 +2575,15 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType,
25742575
return builder.create<mlir::arith::MulFOp>(loc, atan, factor);
25752576
}
25762577

2578+
mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType,
2579+
llvm::ArrayRef<mlir::Value> args) {
2580+
assert(args.size() == 2);
2581+
llvm::errs() << "In genAtomicAdd\n";
2582+
return builder.create<mlir::LLVM::AtomicRMWOp>(
2583+
loc, mlir::LLVM::AtomicBinOp::add, args[0], args[1],
2584+
mlir::LLVM::AtomicOrdering::seq_cst);
2585+
}
2586+
25772587
// ASSOCIATED
25782588
fir::ExtendedValue
25792589
IntrinsicLibrary::genAssociated(mlir::Type resultType,

flang/module/cudadevice.f90

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,38 @@ attributes(device) subroutine threadfence_system()
9292
end function
9393
end interface
9494
public :: __fadd_ru
95-
95+
96+
interface
97+
attributes(device) real*8 function atomicaddd(address, val)
98+
real*8, intent(inout) :: address
99+
real*8 :: val
100+
end function
101+
end interface
102+
public :: atomicaddd
103+
104+
105+
!interface atomicadd
106+
! attributes(device) pure integer function atomicaddi(address, val)
107+
!!dir$ ignore_tkr (rd) address, (d) val
108+
! integer, intent(inout) :: address
109+
! integer, value :: val
110+
! end function
111+
! attributes(device) pure real function atomicaddf(address, val)
112+
!!dir$ ignore_tkr (rd) address, (d) val
113+
! real, intent(inout) :: address
114+
! real, value :: val
115+
! end function
116+
! attributes(device) pure real*8 function atomicaddd(address, val)
117+
!!dir$ ignore_tkr (rd) address, (d) val
118+
! real*8, intent(inout) :: address
119+
! real*8, value :: val
120+
! end function
121+
! attributes(device) pure integer(8) function atomicaddul(address, val)
122+
!!dir$ ignore_tkr (rd) address, (dk) val
123+
! integer(8), intent(inout) :: address
124+
! integer(8), value :: val
125+
! end function
126+
!end interface
127+
!public :: atomicadd
128+
96129
end module

0 commit comments

Comments
 (0)