Skip to content
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

[Do not merge] Test for investigating Jenkins test error in PR2917 #2941

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a589aa2
Add and use ConstantOpInterface for KrnlGlobalOps.
imaihal Aug 5, 2024
76e9dcb
Add and use ConstantOpInterface in lowering of KrnlGlobalOp to LLVMIR.
imaihal Aug 7, 2024
84c13c0
Initial implementation for NNPA.
imaihal Aug 19, 2024
42cb5a1
Update to handle stickifiedConstantOp initialized with zero
imaihal Aug 21, 2024
5ac7b1f
Update to free memory correctly
imaihal Aug 22, 2024
e8b935d
Clean up
imaihal Aug 23, 2024
82ada4e
Clean up
imaihal Aug 23, 2024
5dff7cf
Merge branch 'main' into mem_reduction_stickified
imaihal Aug 26, 2024
9c5dd88
format
imaihal Aug 26, 2024
2f23ff8
Merge branch 'main' into mem_reduction_stickified
imaihal Aug 26, 2024
7a5fb6d
Fix for lstm and gru.
imaihal Aug 27, 2024
fd82e47
Merge branch 'main' into mem_reduction_stickified
imaihal Aug 27, 2024
748517f
Fix the case totalsize is less than or equal to totalThreshold.
imaihal Aug 28, 2024
4cb46dd
Merge branch 'main' into mem_reduction_stickified
imaihal Aug 29, 2024
434272a
Fix the case without setting --store-constants-to-file option.
imaihal Aug 29, 2024
18b9919
Fix lit tests.
imaihal Aug 29, 2024
b99a334
Fix getBuffersize() for CategoryMapperOp
imaihal Aug 30, 2024
16773e7
Update attributes in ZHigh/ZLowStickfiedConstantOp.
imaihal Aug 30, 2024
9e236c9
Use stickified attribute and zeroconst attribute
imaihal Sep 2, 2024
56bc50d
Attribute name change: zeroconst to allzero
imaihal Sep 3, 2024
4f08bef
Update lit tests.
imaihal Sep 3, 2024
67d0f20
clean up.
imaihal Sep 3, 2024
dbf4c82
Add an option.
imaihal Sep 10, 2024
208020b
Merge branch 'main' into mem_reduction_stickified
imaihal Sep 11, 2024
ac37742
The option is true by default.
imaihal Sep 11, 2024
ad06734
Set the option false by default for testing.
imaihal Sep 12, 2024
5dcc2f7
Revert lit-tests for testing.
imaihal Sep 12, 2024
d18539e
Set false in store-constants-to-file for testing.
imaihal Sep 12, 2024
d87408e
Test
imaihal Sep 13, 2024
9b9d281
Do only backendtests
imaihal Sep 13, 2024
418ba11
Revert "Do only backendtests"
imaihal Sep 13, 2024
223ab65
Apply only krnl related part.
imaihal Sep 13, 2024
395c20b
format
imaihal Sep 13, 2024
4f0eb67
Do only backend-numerical tests
imaihal Sep 13, 2024
c98f56a
test change in typeconerter
imaihal Sep 13, 2024
b5cfaf8
Revert "Set the option false by default for testing."
imaihal Sep 13, 2024
f3f3b68
Revert "Revert lit-tests for testing."
imaihal Sep 13, 2024
6c5569e
Revert "Set false in store-constants-to-file for testing."
imaihal Sep 13, 2024
c62db4b
Fix using OpInterfaceConversionPattern
imaihal Sep 13, 2024
ff9dc6e
Only backend-dynamic test
imaihal Sep 14, 2024
25d1bf8
revert krnlops.
imaihal Sep 14, 2024
6eff47c
remove lit tests.
imaihal Sep 15, 2024
c6bd883
Test typeConverter.
imaihal Sep 15, 2024
06235e9
Test typeConverter.
imaihal Sep 16, 2024
5e8931a
typeConverter test.
imaihal Sep 17, 2024
1e4e156
Merge branch 'main' into mem_reduction_stickified
imaihal Sep 17, 2024
940ffd5
Merge branch 'mem_reduction_stickified' into test_mem_reduction_stick…
imaihal Sep 17, 2024
4f2d7a1
Disable ArithExpandPattern for testing.
imaihal Sep 18, 2024
1938e5f
Reduce tests.
imaihal Sep 18, 2024
42f045f
Change the order of conversion.
imaihal Sep 20, 2024
b8c7874
Test all backend tests.
imaihal Sep 20, 2024
04bf69f
Add krnlglobal
imaihal Sep 20, 2024
65043c0
Test O0
imaihal Sep 24, 2024
b39c35a
Test O0
imaihal Sep 24, 2024
cc96b4f
Test O3
imaihal Sep 24, 2024
f32f868
Test O0 again
imaihal Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docker/Dockerfile.onnx-mlir
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
-DCMAKE_INSTALL_MESSAGE=NEVER \
-DONNX_MLIR_ACCELERATORS=${ACCEL} .. \
&& make -j${NPROC} \
&& make -j${NPROC} LIT_OPTS=-v check-onnx-lit \
# && make -j${NPROC} LIT_OPTS=-v check-onnx-lit \
# FLOAT16 backend tests only work on ppc64le platform at the moment
&& TEST_NOFLOAT16=${TEST_NOFLOAT16:-$([ "$(uname -m)" = "s390x" ] && echo true || \
([ "$(uname -m)" = "x86_64" ] && echo true || \
Expand All @@ -57,16 +57,15 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
([ "$(uname -m)" = "x86_64" ] && echo || \
([ "$(uname -m)" = "ppc64le" ] && echo || echo)))} \
&& TEST_ARGS="-mcpu=${TEST_MCPU}" \
&& make check-docs \
&& make check-unittest \
&& make check-multiple-models \
&& make NPROC=${NPROC} \
CTEST_PARALLEL_LEVEL=${NPROC} \
TEST_NOFLOAT16=${TEST_NOFLOAT16} \
TEST_MCPU=${TEST_MCPU} \
TEST_ARGS="${TEST_ARGS}" \
TEST_CASE_BY_USER="test_min_float16_cpu test_max_float16_cpu" \
TEST_OPTLEVEL=0 \
-j${NPROC} \
check-onnx-backend-numerical \
check-onnx-backend-dynamic \
&& make -j${NPROC} install && ldconfig \
# Clean up
&& cd ${WORK_DIR} \
Expand Down
9 changes: 4 additions & 5 deletions docker/Dockerfile.onnx-mlir-dev
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
${ONNX_MLIR_ROOT}/utils/cppcheck_scan/cppcheck-scan.py; \
fi \
&& make -j${NPROC} \
&& make -j${NPROC} LIT_OPTS=-v check-onnx-lit \
# && make -j${NPROC} LIT_OPTS=-v check-onnx-lit \
# FLOAT16 backend tests only work on ppc64le platform at the moment
&& TEST_NOFLOAT16=${TEST_NOFLOAT16:-$([ "$(uname -m)" = "s390x" ] && echo true || \
([ "$(uname -m)" = "x86_64" ] && echo true || \
Expand All @@ -56,17 +56,16 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
([ "$(uname -m)" = "ppc64le" ] && echo || echo))) \
&& TEST_ARGS="-mcpu=${TEST_MCPU}" \
&& TEST_OPTLEVEL=0 \
&& make check-docs \
&& make check-unittest \
&& make check-multiple-models \
&& make NPROC=${NPROC} \
CTEST_PARALLEL_LEVEL=${NPROC} \
TEST_NOFLOAT16=${TEST_NOFLOAT16} \
TEST_MCPU=${TEST_MCPU} \
TEST_ARGS="${TEST_ARGS}" \
TEST_OPTLEVEL=${TEST_OPTLEVEL} \
TEST_CASE_BY_USER="test_min_float16_cpu test_max_float16_cpu" \
TEST_OPTLEVEL=0 \
-j${NPROC} \
check-onnx-backend-numerical \
check-onnx-backend-dynamic \
&& rm -f Debug/bin/*Test Debug/bin/Perf* Debug/bin/Test* \
# When building for push event to publish the image, unshallow and
# rename origin to upstream to make the repo a bit more dev friendly.
Expand Down
6 changes: 6 additions & 0 deletions src/Accelerators/NNPA/Compiler/NNPACompilerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ llvm::cl::opt<bool> nnpaEnableSaturation("nnpa-saturation",
"Default is false."),
llvm::cl::init(false), llvm::cl::cat(OnnxMlirCommonOptions));

llvm::cl::opt<bool> nnpaDelayStickifiedConstGen(
"nnpa-delay-stickified-const-generation",
llvm::cl::desc(
"Generate stickified constants when storing constants to file. This "
"will be able to reduce peak memory usage. Default is true."),
llvm::cl::init(true), llvm::cl::cat(OnnxMlirCommonOptions));
} // namespace onnx_mlir
1 change: 1 addition & 0 deletions src/Accelerators/NNPA/Compiler/NNPACompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern llvm::cl::opt<bool> profileZHighIR;
extern llvm::cl::opt<std::string> nnpaLoadDevicePlacementFile;
extern llvm::cl::opt<std::string> nnpaSaveDevicePlacementFile;
extern llvm::cl::opt<bool> nnpaEnableSaturation;
extern llvm::cl::opt<bool> nnpaDelayStickifiedConstGen;

} // namespace onnx_mlir
#endif
119 changes: 73 additions & 46 deletions src/Accelerators/NNPA/Conversion/ZHighToZLow/ZHighToZLow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "src/Accelerators/NNPA/Pass/NNPAPasses.hpp"
#include "src/Accelerators/NNPA/Support/LayoutHelper.hpp"
#include "src/Accelerators/NNPA/Support/Stickify/Convert.hpp"
#include "src/Compiler/CompilerOptions.hpp"
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp"
#include "src/Dialect/Krnl/KrnlHelper.hpp"
#include "src/Support/TypeUtilities.hpp"
Expand Down Expand Up @@ -193,25 +194,30 @@ Value insertAllocOrEmitZeroConstant(ArrayRef<IndexExpr> dims,
ZHighStickifiedConstantOp stickifiedConstant =
rewriter.create<ZHighStickifiedConstantOp>(loc, resType,
/*value=*/nullptr,
/*stickified=*/nullptr,
/*allzero=*/rewriter.getBoolAttr(true),
/*alignment=*/rewriter.getI64IntegerAttr(4096));

// Use an dense resource attribute to store stickified data.
// Attribute type: tensor<sizeInBytes x i8>
int64_t sizeInBytes =
affine::getIntOrFloatMemRefSizeInBytes(resType).value();
char *rawData = static_cast<char *>(malloc(sizeInBytes));
assert(rawData && "failed to allocate memory for stickified data");
memset(rawData, 0, sizeInBytes);
DenseResourceElementsAttr valueAttr = DenseUI8ResourceElementsAttr::get(
RankedTensorType::get({sizeInBytes}, rewriter.getI8Type()),
stickifiedConstant.getOperation()
->getDialect()
->getNamespace(), // use the dialect as the blob "hint"
HeapAsmResourceBlob::allocateAndCopyWithAlign(
llvm::ArrayRef(rawData, sizeInBytes), alignof(char)));
stickifiedConstant.setValueAttr(valueAttr);
free(rawData);

// Set all zero in value attribute here, except when stickified constants
// are generated at the time constants are stored to file.
if (!(storeConstantsToFile && nnpaDelayStickifiedConstGen)) {
// Use an dense resource attribute to store stickified data.
// Attribute type: tensor<sizeInBytes x i8>
int64_t sizeInBytes =
affine::getIntOrFloatMemRefSizeInBytes(resType).value();
char *rawData = static_cast<char *>(malloc(sizeInBytes));
assert(rawData && "failed to allocate memory for stickified data");
memset(rawData, 0, sizeInBytes);
DenseResourceElementsAttr valueAttr = DenseUI8ResourceElementsAttr::get(
RankedTensorType::get({sizeInBytes}, rewriter.getI8Type()),
stickifiedConstant.getOperation()
->getDialect()
->getNamespace(), // use the dialect as the blob "hint"
HeapAsmResourceBlob::allocateAndCopyWithAlign(
llvm::ArrayRef(rawData, sizeInBytes), alignof(char)));
stickifiedConstant.setValueAttr(valueAttr);
free(rawData);
}
res = stickifiedConstant.getResult();
} else {
MultiDialectBuilder<KrnlBuilder, MathBuilder> create(rewriter, loc);
Expand Down Expand Up @@ -686,7 +692,7 @@ struct ZHighToZLowUnstickOpLowering : public ConversionPattern {
};

//===----------------------------------------------------------------------===//
// Lower ZHigh Stickified Constant to KrnlGlobal
// Lower ZHigh Stickified Constant to ZLow Stickified Constant
//===----------------------------------------------------------------------===//

struct ZHighToZLowStickifiedConstantOpLowering : public ConversionPattern {
Expand All @@ -699,7 +705,7 @@ struct ZHighToZLowStickifiedConstantOpLowering : public ConversionPattern {
LogicalResult matchAndRewrite(Operation *op, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const final {
Location loc = op->getLoc();
ZHighStickifiedConstantOp stickifiedConstOp =
ZHighStickifiedConstantOp zhighStickifiedConstOp =
llvm::dyn_cast<ZHighStickifiedConstantOp>(op);

// Convert ZTensor type to MemRefType.
Expand All @@ -713,36 +719,57 @@ struct ZHighToZLowStickifiedConstantOpLowering : public ConversionPattern {
affine::normalizeMemRefType(mlir::cast<MemRefType>(zMemRefType.value));
ArrayRef<int64_t> normalizedShape = normalizedType.getShape();

// Get dense resource attribute.
auto blob = mlir::cast<DenseResourceElementsAttr>(
stickifiedConstOp.getValue().value())
.getRawHandle()
.getBlob();
assert(blob && "Expecting dense resource with a valid blob");
ArrayRef<char> data = blob->getData();

// Validate the stickified tensor.
int64_t memRefSizeInBytes = getMemRefEltSizeInBytes(normalizedType);
memRefSizeInBytes *= normalizedType.getNumElements();
assert((data.size() == static_cast<uint64_t>(memRefSizeInBytes)) &&
"The stickified tensor's buffer size and MemRef's size mismatched");

// Create a KrnlGlobalOp.
KrnlGlobalOp constantGlobal =
rewriter.create<KrnlGlobalOp>(loc, zMemRefType.value,
/*shape=*/
rewriter.getI64ArrayAttr(normalizedShape),
/*name=*/
rewriter.getStringAttr(
"constant_stickify_" + std::to_string(constantID)),
/*value=*/stickifiedConstOp.getValueAttr(),
/*offset=*/nullptr,
/*alignment=*/stickifiedConstOp.getAlignmentAttr());

// When generating stickified constants when storing constants to file,
// create ZLowStickifiedConstantOp. Otherwise, create KrnlGlobalOp.
Value result;
if (storeConstantsToFile && nnpaDelayStickifiedConstGen) {
// Create a ZLowStickifiedConstantOp.
ZLowStickifiedConstantOp constantOp =
rewriter.create<ZLowStickifiedConstantOp>(loc,
mlir::cast<MemRefType>(zMemRefType.value),
/*shape=*/
rewriter.getI64ArrayAttr(normalizedShape),
/*value=*/zhighStickifiedConstOp.getValueAttr(),
/*name=*/
rewriter.getStringAttr(
"constant_stickify_" + std::to_string(constantID)),
/*stickified=*/zhighStickifiedConstOp.getStickifiedAttr(),
/*allzero=*/zhighStickifiedConstOp.getAllzeroAttr(),
/*offset=*/rewriter.getI64IntegerAttr(0),
/*alignment=*/zhighStickifiedConstOp.getAlignmentAttr());
result = constantOp.getResult();
} else {
// Get dense resource attribute.
auto blob = mlir::cast<DenseResourceElementsAttr>(
zhighStickifiedConstOp.getValue().value())
.getRawHandle()
.getBlob();
assert(blob && "Expecting dense resource with a valid blob");
ArrayRef<char> data = blob->getData();

// Validate the stickified tensor.
int64_t memRefSizeInBytes = getMemRefEltSizeInBytes(normalizedType);
memRefSizeInBytes *= normalizedType.getNumElements();
assert(
(data.size() == static_cast<uint64_t>(memRefSizeInBytes)) &&
"The stickified tensor's buffer size and MemRef's size mismatched");
// Create a KrnlGlobalOp.
KrnlGlobalOp constantOp =
rewriter.create<KrnlGlobalOp>(loc, zMemRefType.value,
/*shape=*/
rewriter.getI64ArrayAttr(normalizedShape),
/*name=*/
rewriter.getStringAttr(
"constant_stickify_" + std::to_string(constantID)),
/*value=*/zhighStickifiedConstOp.getValueAttr(),
/*offset=*/nullptr,
/*alignment=*/zhighStickifiedConstOp.getAlignmentAttr());
result = constantOp.getResult();
}
// Increment constant ID:
constantID++;

rewriter.replaceOp(op, constantGlobal.getResult());
rewriter.replaceOp(op, result);
return success();
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/Accelerators/NNPA/Dialect/ZHigh/ZHigh.td
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ def ZHighStickifiedConstantOp:ZHigh_Op<"StickifiedConstant", [Pure]> {
the output tensor's size.
}];
let arguments = (ins OptionalAttr<AnyAttr>:$value,
OptionalAttr<BoolAttr>:$stickified,
OptionalAttr<BoolAttr>:$allzero,
DefaultValuedAttr<I64Attr, "4096">:$alignment);
let results = (outs AnyZTensor:$output);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Accelerators/NNPA/Dialect/ZLow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ add_onnx_mlir_library(OMZLowOps
DEPENDS
OMZLowIncGen
OMONNXZLowCombineIncGen
OMConstantOpInterface

LINK_LIBS PUBLIC
MLIRIR
MLIRMemRefTransforms
OMMlirDialects
OMLayoutHelper
OMStickify
OMZHighOps

ACCEL_INCLUDE_DIRS PRIVATE
${NNPA_INCLUDE_PATH}
)
18 changes: 18 additions & 0 deletions src/Accelerators/NNPA/Dialect/ZLow/ZLow.td
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def ZMemRef : MemRefOf<[DLF16]>;
//===----------------------------------------------------------------------===//

include "mlir/Interfaces/SideEffectInterfaces.td"
include "src/Interface/ConstantOpInterface.td"

def ZLowAddOp:ZLow_Op<"add", [MemRefsNormalizable,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
Expand Down Expand Up @@ -547,4 +548,21 @@ def ZLowConvertF32ToDLF16VectorOp:ZLow_Op<"vec_f32_to_dlf16", [Pure]> {
];
}

def ZLowStickifiedConstantOp:ZLow_Op<"stickifiedConstant", [MemRefsNormalizable,
DeclareOpInterfaceMethods<ConstantOpInterface>]> {
// def ZLowStickifiedConstantOp:ZLow_Op<"stickifiedConstant", [MemRefsNormalizable]> {
let summary = "ZLow Stickified Constant operation";
let description = [{

}];
let arguments = (ins AnyAttr:$shape,
OptionalAttr<AnyAttr>:$value,
StrAttr:$name,
OptionalAttr<BoolAttr>:$stickified,
OptionalAttr<BoolAttr>:$allzero,
OptionalAttr<I64Attr>:$offset,
DefaultValuedAttr<I64Attr, "4096">:$alignment);
let results = (outs ZMemRef:$output);
}

#endif // ZLOW_OPS
Loading
Loading