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

Fix auto-scheduler profile mismatch #2421

Merged

Conversation

fangyi-zhou
Copy link
Contributor

When using the auto-scheduler on certain inputs, the auto-scheduler may throw an error stating:
"Error: profile used for auto-scheduling doesn't match the provided program."
This was reported in Issue #2346 by another user, providing a small example to test on.

Running a git bisect using the example reveals that the commit 43a4ce3 (Working refactor of SIP Graph, 2022-06-23) was the first to introduce the error.

Inspecting the profiler output for that commit and the parent commit, I noted that some new indices appear the join columns and they should probably not be there.

After deep inspection of the refactor, I've noticed the following diff potentially changes the program behaviour:

src/ast/analysis/JoinSize.cpp
in 43a4ce3 (Working refactor of SIP Graph, 2022-06-23)

-  auto& dependentVars = varToOtherVars.at(var->getName());
-  if (!dependentVars.empty() &&
-          std::includes(providedVars.begin(), providedVars.end(),
-                  dependentVars.begin(), dependentVars.end())) {
-      joinColumns.push_back(argIdx);
-      ++numBound;
-      continue;

src/ast/utility/SipGraph.cpp
in 55c3500 (Working SIPGraph for SelingerSIPS, 2022-06-23)

+  if (std::includes(groundedVars.begin(), groundedVars.end(), dependentVars.begin(),
+            dependentVars.end())) {
+    boundColumns.insert(argIdx);
+  }

This commit adds the empty check, and this change makes the error disappear. While I am not certain about whether this is the correct fix, the use of std::includes on an empty range could be a potential cause of bugs.

I tested the join column output against the parent commit of the 43a4ce3 (Working refactor of SIP Graph, 2022-06-23), and can confirm that the join columns in the profile output are the same.

Closes #2346

When using the auto-scheduler on certain inputs, the auto-scheduler may
throw an error stating:
"Error: profile used for auto-scheduling doesn't match the provided
program."
This was reported in Issue souffle-lang#2346 by another user, providing a small
example to test on.

Running a `git bisect` using the example reveals that the commit
43a4ce3 (Working refactor of SIP Graph, 2022-06-23)
was the first to introduce the error.

Inspecting the profiler output for that commit and the parent commit,
I noted that some new indices appear the join columns and they should
probably not be there.

After deep inspection of the refactor, I've noticed the following diff
potentially changes the program behaviour:

src/ast/analysis/JoinSize.cpp
in 43a4ce3 (Working refactor of SIP Graph, 2022-06-23)
```diff
-  auto& dependentVars = varToOtherVars.at(var->getName());
-  if (!dependentVars.empty() &&
-          std::includes(providedVars.begin(), providedVars.end(),
-                  dependentVars.begin(), dependentVars.end())) {
-      joinColumns.push_back(argIdx);
-      ++numBound;
-      continue;
```

src/ast/utility/SipGraph.cpp
in 55c3500 (Working SIPGraph for SelingerSIPS, 2022-06-23)
```diff
+  if (std::includes(groundedVars.begin(), groundedVars.end(), dependentVars.begin(),
+            dependentVars.end())) {
+    boundColumns.insert(argIdx);
+  }
```

This commit adds the empty check, and this change makes the error
disappear. While I am not certain about whether this is the correct fix,
the use of `std::includes` on an empty range could be a potential cause
of bugs.

I tested the join column output against the parent commit of the
43a4ce3 (Working refactor of SIP Graph, 2022-06-23),
and can confirm that the join columns in the profile output are the same.

Closes souffle-lang#2346
@codecov
Copy link

codecov bot commented Jun 30, 2023

Codecov Report

Merging #2421 (b643681) into master (2914f7b) will increase coverage by 0.13%.
The diff coverage is 81.43%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2421      +/-   ##
==========================================
+ Coverage   77.75%   77.89%   +0.13%     
==========================================
  Files         474      479       +5     
  Lines       31164    31398     +234     
==========================================
+ Hits        24232    24456     +224     
- Misses       6932     6942      +10     
Impacted Files Coverage Δ
src/ast/analysis/typesystem/Type.cpp 47.37% <0.00%> (-0.47%) ⬇️
src/ast/analysis/typesystem/Type.h 50.00% <ø> (ø)
...c/ast/analysis/typesystem/TypeConstrainsAnalysis.h 100.00% <ø> (ø)
src/ast2ram/seminaive/ValueTranslator.h 100.00% <ø> (ø)
src/ast2ram/utility/TranslatorContext.h 100.00% <ø> (ø)
src/include/souffle/utility/SubProcess.h 55.00% <0.00%> (ø)
src/interpreter/Node.h 96.95% <ø> (ø)
src/ram/Variable.h 45.45% <45.45%> (ø)
src/ram/Assign.h 50.00% <50.00%> (ø)
src/parser/parser.yy 93.85% <58.33%> (-1.30%) ⬇️
... and 23 more

... and 11 files with indirect coverage changes

@fangyi-zhou
Copy link
Contributor Author

As a side note, this fix does not cover all issues when using the auto-scheduler. I have encountered another profile mismatch error after the fix, and unfortunately I wasn't able to pin down the root cause.

Copy link
Member

@quentin quentin left a comment

Choose a reason for hiding this comment

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

Thanks!
I guess std::include always returns true for the empty sub-sequence.

@quentin quentin merged commit 75dceb4 into souffle-lang:master Jul 3, 2023
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.

Assertion failure on auto-tuning
2 participants