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

Bit optim #1

Merged
merged 71 commits into from
May 30, 2023
Merged

Bit optim #1

merged 71 commits into from
May 30, 2023

Conversation

yuxwang99
Copy link
Collaborator

Merge bits optimization passes into main

Copy link
Member

@lucas-rami lucas-rami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

I've done a sort-of superficial review and will take a closer look at everything soon. In the meantime you can start addressing the comments that are already there. Most of them are about code style or about using the MLIR API to make your life easier :)

Also, please run clang-format (with default parameters) on all the files you have pushed. You just have to install the tool on your machine and then enable "format on save" in your IDE, so that your code is always properly formatted.

.gitignore Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .gitignore file should not be changed.

@@ -15,7 +15,7 @@
"${workspaceFolder}/circt/llvm/build/tools/mlir/include/"
],
"intelliSenseMode": "linux-clang-x64",
"compilerPath": "/usr/bin/clang",
"compilerPath": "/usr/local/bin/clang",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is just provided as an example project configuration for VSCode, so it should not be changed based on your local install.

@@ -0,0 +1,19 @@
//===- BackwardUpdate.h ---------*- C++ -*-===//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: follow the conventions from other file here and make the line 80 characters long
//===- <file_name> - <short description> ---*- C++ -*-===//

The same applies to all other files.


#include "dynamatic/Transforms/UtilsBitsUpdate.h"

namespace backward {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every namespace should be declared under the namespace dynamatic (so that they can be used as e.g., ::dynamatic::backward).


#include "dynamatic/Transforms/UtilsBitsUpdate.h"

namespace forward {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for the backward namespace: this should be declared under the dynamatic namespace.

Also, the number of public functions declared for the pass is small so I don't think we should have multiple namespaces for them (not even sure we should have a namespace below dynamatic...). Please merge backward and forward into one or simply use dynamatic everywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Lucas, different namespace is used because we define the same constructFuncMap function for forward, backward and validation(same functionality, different rules to revise the bit width). I think It might be easier for understanding, but since we pass different arguments for the same named function, I can also merge them into one.
Please let me know which one you think is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more in line with MLIR conventions to not have very small named namespaces. I think you should just remove all custom namespaces, and use the dynamatic namespace whenever you want to declare public functions. You can name your functions constructForwardFuncMap, constructBackwardFuncMap, etc., which makes it clear what each function is for.

@@ -0,0 +1,108 @@
//===- InitIndexType.cpp - Transform the Index Type to IntegerType with system bit width -------*- C++ -*-===//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this fit on 80 characters

OpBuilder builder(ctx);
SmallVector<Operation *> indexCastOps;

for (Operation &op : funcOp.getOps()){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use auto for the type

lib/Transforms/UtilsBitsUpdate.cpp Show resolved Hide resolved
isa<handshake::ConditionalBranchOp>(*Op))
pass = true;

if (isa<mlir::arith::AddIOp>(*Op) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for multiple types at once in a single isa call, like isa<Type1, Type2, ...>(op) instead of checking for each type individually.


unsigned int opWidth;
if (isa<IndexType>(opVal.getType()))
opWidth = 64;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use IndexType::kInternalStorageBitWidth

Copy link
Member

@lucas-rami lucas-rami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally had time to completely review this. There are a lot of comments but the vast majority are trivial fixes. Once everything is addressed we'll be able to merge :) There are one or two things in UtilsBitsUpdate.cpp that I haven't looked at in details yet and I may still do a pass on them in the near future.

include/dynamatic/Transforms/UtilsBitsUpdate.h Outdated Show resolved Hide resolved
include/dynamatic/Transforms/UtilsBitsUpdate.h Outdated Show resolved Hide resolved
lib/Transforms/InitCstWidth.cpp Show resolved Hide resolved
op->erase();
}
}
// llvm::errs() << "Constant saved bits " << savedBits << "\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to use LLVM_DEBUG here, for example

LLVM_DEBUG(llvm::dbgs() << "Number of saved bits is `" << savedBits << "\n");

lib/Transforms/InitCstWidth.cpp Show resolved Hide resolved
lib/Transforms/UtilsBitsUpdate.cpp Outdated Show resolved Hide resolved
lib/Transforms/UtilsBitsUpdate.cpp Outdated Show resolved Hide resolved
lib/Transforms/UtilsBitsUpdate.cpp Outdated Show resolved Hide resolved
lib/Transforms/UtilsBitsUpdate.cpp Outdated Show resolved Hide resolved
lib/Transforms/UtilsBitsUpdate.cpp Show resolved Hide resolved
Copy link
Member

@lucas-rami lucas-rami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple details to address still, but we're super close!

lib/Transforms/InitCstWidth.cpp Show resolved Hide resolved
lib/Transforms/InitCstWidth.cpp Outdated Show resolved Hide resolved
lib/Transforms/InitCstWidth.cpp Outdated Show resolved Hide resolved
lib/Transforms/InitIndexType.cpp Show resolved Hide resolved
lib/Transforms/OptimizeBits.cpp Outdated Show resolved Hide resolved
lib/Transforms/UtilsBitsUpdate.cpp Show resolved Hide resolved
Copy link
Member

@lucas-rami lucas-rami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my last comments cover everything. I also reopened two resolved conversations, but they're just about a formatting issue. After you address those and fix the merge conflict with main we can merge this :)

lib/Transforms/InitCstWidth.cpp Outdated Show resolved Hide resolved
lib/Transforms/OptimizeBits.cpp Show resolved Hide resolved
lib/Transforms/OptimizeBits.cpp Show resolved Hide resolved
test/Transforms/optimize-bitwidth.mlir Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants