Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/cutorch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/init.c
diff options
context:
space:
mode:
authorsoumith <soumith@gmail.com>2015-04-09 19:53:31 +0300
committersoumith <soumith@gmail.com>2015-04-09 19:53:42 +0300
commitf9a2d04c572ac79130c256493c2f54844ed90533 (patch)
treedf46cc1b6eb4b036f4d36f618f036690e4a4acf9 /init.c
parente083f97b8baaca88bbe10f304a689c49d5690b7d (diff)
adding optional device id to getMemoryUsage
Diffstat (limited to 'init.c')
-rw-r--r--init.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/init.c b/init.c
index 2d252c5..3db850a 100644
--- a/init.c
+++ b/init.c
@@ -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;