How to prefetch data using a custom python function in tensorflow

This is a common use case, and most implementations use TensorFlow’s queues to decouple the preprocessing code from the training code. There is a tutorial on how to use queues, but the main steps are as follows: Define a queue, q, that will buffer the preprocessed data. TensorFlow supports the simple tf.FIFOQueue that produces elements … Read more

When should we use prefetch?

This question isn’t really about compilers as they’re just providing some hook to insert prefetch instructions into your assembly code / binary. Different compilers may provide different intrinsic formats but you can just ignore all these and (carefully) add it directly in assembly code. Now the real question seems to be “when are prefetches useful”, … Read more

Why does django’s prefetch_related() only work with all() and not filter()?

In Django 1.6 and earlier, it is not possible to avoid the extra queries. The prefetch_related call effectively caches the results of a.photoset.all() for every album in the queryset. However, a.photoset.filter(format=1) is a different queryset, so you will generate an extra query for every album. This is explained in the prefetch_related docs. The filter(format=1) is … Read more

Prefetching Examples?

Here’s an actual piece of code that I’ve pulled out of a larger project. (Sorry, it’s the shortest one I can find that had a noticable speedup from prefetching.) This code performs a very large data transpose. This example uses the SSE prefetch instructions, which may be the same as the one that GCC emits. … Read more

How do I programmatically disable hardware prefetching?

You can enable or disable the hardware prefetchers using msr-tools http://www.kernel.org/pub/linux/utils/cpu/msr-tools/. The following enables the hardware prefetcher (by unsetting bit 9): [root@… msr-tools-1.2]# ./wrmsr -p 0 0x1a0 0x60628e2089 [root@… msr-tools-1.2]# ./rdmsr 0x1a0 60628e2089 The following disables the hardware prefetcher (by enabling bit 9): [root@… msr-tools-1.2]# ./wrmsr -p 0 0x1a0 0x60628e2289 [root@… msr-tools-1.2]# ./rdmsr 0x1a0 60628e2289 … Read more