diff options
author | soumith <soumith@gmail.com> | 2015-04-09 19:53:31 +0300 |
---|---|---|
committer | soumith <soumith@gmail.com> | 2015-04-09 19:53:42 +0300 |
commit | f9a2d04c572ac79130c256493c2f54844ed90533 (patch) | |
tree | df46cc1b6eb4b036f4d36f618f036690e4a4acf9 /init.c | |
parent | e083f97b8baaca88bbe10f304a689c49d5690b7d (diff) |
adding optional device id to getMemoryUsage
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -515,7 +515,17 @@ static int cutorch_getDeviceCount(lua_State *L) static int cutorch_getMemoryUsage(lua_State *L) { size_t freeBytes = 0; size_t totalBytes = 0; - THCudaCheck(cudaMemGetInfo(&freeBytes, &totalBytes)); + int curDevice; + THCudaCheck(cudaGetDevice(&curDevice)); + + int device = luaL_optint(L, 1, -10); + if (device == -10) { /* no argument passed, current device mem usage */ + THCudaCheck(cudaMemGetInfo(&freeBytes, &totalBytes)); + } else { /* argument was given, particular device's memory usage */ + THCudaCheck(cudaSetDevice(device-1)); /* zero indexed */ + THCudaCheck(cudaMemGetInfo(&freeBytes, &totalBytes)); + THCudaCheck(cudaSetDevice(curDevice)); + } lua_pushnumber(L, freeBytes); lua_pushnumber(L, totalBytes); return 2; |