static int cutorch_getDeviceProperties(lua_State *L) { struct cudaDeviceProp prop; int device = (int)luaL_checknumber(L, 1)-1; THCudaCheck(cudaGetDeviceProperties(&prop, device)); lua_newtable(L); SET_DEVN_PROP(canMapHostMemory); SET_DEVN_PROP(clockRate); SET_DEVN_PROP(computeMode); SET_DEVN_PROP(deviceOverlap); SET_DEVN_PROP(integrated); SET_DEVN_PROP(kernelExecTimeoutEnabled) SET_DEVN_PROP(major); SET_DEVN_PROP(maxThreadsPerBlock); SET_DEVN_PROP(memPitch); SET_DEVN_PROP(minor); SET_DEVN_PROP(multiProcessorCount); SET_DEVN_PROP(regsPerBlock); SET_DEVN_PROP(sharedMemPerBlock); SET_DEVN_PROP(textureAlignment); SET_DEVN_PROP(totalConstMem); SET_DEVN_PROP(totalGlobalMem); SET_DEVN_PROP(warpSize); lua_pushstring(L, prop.name); lua_setfield(L, -2, "name"); return 1; }
static int cutorch_getDeviceProperties(lua_State *L) { int device = (int)luaL_checknumber(L, 1)-1; // switch context to given device so the call to cudaMemGetInfo is for the correct device int oldDevice; THCudaCheck(cudaGetDevice(&oldDevice)); THCudaCheck(cudaSetDevice(device)); struct cudaDeviceProp prop; THCudaCheck(cudaGetDeviceProperties(&prop, device)); lua_newtable(L); SET_DEVN_PROP(canMapHostMemory); SET_DEVN_PROP(clockRate); SET_DEVN_PROP(computeMode); SET_DEVN_PROP(deviceOverlap); SET_DEVN_PROP(integrated); SET_DEVN_PROP(kernelExecTimeoutEnabled); SET_DEVN_PROP(major); SET_DEVN_PROP(maxThreadsPerBlock); SET_DEVN_PROP(memPitch); SET_DEVN_PROP(minor); SET_DEVN_PROP(multiProcessorCount); SET_DEVN_PROP(regsPerBlock); SET_DEVN_PROP(sharedMemPerBlock); SET_DEVN_PROP(textureAlignment); SET_DEVN_PROP(totalConstMem); SET_DEVN_PROP(totalGlobalMem); SET_DEVN_PROP(warpSize); SET_DEVN_PROP(pciBusID); SET_DEVN_PROP(pciDeviceID); SET_DEVN_PROP(pciDomainID); SET_DEVN_PROP(maxTexture1D); SET_DEVN_PROP(maxTexture1DLinear); size_t freeMem; THCudaCheck(cudaMemGetInfo (&freeMem, NULL)); lua_pushnumber(L, freeMem); lua_setfield(L, -2, "freeGlobalMem"); lua_pushstring(L, prop.name); lua_setfield(L, -2, "name"); // restore context THCudaCheck(cudaSetDevice(oldDevice)); return 1; }