# Batch sizing for convolution neural networks — powers of 2 or powers of primes?

The conventional wisdom for convolution neural networks (CNNs) is to make the batch size a power of 2 because of hardware utilization/optimizations done in the convolution layers.

A similar logic applies to the Fast Fourier Transform (FFT). However, the FFT is actually best used when it is a size of a power of primes (e.g. $$2^M3^N5^P$$ where $$M,N,P$$ are positive integers.) I was wondering if this also applies to CNNs.

• This depends entirely on the implementation details. Have you had a look at the internals of whatever you care about or simply tried it? – Juho Jan 2 '19 at 17:37
• I am using cudnn which doesnt have source available that I am aware of. Also, I have tried to measure performance it seems powers of primes is just as good as power of 2. However, this could be by sure luck or some other inefficiency in my training regime. – Isaac Gerg Jan 2 '19 at 17:45
• There are plenty of implementations of both CNNs and FFTs that you can peruse; many of them are open source. – D.W. Feb 11 '19 at 0:03

## 1 Answer

No. It doesn't apply to CNNs. CNNs are doing the same operation on each item in the batch; it's much simpler than what's happening in a FFT (which involves interaction between the elements of the array; you can't compute a FFT by just separately doing something to each element of the array in parallel).

• How do you know this? – Isaac Gerg Feb 10 '19 at 19:48
• @IsaacGerg, I explained my reasoning in the answer. If that's not sufficient, I suggest you try implementing it and see what happens! – D.W. Feb 10 '19 at 20:14
• Its possible that the twiddle factors are being reused between kernels. The convolution can be implemented in frequency domain in )(nlogn) where if you compute the convolution directly its O(n^2) – Isaac Gerg Feb 10 '19 at 20:43
• @IsaacGerg, great, but I don't see how that has any relevance to my answer. – D.W. Feb 11 '19 at 0:03
• Your answer states that the power rules for FFT sizing don't apply to CNNs because FFT's dont' apply to CNNs. You make this claim without fact. I am providing evidence that this is not a fact. – Isaac Gerg Feb 11 '19 at 0:58