Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

relu3 upper bounds with compiler flags (benchmark combinations report)#942

Merged
toelli-msft merged 3 commits into
masterfrom
toelli/relu3-upper-bounds
Jul 21, 2021
Merged

relu3 upper bounds with compiler flags (benchmark combinations report)#942
toelli-msft merged 3 commits into
masterfrom
toelli/relu3-upper-bounds

Conversation

@toelli-msft

@toelli-msft toelli-msft commented Jul 12, 2021

Copy link
Copy Markdown
Contributor

This allows to set compiler flags for the compilation of embedded C++ and KS benchmarks. See #942 (comment) for up-to-date benchmark numbers. Most important feature of benchmark: with the right compiler flags if is as fast as masking (and they're both a bit faster than PyTorch)!

This PR introduces the CFlags class for bundling together compiler flags we might feed to gcc or cl. It's a bit hokey but seems to strike a good balance between simplicity and robustness. An alternative could be to pass around flags for both compilers separately, but that's rather messy and not robust to adding a new compiler in the future.

Old

As of 207d412 we get a 10%-30% improvement by using compiler flags (-march=native- -funroll-loops -ffast-math -mprefer-vector-width=512. I don't (yet) know which specific flags here make the difference.).

image

image

image

@toelli-msft
toelli-msft force-pushed the toelli/relu3-upper-bounds branch from edb1801 to abdf9e3 Compare July 14, 2021 10:50
@toelli-msft

Copy link
Copy Markdown
Contributor Author

[Now rebased]

@toelli-msft
toelli-msft force-pushed the toelli/relu3-upper-bounds branch 4 times, most recently from cf7642c to c8aea06 Compare July 15, 2021 12:39
@toelli-msft

Copy link
Copy Markdown
Contributor Author

Interestingly, the version using if is as fast as the version using masking, when these new compiler flags are on (c8aea06)

image

image

image

@toelli-msft
toelli-msft force-pushed the toelli/relu3-upper-bounds branch 2 times, most recently from 7d2ecfb to 1136d9a Compare July 15, 2021 13:36
@toelli-msft
toelli-msft marked this pull request as ready for review July 15, 2021 14:40
@toelli-msft
toelli-msft requested review from cgravill and dcrc2 July 15, 2021 14:42
@toelli-msft toelli-msft changed the title WIP relu3 upper bounds with compiler flags relu3 upper bounds with compiler flags (benchmark combinations report) Jul 15, 2021
@toelli-msft
toelli-msft requested a review from awf July 15, 2021 14:55
@awf

awf commented Jul 15, 2021

Copy link
Copy Markdown
Contributor

Cool! Do we think that float is more than 2x the speed of double? I realize that's not easily checkable from here, just wondering.

@toelli-msft

toelli-msft commented Jul 15, 2021

Copy link
Copy Markdown
Contributor Author

Looks like it, based on the difference between these two (from #877). PyTorch backwards goes from 3.4ms on float64 to 1.3ms on float32, which is a bit more than 2x faster. That would be consistent with vectorisation.

float64

https://user-images.githubusercontent.com/51626669/125292570-7ebe7d00-e31a-11eb-85c8-395b7e05d90b.png

float32

https://user-images.githubusercontent.com/51626669/125289029-aca1c280-e316-11eb-91ad-2d282e458e91.png

Comment thread examples/dl-activations/relu3.py Outdated


def vrelu3_embedded_ks_checkpointed_map_handwritten_relu3():
def no_vrelu3_embedded_ks_checkpointed_map_handwritten_relu3():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Has this been disabled intentionally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was an accident. Thanks for spotting! I have pushed a fix.

@awf awf mentioned this pull request Jul 19, 2021
8 tasks
@toelli-msft
toelli-msft force-pushed the toelli/relu3-upper-bounds branch 2 times, most recently from 497ca64 to 86af442 Compare July 19, 2021 15:12
@toelli-msft

Copy link
Copy Markdown
Contributor Author

We still have great performance post https://github.com/microsoft/knossos-ksc/pull/931/files

@awf

awf commented Jul 20, 2021

Copy link
Copy Markdown
Contributor

We still have great performance post https://github.com/microsoft/knossos-ksc/pull/931/files

Tables updated above?

Comment thread src/python/ksc/compile.py
return CFlags(cl_flags=[], gcc_flags=gcc_flags)


default_cflags = CFlags(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thanks.

@toelli-msft

Copy link
Copy Markdown
Contributor Author

Tables updated above?

I'm not sure what you mean, but if you're asking whether the tables above have been updated to show performance after https://github.com/microsoft/knossos-ksc/pull/931/files was merged, then no, they haven't been updated. Here are such tables though:

(86af442)

image

image

image

@toelli-msft
toelli-msft force-pushed the toelli/relu3-upper-bounds branch from 86af442 to 1e93252 Compare July 21, 2021 09:21
@toelli-msft
toelli-msft merged commit 0ab1a29 into master Jul 21, 2021
@toelli-msft
toelli-msft deleted the toelli/relu3-upper-bounds branch July 21, 2021 09:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants