-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[aievec] Move common utility code to library (1/N)
There are several utility functions that don't have a proper place in which to live. Some of them are defined as "inline" in a header, and one of them is duplicated in two source files. This patch creates an AIEVecUtils library specifically for these, and starts the migration process by moving the duplicated function to this library.
- Loading branch information
Showing
7 changed files
with
175 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===- Utils.h - Utilities to support AIE vectorization ---------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// (c) Copyright 2023, Advanced Micro Devices, Inc. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef AIE_DIALECT_AIEVEC_UTILS_UTILS_H | ||
#define AIE_DIALECT_AIEVEC_UTILS_UTILS_H | ||
|
||
#include "mlir/Dialect/Vector/IR/VectorOps.h" | ||
#include <cstdint> | ||
#include <type_traits> | ||
|
||
namespace mlir { | ||
|
||
class AffineExpr; | ||
class AffineForOp; | ||
class AffineMap; | ||
|
||
} // namespace mlir | ||
|
||
namespace xilinx::aievec { | ||
|
||
template < | ||
typename TransferReadLikeOp, | ||
typename = std::enable_if_t< | ||
std::is_same_v<TransferReadLikeOp, mlir::vector::TransferReadOp> || | ||
std::is_same_v<TransferReadLikeOp, | ||
mlir::vector::TransferReadOp::Adaptor>>> | ||
int64_t getTransferReadAlignmentOffset(TransferReadLikeOp readOp, | ||
mlir::VectorType vType, | ||
int64_t alignment); | ||
|
||
} | ||
|
||
#endif // AIE_DIALECT_AIEVEC_UTILS_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
|
||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) | ||
add_subdirectory(Utils) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# (c) Copyright 2023, Advanced Micro Devices, Inc. | ||
# | ||
|
||
add_mlir_dialect_library(MLIRAIEVecUtils | ||
Utils.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/aie/Dialect/AIEVec | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRAIEVec | ||
MLIRAffineDialect | ||
MLIRAffineAnalysis | ||
MLIRAffineUtils | ||
MLIRArithDialect | ||
MLIRFuncDialect | ||
MLIRIR | ||
MLIRVectorDialect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===- Utils.cpp - Utilities to support AIE vectorization -----------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// (c) Copyright 2023, Advanced Micro Devices, Inc. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements utilities for the AIEVec dialect | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "aie/Dialect/AIEVec/Utils/Utils.h" | ||
#include "mlir/Dialect/Affine/IR/AffineOps.h" | ||
#include "mlir/Dialect/Arith/IR/Arith.h" | ||
#include "mlir/Dialect/Vector/IR/VectorOps.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
#include "llvm/Support/Debug.h" | ||
#include <optional> | ||
|
||
#define DEBUG_TYPE "aievec-utils" | ||
|
||
using namespace mlir; | ||
|
||
namespace xilinx::aievec { | ||
// Return the offset of a given transfer read operation with regards to the | ||
// specified vector type. If the read is aligned to the specified alignment | ||
// parameter (in bits), then the offset is 0. Otherwise, the offset is the | ||
// number of elements past the immediately preceding aligned vector length. | ||
template <typename TransferReadLikeOp, typename> | ||
int64_t getTransferReadAlignmentOffset(TransferReadLikeOp readOp, | ||
VectorType vType, int64_t alignment) { | ||
// TODO: Add support for cases where the index is not comming from an | ||
// TODO: `affine.apply` op or when the affine map has more than one | ||
// TODO: dimension. We also need to address the case where the index is an | ||
// TODO: induction variable. | ||
auto innerMostIndex = readOp.getIndices().back(); | ||
auto vectorLength = vType.getShape().back(); | ||
auto idxDefOp = innerMostIndex.getDefiningOp(); | ||
if (!idxDefOp) | ||
return 0L; | ||
int64_t vectorLengthAlignmentOffset = | ||
TypeSwitch<Operation *, int64_t>(idxDefOp) | ||
.Case<arith::ConstantOp>([&](auto constantOp) { | ||
return cast<IntegerAttr>(constantOp.getValue()).getInt() % | ||
vectorLength; | ||
}) | ||
.template Case<AffineApplyOp>([&](auto applyOp) { | ||
if (applyOp.getAffineMap().getNumDims() == 1) | ||
return applyOp.getAffineMap().compose(ArrayRef<int64_t>{0})[0] % | ||
vectorLength; | ||
return 0L; | ||
}) | ||
.Default([&](auto) { | ||
// XXX: If we can't determine the offset, we assume the access is | ||
// XXX: aligned. | ||
return 0L; | ||
}); | ||
int64_t absoluteAlignmentOffset = alignment / vType.getElementTypeBitWidth(); | ||
if (vectorLengthAlignmentOffset % absoluteAlignmentOffset) | ||
return vectorLengthAlignmentOffset; | ||
return 0; | ||
} | ||
|
||
template int64_t getTransferReadAlignmentOffset(vector::TransferReadOp readOp, | ||
VectorType vType, | ||
int64_t alignment); | ||
template int64_t | ||
getTransferReadAlignmentOffset(vector::TransferReadOp::Adaptor readOp, | ||
VectorType vType, int64_t alignment); | ||
|
||
} // namespace xilinx::aievec |