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

[NNPA] AffineLoad and AffineStore from/to zTensor without zlow.stick and zlow.unstick #1983

Draft
wants to merge 58 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2239b27
zlow: add type constraints
tungld Dec 14, 2022
c560b21
initial test
tungld Dec 15, 2022
555955e
Use the pointer version
tungld Dec 16, 2022
5d38fc6
Merge branch 'main' into nnpa-compute-on-ztensor
tungld Dec 20, 2022
fbd1ce1
ONNXUnaryOp supports zTensor
tungld Dec 20, 2022
477b6fa
ONNXBinaryVariadicOp supports zTensor
tungld Dec 21, 2022
aa55856
Enable layout propagation
tungld Dec 21, 2022
b8d91ba
BinaryOp of ztensor and normal tensor
tungld Dec 22, 2022
592dcc1
COndition on f32
tungld Dec 22, 2022
2d215b6
minor change
tungld Dec 22, 2022
68d8e6f
update condition
tungld Dec 22, 2022
36221d5
fix affine map for 1D
tungld Dec 22, 2022
1ab9450
fix affine map for 2ds
tungld Dec 22, 2022
1721dff
undo affinemap for 1d and 2ds, since it's not the solution
tungld Dec 22, 2022
f62f505
do not support 1d and 2ds
tungld Dec 22, 2022
73348db
use malloc instead of alloca
tungld Dec 23, 2022
b2658d1
Reciprocal caused errors
tungld Jan 13, 2023
1894455
No use pointers
tungld Jan 16, 2023
6ed5a59
Merge branch 'main' into nnpa-compute-on-ztensor
tungld Jan 17, 2023
087f740
clang-format
tungld Jan 17, 2023
be9186f
fix OMShapeHelperOpInterface link issue
tungld Jan 17, 2023
aad619d
no unstick in layout propagation
tungld Jan 17, 2023
1159ece
Merge branch 'main' into nnpa-compute-on-ztensor
tungld Jan 26, 2023
696437a
Use LLVM code instead of calling external funcs
tungld Jan 27, 2023
137ffa6
Merge branch 'main' into nnpa-compute-on-ztensor
tungld Jan 27, 2023
ca3602a
clang-format
tungld Jan 27, 2023
d59b092
fix wrong instruction
tungld Jan 27, 2023
793e004
Use a separate pass at zlow instead of layout-prop at zhigh
tungld Jan 27, 2023
ebe7913
missing file
tungld Jan 27, 2023
94fa3f8
clean up
tungld Jan 27, 2023
f1169e6
clean up
tungld Jan 27, 2023
3002e2b
fix linking
tungld Jan 27, 2023
ebef21d
clean up
tungld Jan 27, 2023
e8290f4
Write a pattern on ZLowUnstickOp instead of AffineLoadOp
tungld Jan 29, 2023
bb8ba10
Generate LLVM code for fp32_to_dlf16
tungld Jan 30, 2023
0ec2319
Pattern to replace AffineStore
tungld Jan 30, 2023
56df83a
fix moving ops
tungld Jan 30, 2023
15672c8
Full LLVM code for dlf16 to f32
tungld Jan 31, 2023
50beddf
Correct result for dlf16-to-f32
tungld Jan 31, 2023
d2c133d
fix f32-to-dlf16
tungld Jan 31, 2023
a45bc7a
SIMD for dlf16 to f32
tungld Feb 1, 2023
e153430
update
tungld Feb 1, 2023
5a22e53
simd
tungld Feb 1, 2023
a10f3c4
Remove redundant code
tungld Feb 1, 2023
000780f
simd for f32 to dlf16
tungld Feb 1, 2023
db31c7e
clang-format
tungld Feb 1, 2023
4886062
rule to remove a pair of dlf16-f32
tungld Feb 1, 2023
3a82880
use 8 float16
tungld Feb 1, 2023
089164e
upperbound for memref size
tungld Feb 1, 2023
cb9676b
Merge branch 'main' into nnpa-compute-on-ztensor-simd
tungld Feb 2, 2023
f1707b9
Merge branch 'main' into nnpa-compute-on-ztensor-simd
tungld Feb 2, 2023
805b541
update to the new LLVM
tungld Feb 2, 2023
7c48949
merge
tungld Feb 2, 2023
a39103a
update submodule
tungld Feb 2, 2023
f53491e
Merge branch 'nnpa-compute-on-ztensor-simd' of github.com:tungld/onnx…
tungld Feb 2, 2023
9e35d43
merge and resolve conflict
tungld Feb 2, 2023
3b36e23
Merge branch 'nnpa-compute-on-ztensor-simd' into nnpa-compute-on-ztensor
tungld Feb 2, 2023
69f6ed4
Merge branch 'main' into nnpa-compute-on-ztensor
tungld Feb 2, 2023
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
7 changes: 6 additions & 1 deletion src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ void addPassesNNPA(mlir::OwningOpRef<mlir::ModuleOp> &module,
else {
// Partially lower Krnl ops to Affine dialect.
addKrnlToAffinePasses(pm);
// Replace zlow.stick, zlow.unstick by inserting dlf16 conversion
// directly into affine.for loops. This must be done before
// normalize-memrefs so that access indices are automatically generated.
pm.addPass(zlow::createZLowInsertDLF16ConversionPass());
pm.addPass(mlir::createCanonicalizerPass());
// Normalize MemRefs.
normalizeMemRefsPasses(pm);
// Some Knrl ops, e.g. KrnlMemset, potentially exist and will be lowered
// Some Krnl ops, e.g. KrnlMemset, potentially exist and will be lowered
// to Affine when its operands are normalized.
addKrnlToAffinePasses(pm);
// Optimizations at ZLow.
Expand Down
333 changes: 332 additions & 1 deletion src/Accelerators/NNPA/Conversion/ZLowToLLVM/ZLowToLLVM.cpp

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/Accelerators/NNPA/Conversion/ZLowToLLVM/ZLowToLLVMCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ namespace zlow {

ApiRegistry RegisterAllApis(MLIRContext *context) {
auto voidTy = LLVM::LLVMVoidType::get(context);
auto opaquePtrTy = LLVM::LLVMPointerType::get(IntegerType::get(context, 8));
auto int8Ty = IntegerType::get(context, 8);
auto int16Ty = IntegerType::get(context, 16);
auto int32Ty = IntegerType::get(context, 32);
auto int64Ty = IntegerType::get(context, 64);
auto float32Ty = FloatType::getF32(context);
auto opaquePtrTy = LLVM::LLVMPointerType::get(int8Ty);

// Declare API type as an enum value, its string name and an LLVM Type
// specifying its signature.
Expand Down Expand Up @@ -74,9 +77,13 @@ ApiRegistry RegisterAllApis(MLIRContext *context) {
ApiSpec(API::ZDNN_MATMUL_BCAST_OP, "zdnn_matmul_bcast_op", int32Ty, {opaquePtrTy, opaquePtrTy, opaquePtrTy, int64Ty, opaquePtrTy}, false),
ApiSpec(API::ZDNN_CONV2D, "zdnn_conv2d", int32Ty, {opaquePtrTy, opaquePtrTy, opaquePtrTy, int64Ty, int64Ty, int64Ty, int64Ty, opaquePtrTy, opaquePtrTy}, false),
ApiSpec(API::ZDNN_AVGPOOL2D, "zdnn_avgpool2d", int32Ty, {opaquePtrTy, int64Ty, int64Ty, int64Ty, int64Ty, int64Ty, opaquePtrTy}, false),
ApiSpec(API:: ZDNN_MAXPOOL2D, "zdnn_maxpool2d", int32Ty, {opaquePtrTy, int64Ty, int64Ty, int64Ty, int64Ty, int64Ty, opaquePtrTy}, false),
ApiSpec(API:: ZDNN_MEANREDUCE2D, "zdnn_meanreduce2d", int32Ty, {opaquePtrTy, opaquePtrTy}, false),
ApiSpec(API:: ZDNN_BATCHNORM, "zdnn_batchnorm", int32Ty, {opaquePtrTy, opaquePtrTy, opaquePtrTy, opaquePtrTy}, false),
ApiSpec(API::ZDNN_MAXPOOL2D, "zdnn_maxpool2d", int32Ty, {opaquePtrTy, int64Ty, int64Ty, int64Ty, int64Ty, int64Ty, opaquePtrTy}, false),
ApiSpec(API::ZDNN_MEANREDUCE2D, "zdnn_meanreduce2d", int32Ty, {opaquePtrTy, opaquePtrTy}, false),
ApiSpec(API::ZDNN_BATCHNORM, "zdnn_batchnorm", int32Ty, {opaquePtrTy, opaquePtrTy, opaquePtrTy, opaquePtrTy}, false),
// Scalar operations
// Note: these APIs are for testing purpose only.
ApiSpec(API::DLF16_TO_F32, "cnvt_1_dlf16_to_fp32", float32Ty, {int16Ty}, false),
ApiSpec(API::F32_TO_DLF16, "cnvt_1_fp32_to_dlf16", int16Ty, {float32Ty}, false),
};
// clang-format on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ enum class API {
ZDNN_AVGPOOL2D,
ZDNN_MAXPOOL2D,
ZDNN_MEANREDUCE2D,
ZDNN_BATCHNORM
ZDNN_BATCHNORM,
// Scalar operations.
DLF16_TO_F32,
F32_TO_DLF16,
};

// Obtain a zDNN API for an elementwise ZLow operation.
Expand Down
Loading