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
f4838e86
Commit
f4838e86
authored
Sep 12, 2019
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update XTensor interface which is able to set the enableGrad (enableGrad is true as default).
parent
182f9bf4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
41 行删除
+44
-41
source/tensor/XTensor.cpp
+30
-27
source/tensor/XTensor.h
+14
-14
没有找到文件。
source/tensor/XTensor.cpp
查看文件 @
f4838e86
...
...
@@ -2181,7 +2181,7 @@ initialize a dense tensor V2
void
InitTensorV2
(
XTensor
*
tensor
,
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
int
myDevID
,
const
bool
isEnableGrad
)
{
if
(
tensor
->
mem
==
NULL
)
{
XMem
*
myMem
=
GMems
.
GetMem
(
myDevID
);
...
...
@@ -2213,6 +2213,7 @@ void InitTensorV2(XTensor * tensor,
if
(
allocated
)
XTensor
::
AllocateData
(
tensor
);
}
tensor
->
enableGrad
=
isEnableGrad
;
}
/*
...
...
@@ -2246,12 +2247,12 @@ initialize a dense tensor V2
*/
void
InitTensor1DV2
(
XTensor
*
tensor
,
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
1
];
dims
[
0
]
=
num
;
InitTensorV2
(
tensor
,
1
,
dims
,
myDataType
,
myDevID
);
InitTensorV2
(
tensor
,
1
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2288,13 +2289,13 @@ initialize a dense matrix V2
*/
void
InitTensor2DV2
(
XTensor
*
tensor
,
const
int
rowNum
,
const
int
colNum
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
2
];
dims
[
0
]
=
rowNum
;
dims
[
1
]
=
colNum
;
InitTensorV2
(
tensor
,
2
,
dims
,
myDataType
,
myDevID
);
InitTensorV2
(
tensor
,
2
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2334,14 +2335,14 @@ initialize a dense 3d tensor V2
*/
void
InitTensor3DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
3
];
dims
[
0
]
=
d0
;
dims
[
1
]
=
d1
;
dims
[
2
]
=
d2
;
InitTensorV2
(
tensor
,
3
,
dims
,
myDataType
,
myDevID
);
InitTensorV2
(
tensor
,
3
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2384,7 +2385,7 @@ initialize a dense 4d tensor V2
*/
void
InitTensor4DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
4
];
dims
[
0
]
=
d0
;
...
...
@@ -2392,7 +2393,7 @@ void InitTensor4DV2(XTensor * tensor, const int d0, const int d1, const int d2,
dims
[
2
]
=
d2
;
dims
[
3
]
=
d3
;
InitTensorV2
(
tensor
,
4
,
dims
,
myDataType
,
myDevID
);
InitTensorV2
(
tensor
,
4
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2438,7 +2439,7 @@ initialize a dense 5d tensor V2
*/
void
InitTensor5DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
5
];
dims
[
0
]
=
d0
;
...
...
@@ -2447,7 +2448,7 @@ void InitTensor5DV2(XTensor * tensor, const int d0, const int d1, const int d2,
dims
[
3
]
=
d3
;
dims
[
4
]
=
d4
;
InitTensorV2
(
tensor
,
5
,
dims
,
myDataType
,
myDevID
);
InitTensorV2
(
tensor
,
5
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2539,10 +2540,12 @@ generate a dense XTensor V2
*/
XTensor
*
NewTensorV2
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
int
myDevID
,
const
bool
isEnableGrad
)
{
XMem
*
myMem
=
GMems
.
GetMem
(
myDevID
);
return
new
XTensor
(
myOrder
,
myDimSize
,
myDataType
,
1.0
F
,
myDevID
,
myMem
);
XTensor
*
tensor
=
new
XTensor
(
myOrder
,
myDimSize
,
myDataType
,
1.0
F
,
myDevID
,
myMem
);
tensor
->
enableGrad
=
isEnableGrad
;
return
tensor
;
}
/*
...
...
@@ -2589,14 +2592,14 @@ generate a dense XTensor which allocates data on the buffer V2
*/
XTensor
*
NewTensorBufV2
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
devID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
devID
,
const
bool
isEnableGrad
)
{
int
dims
[
MAX_TENSOR_DIM_NUM
];
memcpy
(
dims
,
myDimSize
,
sizeof
(
int
)
*
myOrder
);
dims
[
0
]
=
-
abs
(
dims
[
0
]);
XTensor
*
tensor
=
NewTensorV2
(
myOrder
,
dims
,
myDataType
,
devID
);
XTensor
*
tensor
=
NewTensorV2
(
myOrder
,
dims
,
myDataType
,
devID
,
isEnableGrad
);
if
(
tensor
->
unitNum
*
tensor
->
unitSize
==
176657664
)
{
tensor
->
Dump
(
stderr
,
""
,
200
);
...
...
@@ -2628,10 +2631,10 @@ generate a XTensor which allocates data on the buffer V2
>> reference - reference tensor
>> devID - device id
*/
XTensor
*
NewTensorBufV2
(
const
XTensor
*
reference
,
int
devID
)
XTensor
*
NewTensorBufV2
(
const
XTensor
*
reference
,
int
devID
,
const
bool
isEnableGrad
)
{
return
NewTensorBufV2
(
reference
->
order
,
reference
->
dimSize
,
reference
->
dataType
,
devID
);
reference
->
dataType
,
devID
,
isEnableGrad
);
}
/*
...
...
@@ -2663,12 +2666,12 @@ generate a dense vector V2
*/
XTensor
*
NewTensor1DV2
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
1
];
dims
[
0
]
=
num
;
return
NewTensorV2
(
1
,
dims
,
myDataType
,
myDevID
);
return
NewTensorV2
(
1
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2703,13 +2706,13 @@ generate a dense matrix V2
*/
XTensor
*
NewTensor2DV2
(
const
int
rowNum
,
const
int
colNum
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
2
];
dims
[
0
]
=
rowNum
;
dims
[
1
]
=
colNum
;
return
NewTensorV2
(
2
,
dims
,
myDataType
,
myDevID
);
return
NewTensorV2
(
2
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2747,14 +2750,14 @@ generate a dense 3d tensor V2
*/
XTensor
*
NewTensor3DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
3
];
dims
[
0
]
=
d0
;
dims
[
1
]
=
d1
;
dims
[
2
]
=
d2
;
return
NewTensorV2
(
3
,
dims
,
myDataType
,
myDevID
);
return
NewTensorV2
(
3
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2795,7 +2798,7 @@ generate a dense 4d tensor V2
*/
XTensor
*
NewTensor4DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
4
];
dims
[
0
]
=
d0
;
...
...
@@ -2803,7 +2806,7 @@ XTensor * NewTensor4DV2(const int d0, const int d1, const int d2, const int d3,
dims
[
2
]
=
d2
;
dims
[
3
]
=
d3
;
return
NewTensorV2
(
4
,
dims
,
myDataType
,
myDevID
);
return
NewTensorV2
(
4
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
@@ -2847,7 +2850,7 @@ generate a dense 5d tensor V2
*/
XTensor
*
NewTensor5DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
)
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
dims
[
5
];
dims
[
0
]
=
d0
;
...
...
@@ -2856,7 +2859,7 @@ XTensor * NewTensor5DV2(const int d0, const int d1, const int d2, const int d3,
dims
[
3
]
=
d3
;
dims
[
4
]
=
d4
;
return
NewTensorV2
(
5
,
dims
,
myDataType
,
myDevID
);
return
NewTensorV2
(
5
,
dims
,
myDataType
,
myDevID
,
isEnableGrad
);
}
/*
...
...
source/tensor/XTensor.h
查看文件 @
f4838e86
...
...
@@ -463,7 +463,7 @@ void InitTensor(XTensor * tensor,
/* initialize a dense XTensor V2 */
void
InitTensorV2
(
XTensor
*
tensor
,
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* initialize a dense vector */
void
InitTensor1D
(
XTensor
*
tensor
,
const
int
num
,
...
...
@@ -471,7 +471,7 @@ void InitTensor1D(XTensor * tensor, const int num,
/* initialize a dense vector V2 */
void
InitTensor1DV2
(
XTensor
*
tensor
,
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* initialize a dense matrix */
void
InitTensor2D
(
XTensor
*
tensor
,
const
int
rowNum
,
const
int
colNum
,
...
...
@@ -479,7 +479,7 @@ void InitTensor2D(XTensor * tensor, const int rowNum, const int colNum,
/* initialize a dense matrix V2 */
void
InitTensor2DV2
(
XTensor
*
tensor
,
const
int
rowNum
,
const
int
colNum
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* initialize a dense 3d tensor */
void
InitTensor3D
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
...
...
@@ -487,7 +487,7 @@ void InitTensor3D(XTensor * tensor, const int d0, const int d1, const int d2,
/* initialize a dense 3d tensor V2 */
void
InitTensor3DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* initialize a dense 4d tensor */
void
InitTensor4D
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
...
...
@@ -495,7 +495,7 @@ void InitTensor4D(XTensor * tensor, const int d0, const int d1, const int d2, co
/* initialize a dense 4d tensor V2 */
void
InitTensor4DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* initialize a dense 5d tensor */
void
InitTensor5D
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
...
...
@@ -503,7 +503,7 @@ void InitTensor5D(XTensor * tensor, const int d0, const int d1, const int d2, co
/* initialize a dense 5d tensor V2 */
void
InitTensor5DV2
(
XTensor
*
tensor
,
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* initialize a tensor with a reference tensor */
void
InitTensor
(
XTensor
*
tensor
,
const
XTensor
*
reference
);
...
...
@@ -523,7 +523,7 @@ XTensor * NewTensor(const int myOrder, const int * myDimSize, const TENSOR_DATA_
/* generate a dense XTensor V2 */
XTensor
*
NewTensorV2
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a XTensor which allocates data on the buffer */
XTensor
*
NewTensorBuf
(
const
int
myOrder
,
const
int
*
myDimSize
,
...
...
@@ -532,20 +532,20 @@ XTensor * NewTensorBuf(const int myOrder, const int * myDimSize,
/* generate a dense XTensor which allocates data on the buffer V2 */
XTensor
*
NewTensorBufV2
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a XTensor which allocates data on the buffer */
XTensor
*
NewTensorBuf
(
const
XTensor
*
reference
,
int
devID
,
XMem
*
myMem
);
/* generate a XTensor which allocates data on the buffer V2 */
XTensor
*
NewTensorBufV2
(
const
XTensor
*
reference
,
int
devID
);
XTensor
*
NewTensorBufV2
(
const
XTensor
*
reference
,
int
devID
,
const
bool
isEnableGrad
=
true
);
/* generate a dense vector */
XTensor
*
NewTensor1D
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* generate a dense vector V2 */
XTensor
*
NewTensor1DV2
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
XTensor
*
NewTensor1DV2
(
const
int
num
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a dense matrix */
XTensor
*
NewTensor2D
(
const
int
rowNum
,
const
int
colNum
,
...
...
@@ -555,7 +555,7 @@ XTensor * NewTensor2D(const int rowNum, const int colNum,
/* generate a dense matrix V2 */
XTensor
*
NewTensor2DV2
(
const
int
rowNum
,
const
int
colNum
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a dense 3d tensor */
XTensor
*
NewTensor3D
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
...
...
@@ -565,7 +565,7 @@ XTensor * NewTensor3D(const int d0, const int d1, const int d2,
/* generate a dense 3d tensor V2 */
XTensor
*
NewTensor3DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a dense 4d tensor */
XTensor
*
NewTensor4D
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
...
...
@@ -575,7 +575,7 @@ XTensor * NewTensor4D(const int d0, const int d1, const int d2, const int d3,
/* generate a dense 4d tensor V2 */
XTensor
*
NewTensor4DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a dense 5d tensor */
XTensor
*
NewTensor5D
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
...
...
@@ -585,7 +585,7 @@ XTensor * NewTensor5D(const int d0, const int d1, const int d2, const int d3, co
/* generate a dense 5d tensor V2 */
XTensor
*
NewTensor5DV2
(
const
int
d0
,
const
int
d1
,
const
int
d2
,
const
int
d3
,
const
int
d4
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
int
myDevID
=
-
1
);
const
int
myDevID
=
-
1
,
const
bool
isEnableGrad
=
true
);
/* generate a copy of XTensor (with a reference to a given tensor) */
XTensor
*
NewTensor
(
const
XTensor
*
a
,
bool
isFilledData
=
true
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论