1
$\begingroup$

I am currently reading Deep Learning with Python by Francois Chollet, the author of Keras, and in one of his definitions for Mini-batch, he explains that the power of 2 for the batch_size is due to memory allocations in gpu/ Could anyone elaborate on this?

Mini-batch or batch—A small set of samples (typically between 8 and 128) that are processed simultaneously by the model. The number of samples is often a power of 2, to facilitate memory allocation on GPU. When training, a mini-batch is used to compute a single gradient-descent update applied to the weights of the model.

$\endgroup$

1 Answer 1

1
$\begingroup$

It's not just on GPU, you want to have a small power of two as submultiple for CPU as well.

The reason is to allocate the processors on the GPU (or the SIMD registers) as best as possibles. This is directly linked to the warp sizes and what the GPU vendors offer for maximum block sizes,

See also this thread on SO which what the warp size is and its relation to best occupancy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.