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
c63a9754
Commit
c63a9754
authored
Mar 19, 2020
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixed.
1. Fix the bugs in SetDevice functions and FlushToMem functions. 2. Fix the minor errors.
parent
29c26ce6
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
7 行删除
+45
-7
source/tensor/XMem.cpp
+2
-1
source/tensor/XTensor.cpp
+11
-5
source/tensor/core/utilities/FlushToMem.cu
+32
-1
没有找到文件。
source/tensor/XMem.cpp
查看文件 @
c63a9754
...
...
@@ -1632,7 +1632,8 @@ XMem * XMemManager::GetMem(const int devID)
mem
=
GPUMems
+
devID
;
}
else
{
XPRINT1
(
0
,
stderr
,
"Cannot get the memory (%d). Please check your device id!"
,
devID
);
XPRINT1
(
0
,
stderr
,
"Please check your device id (%d)!"
,
devID
);
ShowNTErrors
(
"Cannot get the memory!"
);
}
}
...
...
source/tensor/XTensor.cpp
查看文件 @
c63a9754
...
...
@@ -520,9 +520,8 @@ relocate the data on the target device
*/
void
XTensor
::
SetDevice
(
int
myDevId
,
XMem
*
myMem
)
{
if
(
myMem
==
NULL
)
{
if
(
myMem
==
NULL
)
myMem
=
GMems
.
GetMem
(
myDevId
);
}
FlushToMem
(
myMem
);
isInGlobalMem
=
false
;
}
...
...
@@ -1914,6 +1913,7 @@ void XTensor::FlushToMem(XMem* targetMem)
else
if
(
mem
!=
targetMem
)
{
void
*
tmpData
=
targetMem
->
Alloc
(
targetMem
->
devID
,
GetDataSizeInChar
());
XMemCopy
(
tmpData
,
targetMem
->
devID
,
data
,
devID
,
GetDataSizeInChar
());
mem
->
Release
(
data
,
GetDataSizeInChar
(),
signature
);
data
=
tmpData
;
mem
=
targetMem
;
devID
=
mem
->
devID
;
...
...
@@ -1925,13 +1925,19 @@ void XTensor::FlushToMem(XMem* targetMem)
else
{
if
(
devID
>=
0
)
{
#ifdef USE_CUDA
CudaGPUToCPUFlush
(
this
);
mem
=
targetMem
;
devID
=
mem
->
devID
;
CudaGPUToCPUFlush
(
this
,
targetMem
->
devID
,
targetMem
);
#else
ShowNTErrors
(
"Recompile the code with USE_CUDA!"
);
#endif
}
else
if
(
mem
!=
targetMem
)
{
void
*
tmpData
=
targetMem
->
Alloc
(
targetMem
->
devID
,
GetDataSizeInChar
());
XMemCopy
(
tmpData
,
targetMem
->
devID
,
data
,
devID
,
GetDataSizeInChar
());
mem
->
Release
(
data
,
GetDataSizeInChar
(),
signature
);
data
=
tmpData
;
mem
=
targetMem
;
devID
=
mem
->
devID
;
}
}
}
...
...
source/tensor/core/utilities/FlushToMem.cu
查看文件 @
c63a9754
...
...
@@ -78,6 +78,8 @@ void CudaCPUToGPUFlush(TensorList * mList, int devID, XMem * GPUMem)
if(m->mem == NULL)
delete[] (char*)m->data;
else
m->mem->Release(m->data, m->GetDataSizeInChar(), m->signature);
m->dataHost = NULL;
m->data = GPUData + p;
...
...
@@ -94,7 +96,36 @@ void CudaCPUToGPUFlush(TensorList * mList, int devID, XMem * GPUMem)
#endif
}
/* copy the data from GPU memory to CPU memory */
/* copy the data from GPU memory to CPU memory (memory pool) */
void CudaGPUToCPUFlush(XTensor * tensor, int devID, XMem * CPUMem)
{
#ifdef USE_CUDA
CheckNTErrors((tensor->devID >= 0), "Cannot do cpu-flush on matrices that are already on CPU.");
/* compute the requried memory size */
int size = 0;
if (m->isSparse)
size = sizeof(int) + (sizeof(int) + tensor->unitSize) * tensor->unitNumNonZero;
else
size = tensor->unitSize * tensor->unitNum;
char * CPUData = CPUMem != NULL ? (char*)CPUMem->Alloc(CPUMem->devID, size):
(char*)XMemAlloc(devID, size);
/* copy from CPU memory to GPU memory */
cudaMemcpy(CPUData, tensor->data, size, cudaMemcpyDeviceToHost);
if (tensor->dataHost != NULL)
delete[](char*)tensor->dataHost;
tensor->dataHost = NULL;
tensor->mem->Release(tensor->data, tensor->GetDataSizeInChar(), tensor->signature);
tensor->data = CPUData;
tensor->devID = CPUMem != NULL ? CPUMem->devID : devID;
tensor->mem = CPUMem;
#endif
}
/* copy the data from GPU memory to CPU memory ((dataHost)) and do not delete the data */
void CudaGPUToCPUFlush(XTensor * tensor)
{
CheckNTErrors((sizeof(DTYPE) == tensor->unitSize), "Unsupported data type.");
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论