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
c04ec38e
Commit
c04ec38e
authored
Jun 20, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add SetData-by-condition
parent
04d23e39
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
87 行增加
和
0 行删除
+87
-0
source/tensor/core/getandset/SetData.cpp
+33
-0
source/tensor/core/getandset/SetData.cu
+47
-0
source/tensor/core/getandset/SetData.cuh
+4
-0
source/tensor/core/getandset/SetData.h
+3
-0
没有找到文件。
source/tensor/core/getandset/SetData.cpp
查看文件 @
c04ec38e
...
...
@@ -226,6 +226,39 @@ void _SetDataFixedDouble(XTensor * tensor, double p)
}
/*
generate data items with a fixed value p only if
the condition entry is non-zero
>> tensor - the tensor whose data array would be initialized
>> condition - the condition tensor whose entries would be checked
for set the corresponding entries in "tensor"
>> p - a given value
*/
void
_SetDataFixedCond
(
XTensor
*
tensor
,
XTensor
*
condition
,
DTYPE
p
)
{
int
num
=
tensor
->
unitNum
;
CheckNTErrors
(
num
==
condition
->
unitNum
,
"Wrong size of the condition tensor!"
);
CheckNTErrors
(
condition
->
unitSize
!=
sizeof
(
DTYPE
),
"TODO!"
);
if
(
tensor
->
dataType
==
DEFAULT_DTYPE
){
if
(
tensor
->
devID
<
0
){
DTYPE
*
data
=
(
DTYPE
*
)
tensor
->
data
;
DTYPE
*
cond
=
(
DTYPE
*
)
condition
->
data
;
for
(
int
i
=
0
;
i
<
num
;
i
++
){
if
(
cond
[
i
]
!=
0
)
data
[
i
]
=
p
;
}
}
else
{
_CudaSetDataFixedCondFloat
(
tensor
,
condition
,
p
);
}
}
else
{
ShowNTErrors
(
"TODO!"
);
}
}
/*
set data items along with a given dimension (and keep the remaining items unchanged)
>> tensor - the tensor whose data array would be initialized
>> beg - the beginning position
...
...
source/tensor/core/getandset/SetData.cu
查看文件 @
c04ec38e
...
...
@@ -151,6 +151,53 @@ void _CudaSetDataFixedDouble(XTensor * tensor, double p)
}
/*
set a float data array with a fixed value p (in int) only
if the condition entry is non-zero
>> d - pointer to the data array
>> c - pointer to the condition array
>> size - size of the array
>> p - the initial value
*/
__global__
void KernelSetDataFixedCondFloat(float * d, float * c, int size, float p)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < size && c[i] != 0)
d[i] = p;
}
/*
generate data items with a fixed value p (in float) only
if the condition entry is non-zero
>> tensor - the tensor for initialization
>> condition - the condition tensor whose entry would be check to
set the corresponding entry in "tensor"
>> p - the initial value
*/
void _CudaSetDataFixedCondFloat(XTensor * tensor, XTensor * condition, float p)
{
CheckNTErrors(tensor->dataType == X_FLOAT, "the tensor must be in X_FLOAT!");
CheckNTErrors(condition->unitSize != sizeof(DTYPE), "TODO!");
int gridSize[3];
int blockSize[3];
GDevs.GetCudaThread(tensor->devID, tensor->unitNum, gridSize, blockSize);
dim3 blocks(gridSize[0]);
dim3 threads(blockSize[0]);
int devIDBackup;
ProtectCudaDev(tensor->devID, devIDBackup);
KernelSetDataFixedCondFloat <<<blocks, threads >>>((float*)tensor->data, (float*)condition->data,
tensor->unitNum, p);
BacktoCudaDev(tensor->devID, devIDBackup);
}
/*
set data array with a uniform distribution in [low, high]
>> deviceStates - the state of curand
>> d - float datatype pointer to the data array
...
...
source/tensor/core/getandset/SetData.cuh
查看文件 @
c04ec38e
...
...
@@ -37,6 +37,10 @@ void _CudaSetDataFixedFloat(XTensor * tensor, float p);
/* generate data items with a fixed value p (in double) */
void _CudaSetDataFixedDouble(XTensor * tensor, double p);
/* generate data items with a fixed value p (in float) only
if the condition entry is non-zero */
void _CudaSetDataFixedCondFloat(XTensor * tensor, XTensor * condition, float p);
/* set data items along with a given dimension (and keep the remaining items unchanged) */
void _CudaSetDataDim(XTensor * tensor, int beg, int len, int dim, DTYPE p);
...
...
source/tensor/core/getandset/SetData.h
查看文件 @
c04ec38e
...
...
@@ -48,6 +48,9 @@ void _SetDataFixedFloat(XTensor * tensor, float p);
/* generate data items with a fixed value p (in double) */
void
_SetDataFixedDouble
(
XTensor
*
tensor
,
double
p
);
/* generate data items with a fixed value p only if the condition entry is non-zero */
void
_SetDataFixedCond
(
XTensor
*
tensor
,
XTensor
*
condition
,
DTYPE
p
);
/* set data items along with a given dimension (and keep the remaining items unchanged) */
void
_SetDataDim
(
XTensor
*
tensor
,
int
beg
,
int
len
,
int
dim
,
DTYPE
p
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论