Maximum Number of blocks , SMs, and Grids

Hi

I have a misunderstanding of the maximum number of blocks per grid, the maximum number of blocks per streaming multiprocessors, and a maximum number of blocks for GPU.

Here is my understanding,
First thought: A grid can have the maximum number of blocks (how many?) . Each block will be assigned to a streaming multiprocessor.
If I have 16 streaming multiprocessor, I will have 16 blocks per grid?

Second thought, each streaming multiprocessor has the maximum number of blocks (32 blocks). If I have 16 streaming multiprocessor, there can be 32*16 = 512 blocks per grid. How many grids do I have?

Can someone clarify this?