You can pad these matrices with zeros and concatenate them to form one big tensor. An then, you’ll be able to perform a normal matrix multiply, and slice the result to get the corresponding sub-matrices results. However, I’m not sure it is the best way to do this, it will depend on the values of n1, n2, etc. Maybe looping is better.
If you really need performance, and if you have big matrices, you’ll actually need to implement your own CUDA kernel, and this I think is the best you can do.