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
ddba745c
Commit
ddba745c
authored
Jun 20, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conditional set of data for integer-typed data arrays
parent
c04ec38e
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
89 行增加
和
2 行删除
+89
-2
source/tensor/core/getandset/SetData.cpp
+34
-1
source/tensor/core/getandset/SetData.cu
+48
-1
source/tensor/core/getandset/SetData.cuh
+4
-0
source/tensor/core/getandset/SetData.h
+3
-0
没有找到文件。
source/tensor/core/getandset/SetData.cpp
查看文件 @
ddba745c
...
...
@@ -238,7 +238,7 @@ 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!"
);
CheckNTErrors
(
condition
->
unitSize
==
sizeof
(
float
),
"TODO!"
);
if
(
tensor
->
dataType
==
DEFAULT_DTYPE
){
if
(
tensor
->
devID
<
0
){
...
...
@@ -259,6 +259,39 @@ void _SetDataFixedCond(XTensor * tensor, XTensor * condition, DTYPE 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
_SetDataFixedCondInt
(
XTensor
*
tensor
,
XTensor
*
condition
,
int
p
)
{
int
num
=
tensor
->
unitNum
;
CheckNTErrors
(
num
==
condition
->
unitNum
,
"Wrong size of the condition tensor!"
);
CheckNTErrors
(
condition
->
unitSize
==
sizeof
(
float
),
"TODO!"
);
if
(
tensor
->
dataType
==
DEFAULT_DTYPE
){
if
(
tensor
->
devID
<
0
){
int
*
data
=
(
int
*
)
tensor
->
data
;
int
*
cond
=
(
int
*
)
condition
->
data
;
for
(
int
i
=
0
;
i
<
num
;
i
++
){
if
(
cond
[
i
]
!=
0
)
data
[
i
]
=
p
;
}
}
else
{
_CudaSetDataFixedCondInt
(
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
查看文件 @
ddba745c
...
...
@@ -178,7 +178,7 @@ if the condition entry is non-zero
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!");
CheckNTErrors(condition->unitSize != sizeof(
float
), "TODO!");
int gridSize[3];
int blockSize[3];
...
...
@@ -198,6 +198,53 @@ void _CudaSetDataFixedCondFloat(XTensor * tensor, XTensor * condition, float 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 KernelSetDataFixedCondInt(int * d, float * c, int size, int 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 int) 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 _CudaSetDataFixedCondInt(XTensor * tensor, XTensor * condition, int p)
{
CheckNTErrors(tensor->dataType == X_FLOAT, "the tensor must be in X_FLOAT!");
CheckNTErrors(condition->unitSize != sizeof(float), "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);
KernelSetDataFixedCondInt <<<blocks, threads >>>((int*)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
查看文件 @
ddba745c
...
...
@@ -41,6 +41,10 @@ void _CudaSetDataFixedDouble(XTensor * tensor, double p);
if the condition entry is non-zero */
void _CudaSetDataFixedCondFloat(XTensor * tensor, XTensor * condition, float p);
/* generate data items with a fixed value p (in int) only
if the condition entry is non-zero */
void _CudaSetDataFixedCondInt(XTensor * tensor, XTensor * condition, int 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
查看文件 @
ddba745c
...
...
@@ -51,6 +51,9 @@ 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
);
/* generate data items with a fixed value p only if the condition entry is non-zero */
void
_SetDataFixedCondInt
(
XTensor
*
tensor
,
XTensor
*
condition
,
int
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论