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
Emmay
NiuTrans.Tensor
Commits
e9f4a75b
Commit
e9f4a75b
authored
Apr 06, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixes of binary math functions
parent
97338baf
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
68 行增加
和
37 行删除
+68
-37
source/sample/transformer/T2TSearch.cpp
+1
-0
source/tensor/core/math/Binary.cpp
+32
-22
source/tensor/core/math/Binary.cu
+1
-1
source/tensor/core/math/Binary.cuh
+2
-2
source/tensor/core/math/Binary.h
+32
-12
没有找到文件。
source/sample/transformer/T2TSearch.cpp
查看文件 @
e9f4a75b
...
...
@@ -129,6 +129,7 @@ void T2TSearch::Generate(T2TStateBundle * beam)
int
sizePredict
=
score
.
GetDim
(
-
1
);
/* pre id !!! */
Descale
(
preID
,
sizePredict
);
/* mod !!! */
...
...
source/tensor/core/math/Binary.cpp
查看文件 @
e9f4a75b
...
...
@@ -54,11 +54,10 @@ void _funcName(const XTensor * a, XTensor * b, int num) \
/* run it on GPUs */
\
if (a->devID >= 0) { \
_cudaFuncName(a, b, num); \
b->Dump(stderr, "zxc"); \
return; \
} \
CheckNTErrors((XTensor::IsSameShaped(a, b)), \
"Input tensors should have the same
type!");
\
"Input tensors should have the same
data type!");
\
CheckNTErrors((a->dataType == X_INT), "TODO!"); \
int * d = (int*)a->data; \
int * db = (int*)b->data; \
...
...
@@ -66,63 +65,74 @@ void _funcName(const XTensor * a, XTensor * b, int num) \
db[i] = (int)origFunc(d[i], num); \
}
#define SIMPLE_BINARY_FUNCTION_ME(funcName, _funcName) \
void funcName(XTensor &a, int num) \
{ \
_funcName(&a, &a, num); \
}
#define SIMPLE_BINARY_FUNCTION(funcName, _funcName) \
XTensor funcName(const XTensor &a, int num)
\
void funcName(const XTensor &a, int num)
\
{ \
XTensor b(&a); \
b.SetTMPFlag(); \
_funcName(&a, &b, num); \
b.Dump(stderr, "asd"); \
return b; \
}
_SIMPLE_BINARY_FUNCTION
(
_Scale
,
_CudaScale
,
scale
)
SIMPLE_BINARY_FUNCTION_ME
(
Scale
,
_Scale
)
SIMPLE_BINARY_FUNCTION
(
Scale
,
_Scale
)
_SIMPLE_BINARY_FUNCTION
(
_DeScale
,
_CudaDeScale
,
descale
)
SIMPLE_BINARY_FUNCTION
(
DeScale
,
_DeScale
)
_SIMPLE_BINARY_FUNCTION
(
_Descale
,
_CudaDescale
,
descale
)
SIMPLE_BINARY_FUNCTION_ME
(
Descale
,
_Descale
)
SIMPLE_BINARY_FUNCTION
(
Descale
,
_Descale
)
_SIMPLE_BINARY_FUNCTION
(
_Shift
,
_CudaShift
,
shift
)
SIMPLE_BINARY_FUNCTION_ME
(
Shift
,
_Shift
)
SIMPLE_BINARY_FUNCTION
(
Shift
,
_Shift
)
_SIMPLE_BINARY_FUNCTION
(
_Mod
,
_CudaMod
,
mod
)
SIMPLE_BINARY_FUNCTION_ME
(
Mod
,
_Mod
)
SIMPLE_BINARY_FUNCTION
(
Mod
,
_Mod
)
#else
/* define three marco separately, specify the respective function names (CPU mode) */
#define _SIMPLE_BINARY_FUNCTION(_funcName,
_cudaFuncName, origFunc)
\
#define _SIMPLE_BINARY_FUNCTION(_funcName,
origFunc)
\
void _funcName(const XTensor * a, XTensor * b, int num) \
{ \
/* run it on GPUs */
\
if (a->devID >= 0) { \
_cudaFuncName(a, b, num); \
return; \
} \
CheckNTErrors((XTensor::IsSameShaped(a, b)), \
"Input tensors should have the same
type!");
\
CheckNTErrors((a->dataType ==
DEFAULT_DTYPE), "TODO!");
\
"Input tensors should have the same
data type!");
\
CheckNTErrors((a->dataType ==
X_INT), "TODO!");
\
int * d = (int*)a->data; \
int * db = (int*)b->data; \
for (int i = 0; i < a->unitNum; i++) \
db[i] = (int)origFunc(d[i], num); \
}
#define SIMPLE_BINARY_FUNCTION_ME(funcName, _funcName) \
void funcName(XTensor & a, int num) \
{ \
_funcName(&a, &a, num); \
}
#define SIMPLE_BINARY_FUNCTION(funcName, _funcName) \
void funcName(const XTensor & a, XTensor &b, int num) \
{ \
_funcName(&a, &b, num); \
}
_SIMPLE_BINARY_FUNCTION
(
_Scale
,
_CudaScale
,
scale
)
_SIMPLE_BINARY_FUNCTION
(
_Scale
,
scale
)
SIMPLE_BINARY_FUNCTION_ME
(
Scale
,
_Scale
)
SIMPLE_BINARY_FUNCTION
(
Scale
,
_Scale
)
_SIMPLE_BINARY_FUNCTION
(
_DeScale
,
_CudaDeScale
,
descale
)
SIMPLE_BINARY_FUNCTION
(
DeScale
,
_DeScale
)
_SIMPLE_BINARY_FUNCTION
(
_Descale
,
descale
)
SIMPLE_BINARY_FUNCTION_ME
(
Descale
,
_Descale
)
SIMPLE_BINARY_FUNCTION
(
Descale
,
_Descale
)
_SIMPLE_BINARY_FUNCTION
(
_Shift
,
_CudaShift
,
shift
)
_SIMPLE_BINARY_FUNCTION
(
_Shift
,
shift
)
SIMPLE_BINARY_FUNCTION_ME
(
Shift
,
_Shift
)
SIMPLE_BINARY_FUNCTION
(
Shift
,
_Shift
)
_SIMPLE_BINARY_FUNCTION
(
_Mod
,
_CudaMod
,
mod
)
_SIMPLE_BINARY_FUNCTION
(
_Mod
,
mod
)
SIMPLE_BINARY_FUNCTION_ME
(
Mod
,
_Mod
)
SIMPLE_BINARY_FUNCTION
(
Mod
,
_Mod
)
#endif
...
...
source/tensor/core/math/Binary.cu
查看文件 @
e9f4a75b
...
...
@@ -93,7 +93,7 @@ void _Cuda##funcName(const XTensor * a, XTensor * b, int num) \
} \
SIMPLE_BINARY_FUNCTION_GPU(Scale, cudascale)
SIMPLE_BINARY_FUNCTION_GPU(De
S
cale, cudadescale)
SIMPLE_BINARY_FUNCTION_GPU(De
s
cale, cudadescale)
SIMPLE_BINARY_FUNCTION_GPU(Shift, cudashift)
SIMPLE_BINARY_FUNCTION_GPU(Mod, cudamod)
...
...
source/tensor/core/math/Binary.cuh
查看文件 @
e9f4a75b
...
...
@@ -37,9 +37,9 @@ void _CudaScale(const XTensor * a, XTensor * b, int num);
/* descale each entry (CUDA Kernel) */
__global__
void KernelDe
S
cale(int * a, int * b, int size, int num);
void KernelDe
s
cale(int * a, int * b, int size, int num);
/* descale each entry */
void _CudaDe
S
cale(const XTensor * a, XTensor * b, int num);
void _CudaDe
s
cale(const XTensor * a, XTensor * b, int num);
/* shift each entry (CUDA Kernel) */
__global__
...
...
source/tensor/core/math/Binary.h
查看文件 @
e9f4a75b
...
...
@@ -30,14 +30,19 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
scale all tensor entires
b = a * scale
*/
void
_Scale
(
const
XTensor
*
a
,
XTensor
*
b
,
int
num
);
void
_Scale
(
const
XTensor
*
a
,
XTensor
*
b
,
int
scale
);
/*
scale tensor entires (on site)
b = a * scale
*/
void
Scale
(
XTensor
&
a
,
int
scale
);
/*
scale tensor entires
make a new tensor to keep the result and return it
b = a * scale
*/
XTensor
Scale
(
const
XTensor
&
a
,
int
num
);
void
Scale
(
const
XTensor
&
a
,
XTensor
&
b
,
int
scale
);
//void Scale(const XTensor & a, XTensor & b, int num);
...
...
@@ -45,40 +50,55 @@ XTensor Scale(const XTensor & a, int num);
descale tensor entires
b = a / scale
*/
void
_DeScale
(
const
XTensor
*
a
,
XTensor
*
b
,
int
num
);
void
_Descale
(
const
XTensor
*
a
,
XTensor
*
b
,
int
scale
);
/*
descale tensor entires (on site)
b = a / scale
*/
void
Descale
(
XTensor
&
a
,
int
scale
);
/*
descale tensor entires
make a new tensor to keep the result and return it
b = a / scale
*/
XTensor
DeScale
(
const
XTensor
&
a
,
int
num
);
void
Descale
(
const
XTensor
&
a
,
XTensor
&
b
,
int
scale
);
/*
shift tensor entires
b = a + shift
*/
void
_Shift
(
const
XTensor
*
a
,
XTensor
*
b
,
int
num
);
void
_Shift
(
const
XTensor
*
a
,
XTensor
*
b
,
int
shift
);
/*
shift tensor entires (on site)
b = a + shift
*/
void
Shift
(
XTensor
&
a
,
int
shift
);
/*
shift tensor entires
make a new tensor to keep the result and return it
b = a + shift
*/
XTensor
Shift
(
const
XTensor
&
a
,
int
num
);
void
Shift
(
const
XTensor
&
a
,
XTensor
&
b
,
int
shift
);
/*
mod tensor entires
b = a % mod
*/
void
_Mod
(
const
XTensor
*
a
,
XTensor
*
b
,
int
num
);
void
_Mod
(
const
XTensor
*
a
,
XTensor
*
b
,
int
base
);
/*
mod tensor entires (on site)
b = a % mod
*/
void
Mod
(
XTensor
&
a
,
int
base
);
/*
mod tensor entires
make a new tensor to keep the result and return it
b = a % mod
*/
XTensor
Mod
(
const
XTensor
&
a
,
int
num
);
void
Mod
(
const
XTensor
&
a
,
XTensor
&
b
,
int
base
);
}
// namespace nts(NiuTrans.Tensor)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论