sudo ldconfig
to update all the linker paths. Then, you can do sudo ldconfig -p | grep -i cuda
to see that your system knows where all the cuda libraries are.
It seems like you linked to mkl (Intel math kernel library). You could either see that pytorch finds it or not have the build link to it. Note that sudo sanitizes your environment variables unless you pass -E, so if you rely on these to find Magma, this cab be a problem.
I usually build with setup.py bdist_wheel (no sudo) and then uses pip to install the whl in dist. That has turned out to have less potential for surprises for me.