Skip to content
Snippets Groups Projects
Unverified Commit 21b9863d authored by fireice-uk's avatar fireice-uk Committed by GitHub
Browse files

Merge pull request #114 from psychocrypt/fix-wrongMemoryDetection

fix wrong memory detection
parents 117493dc 06594585
No related branches found
No related tags found
No related merge requests found
...@@ -60,17 +60,15 @@ public: ...@@ -60,17 +60,15 @@ public:
ctx.device_bfactor = 6; ctx.device_bfactor = 6;
ctx.device_bsleep = 25; ctx.device_bsleep = 25;
#endif #endif
if( cuda_get_deviceinfo(&ctx) != 1 ) if(cuda_get_deviceinfo(&ctx) == 0)
{ nvidCtxVec.push_back(ctx);
printer::inst()->print_msg(L0, "Setup failed for GPU %d. Exitting.\n", i); else
std::exit(0); printer::inst()->print_msg(L0, "WARNING: NVIDIA setup failed for GPU %d.\n", i);
}
nvidCtxVec.push_back(ctx);
} }
generateThreadConfig(); generateThreadConfig();
return true; return true;
} }
...@@ -94,6 +92,7 @@ private: ...@@ -94,6 +92,7 @@ private:
{ {
conf += std::string(" // gpu: ") + ctx.name + " architecture: " + std::to_string(ctx.device_arch[0] * 10 + ctx.device_arch[1]) + "\n"; conf += std::string(" // gpu: ") + ctx.name + " architecture: " + std::to_string(ctx.device_arch[0] * 10 + ctx.device_arch[1]) + "\n";
conf += std::string(" // memory: ") + std::to_string(ctx.free_device_memory / byte2mib) + "/" + std::to_string(ctx.total_device_memory / byte2mib) + " MiB\n"; conf += std::string(" // memory: ") + std::to_string(ctx.free_device_memory / byte2mib) + "/" + std::to_string(ctx.total_device_memory / byte2mib) + " MiB\n";
conf += std::string(" // smx: ") + std::to_string(ctx.device_mpcount) + "\n";
conf += std::string(" { \"index\" : ") + std::to_string(ctx.device_id) + ",\n" + conf += std::string(" { \"index\" : ") + std::to_string(ctx.device_id) + ",\n" +
" \"threads\" : " + std::to_string(ctx.device_threads) + ", \"blocks\" : " + std::to_string(ctx.device_blocks) + ",\n" + " \"threads\" : " + std::to_string(ctx.device_threads) + ", \"blocks\" : " + std::to_string(ctx.device_blocks) + ",\n" +
" \"bfactor\" : " + std::to_string(ctx.device_bfactor) + ", \"bsleep\" : " + std::to_string(ctx.device_bsleep) + ",\n" + " \"bfactor\" : " + std::to_string(ctx.device_bfactor) + ", \"bsleep\" : " + std::to_string(ctx.device_bsleep) + ",\n" +
......
...@@ -270,6 +270,14 @@ extern "C" int cuda_get_devicecount( int* deviceCount) ...@@ -270,6 +270,14 @@ extern "C" int cuda_get_devicecount( int* deviceCount)
return 1; return 1;
} }
/** get device information
*
* @return 0 = all OK,
* 1 = something went wrong,
* 2 = gpu cannot be selected,
* 3 = context cannot be created
* 4 = not enough memory
*/
extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx) extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
{ {
cudaError_t err; cudaError_t err;
...@@ -279,25 +287,25 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx) ...@@ -279,25 +287,25 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
if(err != cudaSuccess) if(err != cudaSuccess)
{ {
printf("Unable to query CUDA driver version! Is an nVidia driver installed?\n"); printf("Unable to query CUDA driver version! Is an nVidia driver installed?\n");
return 0; return 1;
} }
if(version < CUDART_VERSION) if(version < CUDART_VERSION)
{ {
printf("Driver does not support CUDA %d.%d API! Update your nVidia driver!\n", CUDART_VERSION / 1000, (CUDART_VERSION % 1000) / 10); printf("Driver does not support CUDA %d.%d API! Update your nVidia driver!\n", CUDART_VERSION / 1000, (CUDART_VERSION % 1000) / 10);
return 0; return 1;
} }
int GPU_N; int GPU_N;
if(cuda_get_devicecount(&GPU_N) == 0) if(cuda_get_devicecount(&GPU_N) == 0)
{ {
return 0; return 1;
} }
if(ctx->device_id >= GPU_N) if(ctx->device_id >= GPU_N)
{ {
printf("Invalid device ID!\n"); printf("Invalid device ID!\n");
return 0; return 1;
} }
cudaDeviceProp props; cudaDeviceProp props;
...@@ -305,7 +313,7 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx) ...@@ -305,7 +313,7 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
if(err != cudaSuccess) if(err != cudaSuccess)
{ {
printf("\nGPU %d: %s\n%s line %d\n", ctx->device_id, cudaGetErrorString(err), __FILE__, __LINE__); printf("\nGPU %d: %s\n%s line %d\n", ctx->device_id, cudaGetErrorString(err), __FILE__, __LINE__);
return 0; return 1;
} }
ctx->device_name = strdup(props.name); ctx->device_name = strdup(props.name);
...@@ -347,9 +355,31 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx) ...@@ -347,9 +355,31 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
maxMemUsage = size_t(1024u) * byteToMiB; maxMemUsage = size_t(1024u) * byteToMiB;
} }
int* tmp;
cudaError_t err;
// a device must be selected to get the right memory usage later on
err = cudaSetDevice(ctx->device_id);
if(err != cudaSuccess)
{
printf("WARNING: NVIDIA GPU %d: cannot be selected.\n", ctx->device_id);
return 2;
}
// trigger that a context on the gpu will be allocated
err = cudaMalloc(&tmp, 256);
if(err != cudaSuccess)
{
printf("WARNING: NVIDIA GPU %d: context cannot be created.\n", ctx->device_id);
return 3;
}
size_t freeMemory = 0; size_t freeMemory = 0;
size_t totalMemory = 0; size_t totalMemory = 0;
CUDA_CHECK(ctx->device_id, cudaMemGetInfo(&freeMemory, &totalMemory)); CUDA_CHECK(ctx->device_id, cudaMemGetInfo(&freeMemory, &totalMemory));
cudaFree(tmp);
// delete created context on the gpu
cudaDeviceReset();
ctx->total_device_memory = totalMemory; ctx->total_device_memory = totalMemory;
ctx->free_device_memory = freeMemory; ctx->free_device_memory = freeMemory;
...@@ -379,6 +409,7 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx) ...@@ -379,6 +409,7 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
printf("WARNING: NVIDIA GPU %d: already %s MiB memory in use, skip GPU.\n", printf("WARNING: NVIDIA GPU %d: already %s MiB memory in use, skip GPU.\n",
ctx->device_id, ctx->device_id,
std::to_string(usedMem/byteToMiB).c_str()); std::to_string(usedMem/byteToMiB).c_str());
return 4;
} }
else else
maxMemUsage -= usedMem; maxMemUsage -= usedMem;
...@@ -404,5 +435,5 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx) ...@@ -404,5 +435,5 @@ extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
} }
return 1; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment