3030#include < string>
3131#include < vector>
3232#include < algorithm>
33+ #ifndef _MSC_VER
3334#include < dlfcn.h>
34- #include < unistd.h > // for sleep
35+ #endif
3536
3637#include " cudamatrix/cu-common.h"
3738#include " cudamatrix/cu-device.h"
3839#include " cudamatrix/cu-matrix.h"
3940#include " base/kaldi-error.h"
41+ #include " base/kaldi-utils.h"
4042#include " util/common-utils.h"
4143
4244namespace kaldi {
@@ -105,7 +107,7 @@ void CuDevice::SelectGpuId(std::string use_gpu) {
105107 int32 sec_sleep = (use_gpu == " yes" ? 20 : 2 );
106108 KALDI_WARN << " Will try again to get a GPU after " << sec_sleep
107109 << " seconds." ;
108- sleep (sec_sleep);
110+ Sleep (sec_sleep);
109111 cudaGetLastError (); // reset the error state
110112 e = cudaThreadSynchronize (); // << 2nd trial to get CUDA context.
111113 if (e != cudaSuccess) {
@@ -128,7 +130,7 @@ void CuDevice::SelectGpuId(std::string use_gpu) {
128130 << " seconds to get a GPU." ;
129131 num_times++;
130132 wait_time += sec_sleep;
131- sleep (sec_sleep);
133+ Sleep (sec_sleep);
132134 cudaGetLastError (); // reset the error state
133135 e = cudaThreadSynchronize ();
134136 }
@@ -377,6 +379,9 @@ std::string CuDevice::GetFreeMemory(int64* free, int64* total) const {
377379 // pre-fill ``safe'' values that will not cause problems
378380 mem_free = 1 ; mem_total = 1 ;
379381 // open libcuda.so
382+ #ifdef _MSC_VER
383+ cuMemGetInfo (&mem_free, &mem_total);
384+ #else
380385 void * libcuda = dlopen (" libcuda.so" ,RTLD_LAZY);
381386 if (NULL == libcuda) {
382387 KALDI_WARN << " cannot open libcuda.so" ;
@@ -399,6 +404,7 @@ std::string CuDevice::GetFreeMemory(int64* free, int64* total) const {
399404 // close the library
400405 dlclose (libcuda);
401406 }
407+ #endif
402408 }
403409 // copy the output values outside
404410 if (NULL != free) *free = mem_free;
@@ -416,6 +422,9 @@ std::string CuDevice::GetFreeMemory(int64* free, int64* total) const {
416422void CuDevice::DeviceGetName (char * name, int32 len, int32 dev) {
417423 // prefill with something reasonable
418424 strncpy (name," Unknown GPU" ,len);
425+ #ifdef _MSC_VER
426+ cuDeviceGetName (name, len, dev);
427+ #else
419428 // open libcuda.so
420429 void * libcuda = dlopen (" libcuda.so" ,RTLD_LAZY);
421430 if (NULL == libcuda) {
@@ -434,6 +443,7 @@ void CuDevice::DeviceGetName(char* name, int32 len, int32 dev) {
434443 // close the library
435444 dlclose (libcuda);
436445 }
446+ #endif
437447}
438448
439449
0 commit comments