Commit 6936bb57 by xiaotong

allocating the global memory pool when it is requested

parent 4fda7c2b
...@@ -53,6 +53,7 @@ XMem::XMem() ...@@ -53,6 +53,7 @@ XMem::XMem()
strcpy(name, "xmem"); strcpy(name, "xmem");
signature = 0; signature = 0;
mergeFreeOTF = true; mergeFreeOTF = true;
isInitialized = false;
} }
/* /*
...@@ -169,6 +170,7 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m ...@@ -169,6 +170,7 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m
#endif #endif
signature++; signature++;
isInitialized = true;
} }
/* free memory */ /* free memory */
...@@ -1579,11 +1581,6 @@ void XMemManager::Initialize() ...@@ -1579,11 +1581,6 @@ void XMemManager::Initialize()
/* CPUs (we actually do not care about how many CPUs are using) */ /* CPUs (we actually do not care about how many CPUs are using) */
nCPUMem = 1; nCPUMem = 1;
MTYPE freeMem = GetAvailableMemory();
MTYPE myBufSize = 0;
GetBufferSize(freeMem, &myBufSize);
CPUMems[0].Initialize(-1, UNI_FREE, MIN_BLOCK_SIZE_FOR_MEMPOOL, MIN_BLOCK_NUM_FOR_MEMPOOL, myBufSize);
/* GPUs */ /* GPUs */
nGPUMem = 0; nGPUMem = 0;
...@@ -1592,15 +1589,8 @@ void XMemManager::Initialize() ...@@ -1592,15 +1589,8 @@ void XMemManager::Initialize()
XPRINT(0, stderr, "cannot get GPU information."); XPRINT(0, stderr, "cannot get GPU information.");
exit(1); exit(1);
} }
for (int i = 0; i < nGPUMem; i++) {
MTYPE freeMem = GetAvailableGPUMemory(i);
MTYPE myBufSize = 0;
GetBufferSize(freeMem, &myBufSize);
GPUMems[i].Initialize(i, UNI_FREE, MIN_BLOCK_SIZE_FOR_MEMPOOL, MIN_BLOCK_NUM_FOR_MEMPOOL, myBufSize);
}
#endif #endif
} }
/* free it */ /* free it */
...@@ -1616,14 +1606,35 @@ void XMemManager::Free() ...@@ -1616,14 +1606,35 @@ void XMemManager::Free()
XMem * XMemManager::GetMem(const int devID) XMem * XMemManager::GetMem(const int devID)
{ {
XMem * mem = NULL; XMem * mem = NULL;
if (devID < 0) if (devID < 0){
if(!CPUMems[0].isInitialized){
MTYPE freeMem = GetAvailableMemory();
MTYPE myBufSize = 0;
GetBufferSize(freeMem, &myBufSize);
CPUMems[0].Initialize(-1, FREE_ON_THE_FLY,
MIN_BLOCK_SIZE_FOR_MEMPOOL,
MIN_BLOCK_NUM_FOR_MEMPOOL,
myBufSize);
}
mem = CPUMems; mem = CPUMems;
}
else{ else{
if (devID < nGPUMem) if (devID < nGPUMem){
if(!GPUMems[devID].isInitialized){
MTYPE freeMem = GetAvailableGPUMemory(devID);
MTYPE myBufSize = 0;
GetBufferSize(freeMem, &myBufSize);
GPUMems[devID].Initialize(devID, FREE_ON_THE_FLY,
MIN_BLOCK_SIZE_FOR_MEMPOOL,
MIN_BLOCK_NUM_FOR_MEMPOOL,
myBufSize);
}
mem = GPUMems + devID; mem = GPUMems + devID;
else }
else{
XPRINT1(0, stderr, "Cannot get the memory (%d). Please check your device id!", devID); XPRINT1(0, stderr, "Cannot get the memory (%d). Please check your device id!", devID);
} }
}
return mem; return mem;
} }
......
...@@ -213,6 +213,9 @@ public: ...@@ -213,6 +213,9 @@ public:
MTYPE curUsedPin; MTYPE curUsedPin;
MTYPE bufUsedPin; MTYPE bufUsedPin;
/* indicates whether the memory pool is initialized */
bool isInitialized;
#ifdef USE_CUDA #ifdef USE_CUDA
/* handle used for cublas */ /* handle used for cublas */
cublasHandle_t cublasHandle; cublasHandle_t cublasHandle;
...@@ -429,7 +432,7 @@ a class for the management of memory ...@@ -429,7 +432,7 @@ a class for the management of memory
*/ */
class XMemManager class XMemManager
{ {
public: private:
/* cpu memory pool information */ /* cpu memory pool information */
XMem CPUMems[MAX_CPU_NUM]; XMem CPUMems[MAX_CPU_NUM];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论