Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
杨迪
NiuTrans.Tensor
Commits
ca343382
Commit
ca343382
authored
Nov 15, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce memory footprint for XMem
parent
12f84346
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
27 行删除
+14
-27
source/tensor/XMem.cpp
+13
-27
source/tensor/test/TXMem.cpp
+1
-0
没有找到文件。
source/tensor/XMem.cpp
查看文件 @
ca343382
...
@@ -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
;
...
...
source/tensor/test/TXMem.cpp
查看文件 @
ca343382
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论