Commit d969fe7b by liyinqiao

Update codes

Allocating the global memory pool when it is requested.
parent 6946149c
...@@ -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, FREE_ON_THE_FLY, 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, FREE_ON_THE_FLY, MIN_BLOCK_SIZE_FOR_MEMPOOL, MIN_BLOCK_NUM_FOR_MEMPOOL, myBufSize);
}
#endif #endif
} }
/* free it */ /* free it */
...@@ -1616,13 +1606,34 @@ void XMemManager::Free() ...@@ -1616,13 +1606,34 @@ 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;
......
...@@ -60,10 +60,10 @@ typedef long long INT_64; ...@@ -60,10 +60,10 @@ typedef long long INT_64;
#define CUDA_HOST_MALLOC 1 #define CUDA_HOST_MALLOC 1
#define MY_PITCH CUDA_PITCH #define MY_PITCH CUDA_PITCH
#define BUF_PITCH 256 #define BUF_PITCH 256
#define MIN_BLOCK_SIZE_FOR_MEMPOOL 256 * 1024 * 1024 #define MIN_BLOCK_SIZE_FOR_MEMPOOL 128 * 1024 * 1024
#define MIN_BLOCK_NUM_FOR_MEMPOOL 1024 #define MIN_BLOCK_NUM_FOR_MEMPOOL 1024
#define MAX_CPU_NUM 16 #define MAX_CPU_NUM 1
#define MAX_GPU_NUM 16 #define MAX_GPU_NUM 1
/* /*
mode of runnig a memory pool mode of runnig a memory pool
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论