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

#0: Faster builds by enabling Unity build for TTNN and tests #14461

Merged
merged 14 commits into from
Oct 30, 2024

Conversation

sminakov-tt
Copy link
Contributor

@sminakov-tt sminakov-tt commented Oct 30, 2024

Ticket

Problem description

Currently build times are really slow. After this change, clean build of the whole repo with tests is about 2x faster.

What's changed

Enable Unity build for TTNN and tests
Fix all of the compilation issues, primarily missing #pragma once in headers and usage of anonymous namespaces.

Future work

According to my observation, build times can be improved significantly by merging a lot of single-cpp test binaries together and applying Unity builds to them. This is considered to be out of scope of this pull request.

Checklist

  • Post commit CI passes
  • Blackhole Post commit (if applicable)
  • Model regression CI testing passes (if applicable)
  • Device performance regression CI testing passes (if applicable)
  • New/Existing tests provide coverage for changes

@tt-rkim
Copy link
Collaborator

tt-rkim commented Oct 30, 2024

@afuller-TT I'm good with the suggestions, but we should plan to keep an eye on the build artifact times over a period. (which is what you said)

@sminakov-tt

There is a change in some header, which is used everywhere - triggers a full rebuild, unity build is significantly faster.

I agree.

There is a change in a few isolated files - triggers a rebuild of a few merged .cpp files, which is extremely likely to be faster than a build without ccache

Faster than a build without ccache, yes, but then why would the rebuild of a few merged .cpp files (and remember, given our software size, these are probably going to be large TUs) be faster than re-building only the affected TUs with the others cached? Wouldn't we be compiling either an equal amount or more stuff fundamentally upon a ccache miss with unity build on, as opposed to ccache miss with unity build off?

And sure, we would have likely <N cache misses with unity build on, but these TUs are still quite large, so the cache entries are large. Re-building smaller parts of it via individual TUs rather than a larger merged one with files that may have no changes should take less time, regardless of how many less cache misses we have. As a thought experiment, what happens if we were to have only one giant TU? (obviously not the case but I'm just saying)

Again, given @afuller-TT 's response above, I think it's still worth trying to see what the effect is on main. But I still am having trouble understanding your last point.

@sminakov-tt
Copy link
Contributor Author

sminakov-tt commented Oct 30, 2024

@tt-rkim
Let me clarify. I was trying to make a point that we should have ccache + unity turned on on CI. Because:

  1. If we turn off ccache on CI, small changes which touch a few files will get a significant slowdown.
  2. If we turn off unity on CI, large changes (close to full rebuild) will get a 2x slowdown. It's likely that small changes (a few files) would get a bit faster, but I think with unity they are still "fast enough".

I also agree, let's just wait and see what's going to happen in practice.

Copy link
Member

@ayerofieiev-tt ayerofieiev-tt left a comment

Choose a reason for hiding this comment

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

Lets go! 🚀

@@ -186,6 +190,7 @@ bool writer_kernel_no_receive(
}

TEST_F(N300DeviceFixture, EthKernelsNocReadNoSend) {
using namespace CMAKE_UNIQUE_NAMESPACE;
Copy link
Contributor

Choose a reason for hiding this comment

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

These are kinda noisy and not related to the tests themselves. Does Unity trip up if we have it at file-scope instead of f'n scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Let's say we have two files which are being merged in unity build, and both of them define the same function within CMAKE_UNIQUE_NAMESPACE. If both of them do using namespace at the file level, it would result in both functions being visible at the same time and the call would be ambiguous.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. That makes perfect sense.

@@ -22,12 +22,6 @@ using std::vector;
using namespace tt;
using namespace tt::tt_metal;

struct TestBufferConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead code removal 🔥

Copy link
Contributor

@eyonland eyonland left a comment

Choose a reason for hiding this comment

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

Thanks for doing this.

@sminakov-tt sminakov-tt merged commit 948fafb into main Oct 30, 2024
8 checks passed
@sminakov-tt sminakov-tt deleted the sminakov/unity branch October 30, 2024 23:09
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.