This is an archive of the discontinued LLVM Phabricator instance.

[llvm-exegesis] Move InstructionBenchmarkClustering::isNeighbour() into header
ClosedPublic

Authored by lebedev.ri on Nov 11 2018, 10:12 AM.

Details

Summary

Old: (D54390)

 Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (10 runs):

       7432.421721      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.15% )
...
            7.4336 +- 0.0115 seconds time elapsed  ( +-  0.15% )

New:

 Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (10 runs):

       6569.936144      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.22% )
...
            6.5711 +- 0.0143 seconds time elapsed  ( +-  0.22% )

And another -12%. You'd think it would be inlined anyway, but no! :)

Diff Detail

Repository
rL LLVM

Event Timeline

lebedev.ri created this revision.Nov 11 2018, 10:12 AM
lebedev.ri edited the summary of this revision. (Show Details)Nov 11 2018, 10:17 AM
MaskRay added inline comments.Nov 11 2018, 5:01 PM
tools/llvm-exegesis/lib/Clustering.cpp
44 ↗(On Diff #173562)

I think the emptiness check can get folded into isNeighbour

tools/llvm-exegesis/lib/Clustering.h
92 ↗(On Diff #173562)

It is interesting that it does not get inlined... Does an inlinespecifier help?

isNeighbour is also used in tools/llvm-exegesis/lib/Analysis.cpp#L503. I'm not familiar with the code but I guess there the performance may not matter too much.

lebedev.ri added inline comments.Nov 12 2018, 12:27 AM
tools/llvm-exegesis/lib/Clustering.cpp
44 ↗(On Diff #173562)

If this check is here it says "there are no measurements, therefore we can't determine
whether it is a neighbor or not".
If it is in isNeighbour(), it will say "we do not have any measurements for that point,
so let's assume that it is located more than EpsilonSquared_ from the current point,
and is not a neighbour".

As per c++ syntax, these will be equivalent.
But will that not conceal the actual algo? I'm not sure.

tools/llvm-exegesis/lib/Clustering.h
92 ↗(On Diff #173562)

That won't (doesn't) work.
If i mark either both the declaration and definition, or either one of them, with inline,
linking fails with this symbol being missing.

This function is called multiple times from the innermost loops.
It *should* be in the header.

lebedev.ri retitled this revision from [llvm-exegesis] Move InstructionBenchmarkClustering::() into header to [llvm-exegesis] Move InstructionBenchmarkClustering::isNeighbour() into header.Nov 12 2018, 12:28 AM
MaskRay accepted this revision.Nov 12 2018, 12:28 PM
This revision is now accepted and ready to land.Nov 12 2018, 12:28 PM
courbet accepted this revision.Nov 19 2018, 1:50 AM
courbet added inline comments.
tools/llvm-exegesis/lib/Clustering.cpp
44 ↗(On Diff #173562)

But will that not conceal the actual algo? I'm not sure.

Let's keep it like this for clarity.

tools/llvm-exegesis/lib/Clustering.h
92 ↗(On Diff #173562)

moving to the class declaration makes the function implicitly inline (https://en.cppreference.com/w/cpp/language/inline, second sentence), so you don't need the inline here.

@MaskRay @courbet thank you for the reviews!

tools/llvm-exegesis/lib/Clustering.h
92 ↗(On Diff #173562)

Good point. Will adjust.