Skip to content

bench(exla): time matmul compile separately from warm runs - #1844

Open
Chapaman wants to merge 2 commits into
elixir-nx:mainfrom
Chapaman:exla-matmul-bench
Open

Chapaman wants to merge 2 commits into
elixir-nx:mainfrom
Chapaman:exla-matmul-bench

Conversation

@Chapaman

Copy link
Copy Markdown
Contributor

mix run bench/matmul.exs times an f32 matmul at 64, 256, and 1024 on the host client. Cold, shape-cache miss, and shape-cache hit are single calls. Warm runs go through Benchee after that shape has already been compiled. Inputs are on device before the timer starts, and the executable waits for the result buffer, so a sample is not just a launch.

On this machine the first shape compiled in 334 ms. The next two compiled in 18 ms and 12 ms, and each emitted one [:exla, :compilation] event. Warm runs and the hits emitted none. Steady state was about 79 μs, 1.6 ms, and 27 ms. Nothing in that suggested a cache change.

Comment thread exla/bench/matmul.exs Outdated
@@ -0,0 +1,125 @@
# CPU benchmark of an f32 matmul. Cold, warm, and shape-cache phases are timed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we could turn this into an example livebook instead?

Seems like a good opportunity to teach about compiler cache hits and misses, and how that can affect benchmarks.

Also, Benchee.run has a warm time option, so any compilation times can be separated out using that instead of forcing compilation before running

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.

Moved it to guides/compilation-cache.livemd. The first cells time a miss, a hit, and a new shape. Benchee uses warmup for 1024, so that compile stays out of the samples without a call beforehand.

Cold, shape-cache miss, and shape-cache hit are one-shot timings. Warm runs go through Benchee. A new shape emits one compilation event; repeating it does not.
The notebook shows a cache miss, a hit, and a new shape, then measures the warm matmul with Benchee's warmup so the compile stays out of the samples.
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.

2 participants