Commit 89ad96e6 by xuchen

fix the bug about device reset

parent e84a764b
...@@ -191,18 +191,17 @@ void XDevice::Clear() ...@@ -191,18 +191,17 @@ void XDevice::Clear()
void XDevice::Reset() void XDevice::Reset()
{ {
Clear(); XMem * mem = GMems.GetMem(devID);
mem->Free();
if (!isInitialized) int devIDReset = devID;
return; Clear();
for (int i = 0; i < MAX_CPU_MEM_NUM; i++)
delete GMems.GetMem(devID);
#ifdef USE_CUDA #ifdef USE_CUDA
if (devID >= 0) { if (devIDReset >= 0) {
int devIDBackup = -1; int devIDBackup = -1;
cudaGetDevice(&devIDBackup); cudaGetDevice(&devIDBackup);
cudaSetDevice(devID); cudaSetDevice(devIDReset);
cudaDeviceReset(); cudaDeviceReset();
......
...@@ -176,8 +176,9 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m ...@@ -176,8 +176,9 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m
/* free memory */ /* free memory */
void XMem::Free() void XMem::Free()
{ {
for(int i = 0; i < blockNum; i++){ for (int i = 0; i < blockNum; i++) {
Free(devID, blocks[i].mem); if (blocks != NULL)
Free(devID, blocks[i].mem);
} }
delete[] blocks; delete[] blocks;
blocks = NULL; blocks = NULL;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论