diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..9b3aa8b72 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: LLVM diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 000000000..de154eac8 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,23 @@ +name: clang-format + +on: + pull_request: + branches: + - main + +jobs: + clang-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v2 + with: + python-version: "3.12" + - name: Install dependencies + run: | + pip install clang-format==20.1.8 ripgrep==14.1.0 + - name: Running clang-format + run: | + rg . --type cpp --type c --files-with-matches \ + | xargs clang-format --dry-run --Werror \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4a6e3b4cc..544caa81f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ compile_commands.json build/* .vscode/* -/.clang-format -test_core.py -test_annotations.py +/python/examples/test_core.py +/python/examples/test_annotations.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 414e40783..7ae68d382 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,15 +27,12 @@ if (TRITON_SHARED_BUILD_CPU_BACKEND) target_link_libraries(TritonShared PRIVATE Python3::Module pybind11::headers) endif() -# Add symlinks to selected pytest files and the clang-format setting in triton. The tests are imported into triton-shared’s test folder to -# run under triton-shared's conftest configuration, and the clang-format link ensures consistent code style enforcement across both repositories. +# Add symlinks to selected pytest files in triton. The tests are imported into triton-shared’s test folder to +# run under triton-shared's conftest configuration. cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "python" "examples" "test_core.py" OUTPUT_VARIABLE TRITON_SHARED_TEST_CORE) cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "python" "examples" "test_annotations.py" OUTPUT_VARIABLE TRITON_SHARED_TEST_ANNOTATIONS) -cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR ".clang-format" OUTPUT_VARIABLE TRITON_SHARED_CLANG_FORMAT_SETTING) cmake_path(APPEND CMAKE_SOURCE_DIR "python" "test" "unit" "language" "test_core.py" OUTPUT_VARIABLE TRITON_TEST_CORE) cmake_path(APPEND CMAKE_SOURCE_DIR "python" "test" "unit" "language" "test_annotations.py" OUTPUT_VARIABLE TRITON_TEST_ANNOTATIONS) -cmake_path(APPEND CMAKE_SOURCE_DIR ".clang-format" OUTPUT_VARIABLE TRITON_CLANG_FORMAT_SETTING) add_symlink(${TRITON_TEST_CORE} ${TRITON_SHARED_TEST_CORE}) add_symlink(${TRITON_TEST_ANNOTATIONS} ${TRITON_SHARED_TEST_ANNOTATIONS}) -add_symlink(${TRITON_CLANG_FORMAT_SETTING} ${TRITON_SHARED_CLANG_FORMAT_SETTING}) \ No newline at end of file diff --git a/backend/include/ExecutionEngine/CRunnerUtils.cpp b/backend/include/ExecutionEngine/CRunnerUtils.cpp index 48e2afbf5..87e47027f 100644 --- a/backend/include/ExecutionEngine/CRunnerUtils.cpp +++ b/backend/include/ExecutionEngine/CRunnerUtils.cpp @@ -16,7 +16,7 @@ #include "Msan.h" #ifndef _WIN32 -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__DragonFly__) #include #else @@ -37,10 +37,7 @@ #ifdef MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS namespace { -template -void stdSort(uint64_t n, V *p) { - std::sort(p, p + n); -} +template void stdSort(uint64_t n, V *p) { std::sort(p, p + n); } } // namespace diff --git a/backend/include/ExecutionEngine/CRunnerUtils.h b/backend/include/ExecutionEngine/CRunnerUtils.h index 76b04145b..1e55ca923 100644 --- a/backend/include/ExecutionEngine/CRunnerUtils.h +++ b/backend/include/ExecutionEngine/CRunnerUtils.h @@ -50,11 +50,9 @@ constexpr unsigned nextPowerOf2(int n) { return (n <= 1) ? 1 : (isPowerOf2(n) ? n : (2 * nextPowerOf2((n + 1) / 2))); } -template -struct Vector1D; +template struct Vector1D; -template -struct Vector1D { +template struct Vector1D { Vector1D() { static_assert(detail::nextPowerOf2(sizeof(T[Dim])) == sizeof(T[Dim]), "size error"); @@ -68,8 +66,7 @@ struct Vector1D { // 1-D vector, padded to the next power of 2 allocation. // Specialization occurs to avoid zero size arrays (which fail in -Werror). -template -struct Vector1D { +template struct Vector1D { Vector1D() { static_assert(nextPowerOf2(sizeof(T[Dim])) > sizeof(T[Dim]), "size error"); static_assert(nextPowerOf2(sizeof(T[Dim])) < 2 * sizeof(T[Dim]), @@ -86,8 +83,7 @@ struct Vector1D { } // namespace mlir // N-D vectors recurse down to 1-D. -template -struct Vector { +template struct Vector { inline Vector &operator[](unsigned i) { return vector[i]; } inline const Vector &operator[](unsigned i) const { return vector[i]; @@ -105,17 +101,14 @@ struct Vector mlir::detail::isPowerOf2(sizeof(T[Dim]))> { }; -template -using Vector1D = Vector; -template -using Vector2D = Vector; +template using Vector1D = Vector; +template using Vector2D = Vector; template using Vector3D = Vector; template using Vector4D = Vector; -template -void dropFront(int64_t arr[N], int64_t *res) { +template void dropFront(int64_t arr[N], int64_t *res) { for (unsigned i = 1; i < N; ++i) *(res + i - 1) = arr[i]; } @@ -123,12 +116,10 @@ void dropFront(int64_t arr[N], int64_t *res) { //===----------------------------------------------------------------------===// // Codegen-compatible structures for StridedMemRef type. //===----------------------------------------------------------------------===// -template -class StridedMemrefIterator; +template class StridedMemrefIterator; /// StridedMemRef descriptor type with static rank. -template -struct StridedMemRefType { +template struct StridedMemRefType { T *basePtr; T *data; int64_t offset; @@ -165,8 +156,7 @@ struct StridedMemRefType { }; /// StridedMemRef descriptor type specialized for rank 1. -template -struct StridedMemRefType { +template struct StridedMemRefType { T *basePtr; T *data; int64_t offset; @@ -188,8 +178,7 @@ struct StridedMemRefType { }; /// StridedMemRef descriptor type specialized for rank 0. -template -struct StridedMemRefType { +template struct StridedMemRefType { T *basePtr; T *data; int64_t offset; @@ -207,8 +196,7 @@ struct StridedMemRefType { }; /// Iterate over all elements in a strided memref. -template -class StridedMemrefIterator { +template class StridedMemrefIterator { public: using iterator_category = std::forward_iterator_tag; using value_type = T; @@ -261,8 +249,7 @@ class StridedMemrefIterator { }; /// Iterate over all elements in a 0-ranked strided memref. -template -class StridedMemrefIterator { +template class StridedMemrefIterator { public: using iterator_category = std::forward_iterator_tag; using value_type = T; @@ -307,8 +294,7 @@ class StridedMemrefIterator { // Codegen-compatible structure for UnrankedMemRef type. //===----------------------------------------------------------------------===// // Unranked MemRef -template -struct UnrankedMemRefType { +template struct UnrankedMemRefType { int64_t rank; void *descriptor; }; @@ -316,12 +302,10 @@ struct UnrankedMemRefType { //===----------------------------------------------------------------------===// // DynamicMemRefType type. //===----------------------------------------------------------------------===// -template -class DynamicMemRefIterator; +template class DynamicMemRefIterator; // A reference to one of the StridedMemRef types. -template -class DynamicMemRefType { +template class DynamicMemRefType { public: int64_t rank; T *basePtr; @@ -388,8 +372,7 @@ class DynamicMemRefType { }; /// Iterate over all elements in a dynamic memref. -template -class DynamicMemRefIterator { +template class DynamicMemRefIterator { public: using iterator_category = std::forward_iterator_tag; using value_type = T; diff --git a/include/triton-shared/Analysis/MaskAnalysis.h b/include/triton-shared/Analysis/MaskAnalysis.h index 3dd1c6e93..8a8f131f3 100644 --- a/include/triton-shared/Analysis/MaskAnalysis.h +++ b/include/triton-shared/Analysis/MaskAnalysis.h @@ -90,8 +90,9 @@ struct MaskState { LogicalResult addStates(const MaskState &lhsState, const MaskState &rhsState, Location loc, OpBuilder &builder); - LogicalResult minStateScalar(const MaskState &lhsState, const MaskState &rhsState, - Location loc, OpBuilder &builder); + LogicalResult minStateScalar(const MaskState &lhsState, + const MaskState &rhsState, Location loc, + OpBuilder &builder); LogicalResult minStates(const MaskState &lhsState, const MaskState &rhsState, Location loc, OpBuilder &builder); diff --git a/include/triton-shared/AnalysisStructured/PtrAnalysis.h b/include/triton-shared/AnalysisStructured/PtrAnalysis.h index a0e670e6d..b1791aa98 100644 --- a/include/triton-shared/AnalysisStructured/PtrAnalysis.h +++ b/include/triton-shared/AnalysisStructured/PtrAnalysis.h @@ -46,9 +46,9 @@ const extern std::string ptrAnalysisAttr; // address, it will be collapsed to 1D. To support gather/scatter access, treat // the unstructured offset as a whole offset instead of decoding the pointer // arithmetic on it except scalar mul. -// The stride is set to 1 when there's no scalar mul so it still matches the offset * -// stride formula. When there're scalar muls, the stride is set to the multiplication -// of all the scalar strides. +// The stride is set to 1 when there's no scalar mul so it still matches the +// offset * stride formula. When there're scalar muls, the stride is set to the +// multiplication of all the scalar strides. struct PtrState { SmallVector offsets; SmallVector sizes; @@ -321,14 +321,16 @@ class PtrAnalysis { // Operand is the result of tt.int_to_ptr. // Expected result: // Directly grab op result - LogicalResult visitOperandIntToPtr(triton::IntToPtrOp intToPtrOp, PtrState &state, - const Location loc, OpBuilder &builder); + LogicalResult visitOperandIntToPtr(triton::IntToPtrOp intToPtrOp, + PtrState &state, const Location loc, + OpBuilder &builder); // Operand is the result of tt.bitcast. // Expected result: // Directly grab op result - LogicalResult visitOperandBitcast(triton::BitcastOp bitcastOp, PtrState &state, - const Location loc, OpBuilder &builder); + LogicalResult visitOperandBitcast(triton::BitcastOp bitcastOp, + PtrState &state, const Location loc, + OpBuilder &builder); // Get the computed PtrState for the forOp's init-arg at the provided index. FailureOr getLoopInitArgPtrState(scf::ForOp forOp, size_t index); diff --git a/include/triton-shared/Conversion/TritonArithToLinalg/ConversionPatterns.hpp b/include/triton-shared/Conversion/TritonArithToLinalg/ConversionPatterns.hpp index b1ebf1f51..1d9244dfe 100644 --- a/include/triton-shared/Conversion/TritonArithToLinalg/ConversionPatterns.hpp +++ b/include/triton-shared/Conversion/TritonArithToLinalg/ConversionPatterns.hpp @@ -813,40 +813,40 @@ struct AssertConverter : public OpConversionPattern { Value condVal = op.getCondition(); auto assertMessage = - llvm::formatv("Assertion `{0}` failed", op.getMessage()); - - // The condition can only be I1 or I1Tensor (integer or tensor) from TritonOps.td. - // Tensors will always be RankedTensorType. + llvm::formatv("Assertion `{0}` failed", op.getMessage()); + + // The condition can only be I1 or I1Tensor (integer or tensor) from + // TritonOps.td. Tensors will always be RankedTensorType. if (isa(condVal.getType())) { // handle scalar case rewriter.create(op.getLoc(), condVal, assertMessage.str()); - } else if (auto tensorType = dyn_cast(condVal.getType())) { + } else if (auto tensorType = + dyn_cast(condVal.getType())) { // handle tensor case int64_t rank = tensorType.getRank(); // create identity mapping for access pattern - SmallVector indexingMaps{AffineMap::getMultiDimIdentityMap(rank, rewriter.getContext())}; + SmallVector indexingMaps{ + AffineMap::getMultiDimIdentityMap(rank, rewriter.getContext())}; // loops do not depend on each other - SmallVector iteratorTypes(rank, utils::IteratorType::parallel); + SmallVector iteratorTypes( + rank, utils::IteratorType::parallel); rewriter.create( - op.getLoc(), - TypeRange{}, - condVal, - ValueRange{}, - ArrayRef{indexingMaps}, - ArrayRef{iteratorTypes}, - [&](OpBuilder &b, Location loc, ValueRange args) { - // obtain the element in the tensor - Value element = args[0]; - - // make a cf.assert for the current element - b.create(loc, element, assertMessage.str()); - - b.create(loc); - }); + op.getLoc(), TypeRange{}, condVal, ValueRange{}, + ArrayRef{indexingMaps}, + ArrayRef{iteratorTypes}, + [&](OpBuilder &b, Location loc, ValueRange args) { + // obtain the element in the tensor + Value element = args[0]; + + // make a cf.assert for the current element + b.create(loc, element, assertMessage.str()); + + b.create(loc); + }); } else { op.emitError("Unexpected type in triton::AssertOp"); return failure(); diff --git a/include/triton-shared/Conversion/TritonArithToLinalg/ConversionTools.h b/include/triton-shared/Conversion/TritonArithToLinalg/ConversionTools.h index 6d7c00e47..b3b42c196 100644 --- a/include/triton-shared/Conversion/TritonArithToLinalg/ConversionTools.h +++ b/include/triton-shared/Conversion/TritonArithToLinalg/ConversionTools.h @@ -6,7 +6,8 @@ namespace mlir { namespace triton { -static inline SmallVector getNParallelLoopsAttrs(unsigned n) { +static inline SmallVector +getNParallelLoopsAttrs(unsigned n) { return SmallVector(n, utils::IteratorType::parallel); } diff --git a/include/triton-shared/Conversion/TritonToLinalgExperimental/Passes.h b/include/triton-shared/Conversion/TritonToLinalgExperimental/Passes.h index d983afa86..5aa650a22 100644 --- a/include/triton-shared/Conversion/TritonToLinalgExperimental/Passes.h +++ b/include/triton-shared/Conversion/TritonToLinalgExperimental/Passes.h @@ -8,10 +8,10 @@ #ifndef TRITON_TO_LINALG_EXPERIMENTAL_CONVERSION_PASSES_H #define TRITON_TO_LINALG_EXPERIMENTAL_CONVERSION_PASSES_H -#include "triton-shared/Conversion/TritonToLinalgExperimental/TritonToLinalgExperimental.h" +#include "triton-shared/Conversion/TritonToLinalgExperimental/CollapseShape.h" #include "triton-shared/Conversion/TritonToLinalgExperimental/ReconcilePtrCasts.h" +#include "triton-shared/Conversion/TritonToLinalgExperimental/TritonToLinalgExperimental.h" #include "triton-shared/Conversion/TritonToLinalgExperimental/TritonToPtr.h" -#include "triton-shared/Conversion/TritonToLinalgExperimental/CollapseShape.h" namespace mlir { namespace triton { diff --git a/include/triton-shared/Transform/AddLLVMDebugInfo/AddLLVMDebugInfo.h b/include/triton-shared/Transform/AddLLVMDebugInfo/AddLLVMDebugInfo.h index 20ab01fee..e350e8a6f 100644 --- a/include/triton-shared/Transform/AddLLVMDebugInfo/AddLLVMDebugInfo.h +++ b/include/triton-shared/Transform/AddLLVMDebugInfo/AddLLVMDebugInfo.h @@ -20,7 +20,6 @@ namespace triton { std::unique_ptr> createAddLLVMDebugInfoPass(); - } // namespace triton } // namespace mlir diff --git a/include/triton-shared/Utils/Utils.h b/include/triton-shared/Utils/Utils.h index aadccf1d0..e484beee3 100644 --- a/include/triton-shared/Utils/Utils.h +++ b/include/triton-shared/Utils/Utils.h @@ -5,7 +5,8 @@ namespace mlir { namespace triton { -// Return true if the input type is a triton pointer or a tensor of triton pointers +// Return true if the input type is a triton pointer or a tensor of triton +// pointers bool isPtrTypeLike(Type t); } // namespace triton diff --git a/lib/Analysis/OpFoldResultUtils.cpp b/lib/Analysis/OpFoldResultUtils.cpp index 3eb132f90..49ae4c448 100644 --- a/lib/Analysis/OpFoldResultUtils.cpp +++ b/lib/Analysis/OpFoldResultUtils.cpp @@ -355,7 +355,8 @@ OpFoldResult selectOFRs(const OpFoldResult condOFR, const OpFoldResult trueOFR, auto trueValue = ofrToIndexValue(trueOFR, loc, b); auto falseValue = ofrToIndexValue(falseOFR, loc, b); auto condValue = ofrToValue(condOFR, loc, b); - assert(condValue.getType().isInteger(1) && "Condition for selectOp must be a bool type"); + assert(condValue.getType().isInteger(1) && + "Condition for selectOp must be a bool type"); auto selectOp = b.create(loc, condValue, trueValue, falseValue); diff --git a/lib/AnalysisStructured/PtrAnalysis.cpp b/lib/AnalysisStructured/PtrAnalysis.cpp index cbb9c9168..8afda6e96 100644 --- a/lib/AnalysisStructured/PtrAnalysis.cpp +++ b/lib/AnalysisStructured/PtrAnalysis.cpp @@ -284,13 +284,13 @@ LogicalResult PtrState::addState(const PtrState &lhsState, } if (lhsStride == rhsStride) { - // For case like lhs_offset * stride + rhs_offset * stride, it is same as - // (lhs_offset + rhs_offset) * stride. - // We can just - // add the offsets and reuse the stride like this: + // For case like lhs_offset * stride + rhs_offset * stride, it is + // same as (lhs_offset + rhs_offset) * stride. We can just add the + // offsets and reuse the stride like this: // offsets[i] = lhsOffset + rhsOffset // strides[i] = lhsStride - // Expand structured offset since unstructured offset has tensor type. + // Expand structured offset since unstructured offset has tensor + // type. if (!lhsState.dimIsStructured(i)) { rhsOffset = expandOFRIndex(rhsOffset, lhsOffset, loc, builder); } else { @@ -306,10 +306,9 @@ LogicalResult PtrState::addState(const PtrState &lhsState, // equal to 1 earlier for case both offsets and strides not equal. assert(lhsOffset == rhsOffset && "If strides are not equal, offsets must be equal"); - // For case like offset * lhs_stride + offset * rhs_stride, it is same as - // offset * (lhs_stride + rhs_stride). - // We can just - // add the strides and reuse the offset like this: + // For case like offset * lhs_stride + offset * rhs_stride, it is + // same as offset * (lhs_stride + rhs_stride). We can just add the + // strides and reuse the offset like this: // offsets[i] = lhsOffset // strides[i] = lhsStride + rhsStride diff --git a/lib/Conversion/StructuredToMemref/StructuredToMemref.cpp b/lib/Conversion/StructuredToMemref/StructuredToMemref.cpp index 30fd93edd..cfec5b3c1 100644 --- a/lib/Conversion/StructuredToMemref/StructuredToMemref.cpp +++ b/lib/Conversion/StructuredToMemref/StructuredToMemref.cpp @@ -105,9 +105,9 @@ static MemRefType getResultMemrefType(tts::MakeGatherScatterTensorPtrOp op, // If there are dimensions with size 1 and stride 0, replace 0 stride with // the product of sizes of all lower dimensions. This avoids creating memref // with zero stride. -template -llvm::SmallVector -getMixedStridesForMemref(OpType op, OpBuilder &b) { +template +llvm::SmallVector getMixedStridesForMemref(OpType op, + OpBuilder &b) { llvm::SmallVector strides; auto accumulate = 1; for (auto [size, stride] : @@ -140,10 +140,9 @@ static OpFoldResult accumulateTargetOffset(Location loc, static OpFoldResult accumulateTargetOffset(Location loc, ArrayRef offsets, ArrayRef strides, - int gatherDim, - OpBuilder &b) { + int gatherDim, OpBuilder &b) { OpFoldResult targetOffset = b.getIndexAttr(0); - for (int i=0;i { } LogicalResult rewriteGather(tts::MakeGatherScatterTensorPtrOp ptr, - tts::LoadOp op, Value memRefPtr, - ConversionPatternRewriter &rewriter) const { + tts::LoadOp op, Value memRefPtr, + ConversionPatternRewriter &rewriter) const { auto loc = op.getLoc(); Value gatherOffset = ptr.getGatherScatterOffset(); @@ -871,7 +870,8 @@ struct LoadConverter : public OpConversionPattern { // Create loop to iterate every offset in gatherOffset. auto lowerBound = rewriter.create(loc, 0); - Value upperBound = rewriter.create(loc, offsetSize).getResult(); + Value upperBound = + rewriter.create(loc, offsetSize).getResult(); if (op.hasMask()) { SmallVector mixedDims = op.getMixedMaskDims(); OpFoldResult gatherMaskDim = mixedDims[gatherDim]; @@ -883,15 +883,18 @@ struct LoadConverter : public OpConversionPattern { // If the gather mask dimension is a constant, we can use it directly. unsigned gatherMaskDimValue = gatherMaskDimIndex.value(); offsetSize = std::min(offsetSize, gatherMaskDimValue); - upperBound = rewriter.create(loc, offsetSize).getResult(); + upperBound = rewriter.create(loc, offsetSize) + .getResult(); } else { // Use arith::MinSIOp to get the minimum value of gatherMaskDim // and offsetSize. auto gatherMaskDimVal = cast(gatherMaskDim); auto offsetSizeVal = rewriter.create(loc, offsetSize); - upperBound = rewriter.create(loc, gatherMaskDimVal, - offsetSizeVal).getResult(); + upperBound = + rewriter + .create(loc, gatherMaskDimVal, offsetSizeVal) + .getResult(); } } auto step = rewriter.create(loc, 1); @@ -991,9 +994,8 @@ struct StoreConverter : public OpConversionPattern { } LogicalResult rewriteScatter(tts::MakeGatherScatterTensorPtrOp ptr, - tts::StoreOp op, Value memRefPtr, - Value stVal, - ConversionPatternRewriter &rewriter) const { + tts::StoreOp op, Value memRefPtr, Value stVal, + ConversionPatternRewriter &rewriter) const { auto loc = op.getLoc(); Value gatherOffset = ptr.getGatherScatterOffset(); @@ -1018,7 +1020,8 @@ struct StoreConverter : public OpConversionPattern { // Create loop to iterate every offset in gatherOffset. auto lowerBound = rewriter.create(loc, 0); - Value upperBound = rewriter.create(loc, offsetSize).getResult(); + Value upperBound = + rewriter.create(loc, offsetSize).getResult(); if (op.hasMask()) { SmallVector mixedDims = op.getMixedMaskDims(); OpFoldResult gatherMaskDim = mixedDims[gatherDim]; @@ -1030,15 +1033,18 @@ struct StoreConverter : public OpConversionPattern { // If the gather mask dimension is a constant, we can use it directly. unsigned gatherMaskDimValue = gatherMaskDimIndex.value(); offsetSize = std::min(offsetSize, gatherMaskDimValue); - upperBound = rewriter.create(loc, offsetSize).getResult(); + upperBound = rewriter.create(loc, offsetSize) + .getResult(); } else { // Use arith::MinSIOp to get the minimum value of gatherMaskDim // and offsetSize. auto gatherMaskDimVal = cast(gatherMaskDim); auto offsetSizeVal = rewriter.create(loc, offsetSize); - upperBound = rewriter.create(loc, gatherMaskDimVal, - offsetSizeVal).getResult(); + upperBound = + rewriter + .create(loc, gatherMaskDimVal, offsetSizeVal) + .getResult(); } } auto step = rewriter.create(loc, 1); @@ -1110,8 +1116,7 @@ struct StoreConverter : public OpConversionPattern { if (auto gatherScatterPtr = op.getPtr().getDefiningOp()) { return rewriteScatter(gatherScatterPtr, op, adaptor.getPtr(), - adaptor.getValue(), - rewriter); + adaptor.getValue(), rewriter); } auto ptr = adaptor.getPtr(); diff --git a/lib/Conversion/StructuredToMemref/StructuredToMemrefPass.cpp b/lib/Conversion/StructuredToMemref/StructuredToMemrefPass.cpp index 8d5c5b19b..c0d4cd0a2 100644 --- a/lib/Conversion/StructuredToMemref/StructuredToMemrefPass.cpp +++ b/lib/Conversion/StructuredToMemref/StructuredToMemrefPass.cpp @@ -50,15 +50,13 @@ class PtrToUnrankedMemrefConverter : public TypeConverter { }); addTargetMaterialization([&](OpBuilder &builder, UnrankedMemRefType resultType, - ValueRange inputs, - Location loc) -> Value { + ValueRange inputs, Location loc) -> Value { return builder.create(loc, resultType, inputs) .getResult(0); }); addSourceMaterialization([&](OpBuilder &builder, Type resultType, - ValueRange inputs, - Location loc) -> Value { + ValueRange inputs, Location loc) -> Value { return builder.create(loc, resultType, inputs) .getResult(0); }); diff --git a/lib/Conversion/TritonPtrToMemref/TritonPtrToMemrefPass.cpp b/lib/Conversion/TritonPtrToMemref/TritonPtrToMemrefPass.cpp index d84ab5906..b75e7ddb4 100644 --- a/lib/Conversion/TritonPtrToMemref/TritonPtrToMemrefPass.cpp +++ b/lib/Conversion/TritonPtrToMemref/TritonPtrToMemrefPass.cpp @@ -60,8 +60,7 @@ class TritonFunctionSignatureConverter : public TypeConverter { }); auto createUnrealizedCast = [&](OpBuilder &builder, Type resultType, - ValueRange inputs, - Location loc) -> Value { + ValueRange inputs, Location loc) -> Value { return builder.create(loc, resultType, inputs) .getResult(0); }; diff --git a/lib/Conversion/TritonToLinalgExperimental/TritonToLinalgExperimentalPass.cpp b/lib/Conversion/TritonToLinalgExperimental/TritonToLinalgExperimentalPass.cpp index ceb677102..dbfb27495 100644 --- a/lib/Conversion/TritonToLinalgExperimental/TritonToLinalgExperimentalPass.cpp +++ b/lib/Conversion/TritonToLinalgExperimental/TritonToLinalgExperimentalPass.cpp @@ -53,8 +53,7 @@ class TritonToLinalgExperimentalPass auto moduleOp = getOperation(); PassManager pm(&getContext(), moduleOp.getOperationName()); - pm.addPass(createTritonToStructuredPass( - enableMakeGatherScatterTensorPtr)); + pm.addPass(createTritonToStructuredPass(enableMakeGatherScatterTensorPtr)); // Erase dead code and fold constants created during lowering pm.addPass(createCSEPass()); diff --git a/lib/Dialect/TPtr/IR/TPtrOps.cpp b/lib/Dialect/TPtr/IR/TPtrOps.cpp index 930fda370..dad589ea8 100644 --- a/lib/Dialect/TPtr/IR/TPtrOps.cpp +++ b/lib/Dialect/TPtr/IR/TPtrOps.cpp @@ -1,14 +1,14 @@ -#include "mlir/Interfaces/SideEffectInterfaces.h" // Required for IR/TPtrOps.h.inc #include "mlir/Bytecode/BytecodeOpInterface.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" // Required for IR/TPtrOps.h.inc -#include "mlir/IR/OpImplementation.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/Dialect.h" #include "mlir/IR/MLIRContext.h" -#include "mlir/IR/OperationSupport.h" #include "mlir/IR/OpDefinition.h" -#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpImplementation.h" +#include "mlir/IR/OperationSupport.h" #include "mlir/Dialect/Ptr/IR/PtrDialect.h" #include "mlir/Dialect/Ptr/IR/PtrTypes.h" diff --git a/lib/Dialect/TritonStructured/IR/TritonStructuredOps.cpp b/lib/Dialect/TritonStructured/IR/TritonStructuredOps.cpp index 129db34a4..4f22e5a5c 100644 --- a/lib/Dialect/TritonStructured/IR/TritonStructuredOps.cpp +++ b/lib/Dialect/TritonStructured/IR/TritonStructuredOps.cpp @@ -132,10 +132,11 @@ void MakeTensorPtrOp::build(OpBuilder &b, OperationState &state, Value base, } void MakeGatherScatterTensorPtrOp::build(OpBuilder &b, OperationState &state, - Value base, Value gatherScatterOffset, - int gatherScatterDim, ArrayRef sizes, - ArrayRef strides, - ArrayRef offsets) { + Value base, Value gatherScatterOffset, + int gatherScatterDim, + ArrayRef sizes, + ArrayRef strides, + ArrayRef offsets) { SmallVector staticStrides, staticOffsets; SmallVector dynamicStrides, dynamicOffsets; for (auto [i, offset] : llvm::enumerate(offsets)) { diff --git a/lib/Dialect/TritonTilingExt/IR/BufferizableOpInterfaceImpl.cpp b/lib/Dialect/TritonTilingExt/IR/BufferizableOpInterfaceImpl.cpp index eaa8b722f..d98d763f2 100644 --- a/lib/Dialect/TritonTilingExt/IR/BufferizableOpInterfaceImpl.cpp +++ b/lib/Dialect/TritonTilingExt/IR/BufferizableOpInterfaceImpl.cpp @@ -36,8 +36,7 @@ namespace { /// Generic conversion for any DestinationStyleOpInterface on tensors. static LogicalResult bufferizeTritonTilingExtDestinationStyleOpInterface( RewriterBase &rewriter, DestinationStyleOpInterface op, - const BufferizationOptions &options, - BufferizationState &state) { + const BufferizationOptions &options, BufferizationState &state) { // Take a guard before anything else. OpBuilder::InsertionGuard g(rewriter); rewriter.setInsertionPoint(op); @@ -59,7 +58,8 @@ static LogicalResult bufferizeTritonTilingExtDestinationStyleOpInterface( newInputBuffers.push_back(opOperand->get()); continue; } - FailureOr buffer = getBuffer(rewriter, opOperand->get(), options, state); + FailureOr buffer = + getBuffer(rewriter, opOperand->get(), options, state); if (failed(buffer)) return failure(); newInputBuffers.push_back(*buffer); diff --git a/lib/Sanitizer/SanitizerAttributes/SanitizerAttributes.cpp b/lib/Sanitizer/SanitizerAttributes/SanitizerAttributes.cpp index a22af6e3a..a13ed5199 100644 --- a/lib/Sanitizer/SanitizerAttributes/SanitizerAttributes.cpp +++ b/lib/Sanitizer/SanitizerAttributes/SanitizerAttributes.cpp @@ -1,20 +1,20 @@ #include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassPlugin.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; namespace opts { // command line option for the type of sanitizer -static cl::opt SanitizerType( - "sanitizer-type", - cl::desc("Type of sanitizer being used: AddressSanitizer = asan, ThreadSanitizer = tsan"), - cl::value_desc("string") -); +static cl::opt + SanitizerType("sanitizer-type", + cl::desc("Type of sanitizer being used: AddressSanitizer = " + "asan, ThreadSanitizer = tsan"), + cl::value_desc("string")); -} +} // namespace opts namespace { @@ -26,7 +26,7 @@ struct SanitizerAttributes : PassInfoMixin { } else if (opts::SanitizerType == "tsan") { F.addFnAttr(Attribute::SanitizeThread); } - + // this pass modifies all function attributes return PreservedAnalyses::none(); } diff --git a/lib/Transform/AddLLVMDebugInfo/AddLLVMDebugInfoPass.cpp b/lib/Transform/AddLLVMDebugInfo/AddLLVMDebugInfoPass.cpp index 45474ff73..c01356bd0 100644 --- a/lib/Transform/AddLLVMDebugInfo/AddLLVMDebugInfoPass.cpp +++ b/lib/Transform/AddLLVMDebugInfo/AddLLVMDebugInfoPass.cpp @@ -33,7 +33,8 @@ class AddLLVMDebugInfoPass : public AddLLVMDebugInfoBase { subprogramFlags = subprogramFlags | LLVM::DISubprogramFlags::Optimized; } if (funcOp.getSymNameAttr() == "main") { - subprogramFlags = subprogramFlags | LLVM::DISubprogramFlags::MainSubprogram; + subprogramFlags = + subprogramFlags | LLVM::DISubprogramFlags::MainSubprogram; } return subprogramFlags; @@ -63,35 +64,38 @@ class AddLLVMDebugInfoPass : public AddLLVMDebugInfoBase { Location loc = funcOp.getLoc(); if (auto funcLoc = dyn_cast(loc)) { fileName = llvm::sys::path::filename(funcLoc.getFilename().getValue()); - filePath = llvm::sys::path::parent_path(funcLoc.getFilename().getValue()); + filePath = + llvm::sys::path::parent_path(funcLoc.getFilename().getValue()); line = funcLoc.getLine(); col = funcLoc.getColumn(); } else { - // the triton frontend should always provide a FileLineColLoc for the kernel - // if this loc is a different type, error out + // the triton frontend should always provide a FileLineColLoc for the + // kernel if this loc is a different type, error out moduleOp->emitError("invalid #loc attributes for pass ") << this->getName().str(); return signalPassFailure(); } // initialize useful attributes - LLVM::DIFileAttr fileAttr = LLVM::DIFileAttr::get(context, fileName, filePath); + LLVM::DIFileAttr fileAttr = + LLVM::DIFileAttr::get(context, fileName, filePath); StringAttr producer = StringAttr::get(context, "MLIR"); LLVM::DICompileUnitAttr cuAttr = LLVM::DICompileUnitAttr::get( - DistinctAttr::create(UnitAttr::get(context)), - llvm::dwarf::getLanguage("DW_LANG_Python"), fileAttr, producer, - isOptimized, emissionKind); + DistinctAttr::create(UnitAttr::get(context)), + llvm::dwarf::getLanguage("DW_LANG_Python"), fileAttr, producer, + isOptimized, emissionKind); // get subroutine types llvm::SmallVector types; // create subroutine type attribute from return and argument types unsigned callingConvention = llvm::dwarf::DW_CC_normal; - LLVM::DISubroutineTypeAttr type = LLVM::DISubroutineTypeAttr::get(context, callingConvention, types); - + LLVM::DISubroutineTypeAttr type = + LLVM::DISubroutineTypeAttr::get(context, callingConvention, types); + // set flags - LLVM::DISubprogramFlags subprogramFlags = setSubprogramFlags(funcOp); - + LLVM::DISubprogramFlags subprogramFlags = setSubprogramFlags(funcOp); + // retained nodes llvm::ArrayRef importedModules; @@ -100,21 +104,14 @@ class AddLLVMDebugInfoPass : public AddLLVMDebugInfoBase { // initialize DI attribute for function LLVM::DISubprogramAttr spAttr = LLVM::DISubprogramAttr::get( - context, - DistinctAttr::create(UnitAttr::get(context)), - cuAttr, - fileAttr, // scope - funcOp.getSymNameAttr(), - funcOp.getSymNameAttr(), // linkage name - fileAttr, - line, - col, // scope line - subprogramFlags, - type, - importedModules, - annotations - ); - + context, DistinctAttr::create(UnitAttr::get(context)), cuAttr, + fileAttr, // scope + funcOp.getSymNameAttr(), + funcOp.getSymNameAttr(), // linkage name + fileAttr, line, + col, // scope line + subprogramFlags, type, importedModules, annotations); + // annotate function funcOp->setLoc(builder.getFusedLoc({loc}, spAttr)); }); diff --git a/tools/triton-shared-opt/triton-shared-opt.cpp b/tools/triton-shared-opt/triton-shared-opt.cpp index 837c158d7..3ed831de9 100644 --- a/tools/triton-shared-opt/triton-shared-opt.cpp +++ b/tools/triton-shared-opt/triton-shared-opt.cpp @@ -13,6 +13,6 @@ int main(int argc, char **argv) { mlir::DialectRegistry registry; registerTritonSharedDialects(registry); - return mlir::asMainReturnCode(mlir::MlirOptMain( - argc, argv, "Triton-Shared test driver\n", registry)); + return mlir::asMainReturnCode( + mlir::MlirOptMain(argc, argv, "Triton-Shared test driver\n", registry)); }