-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[flang][cuda] Adding atomicadd as a cudadevice intrinsic and converting it LLVM dialect #123840
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,14 +44,14 @@ | |
| #include "flang/Runtime/iostat-consts.h" | ||
| #include "mlir/Dialect/Complex/IR/Complex.h" | ||
| #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
| #include "mlir/Dialect/LLVMIR/LLVMTypes.h" | ||
| #include "mlir/Dialect/Math/IR/Math.h" | ||
| #include "mlir/Dialect/Vector/IR/VectorOps.h" | ||
| #include "llvm/Support/CommandLine.h" | ||
| #include "llvm/Support/Debug.h" | ||
| #include "llvm/Support/MathExtras.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
| #include <cfenv> // temporary -- only used in genIeeeGetOrSetModesOrStatus | ||
| #include <mlir/IR/Value.h> | ||
| #include <optional> | ||
|
|
||
| #define DEBUG_TYPE "flang-lower-intrinsic" | ||
|
|
@@ -147,6 +147,10 @@ static constexpr IntrinsicHandler handlers[]{ | |
| {"atan2pi", &I::genAtanpi}, | ||
| {"atand", &I::genAtand}, | ||
| {"atanpi", &I::genAtanpi}, | ||
| {"atomicaddd", &I::genAtomAdd, {{{"addr", asAddr}, {"v", asValue}}}, false}, | ||
|
||
| {"atomicaddf", &I::genAtomAdd, {{{"addr", asAddr}, {"v", asValue}}}, false}, | ||
| {"atomicaddi", &I::genAtomAdd, {{{"addr", asAddr}, {"v", asValue}}}, false}, | ||
| {"atomicaddl", &I::genAtomAdd, {{{"addr", asAddr}, {"v", asValue}}}, false}, | ||
| {"bessel_jn", | ||
| &I::genBesselJn, | ||
| {{{"n1", asValue}, {"n2", asValue}, {"x", asValue}}}, | ||
|
|
@@ -2574,6 +2578,26 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, | |
| return builder.create<mlir::arith::MulFOp>(loc, atan, factor); | ||
| } | ||
|
|
||
| static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, | ||
| mlir::LLVM::AtomicBinOp binOp, mlir::Value arg0, | ||
| mlir::Value arg1) { | ||
| auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, do you now if FIR alias analysis is clever enough to go through convert from this LLVM type and deduce what the It makes sense to me that we interoperate with LLVM pointer type to avoid redefining all the intrinsics at the FIR level, I just wonder if we need to improve AA here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We always skip through I was trying to make sense of the MemoryEffects of We talked about these ops in the office hours today and while we need the hooks in place to create the appropriate instructions we may eventually replace them with higher level atomic operations. TDB.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, the effect description is not straightforward. If found this patch that explains some of it: feb7bea From what I understand, it is giving atomic operation a global write effects because the synchronization aspect (e.g., could write some global lock). |
||
| arg0 = builder.createConvert(loc, llvmPointerType, arg0); | ||
| return builder.create<mlir::LLVM::AtomicRMWOp>( | ||
| loc, binOp, arg0, arg1, mlir::LLVM::AtomicOrdering::seq_cst); | ||
| } | ||
|
|
||
| mlir::Value IntrinsicLibrary::genAtomAdd(mlir::Type resultType, | ||
| llvm::ArrayRef<mlir::Value> args) { | ||
| assert(args.size() == 2); | ||
|
|
||
| mlir::LLVM::AtomicBinOp binOp = | ||
| mlir::isa<mlir::IntegerType>(args[1].getType()) | ||
| ? mlir::LLVM::AtomicBinOp::add | ||
| : mlir::LLVM::AtomicBinOp::fadd; | ||
| return genAtomBinOp(builder, loc, binOp, args[0], args[1]); | ||
| } | ||
|
|
||
| // ASSOCIATED | ||
| fir::ExtendedValue | ||
| IntrinsicLibrary::genAssociated(mlir::Type resultType, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,5 +92,31 @@ attributes(device) subroutine threadfence_system() | |
| end function | ||
| end interface | ||
| public :: __fadd_ru | ||
|
|
||
| ! Atomic Operations | ||
|
|
||
| interface atomicadd | ||
| attributes(device) pure integer function atomicaddi(address, val) | ||
| !dir$ ignore_tkr (rd) address, (d) val | ||
|
||
| integer, intent(inout) :: address | ||
| integer, value :: val | ||
| end function | ||
| attributes(device) pure real function atomicaddf(address, val) | ||
| !dir$ ignore_tkr (rd) address, (d) val | ||
| real, intent(inout) :: address | ||
| real, value :: val | ||
| end function | ||
| attributes(device) pure real*8 function atomicaddd(address, val) | ||
| !dir$ ignore_tkr (rd) address, (d) val | ||
| real*8, intent(inout) :: address | ||
| real*8, value :: val | ||
| end function | ||
| attributes(device) pure integer(8) function atomicaddl(address, val) | ||
| !dir$ ignore_tkr (rd) address, (dk) val | ||
| integer(8), intent(inout) :: address | ||
| integer(8), value :: val | ||
| end function | ||
| end interface | ||
| public :: atomicadd | ||
|
|
||
| end module | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to truncate Atomic to Atom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting. It will make each line become 3 lines. I found it a lot less readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it fits here. Are you talking about about the implementation or in the table?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As someone that spending a lot of time grepping, I would much rather having the full "atomic" spelled at the cost of extra lines in the table.