Skip to content

Commit

Permalink
Revert the place of cl option
Browse files Browse the repository at this point in the history
  • Loading branch information
lialan committed Dec 13, 2024
1 parent 647af24 commit 8588cfd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
3 changes: 1 addition & 2 deletions compiler/src/iree/compiler/Codegen/Common/EncodingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ static RankedTensorType transposeIfNarrowNResult(RankedTensorType tensorType) {
}
auto newEncoding = IREE::Encoding::EncodingAttr::get(
context, operandIndex, encoding.getOpType().getValue(),
encoding.getElementTypesArray(), maps, newBcastMap, newRoundDimsTo,
encoding.getLayouts());
encoding.getElementTypesArray(), maps, newBcastMap, newRoundDimsTo);
return RankedTensorType::get(newShape, elemType, newEncoding);
}

Expand Down
29 changes: 3 additions & 26 deletions compiler/src/iree/compiler/DispatchCreation/SetEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenAttrs.h"
#include "iree/compiler/Dialect/Encoding/IR/EncodingDialect.h"
#include "iree/compiler/Dialect/Encoding/IR/EncodingOps.h"
#include "iree/compiler/Dialect/Encoding/IR/EncodingTypes.h"
#include "iree/compiler/Dialect/Flow/IR/FlowDialect.h"
#include "iree/compiler/Dialect/Flow/IR/FlowOps.h"
#include "iree/compiler/Dialect/Flow/Transforms/RegionOpUtils.h"
Expand All @@ -26,13 +25,6 @@
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

llvm::cl::opt<bool> clEnableI1Support(
"iree-experimental-packed-i1-storage",
llvm::cl::desc(
"Experimental feature: use packed storage for i1 tensors. This feature "
"can be dropped once the frontend can emit packed i1 tensors."),
llvm::cl::init(false));

#define DEBUG_TYPE "iree-dispatch-creation-set-encoding"

namespace mlir::iree_compiler::DispatchCreation {
Expand All @@ -46,13 +38,6 @@ using IREE::Encoding::PackedStorageAttr;
// Utility functions
//===---------------------------------------------------------------------===//

static std::optional<Attribute> getI1PackedStorageAttr(MLIRContext *context) {
if (clEnableI1Support) {
return PackedStorageAttr::get(context);
}
return {};
}

Value setEncoding(OpBuilder &builder, Location loc, Value source,
EncodingAttr encodingAttr) {
auto sourceType = cast<RankedTensorType>(source.getType());
Expand Down Expand Up @@ -232,17 +217,9 @@ class setContractionOpEncoding
if (narrowDim.isN()) {
roundDimsTo[1] = llvm::PowerOf2Ceil(narrowDim.size);
}
// This is a temporary solution that we can use
// `--iree-experimental-packed-i1-storage` to enable packed storage for i1
// tensors without specifying attributes.
auto optI1PackedStorageAttr =
getI1PackedStorageAttr(rewriter.getContext());
auto layouts = optI1PackedStorageAttr
? ArrayRef<Attribute>(*optI1PackedStorageAttr)
: ArrayRef<Attribute>{};
auto encoding = EncodingAttr::get(
linalgOp.getContext(), operandIndex, opType, elemTypes, maps,
/*bcastMap=*/std::nullopt, roundDimsTo, layouts);
auto encoding = EncodingAttr::get(linalgOp.getContext(), operandIndex,
opType, elemTypes, maps,
/*bcastMap=*/std::nullopt, roundDimsTo);
return setEncoding(rewriter, loc, src, encoding);
};
Value encodedLhs = setEncodingWrapper(lhs, IREE::Encoding::MATMUL_LHS);
Expand Down
11 changes: 8 additions & 3 deletions compiler/src/iree/compiler/Utils/ElementPackingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/IR/BuiltinTypes.h"

llvm::cl::opt<bool> clEnableI1Support(
"iree-experimental-packed-i1-storage",
llvm::cl::desc(
"Experimental feature: use packed storage for i1 tensors. This feature "
"can be dropped once the frontend can emit packed i1 tensors."),
llvm::cl::init(false));

namespace mlir::iree_compiler {

bool needToPackSubByteElementBitWidth(unsigned bitWidth,
Expand Down Expand Up @@ -114,9 +121,7 @@ Value calculateStorageElementOffsetInBytes(Location loc,
Type alignedElementType =
legalizeStorageElementType(originalType.getElementType());
unsigned elementBits = IREE::Util::getTypeBitWidth(alignedElementType);

auto encoding = IREE::Encoding::getEncodingAttr(originalType);
bool isI1PackedStorage = encoding && encoding.i1PackedStorage();
bool isI1PackedStorage = IREE::Encoding::hasPackedStorageAttr(originalType);

// Sub-byte packing requires putting multiple elements in the same byte.
if (needToPackSubByteElementBitWidth(elementBits, isI1PackedStorage)) {
Expand Down

0 comments on commit 8588cfd

Please sign in to comment.