Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
d969fe7b
Commit
d969fe7b
authored
Jul 22, 2019
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update codes
Allocating the global memory pool when it is requested.
parent
6946149c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
20 行删除
+34
-20
source/tensor/XMem.cpp
+27
-16
source/tensor/XMem.h
+7
-4
没有找到文件。
source/tensor/XMem.cpp
查看文件 @
d969fe7b
...
...
@@ -53,6 +53,7 @@ XMem::XMem()
strcpy
(
name
,
"xmem"
);
signature
=
0
;
mergeFreeOTF
=
true
;
isInitialized
=
false
;
}
/*
...
...
@@ -169,6 +170,7 @@ void XMem::Initialize(int myDevID, MEMPOOL_MODE myMode, MTYPE myBlockSize, int m
#endif
signature
++
;
isInitialized
=
true
;
}
/* free memory */
...
...
@@ -1579,11 +1581,6 @@ void XMemManager::Initialize()
/* CPUs (we actually do not care about how many CPUs are using) */
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 */
nGPUMem
=
0
;
...
...
@@ -1592,15 +1589,8 @@ void XMemManager::Initialize()
XPRINT
(
0
,
stderr
,
"cannot get GPU information."
);
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
}
/* free it */
...
...
@@ -1616,13 +1606,34 @@ void XMemManager::Free()
XMem
*
XMemManager
::
GetMem
(
const
int
devID
)
{
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
;
}
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
;
else
}
else
{
XPRINT1
(
0
,
stderr
,
"Cannot get the memory (%d). Please check your device id!"
,
devID
);
}
}
return
mem
;
...
...
source/tensor/XMem.h
查看文件 @
d969fe7b
...
...
@@ -60,10 +60,10 @@ typedef long long INT_64;
#define CUDA_HOST_MALLOC 1
#define MY_PITCH CUDA_PITCH
#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 MAX_CPU_NUM 1
6
#define MAX_GPU_NUM 1
6
#define MAX_CPU_NUM 1
#define MAX_GPU_NUM 1
/*
mode of runnig a memory pool
...
...
@@ -213,6 +213,9 @@ public:
MTYPE
curUsedPin
;
MTYPE
bufUsedPin
;
/* indicates whether the memory pool is initialized */
bool
isInitialized
;
#ifdef USE_CUDA
/* handle used for cublas */
cublasHandle_t
cublasHandle
;
...
...
@@ -429,7 +432,7 @@ a class for the management of memory
*/
class
XMemManager
{
p
ublic
:
p
rivate
:
/* cpu memory pool information */
XMem
CPUMems
[
MAX_CPU_NUM
];
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论