einpoklum
einpoklum

Reputation: 132320

How can I clear/flush the L2 cache (and the TLB) of a GPU?

I have a discrete NVIDIA GPU (say, Kepler or Maxwell). I want to clear my L2 cache before some kernel is scheduled, so as not to taint my test results.

I could do something like allocate a large slab of memory and read sequentially a lot of it that's someplace far away, and that will probably work. But I'd much rather do something simpler...

Notes:

Upvotes: 6

Views: 1832

Answers (1)

einpoklum
einpoklum

Reputation: 132320

So, to recap the comments by @MaximMilakov and @paleonix:

  1. Allocate a large slab of memory (at least as large as L2; perhaps larger)?
  2. Perform a cudaMemset() on this large slab.
  3. Supposedly, the memory you will have written to with the memset operation will be cached in L2 - clearing whatever else was in L2 previously.

... and this approach is used in NVIDIA's own nvbench utility.

caveat: It's a bit strange that this works, since the reads and writes with cudaMemset() shouldn't necessarily result in L2 caching.

Upvotes: 1

Related Questions