Skip to content

Add config validity check #376

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

Merged
merged 3 commits into from
Oct 14, 2024
Merged

Add config validity check #376

merged 3 commits into from
Oct 14, 2024

Conversation

yifeizh2
Copy link
Contributor

@yifeizh2 yifeizh2 commented Oct 9, 2024

Add matmul config validity check to avoid invalid configs.

Resolves issue #375 and #377.

@yifeizh2 yifeizh2 added the bug Something isn't working label Oct 9, 2024
@yifeizh2 yifeizh2 requested a review from zhczhong October 9, 2024 08:11
@yifeizh2 yifeizh2 force-pushed the yifei/add_K_constraint branch from 8821346 to ceabcc2 Compare October 9, 2024 08:14
@yifeizh2
Copy link
Contributor Author

yifeizh2 commented Oct 9, 2024

I will further add unit test or local check with benchgc. Currently, we also require the tuner side to reject such invalid config @xurui1995

@xurui1995
Copy link
Contributor

I will further add unit test or local check with benchgc. Currently, we also require the tuner side to reject such invalid config @xurui1995

I will add this validating rule on python side

return cfgItemCnt == 9;
} else {
LLVM_DEBUG(llvm::dbgs() << "The predefined config is invalid\n");
assert(validateConfig(config, shape) && "config is invalid");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zhczhong Replaced the original debug info with assertion to avoid invalid config being replaced with a valid one, which potentially will lead to error in tuning result.

@WangJialei-A
Copy link
Contributor

I will further add unit test or local check with benchgc. Currently, we also require the tuner side to reject such invalid config @xurui1995

I will add this validating rule on python side

It is not reasonable to add special check on benchgc side and we do not need to maintain two implementations. Throw an exception or error code to told the caller that the config is invalid is a better way, I think.

@yifeizh2
Copy link
Contributor Author

yifeizh2 commented Oct 9, 2024

I will further add unit test or local check with benchgc. Currently, we also require the tuner side to reject such invalid config @xurui1995

I will add this validating rule on python side

It is not reasonable to add special check on benchgc side and we do not need to maintain two implementations. Throw an exception or error code to told the caller that the config is invalid is a better way, I think.

Just replaced the original debug message with an assertion.

@xurui1995
Copy link
Contributor

I will further add unit test or local check with benchgc. Currently, we also require the tuner side to reject such invalid config @xurui1995

I will add this validating rule on python side

It is not reasonable to add special check on benchgc side and we do not need to maintain two implementations. Throw an exception or error code to told the caller that the config is invalid is a better way, I think.

Will add that too. And I still prefer adding a validation rule on python side which can help reduce tuning time

@WangJialei-A
Copy link
Contributor

I will further add unit test or local check with benchgc. Currently, we also require the tuner side to reject such invalid config @xurui1995

I will add this validating rule on python side

It is not reasonable to add special check on benchgc side and we do not need to maintain two implementations. Throw an exception or error code to told the caller that the config is invalid is a better way, I think.

Will add that too. And I still prefer adding a validation rule on python side which can help reduce tuning time

From my perspective, it will be better if function validateConfig is exposed in python binding.

if (validateConfig(config, shape))
return true;
else {
assert(0 && "config is invalid");
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use llvm::dbgs() to give the warning when there's invalid config, assert only throw error in debug mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better to use llvm::dbgs() to give the warning when there's invalid config, assert only throw error in debug mode.

I will update to giving both assert and llvm::dbgs().

@@ -47,6 +47,12 @@ bool validateConfig(const MatmulConfig &cfg) {
cfg.NBlock % cfg.innerMostNBlock != 0 ||
cfg.KBlock % cfg.innerMostKBlock != 0)
return false;
if (!shape.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the case that generated by heuristic rule, we also need to update the logic there?
BTW, seems it only use the K dim size, no need to pass the entire shape here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is the case that generated by heuristic rule, we also need to update the logic there? BTW, seems it only use the K dim size, no need to pass the entire shape here?

Heuristic rule will not generate this kind of invalid config. This issue is exposed by tuner side generated config.
The reason for only checking K dim size is because, only the KThreads value will not shrink automatically while M and N would (which is an upstream limitation). I currently passed the entire shape here in case we further need to check shape related constraint for M and N in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I would suggest we only pass the things that is necessary as you mentioned on M and N, anyway you can keep it as is.

@yifeizh2 yifeizh2 changed the title Add config validity check for KThreads Add config validity check Oct 11, 2024
@yifeizh2 yifeizh2 force-pushed the yifei/add_K_constraint branch from 9ecf54e to f2bbd60 Compare October 11, 2024 08:17
@yifeizh2 yifeizh2 merged commit 27a7da6 into main Oct 14, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants