-
Notifications
You must be signed in to change notification settings - Fork 14.3k
mlir/MathExtras: consolidate with llvm/MathExtras #95087
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 all commits
3fdbdf6
10c979a
3006125
19960b7
a70c51d
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
#include "mlir/IR/SymbolTable.h" | ||
#include "mlir/Interfaces/InferTypeOpInterface.h" | ||
#include "mlir/Interfaces/SideEffectInterfaces.h" | ||
#include "mlir/Support/MathExtras.h" | ||
#include "llvm/Support/MathExtras.h" | ||
|
||
namespace mlir { | ||
namespace mesh { | ||
|
@@ -114,7 +114,7 @@ inline int64_t shardDimension(int64_t dimSize, int64_t shardCount) { | |
return ShapedType::kDynamic; | ||
|
||
assert(dimSize % shardCount == 0); | ||
return ceilDiv(dimSize, shardCount); | ||
return llvm::divideCeilSigned(dimSize, shardCount); | ||
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. Using divideCeil here doesn't make sense because the preceding assert ensures that the division is exact, so this is equivalent to a normal division. |
||
} | ||
|
||
// Get the size of an unsharded dimension. | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMTypes.h" | ||
#include "mlir/IR/Builders.h" | ||
#include "mlir/Support/MathExtras.h" | ||
#include "llvm/Support/MathExtras.h" | ||
|
||
using namespace mlir; | ||
|
||
|
@@ -363,9 +363,9 @@ void UnrankedMemRefDescriptor::computeSizes( | |
// Initialize shared constants. | ||
Value one = createIndexAttrConstant(builder, loc, indexType, 1); | ||
Value two = createIndexAttrConstant(builder, loc, indexType, 2); | ||
Value indexSize = | ||
createIndexAttrConstant(builder, loc, indexType, | ||
ceilDiv(typeConverter.getIndexTypeBitwidth(), 8)); | ||
Value indexSize = createIndexAttrConstant( | ||
builder, loc, indexType, | ||
llvm::divideCeilSigned(typeConverter.getIndexTypeBitwidth(), 8)); | ||
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. It looks like this used signed division by accident -- both quantities here are unsigned. |
||
|
||
sizes.reserve(sizes.size() + values.size()); | ||
for (auto [desc, addressSpace] : llvm::zip(values, addressSpaces)) { | ||
|
@@ -378,7 +378,8 @@ void UnrankedMemRefDescriptor::computeSizes( | |
// to data layout) into the unranked descriptor. | ||
Value pointerSize = createIndexAttrConstant( | ||
builder, loc, indexType, | ||
ceilDiv(typeConverter.getPointerBitwidth(addressSpace), 8)); | ||
llvm::divideCeilSigned(typeConverter.getPointerBitwidth(addressSpace), | ||
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. Same here. |
||
8)); | ||
Value doublePointerSize = | ||
builder.create<LLVM::MulOp>(loc, indexType, two, pointerSize); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,8 @@ | |
#include "mlir/IR/BuiltinTypes.h" | ||
#include "mlir/IR/IRMapping.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Support/MathExtras.h" | ||
#include "llvm/ADT/SmallBitVector.h" | ||
#include "llvm/Support/MathExtras.h" | ||
#include <optional> | ||
|
||
namespace mlir { | ||
|
@@ -971,8 +971,8 @@ struct MemorySpaceCastOpLowering | |
resultUnderlyingDesc, resultElemPtrType); | ||
|
||
int64_t bytesToSkip = | ||
2 * | ||
ceilDiv(getTypeConverter()->getPointerBitwidth(resultAddrSpace), 8); | ||
2 * llvm::divideCeilSigned( | ||
getTypeConverter()->getPointerBitwidth(resultAddrSpace), 8); | ||
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. Here as well, this should use the unsigned variant. |
||
Value bytesToSkipConst = rewriter.create<LLVM::ConstantOp>( | ||
loc, getIndexType(), rewriter.getIndexAttr(bytesToSkip)); | ||
Value copySize = rewriter.create<LLVM::SubOp>( | ||
|
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.
Orthogonal to this change, but I think it would be good to template these functions in a follow-up. I think we have many places where we're upcasting unsigned to uint64_t to make use of these, and especially for divisions performing it in a larger width can be much more expensive.
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.
Yes, I was planning to do that in a follow-up.