It turns out that it is quite complicated to get this information in a portable and reliable way. However the hwloc library provides such information : http://www.open-mpi.org/projects/hwloc/ perhaps that’s worth giving a try.
Also note that it is certainly impossible to actually know how much memory is currently available for real, except if you have a perfectly dedicated machine (where you would have only a few processes that you totally control). So you can perhaps get the max amount of RAM available, but you certainly can’t get the amount of RAM that you should be able to alloc. Of course, in case you have a dedicated machine, and if you limit yourself to, say, 75% of the memory, it becomes a reasonnable approximation.
Valgrind works with CUDA. In fact, valgrind with device emulation has, until very recently, been the recommended way of debugging out of bounds memory errors in CUDA.
Just be a piece of code “works fine”, doesn’t mean it doesn’t contain memory management errors.
OK, now I am a little confused. I assumed, based on your original post, that you want to instrument your host memory usage because you have memory leaks or other problems with memory management. That is precisely what valgrind is designed for. Perhaps I misunderstood something, but what is it you actually want to achieve?