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
91fdf94e
Commit
91fdf94e
authored
Sep 09, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite parts of the memory pool to free the space on the fly
parent
97b41e35
全部展开
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
100 行增加
和
18 行删除
+100
-18
source/tensor/XMem.cpp
+0
-0
source/tensor/XMem.h
+34
-11
source/tensor/XTensor.cpp
+8
-6
source/tensor/test/TXMem.cpp
+58
-1
没有找到文件。
source/tensor/XMem.cpp
查看文件 @
91fdf94e
差异被折叠。
点击展开。
source/tensor/XMem.h
查看文件 @
91fdf94e
...
@@ -60,6 +60,8 @@ mode of runnig a memory pool
...
@@ -60,6 +60,8 @@ mode of runnig a memory pool
*/
*/
enum
MEMPOOL_MODE
{
UNI_FREE
,
FREE_ON_THE_FLY
};
enum
MEMPOOL_MODE
{
UNI_FREE
,
FREE_ON_THE_FLY
};
struct
MPieceNode
;
/* header of a memory piece (FREE_ON_THE_FLY) */
/* header of a memory piece (FREE_ON_THE_FLY) */
struct
MHeader
struct
MHeader
{
{
...
@@ -80,6 +82,9 @@ struct MHeader
...
@@ -80,6 +82,9 @@ struct MHeader
/* id of the memory block */
/* id of the memory block */
int
blockID
;
int
blockID
;
/* pointer to the index node */
MPieceNode
*
indexNode
;
};
};
/* index of memory piece */
/* index of memory piece */
...
@@ -97,8 +102,11 @@ struct MPieceNode
...
@@ -97,8 +102,11 @@ struct MPieceNode
/* pointer to the head of a memory piece */
/* pointer to the head of a memory piece */
void
*
p
;
void
*
p
;
/* pointer to the head of memory that is returned back to the user */
void
*
pReal
;
/* header of the memory piece */
/* header of the memory piece */
MHeader
*
head
;
MHeader
head
;
};
};
/* memory block */
/* memory block */
...
@@ -115,6 +123,9 @@ struct XMemBlock
...
@@ -115,6 +123,9 @@ struct XMemBlock
/* desired size of the block */
/* desired size of the block */
MTYPE
sizeDesired
;
MTYPE
sizeDesired
;
/* first head of the block */
MHeader
*
head
;
};
};
/*
/*
...
@@ -197,13 +208,16 @@ public:
...
@@ -197,13 +208,16 @@ public:
public
:
public
:
/* index of the free memory pieces */
/* index of the free memory pieces */
MPieceNode
*
freeMemIndex
;
MPieceNode
*
memIndex
;
/* for double buffering */
MPieceNode
*
memIndex2
;
/* maximum number of index nodes */
/* maximum number of index nodes */
INT_64
indexN
odeNum
;
INT_64
n
odeNum
;
/* count of the used nodes */
/* count of the used nodes */
INT_64
indexN
odeNumUsed
;
INT_64
n
odeNumUsed
;
/* minimal size allocation for each index entry */
/* minimal size allocation for each index entry */
MTYPE
*
minSizeIndex
;
MTYPE
*
minSizeIndex
;
...
@@ -285,10 +299,10 @@ public:
...
@@ -285,10 +299,10 @@ public:
void
*
AllocBuf
(
int
myDevID
,
MTYPE
mySize
,
int
pitch
=
BUF_PITCH
);
void
*
AllocBuf
(
int
myDevID
,
MTYPE
mySize
,
int
pitch
=
BUF_PITCH
);
/* release a piece of memory */
/* release a piece of memory */
void
Release
(
void
*
p
);
void
Release
(
void
*
p
,
MTYPE
size
);
/* release a piece of memory */
/* release a piece of memory */
void
Release
(
int
myDevID
,
void
*
p
);
void
Release
(
int
myDevID
,
void
*
p
,
MTYPE
size
);
/* release a piece of memory in the buffer */
/* release a piece of memory in the buffer */
void
ReleaseBuf
(
int
myDevID
,
MTYPE
mySize
,
int
pitch
=
BUF_PITCH
);
void
ReleaseBuf
(
int
myDevID
,
MTYPE
mySize
,
int
pitch
=
BUF_PITCH
);
...
@@ -305,14 +319,20 @@ public:
...
@@ -305,14 +319,20 @@ public:
/* find the index entry for allocation query */
/* find the index entry for allocation query */
int
FindIndexEntry
(
MTYPE
mySize
);
int
FindIndexEntry
(
MTYPE
mySize
);
/* remove an index node */
/* remove an index node for available memory pieces */
void
RemoveIndexNode
(
MPieceNode
*
node
,
MPieceNode
*
entry
=
NULL
);
void
RemoveFreeIndexNode
(
MPieceNode
*
node
,
MPieceNode
*
entry
=
NULL
);
/* add an index node for available memory pieces */
void
AddFreeIndexNode
(
MPieceNode
*
node
,
MPieceNode
*
entry
=
NULL
);
/* add an index node */
/* remove an index node for memory pieces in use */
void
AddIndexNode
(
MPieceNode
*
node
,
MPieceNode
*
entry
=
NULL
);
void
RemoveAllocIndexNode
(
MPieceNode
*
node
,
MPieceNode
*
entry
=
NULL
);
/* add an index node for available memory pieces ∂*/
void
AddAllocIndexNode
(
MPieceNode
*
node
,
MPieceNode
*
entry
=
NULL
);
/* release a piece of memory as "free" */
/* release a piece of memory as "free" */
void
ReleaseStandard
(
int
myDevID
,
void
*
p
);
void
ReleaseStandard
(
int
myDevID
,
void
*
p
,
MTYPE
size
);
/* rebuild index to merge small fragments of memory and free the block with no use */
/* rebuild index to merge small fragments of memory and free the block with no use */
void
RebuildIndex
();
void
RebuildIndex
();
...
@@ -382,6 +402,9 @@ public:
...
@@ -382,6 +402,9 @@ public:
extern
XMem
*
GMem
;
extern
XMem
*
GMem
;
extern
int
testxmemid
;
extern
void
*
recordp
;
}
/* end of the nts (NiuTrans.Tensor) namespace */
}
/* end of the nts (NiuTrans.Tensor) namespace */
#endif
#endif
source/tensor/XTensor.cpp
查看文件 @
91fdf94e
...
@@ -254,7 +254,7 @@ void XTensor::DestroyData()
...
@@ -254,7 +254,7 @@ void XTensor::DestroyData()
else
if
(
data
!=
NULL
&&
isInGlobalMem
)
else
if
(
data
!=
NULL
&&
isInGlobalMem
)
FreeData
(
this
,
mem
);
FreeData
(
this
,
mem
);
else
if
(
data
!=
NULL
)
else
if
(
data
!=
NULL
)
mem
->
Release
(
data
);
mem
->
Release
(
data
,
GetDataSizeInChar
()
);
data
=
NULL
;
data
=
NULL
;
if
(
dataHost
!=
NULL
)
if
(
dataHost
!=
NULL
)
...
@@ -1135,19 +1135,21 @@ resize a tensor with a specified tensor size
...
@@ -1135,19 +1135,21 @@ resize a tensor with a specified tensor size
bool
XTensor
::
Resize
(
const
int
myOrder
,
const
int
*
myDimSize
,
bool
XTensor
::
Resize
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
,
const
float
myDenseRatio
)
const
TENSOR_DATA_TYPE
myDataType
,
const
float
myDenseRatio
)
{
{
order
=
myOrder
;
unitNum
=
1
;
unitNumNonZero
=
0
;
isInit
=
true
;
/* free old mem */
/* free old mem */
if
(
data
!=
NULL
){
if
(
data
!=
NULL
){
if
(
mem
==
NULL
)
if
(
mem
==
NULL
)
XMemFree
(
devID
,
data
);
XMemFree
(
devID
,
data
);
else
else
mem
->
Release
(
data
);
mem
->
Release
(
data
,
GetDataSizeInChar
()
);
}
}
order
=
myOrder
;
unitNum
=
1
;
unitNumNonZero
=
0
;
isInit
=
true
;
bool
filledData
=
true
;
bool
filledData
=
true
;
bool
zeroData
=
false
;
bool
zeroData
=
false
;
for
(
int
i
=
0
;
i
<
order
;
i
++
){
for
(
int
i
=
0
;
i
<
order
;
i
++
){
...
...
source/tensor/test/TXMem.cpp
查看文件 @
91fdf94e
...
@@ -63,6 +63,8 @@ bool TestXMemCase1()
...
@@ -63,6 +63,8 @@ bool TestXMemCase1()
}
}
for
(
int
i
=
0
;
i
<
testNum
*
scalar
;
i
++
)
{
for
(
int
i
=
0
;
i
<
testNum
*
scalar
;
i
++
)
{
testxmemid
++
;
//fprintf(stderr, "%d\n", testxmemid);
int
j
=
rand
()
%
caseNum
;
int
j
=
rand
()
%
caseNum
;
if
(
p
[
j
]
==
NULL
)
{
if
(
p
[
j
]
==
NULL
)
{
...
@@ -71,7 +73,7 @@ bool TestXMemCase1()
...
@@ -71,7 +73,7 @@ bool TestXMemCase1()
p
[
j
][
k
]
=
j
;
p
[
j
][
k
]
=
j
;
}
}
else
{
else
{
mem
.
ReleaseStandard
(
mem
.
devID
,
p
[
j
]);
mem
.
ReleaseStandard
(
mem
.
devID
,
p
[
j
]
,
size
[
j
]
*
sizeof
(
int
)
);
for
(
int
k
=
0
;
k
<
size
[
j
];
k
++
)
for
(
int
k
=
0
;
k
<
size
[
j
];
k
++
)
p
[
j
][
k
]
=
-
1
;
p
[
j
][
k
]
=
-
1
;
p
[
j
]
=
NULL
;
p
[
j
]
=
NULL
;
...
@@ -86,6 +88,61 @@ bool TestXMemCase1()
...
@@ -86,6 +88,61 @@ bool TestXMemCase1()
}
}
}
}
}
}
/*MPieceNode * entry = NULL;
MPieceNode * node = NULL;
entry = mem.memIndex + mem.indexEntryNum + mem.FindIndexEntry(112);
int cc = 0;
node = entry->next;
while(node != NULL){
fprintf(stderr, "%d ", cc++);
if(node->size == 0){
MPieceNode * next = node->next;
node = next;
}
else{
CheckNTErrors(node->pReal != NULL, "Illegal pointer!");
node = node->next;
}
}
fprintf(stderr, "\n");*/
/*int ccc = 0;
bool hhh = recordp != NULL ? false : true;
for(int i = 0; i < mem.indexEntryNum; i++){
MPieceNode * entry = mem.memIndex + mem.indexEntryNum + i;
MPieceNode * last = entry;
MPieceNode * node = entry->next;
ccc = 0;
while(node != NULL){
CheckNTErrors(node->pre == last, "XSomething is wrong!");
CheckNTErrors(last->next == node, "XSomething is wrong!");
last = node;
ccc++;
if(node->pReal == recordp){
hhh = true;
}
if(node->size == 0){
MPieceNode * next = node->next;
node = next;
}
else{
CheckNTErrors(node->pReal != NULL, "Illegal pointer!");
node = node->next;
}
}
}
if(!hhh){
int nnn = 0;
}*/
}
}
delete
[]
p
;
delete
[]
p
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论