Commit ca343382 by xiaotong

reduce memory footprint for XMem

parent 12f84346
...@@ -155,8 +155,13 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m ...@@ -155,8 +155,13 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m
bufSize = myBufSize; bufSize = myBufSize;
#ifdef SMALL_DEVICE
if (myMode == FREE_ON_THE_FLY)
SetIndex(50000);
#else
if (myMode == FREE_ON_THE_FLY) if (myMode == FREE_ON_THE_FLY)
SetIndex(MILLION); SetIndex(MILLION);
#endif
signature++; signature++;
} }
...@@ -659,6 +664,9 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -659,6 +664,9 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
cur.next = &next; cur.next = &next;
cur.size = needed; cur.size = needed;
if(next.next != NULL)
next.next->pre = &next;
next.state = 1; next.state = 1;
next.size = remaining; next.size = remaining;
next.blockID = cur.blockID; next.blockID = cur.blockID;
...@@ -683,7 +691,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -683,7 +691,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
} }
/* if there is still no available memory piece, we have to obtain a new block of memory. */ /* if there is still no available memory piece, we have to obtain a new block of memory. */
else{ else{
MTYPE used = 0; /*MTYPE used = 0;
MTYPE total = 0; MTYPE total = 0;
MTYPE free = 0; MTYPE free = 0;
for(int i = 0; i < blockNum; i++){ for(int i = 0; i < blockNum; i++){
...@@ -706,11 +714,11 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -706,11 +714,11 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
node = next; node = next;
} }
else{ else{
if(node->size >= mySize){ if(node->head.state == 1 && node->size >= mySize){
fprintf(stderr, "hit!!!!!!!!!!!\n"); fprintf(stderr, "hit!!!!!!!!!!!\n");
} }
fprintf(stderr, "%d %lld %lld %lld\n", node->head.blockID, free, node->size, mySize); //fprintf(stderr, "%d %lld %lld %lld\n", node->head.blockID, free, node->size, mySize);
free += node->size; free += node->size;
node = node->next; node = node->next;
...@@ -718,19 +726,6 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -718,19 +726,6 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
} }
} }
for(int i = 0; i < bufNodeCount; i++){
for(int j = i + 1; j < bufNodeCount; j++){
MTYPE gap1 = (MTYPE)bufNodes[i].p - (MTYPE)bufNodes[j].p - bufNodes[j].head.size;
MTYPE gap2 = (MTYPE)bufNodes[j].p - (MTYPE)bufNodes[i].p - bufNodes[i].head.size;
if(gap1 > 0 && gap1 < 128){
int nnn = 0;
}
if(gap2 > 0 && gap2 < 128){
int nnn = 0;
}
}
}
MTYPE headSize = 0; MTYPE headSize = 0;
MTYPE headSizeUsed = 0; MTYPE headSizeUsed = 0;
for(int i = 0, j = 0; i < blockNum; i++){ for(int i = 0, j = 0; i < blockNum; i++){
...@@ -753,7 +748,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -753,7 +748,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
delete[] bufNodes; delete[] bufNodes;
fprintf(stderr, "%lld %lld\n", headSize, headSizeUsed); fprintf(stderr, "%lld %lld\n", headSize, headSizeUsed);
fprintf(stderr, "mem: %lld %lld %lld %lld\n", used, total, free, mySize); fprintf(stderr, "mem: %lld %lld %lld %lld\n", used, total, free, mySize);*/
int bi; int bi;
for(bi = 0; bi < blockNum; bi++){ for(bi = 0; bi < blockNum; bi++){
...@@ -1086,14 +1081,6 @@ void XMem::ReleaseStandard(int myDevID, void * p, MTYPE size) ...@@ -1086,14 +1081,6 @@ void XMem::ReleaseStandard(int myDevID, void * p, MTYPE size)
hit->head.size += pre->size; hit->head.size += pre->size;
RemoveAllocIndexNode(pre->indexNode); RemoveAllocIndexNode(pre->indexNode);
if(pre == blocks[head->blockID].head){
int nnn = 0;
}
if(head == blocks[head->blockID].head){
int nnn = 0;
}
if(pre == blocks[head->blockID].head) if(pre == blocks[head->blockID].head)
blocks[head->blockID].head = head; blocks[head->blockID].head = head;
} }
...@@ -1182,7 +1169,7 @@ void XMem::RebuildIndex() ...@@ -1182,7 +1169,7 @@ void XMem::RebuildIndex()
if(head->state == 1){ if(head->state == 1){
newNode->size = (char*)p + head->size - newNode->size = (char*)p + head->size -
( head->state == 1 ? (char*)GetPitchedAddress((char*)p, MY_PITCH) : (char*)head->indexNode->pReal); (head->state == 1 ? (char*)GetPitchedAddress((char*)p, MY_PITCH) : (char*)head->indexNode->pReal);
} }
else else
newNode->size = node->size; newNode->size = node->size;
...@@ -1203,7 +1190,6 @@ void XMem::RebuildIndex() ...@@ -1203,7 +1190,6 @@ void XMem::RebuildIndex()
if(newLast != NULL) if(newLast != NULL)
newLast->next = newHeader; newLast->next = newHeader;
newHeader->pre = newLast;
if(head->state == 1){ if(head->state == 1){
newNode->pReal = NULL; newNode->pReal = NULL;
......
...@@ -68,6 +68,7 @@ bool TestXMemCase1() ...@@ -68,6 +68,7 @@ bool TestXMemCase1()
int j = rand() % caseNum; int j = rand() % caseNum;
//fprintf(stderr, "%d %d %d\n", testxmemid, j, ok); //fprintf(stderr, "%d %d %d\n", testxmemid, j, ok);
//fprintf(stderr, "iter %d %d %d\n", iter, i, j);
if (p[j] == NULL) { if (p[j] == NULL) {
p[j] = (int*)mem.AllocStandard(mem.devID, size[j] * sizeof(int)); p[j] = (int*)mem.AllocStandard(mem.devID, size[j] * sizeof(int));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论