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
913e2251
Commit
913e2251
authored
Jul 02, 2019
by
huchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separating header and implementation files for XList, now XList refers to a list containing void*
parent
1f5627f9
全部展开
显示空白字符变更
内嵌
并排
正在显示
55 个修改的文件
包含
175 行增加
和
506 行删除
+175
-506
source/network/XBackwardShape.cpp
+3
-3
source/network/XNet.cpp
+19
-19
source/network/XNet.h
+9
-9
source/sample/fnnlm/FNNLM.cpp
+6
-6
source/sample/main.cpp
+11
-32
source/sample/transformer/T2TAttention.cpp
+1
-1
source/sample/transformer/T2TModel.cpp
+4
-4
source/sample/transformer/T2TModel.h
+1
-1
source/sample/transformer/T2TPredictor.h
+2
-2
source/sample/transformer/T2TTrainer.cpp
+2
-2
source/sample/transformer/T2TTrainer.h
+2
-2
source/tensor/XDevice.cpp
+2
-2
source/tensor/XLink.cpp
+5
-5
source/tensor/XLink.h
+2
-2
source/tensor/XList.cpp
+0
-0
source/tensor/XList.h
+20
-330
source/tensor/XPRunner.cpp
+2
-2
source/tensor/XPRunner.h
+1
-1
source/tensor/XQueue.cpp
+4
-4
source/tensor/XQueue.h
+4
-4
source/tensor/XTensor.cpp
+1
-1
source/tensor/XThread.h
+2
-2
source/tensor/core/arithmetic/MatrixMul.cpp
+3
-3
source/tensor/core/arithmetic/MatrixMul2DMultiTheading.cpp
+2
-2
source/tensor/core/arithmetic/MatrixMul2DMultiTheading.h
+1
-1
source/tensor/core/arithmetic/MatrixMulBatched.cpp
+3
-3
source/tensor/core/arithmetic/MatrixMulBatched.h
+2
-2
source/tensor/core/arithmetic/XTensorBLAS.cu
+3
-3
source/tensor/core/arithmetic/XTensorBLAS.h
+2
-2
source/tensor/core/math/Normalize.cpp
+1
-1
source/tensor/core/movement/CopyIndexed.cpp
+1
-1
source/tensor/core/shape/Concatenate.cpp
+4
-4
source/tensor/core/shape/Concatenate.h
+2
-2
source/tensor/core/shape/ConcatenateSolely.cpp
+2
-2
source/tensor/core/shape/ConcatenateSolely.h
+1
-1
source/tensor/core/shape/Merge.cpp
+3
-3
source/tensor/core/shape/Merge.h
+2
-2
source/tensor/core/shape/MergeBlockLists.cpp
+1
-1
source/tensor/core/shape/MergeBlockLists.cu
+1
-1
source/tensor/core/shape/MergeBlockLists.cuh
+2
-2
source/tensor/core/shape/MergeBlockLists.h
+1
-1
source/tensor/core/shape/Split.cpp
+2
-2
source/tensor/core/shape/Split.h
+3
-3
source/tensor/core/shape/Unsqueeze.cpp
+1
-1
source/tensor/core/sort/Sort.cpp
+1
-1
source/tensor/core/sort/TopK.cpp
+1
-1
source/tensor/core/utilities/FlushToMem.cpp
+1
-1
source/tensor/core/utilities/FlushToMem.cu
+1
-1
source/tensor/core/utilities/FlushToMem.cuh
+1
-1
source/tensor/core/utilities/FlushToMem.h
+1
-1
source/tensor/core/utilities/XMatrixSegment.cpp
+13
-13
source/tensor/test/TConcatenate.cpp
+3
-3
source/tensor/test/TConcatenateSolely.cpp
+3
-3
source/tensor/test/TMerge.cpp
+2
-2
source/tensor/test/TSplit.cpp
+2
-2
没有找到文件。
source/network/XBackwardShape.cpp
查看文件 @
913e2251
...
...
@@ -232,8 +232,8 @@ void XShapeGrad::GradMergeList(XTensor * node, bool isEfficient)
CheckNTErrors
(
income
.
tailNum
>
0
,
"Wrong input tensor number for MERGE!"
);
XTensor
*
last
=
NULL
;
X
List
smalls
(
income
.
tailNum
);
X
List
smallsGrad
(
income
.
tailNum
);
Tensor
List
smalls
(
income
.
tailNum
);
Tensor
List
smallsGrad
(
income
.
tailNum
);
bool
mergeOnly
=
true
;
for
(
int
i
=
0
;
i
<
income
.
tailNum
;
i
++
){
XTensor
*
tail
=
income
.
tails
[
i
];
...
...
@@ -401,7 +401,7 @@ void XShapeGrad::GradSplitListPost(XTensor * node, bool isEfficient)
/* we compute the gradient for current node, rather than for
child node, i.e., we use the outgoing edge here */
XLink
&
outgo
=
node
->
outgo
;
X
List
splits
(
outgo
.
tailNum
);
Tensor
List
splits
(
outgo
.
tailNum
);
int
whereToSplit
=
-
1
;
int
splitNum
=
0
;
...
...
source/network/XNet.cpp
查看文件 @
913e2251
...
...
@@ -79,13 +79,13 @@ backward propagation to obtain gradient
*/
void
XNet
::
Backward
(
XTensor
&
root
,
LOSS_FUNCTION_NAME
loss
)
{
X
List
roots
(
1
);
Tensor
List
roots
(
1
);
roots
.
Add
(
&
root
);
X
List
golds
(
1
);
Tensor
List
golds
(
1
);
golds
.
Add
(
NULL
);
X
List
paddings
(
1
);
Tensor
List
paddings
(
1
);
paddings
.
Add
(
NULL
);
Backward
(
roots
,
golds
,
paddings
,
loss
);
...
...
@@ -99,13 +99,13 @@ backward propagation to obtain gradient wrt. the loss/error function
*/
void
XNet
::
Backward
(
XTensor
&
root
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
)
{
X
List
roots
(
1
);
Tensor
List
roots
(
1
);
roots
.
Add
(
&
root
);
X
List
golds
(
1
);
Tensor
List
golds
(
1
);
golds
.
Add
(
&
gold
);
X
List
paddings
(
1
);
Tensor
List
paddings
(
1
);
paddings
.
Add
(
NULL
);
Backward
(
roots
,
golds
,
paddings
,
loss
);
...
...
@@ -120,13 +120,13 @@ backward propagation to obtain gradient wrt. the loss/error function
*/
void
XNet
::
Backward
(
XTensor
&
root
,
XTensor
&
gold
,
XTensor
&
padding
,
LOSS_FUNCTION_NAME
loss
)
{
X
List
roots
(
1
);
Tensor
List
roots
(
1
);
roots
.
Add
(
&
root
);
X
List
golds
(
1
);
Tensor
List
golds
(
1
);
golds
.
Add
(
&
gold
);
X
List
paddings
(
1
);
Tensor
List
paddings
(
1
);
paddings
.
Add
(
&
padding
);
Backward
(
roots
,
golds
,
paddings
,
loss
);
...
...
@@ -138,10 +138,10 @@ with a number of root nodes
>> roots - a list of root nodes (output) of the network
>> loss - name of loss function
*/
void
XNet
::
Backward
(
X
List
&
roots
,
LOSS_FUNCTION_NAME
loss
)
void
XNet
::
Backward
(
Tensor
List
&
roots
,
LOSS_FUNCTION_NAME
loss
)
{
X
List
golds
(
roots
.
count
);
X
List
paddings
(
roots
.
count
);
Tensor
List
golds
(
roots
.
count
);
Tensor
List
paddings
(
roots
.
count
);
for
(
int
i
=
0
;
i
<
roots
.
count
;
i
++
)
{
golds
.
Add
(
NULL
);
paddings
.
Add
(
NULL
);
...
...
@@ -157,9 +157,9 @@ with a number of root nodes
>> golds - a list of gold standard for the output
>> loss - name of loss function
*/
void
XNet
::
Backward
(
XList
&
roots
,
X
List
&
golds
,
LOSS_FUNCTION_NAME
loss
)
void
XNet
::
Backward
(
TensorList
&
roots
,
Tensor
List
&
golds
,
LOSS_FUNCTION_NAME
loss
)
{
X
List
paddings
(
roots
.
count
);
Tensor
List
paddings
(
roots
.
count
);
for
(
int
i
=
0
;
i
<
roots
.
count
;
i
++
)
paddings
.
Add
(
NULL
);
...
...
@@ -174,7 +174,7 @@ with a number of root nodes
>> paddings - specify a target value that is ignored
>> loss - name of loss function
*/
void
XNet
::
Backward
(
XList
&
roots
,
XList
&
golds
,
X
List
&
paddings
,
LOSS_FUNCTION_NAME
loss
)
void
XNet
::
Backward
(
TensorList
&
roots
,
TensorList
&
golds
,
Tensor
List
&
paddings
,
LOSS_FUNCTION_NAME
loss
)
{
Traverse
(
roots
);
...
...
@@ -300,7 +300,7 @@ depth-first search (Tarjan's algorithm)
*/
void
XNet
::
Traverse
(
XTensor
&
root
)
{
X
List
roots
(
1
);
Tensor
List
roots
(
1
);
roots
.
Add
(
&
root
);
Traverse
(
roots
);
...
...
@@ -311,7 +311,7 @@ traverse the net and find the topological order by
depth-first search (Tarjan's algorithm)
>> roots - a list of roots (or output nodes)
*/
void
XNet
::
Traverse
(
X
List
&
roots
)
void
XNet
::
Traverse
(
Tensor
List
&
roots
)
{
id
=
MakeNetID
();
nodes
.
Clear
();
...
...
@@ -336,7 +336,7 @@ depth-first search given a node (Tarjan's algorithm for topological ordering)
>> orders - topological order of the nodes
>> code - code of the network
*/
void
XNet
::
TarjanVisit
(
XTensor
*
node
,
X
List
&
orders
,
const
unsigned
int
code
)
void
XNet
::
TarjanVisit
(
XTensor
*
node
,
Tensor
List
&
orders
,
const
unsigned
int
code
)
{
if
(
node
==
NULL
)
return
;
...
...
@@ -444,7 +444,7 @@ show network topology
*/
void
XNet
::
ShowNetwork
(
FILE
*
file
,
XTensor
*
node
)
{
X
List
roots
(
1
);
Tensor
List
roots
(
1
);
roots
.
Add
(
node
);
Traverse
(
roots
);
...
...
source/network/XNet.h
查看文件 @
913e2251
...
...
@@ -36,16 +36,16 @@ struct XNet
unsigned
int
id
;
/* tensor nodes of the network (in order) */
X
List
nodes
;
Tensor
List
nodes
;
/* tensor nodes to keep gradient for output (e.g., SGD)*/
X
List
gradNodes
;
Tensor
List
gradNodes
;
/* output nodes of the network */
X
List
outputs
;
Tensor
List
outputs
;
/* input nodes of the network */
X
List
inputs
;
Tensor
List
inputs
;
/* indicates whether the network just keeps the gradient for parameter tensors */
bool
isGradEfficient
;
...
...
@@ -70,15 +70,15 @@ struct XNet
/* backward propagation to obtain gradient
with a number of root nodes */
void
Backward
(
X
List
&
roots
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
void
Backward
(
Tensor
List
&
roots
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
/* backward propagation to obtain gradient
with a number of root nodes */
void
Backward
(
XList
&
roots
,
X
List
&
golds
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
void
Backward
(
TensorList
&
roots
,
Tensor
List
&
golds
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
/* backward propagation to obtain gradient wrt. the loss/error function
with a number of root nodes */
void
Backward
(
XList
&
roots
,
XList
&
golds
,
X
List
&
paddings
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
void
Backward
(
TensorList
&
roots
,
TensorList
&
golds
,
Tensor
List
&
paddings
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
/* backward computation for a given node */
void
BackwardNode
(
XTensor
*
node
,
bool
isEfficent
=
false
);
...
...
@@ -92,10 +92,10 @@ struct XNet
/* traverse the net and find the topological order by
depth-first search (Tarjan's algorithm) */
void
Traverse
(
X
List
&
roots
);
void
Traverse
(
Tensor
List
&
roots
);
/* depth-first search given a node (Tarjan's algorithm for topological ordering) */
void
TarjanVisit
(
XTensor
*
node
,
X
List
&
orders
,
const
unsigned
int
code
);
void
TarjanVisit
(
XTensor
*
node
,
Tensor
List
&
orders
,
const
unsigned
int
code
);
/* dump network information */
void
Dump
(
FILE
*
file
);
...
...
source/sample/fnnlm/FNNLM.cpp
查看文件 @
913e2251
...
...
@@ -20,7 +20,7 @@
* This is a simple impelementation of the feed-forward network-baesd language
* model (FNNLM). See more details about FNNLM in
* "A Neural Probabilistic Language Model" by Bengio et al.
* Journal of Machine Learning Research 3 (2003) 1137C1155
* Journal of Machine Learning Research 3 (2003) 1137
�
C1155
*
* $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-06-22
*/
...
...
@@ -537,8 +537,8 @@ update the model parameters using the delta rule
*/
void
Update
(
FNNModel
&
model
,
FNNModel
&
grad
,
float
epsilon
,
bool
isNodeGrad
)
{
X
List
paraList
(
10
);
X
List
gradList
(
10
);
Tensor
List
paraList
(
10
);
Tensor
List
gradList
(
10
);
paraList
.
Add
(
&
model
.
outputW
);
paraList
.
Add
(
&
model
.
outputB
);
...
...
@@ -765,7 +765,7 @@ void Forward(XTensor inputs[], XTensor &output, FNNModel &model, FNNNet &net)
int
batchSize
=
-
1
;
int
n
=
model
.
n
;
int
depth
=
model
.
hDepth
;
X
List
eList
(
n
-
1
);
Tensor
List
eList
(
n
-
1
);
/* previoius n - 1 words */
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
){
...
...
@@ -943,7 +943,7 @@ void Backward(XTensor inputs[], XTensor &output, XTensor &gold, LOSS_FUNCTION_NA
_CopyValues
(
&
dedx
,
&
gradPassed
);
}
X
List
eList
(
n
-
1
);
Tensor
List
eList
(
n
-
1
);
/* back-propagation for the embedding layer */
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
...
...
@@ -1036,7 +1036,7 @@ void ForwardAutoDiff(XTensor inputs[], XTensor &output, FNNModel &model)
XTensor
hidden
;
XTensor
b
;
X
List
inputList
(
n
-
1
);
Tensor
List
inputList
(
n
-
1
);
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
inputList
.
Add
(
inputs
+
i
);
...
...
source/sample/main.cpp
查看文件 @
913e2251
...
...
@@ -21,40 +21,19 @@ void TestDataManager() {
const
int
indices
[]
=
{
0
,
1
};
dataSet
.
LoadBatch
(
src
,
indices
,
sizeof
(
indices
)
/
sizeof
(
*
indices
),
srcField
);
dataSet
.
LoadBatch
(
tgt
,
indices
,
sizeof
(
indices
)
/
sizeof
(
*
indices
),
tgtField
);
//
// tgt.Dump(stderr);
// src.Dump(stderr);
//XListV2<int> list(10);
//int* a = new int[10]{1,2,3,4,5,6,7,8,9};
//list.Add(a);
//auto x = list.Get(0);
//cout << x[0] << endl;
//list.Remove(0);
//auto y = list.Get(0);
//cout << x[0] << endl;
//delete[] a;
XList
list
(
10
);
XTensor
a
,
b
,
c
;
InitTensor2D
(
&
a
,
2
,
2
);
InitTensor2D
(
&
b
,
2
,
2
);
InitTensor2D
(
&
c
,
2
,
2
);
float
arr
[]
=
{
1.
,
2.
,
3.
,
4.
};
a
.
SetData
(
arr
,
4
);
b
.
SetData
(
arr
,
4
);
//c.SetZeroAll();
_MatrixMul
(
&
a
,
X_NOTRANS
,
&
b
,
X_NOTRANS
,
&
c
);
c
.
Dump
(
stderr
);
CharList
str
(
10
);
char
*
s
=
new
char
(
10
);
for
(
int
i
=
0
;
i
<
9
;
++
i
)
{
s
[
i
]
=
i
+
'a'
;
IntList
str
(
10
);
for
(
int
i
=
9
;
i
>
0
;
--
i
)
{
str
.
Add
(
i
);
}
s
[
9
]
=
0
;
str
.
Add
(
s
);
cout
<<
str
.
Get
(
0
);
vector
<
int
>
x
;
str
.
Add
(
'\0'
);
for
(
int
i
=
0
;
i
<
str
.
count
;
++
i
)
cout
<<
str
.
Get
(
i
);
cout
<<
endl
;
str
.
Sort
(
10
);
for
(
int
i
=
0
;
i
<
str
.
count
;
++
i
)
cout
<<
str
.
Get
(
i
);
cout
<<
endl
;
}
...
...
source/sample/transformer/T2TAttention.cpp
查看文件 @
913e2251
...
...
@@ -127,7 +127,7 @@ XTensor T2TAttention::MakeBig(XTensor &kqv, XTensor &mask, bool isTraining)
XTensor
q2
;
XTensor
v2
;
XTensor
kqv2
;
X
List
split
;
Tensor
List
split
;
kqv2
=
MMul
(
kqv
,
wbig
);
...
...
source/sample/transformer/T2TModel.cpp
查看文件 @
913e2251
...
...
@@ -84,7 +84,7 @@ void T2TModel::InitModel(int argc, char ** argv)
if
(
isMT
)
decoder
->
InitModel
(
argc
,
argv
,
true
,
0
,
devID
,
mem
);
X
List
params
(
10
);
Tensor
List
params
(
10
);
GetParams
(
params
);
for
(
int
i
=
0
;
i
<
params
.
count
;
i
++
){
...
...
@@ -388,7 +388,7 @@ void T2TModel::MakeMTMaskDec(XTensor &inputEnc, XTensor &inputDec,
get parameter matrics
>> list - the list that keeps the parameter matrics
*/
void
T2TModel
::
GetParams
(
X
List
&
list
)
void
T2TModel
::
GetParams
(
Tensor
List
&
list
)
{
list
.
Clear
();
list
.
Add
(
&
outputLayer
->
w
);
...
...
@@ -448,7 +448,7 @@ void T2TModel::Dump(const char * fn)
FILE
*
file
=
fopen
(
fn
,
"wb"
);
CheckNTErrors
(
file
,
"Cannot open the model file"
);
X
List
params
(
100
);
Tensor
List
params
(
100
);
GetParams
(
params
);
...
...
@@ -468,7 +468,7 @@ void T2TModel::Read(const char * fn)
FILE
*
file
=
fopen
(
fn
,
"rb"
);
CheckNTErrors
(
file
,
"Cannot open the model file"
);
X
List
params
(
100
);
Tensor
List
params
(
100
);
GetParams
(
params
);
...
...
source/sample/transformer/T2TModel.h
查看文件 @
913e2251
...
...
@@ -98,7 +98,7 @@ public:
XTensor
&
maskDec
,
XTensor
&
maskEncDec
);
/* get parameter matrics */
void
GetParams
(
X
List
&
list
);
void
GetParams
(
Tensor
List
&
list
);
/* dump the parameters */
void
Dump
(
const
char
*
fn
);
...
...
source/sample/transformer/T2TPredictor.h
查看文件 @
913e2251
...
...
@@ -93,10 +93,10 @@ public:
/* layers on the encoder side. We actually use the encoder output instead
of all hidden layers. */
X
List
layersEnc
;
Tensor
List
layersEnc
;
/* layers on the decoder side */
X
List
layersDec
;
Tensor
List
layersDec
;
/* list of states */
T2TState
*
states
;
...
...
source/sample/transformer/T2TTrainer.cpp
查看文件 @
913e2251
...
...
@@ -491,7 +491,7 @@ where
*/
void
T2TTrainer
::
Update
(
T2TModel
*
model
,
const
float
lr
)
{
X
List
ws
(
100
);
Tensor
List
ws
(
100
);
model
->
GetParams
(
ws
);
...
...
@@ -552,7 +552,7 @@ void T2TTrainer::PrepareModel(T2TModel * model)
moments
.
Clear
();
moments2nd
.
Clear
();
X
List
ws
(
100
);
Tensor
List
ws
(
100
);
model
->
GetParams
(
ws
);
...
...
source/sample/transformer/T2TTrainer.h
查看文件 @
913e2251
...
...
@@ -82,10 +82,10 @@ public:
float
adamBeta2T
;
/* list of the moment of the parameter matrics */
X
List
moments
;
Tensor
List
moments
;
/* list of the 2nd order moment of the parameter matrics */
X
List
moments2nd
;
Tensor
List
moments2nd
;
/* indicates whether the data file is shuffled for training */
bool
isShuffled
;
...
...
source/tensor/XDevice.cpp
查看文件 @
913e2251
...
...
@@ -478,7 +478,7 @@ split a string
>> items - splitting result
<< return - how many items are there
*/
int
SplitALine
(
char
*
inputString
,
const
char
*
seperator
,
CharList
*
items
)
int
SplitALine
(
char
*
inputString
,
const
char
*
seperator
,
StrList
*
items
)
{
items
->
Clear
();
...
...
@@ -532,7 +532,7 @@ get device ids for the given device information
*/
int
XDevManager
::
GetDeviceIDs
(
char
*
devInfo
,
int
*
devIDs
)
{
CharList
*
terms
=
new
Cha
rList
(
1
);
StrList
*
terms
=
new
St
rList
(
1
);
SplitALine
(
devInfo
,
" "
,
terms
);
for
(
int
i
=
0
;
i
<
terms
->
count
;
i
++
){
...
...
source/tensor/XLink.cpp
查看文件 @
913e2251
...
...
@@ -300,7 +300,7 @@ void XLink::MakeLink(const XTensor * t1, const XTensor * t2, XTensor * h, int id
if
(
h
==
NULL
)
return
;
X
List
list
(
2
);
Tensor
List
list
(
2
);
list
.
Add
((
XTensor
*
)
t1
);
list
.
Add
((
XTensor
*
)
t2
);
...
...
@@ -320,7 +320,7 @@ void XLink::MakeLink(const XTensor * t1, const XTensor * t2, const XTensor * t3,
if
(
h
==
NULL
)
return
;
X
List
list
(
3
);
Tensor
List
list
(
3
);
list
.
Add
((
XTensor
*
)
t1
);
list
.
Add
((
XTensor
*
)
t2
);
list
.
Add
((
XTensor
*
)
t3
);
...
...
@@ -334,7 +334,7 @@ create a hyper edge with a list of tensors and a output tensor
>> h - head tensor
>> id - id of the edge type
*/
void
XLink
::
MakeLink
(
const
X
List
*
list
,
XTensor
*
h
,
int
id
)
void
XLink
::
MakeLink
(
const
Tensor
List
*
list
,
XTensor
*
h
,
int
id
)
{
/* forward */
XLink
&
income
=
h
->
income
;
...
...
@@ -368,7 +368,7 @@ create a hyper edge with a input tensors and a list of output tensors
>> list - a list of output tensors
>> id - id of the edge type
*/
void
XLink
::
MakeLink
(
XTensor
*
t
,
X
List
*
list
,
int
id
)
void
XLink
::
MakeLink
(
XTensor
*
t
,
Tensor
List
*
list
,
int
id
)
{
/* forward */
for
(
int
i
=
0
;
i
<
list
->
count
;
i
++
){
...
...
@@ -544,7 +544,7 @@ void XLink::CopyIncoming(const XTensor * reference, XTensor * target)
ClearIncoming
(
target
);
int
tailNum
=
reference
->
income
.
tailNum
;
X
List
tails
(
tailNum
);
Tensor
List
tails
(
tailNum
);
for
(
int
i
=
0
;
i
<
tailNum
;
i
++
){
XTensor
*
tail
=
(
XTensor
*
)
reference
->
income
.
tails
[
i
];
tails
.
Add
(
tail
);
...
...
source/tensor/XLink.h
查看文件 @
913e2251
...
...
@@ -144,11 +144,11 @@ struct XLink
/* create a hyper edge with a list of input tensors and a output tensor */
static
void
MakeLink
(
const
X
List
*
list
,
XTensor
*
h
,
int
id
);
void
MakeLink
(
const
Tensor
List
*
list
,
XTensor
*
h
,
int
id
);
/* create a hyper edge with a input tensors and a list of output tensors */
static
void
MakeLink
(
XTensor
*
h
,
X
List
*
list
,
int
id
);
void
MakeLink
(
XTensor
*
h
,
Tensor
List
*
list
,
int
id
);
/* add a parameter */
static
...
...
source/tensor/XList.cpp
查看文件 @
913e2251
差异被折叠。
点击展开。
source/tensor/XList.h
查看文件 @
913e2251
...
...
@@ -25,23 +25,19 @@
#include "XMem.h"
#include "XGlobal.h"
#include <utility>
#ifndef __
XLIST
_H__
#define __
XLIST
_H__
#ifndef __
TensorList
_H__
#define __
TensorList
_H__
/* the nts (NiuTrans.Tensor) namespace */
namespace
nts
{
/* the
X
ListBase class */
/* the
Tensor
ListBase class */
template
<
typename
T
>
struct
X
ListBase
{
struct
Tensor
ListBase
{
public
:
/* compare function */
typedef
int
(
*
ListCompare
)(
const
T
item1
,
const
T
item2
);
/* data items */
T
*
items
;
...
...
@@ -56,16 +52,16 @@ public:
public
:
/* constructor */
X
ListBase
();
Tensor
ListBase
();
/* constructor */
X
ListBase
(
int
myMaxNum
);
Tensor
ListBase
(
int
myMaxNum
);
/* constructor */
X
ListBase
(
int
myMaxNum
,
XMem
*
myMem
);
Tensor
ListBase
(
int
myMaxNum
,
XMem
*
myMem
);
/* de-constructor */
~
X
ListBase
();
~
Tensor
ListBase
();
/* add an item into the list */
void
Add
(
T
&&
item
);
...
...
@@ -77,7 +73,7 @@ public:
void
Add
(
T
*
inputItems
,
int
inputItemCount
);
/* append a list to the current list */
void
AddList
(
X
ListBase
*
l
);
void
AddList
(
Tensor
ListBase
*
l
);
/* insert an item to the given position of the list */
void
Insert
(
int
pos
,
const
T
&
item
);
...
...
@@ -101,7 +97,7 @@ public:
void
Clear
();
/* sort the list */
void
Sort
(
int
itemSize
,
ListCompare
comp
);
void
Sort
(
int
itemSize
);
/* reverse the list */
void
Reverse
();
...
...
@@ -110,7 +106,7 @@ public:
void
Remove
(
int
i
);
/* copy the list */
X
ListBase
*
Copy
(
XMem
*
myMem
);
Tensor
ListBase
*
Copy
(
XMem
*
myMem
);
/* shuffle the list */
void
Shuffle
(
int
nround
=
10
,
int
beg
=
-
1
,
int
len
=
0
);
...
...
@@ -123,325 +119,19 @@ public:
void
Set
(
int
i
,
T
item
)
{
SetItem
(
i
,
item
);
};
};
/* constructor */
template
<
typename
T
>
XListBase
<
T
>::
XListBase
()
{
mem
=
NULL
;
maxNum
=
0
;
count
=
0
;
items
=
NULL
;
}
/*
constructor
>> myMaxNum - maximum number of items to keep
>> isIntListOrNot - specify if the list keeps int items
*/
template
<
typename
T
>
XListBase
<
T
>::
XListBase
(
int
myMaxNum
)
{
mem
=
NULL
;
maxNum
=
myMaxNum
;
count
=
0
;
items
=
new
T
[
myMaxNum
];
}
/*
constructor
>> myMaxNum - maximum number of items to keep
>> myMem - the memory pool used for data allocation
>> isIntListOrNot - specify if the list keeps int items
*/
template
<
typename
T
>
XListBase
<
T
>::
XListBase
(
int
myMaxNum
,
XMem
*
myMem
)
{
mem
=
myMem
;
maxNum
=
myMaxNum
;
count
=
0
;
items
=
(
T
*
)
mem
->
Alloc
(
mem
->
devID
,
sizeof
(
T
)
*
maxNum
);
}
/* de-constructor */
template
<
typename
T
>
XListBase
<
T
>::~
XListBase
()
{
delete
[]
items
;
}
/*
add an item into the list
>> item - a right value
*/
template
<
typename
T
>
void
XListBase
<
T
>::
Add
(
T
&&
item
)
{
if
(
count
==
maxNum
)
{
T
*
newItems
;
if
(
mem
==
NULL
)
newItems
=
new
T
[
maxNum
*
2
+
1
];
else
newItems
=
(
T
*
)
mem
->
Alloc
(
mem
->
devID
,
sizeof
(
T
)
*
(
maxNum
*
2
+
1
));
memcpy
(
newItems
,
items
,
sizeof
(
T
)
*
maxNum
);
if
(
mem
==
NULL
)
delete
[]
items
;
items
=
newItems
;
maxNum
=
maxNum
*
2
+
1
;
}
items
[
count
++
]
=
item
;
}
/*
add an item into the list
>> item - a const reference to the item
*/
template
<
typename
T
>
void
XListBase
<
T
>::
Add
(
const
T
&
item
)
{
if
(
count
==
maxNum
)
{
T
*
newItems
;
if
(
mem
==
NULL
)
newItems
=
new
T
[
maxNum
*
2
+
1
];
else
newItems
=
(
T
*
)
mem
->
Alloc
(
mem
->
devID
,
sizeof
(
T
)
*
(
maxNum
*
2
+
1
));
memcpy
(
newItems
,
items
,
sizeof
(
T
)
*
maxNum
);
if
(
mem
==
NULL
)
delete
[]
items
;
items
=
newItems
;
maxNum
=
maxNum
*
2
+
1
;
}
items
[
count
++
]
=
item
;
}
/*
add a number of items into the list
>> inputItems - pointer to the array of items
>> inputItemCount - number of input items
*/
template
<
typename
T
>
void
XListBase
<
T
>::
Add
(
T
*
inputItems
,
int
inputItemCount
)
{
if
(
count
+
inputItemCount
>=
maxNum
)
{
int
newMaxNum
=
(
count
+
inputItemCount
)
*
2
+
1
;
T
*
newItems
;
if
(
mem
==
NULL
)
newItems
=
new
T
[
newMaxNum
];
else
newItems
=
(
T
*
)
mem
->
Alloc
(
mem
->
devID
,
sizeof
(
T
)
*
newMaxNum
);
memcpy
(
newItems
,
items
,
sizeof
(
T
)
*
maxNum
);
if
(
mem
==
NULL
)
delete
[]
items
;
items
=
newItems
;
maxNum
=
newMaxNum
;
}
memcpy
(
items
+
count
,
inputItems
,
sizeof
(
T
)
*
inputItemCount
);
count
+=
inputItemCount
;
}
/*
append a list to the current list
>> l - the list we use to append
*/
template
<
typename
T
>
void
XListBase
<
T
>::
AddList
(
XListBase
*
l
)
{
Add
(
l
->
items
,
l
->
count
);
}
/*
insert an item to the given position of the list
>> pos - the position
>> item - the item for insertion
*/
template
<
typename
T
>
void
XListBase
<
T
>::
Insert
(
int
pos
,
const
T
&
item
)
{
if
(
count
==
maxNum
)
{
T
*
newItems
;
if
(
mem
==
NULL
)
newItems
=
new
T
[
maxNum
*
2
+
1
];
else
newItems
=
(
T
*
)
mem
->
Alloc
(
mem
->
devID
,
sizeof
(
T
)
*
(
maxNum
*
2
+
1
));
memcpy
(
newItems
,
items
,
sizeof
(
T
)
*
maxNum
);
if
(
mem
==
NULL
)
delete
[]
items
;
items
=
newItems
;
maxNum
=
maxNum
*
2
+
1
;
}
for
(
int
i
=
count
-
1
;
i
>=
pos
;
i
--
)
items
[
i
+
1
]
=
items
[
i
];
items
[
pos
]
=
item
;
count
++
;
}
template
<
typename
T
>
void
XListBase
<
T
>::
Insert
(
int
pos
,
T
&&
item
)
{
if
(
count
==
maxNum
)
{
T
*
newItems
;
if
(
mem
==
NULL
)
newItems
=
new
T
[
maxNum
*
2
+
1
];
else
newItems
=
(
T
*
)
mem
->
Alloc
(
mem
->
devID
,
sizeof
(
T
)
*
(
maxNum
*
2
+
1
));
memcpy
(
newItems
,
items
,
sizeof
(
T
)
*
maxNum
);
if
(
mem
==
NULL
)
delete
[]
items
;
items
=
newItems
;
maxNum
=
maxNum
*
2
+
1
;
}
for
(
int
i
=
count
-
1
;
i
>=
pos
;
i
--
)
items
[
i
+
1
]
=
items
[
i
];
items
[
pos
]
=
item
;
count
++
;
}
/* get the item at position i */
template
<
typename
T
>
T
&
XListBase
<
T
>::
GetItem
(
int
i
)
const
{
CheckNTErrors
(
i
>=
-
1
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
count
>
0
,
"Cannt index the item in an empty list!"
);
if
(
i
==
-
1
)
return
items
[
count
-
1
];
else
return
items
[
i
];
}
/* set the item at position i */
template
<
typename
T
>
void
XListBase
<
T
>::
SetItem
(
int
i
,
const
T
&
item
)
{
if
(
i
>=
0
&&
i
<
count
)
items
[
i
]
=
item
;
}
template
<
typename
T
>
inline
void
XListBase
<
T
>::
SetItem
(
int
i
,
T
&&
item
)
{
if
(
i
>=
0
&&
i
<
count
)
items
[
i
]
=
std
::
move
(
item
);
}
/*
find the position of the first matched item
>> item - the item for matching
<< the position where we hit the item (if any)
*/
template
<
typename
T
>
int
XListBase
<
T
>::
FindFirst
(
const
T
&
item
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
if
(
item
==
items
[
i
])
return
i
;
}
return
-
1
;
}
/* clear the data array */
template
<
typename
T
>
void
XListBase
<
T
>::
Clear
()
{
delete
[]
items
;
count
=
0
;
}
/*
sort the list
>> itemSize - size of an item
>> comp - the comparison function used in sorting
*/
template
<
typename
T
>
void
XListBase
<
T
>::
Sort
(
int
itemSize
,
ListCompare
comp
)
{
qsort
(
items
,
count
,
itemSize
,
comp
);
}
/* reverse the list */
template
<
typename
T
>
void
XListBase
<
T
>::
Reverse
()
{
int
half
=
count
/
2
;
for
(
int
i
=
0
;
i
<
half
;
i
++
)
{
T
tmp
(
std
::
move
(
items
[
i
]));
items
[
i
]
=
std
::
move
(
items
[
count
-
i
-
1
]);
items
[
count
-
i
-
1
]
=
std
::
move
(
tmp
);
}
}
/* remove the item at position i */
template
<
typename
T
>
void
XListBase
<
T
>::
Remove
(
int
i
)
{
if
(
i
>=
count
||
i
<
0
)
return
;
memcpy
(
items
+
i
,
items
+
i
+
1
,
sizeof
(
T
*
)
*
(
count
-
i
-
1
));
count
--
;
}
/*
copy the list
>> myMem - memory pool used for allocating the data in the new list
<< hard copy of the list
*/
template
<
typename
T
>
XListBase
<
T
>*
XListBase
<
T
>::
Copy
(
XMem
*
myMem
)
{
XListBase
<
T
>*
newList
=
new
XListBase
<
T
>
(
maxNum
,
myMem
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
newList
->
Add
(
GetItem
(
i
));
}
return
newList
;
}
/*
shuffle the list
>> nround - number of rounds for shuffling
>> beg - where we start
>> len - how many items are used in shuffling
*/
template
<
typename
T
>
void
XListBase
<
T
>::
Shuffle
(
int
nround
,
int
beg
,
int
len
)
{
if
(
beg
<
0
)
{
beg
=
0
;
len
=
count
;
}
if
(
beg
+
len
>
count
)
return
;
srand
((
unsigned
int
)
time
(
NULL
));
for
(
int
k
=
0
;
k
<
nround
;
k
++
)
{
/* FisherCYates shuffle */
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
float
a
=
(
float
)
rand
()
/
RAND_MAX
;
size_t
j
=
(
unsigned
int
)(
a
*
(
i
+
1
));
T
t
=
items
[
beg
+
j
];
items
[
beg
+
j
]
=
items
[
beg
+
i
];
items
[
beg
+
i
]
=
t
;
}
}
}
struct
XTensor
;
/* typedef for list */
typedef
XListBase
<
int
>
IntList
;
typedef
XListBase
<
char
*>
CharList
;
typedef
XListBase
<
long
>
LongList
;
typedef
XListBase
<
float
>
FloatList
;
typedef
XListBase
<
short
>
ShortList
;
typedef
XListBase
<
XTensor
*>
XList
;
typedef
TensorListBase
<
int
>
IntList
;
typedef
TensorListBase
<
char
>
CharList
;
typedef
TensorListBase
<
char
*>
StrList
;
typedef
TensorListBase
<
long
>
LongList
;
typedef
TensorListBase
<
float
>
FloatList
;
typedef
TensorListBase
<
short
>
ShortList
;
typedef
TensorListBase
<
void
*>
XList
;
typedef
TensorListBase
<
XTensor
*>
TensorList
;
}
/* end of the nts (NiuTrans.Tensor) namespace */
#endif // __
XLIST
_H__
#endif // __
TensorList
_H__
source/tensor/XPRunner.cpp
查看文件 @
913e2251
...
...
@@ -146,7 +146,7 @@ run a set of jobs in parallel
>> jobArgs - the list of arguments for each job
>> sleepTime - time to sleep (in ms) for each round
*/
void
XPRunner
::
Run
(
XList
*
jobFunctions
,
X
List
*
jobArgs
,
float
sleepTime
)
void
XPRunner
::
Run
(
TensorList
*
jobFunctions
,
Tensor
List
*
jobArgs
,
float
sleepTime
)
{
if
(
threadNum
<=
0
){
XPRINT
(
1
,
stderr
,
"Error! No threads were created!
\n
"
);
...
...
@@ -195,7 +195,7 @@ void XPRunner::Run(XList * jobFunctions, XList * jobArgs, float sleepTime)
TFunction
function
=
(
TFunction
)
jobFunctions
->
GetItem
(
jobArgs
->
count
-
c
);
/* the arguments that are passed to the function */
volatile
XList
*
args
=
(
X
List
*
)
jobArgs
->
GetItem
(
jobArgs
->
count
-
c
);
volatile
TensorList
*
args
=
(
Tensor
List
*
)
jobArgs
->
GetItem
(
jobArgs
->
count
-
c
);
/* thread */
XThread
*
thread
=
threads
+
availableThreads
[
i
];
...
...
source/tensor/XPRunner.h
查看文件 @
913e2251
...
...
@@ -106,7 +106,7 @@ public:
void
KillThreads
();
/* run a set of jobs in parallel */
void
Run
(
XList
*
jobFunctions
,
X
List
*
jobArgs
,
float
sleepTime
=
0
);
void
Run
(
TensorList
*
jobFunctions
,
Tensor
List
*
jobArgs
,
float
sleepTime
=
0
);
/* get the number of parallel jobs to run */
int
GetJobNum
(
int
size
);
...
...
source/tensor/XQueue.cpp
查看文件 @
913e2251
...
...
@@ -42,7 +42,7 @@ job item used in queues
JobQueueNode
::
JobQueueNode
()
{
job
=
NULL
;
args
=
new
X
List
(
1
);
args
=
new
Tensor
List
(
1
);
}
/* de-constructor */
...
...
@@ -67,7 +67,7 @@ XQueue::XQueue(int mySize)
head
=
0
;
tail
=
0
;
isJobQueue
=
false
;
jobDequeuerArgs
=
new
X
List
(
1
);
jobDequeuerArgs
=
new
Tensor
List
(
1
);
jobDequeuerBreak
=
false
;
runningJobCount
=
0
;
jobStream
=
NULL
;
...
...
@@ -213,7 +213,7 @@ void XQueue::StopJobConsumer()
}
/* add a job item to process */
void
XQueue
::
EnqueueJob
(
void
*
job
,
X
List
*
jobArgs
)
void
XQueue
::
EnqueueJob
(
void
*
job
,
Tensor
List
*
jobArgs
)
{
MUTEX_LOCK
(
jobQueueMutex
);
runningJobCount
++
;
...
...
@@ -227,7 +227,7 @@ void XQueue::EnqueueJob(void * job, XList * jobArgs)
}
/* job item consumer */
void
XQueue
::
DequeueJobs
(
X
List
*
args
)
void
XQueue
::
DequeueJobs
(
Tensor
List
*
args
)
{
CheckNTErrors
((
args
->
count
==
2
),
"Illegal arguments!"
);
...
...
source/tensor/XQueue.h
查看文件 @
913e2251
...
...
@@ -52,7 +52,7 @@ public:
void
*
job
;
/* arguments of the job */
X
List
*
args
;
Tensor
List
*
args
;
public
:
/* constructor */
...
...
@@ -102,7 +102,7 @@ private:
XThread
jobDequeuer
;
/* argument list of jobDequeuer */
X
List
*
jobDequeuerArgs
;
Tensor
List
*
jobDequeuerArgs
;
/* indicates whether jobDequeuer stops */
bool
jobDequeuerBreak
;
...
...
@@ -141,11 +141,11 @@ public:
void
StopJobConsumer
();
/* add a job item to process */
void
EnqueueJob
(
void
*
job
,
X
List
*
jobArgs
);
void
EnqueueJob
(
void
*
job
,
Tensor
List
*
jobArgs
);
/* job item consumer */
static
void
DequeueJobs
(
X
List
*
args
);
void
DequeueJobs
(
Tensor
List
*
args
);
/* get the break flag */
bool
GetJobBreak
();
...
...
source/tensor/XTensor.cpp
查看文件 @
913e2251
...
...
@@ -1946,7 +1946,7 @@ void XTensor::FlushToMem(XMem * targetMem)
if
(
targetMem
->
devID
>=
0
)
{
#ifdef USE_CUDA
if
(
devID
<
0
)
{
X
List
l
(
1
);
Tensor
List
l
(
1
);
l
.
Add
(
this
);
CudaCPUToGPUFlush
(
&
l
,
targetMem
->
devID
,
targetMem
);
}
...
...
source/tensor/XThread.h
查看文件 @
913e2251
...
...
@@ -85,7 +85,7 @@ namespace nts{
#endif
typedef
void
(
*
TFunction
)
(
volatile
X
List
*
);
typedef
void
(
*
TFunction
)
(
volatile
Tensor
List
*
);
/*
This is a class that wraps the standard implementation of threading
...
...
@@ -133,7 +133,7 @@ public:
/* arguments (for the function to run) */
volatile
X
List
*
argv
;
Tensor
List
*
argv
;
/* a flag to break */
volatile
...
...
source/tensor/core/arithmetic/MatrixMul.cpp
查看文件 @
913e2251
...
...
@@ -108,9 +108,9 @@ void _MatrixMul(const XTensor * a, MATRIX_TRANS_TYPE transposedA,
cBlockNum
*=
b
->
dimSizeRDI
[
i
];
}
XList
*
aList
=
new
X
List
(
10
);
XList
*
bList
=
new
X
List
(
10
);
XList
*
cList
=
new
X
List
(
10
);
TensorList
*
aList
=
new
Tensor
List
(
10
);
TensorList
*
bList
=
new
Tensor
List
(
10
);
TensorList
*
cList
=
new
Tensor
List
(
10
);
int
aDimSize
[
2
]
=
{
-
a
->
dimSizeRDI
[
1
],
a
->
dimSizeRDI
[
0
]
};
int
bDimSize
[
2
]
=
{
-
b
->
dimSizeRDI
[
1
],
b
->
dimSizeRDI
[
0
]
};
int
cDimSize
[
2
]
=
{
-
c
->
dimSizeRDI
[
1
],
c
->
dimSizeRDI
[
0
]
};
...
...
source/tensor/core/arithmetic/MatrixMul2DMultiTheading.cpp
查看文件 @
913e2251
...
...
@@ -38,11 +38,11 @@ argument5: matrix a
argument6: matrix b
argument7: matrix c (c=a*b*\alpha + c*beta)
*/
void
_MatrixMul2DMultiTheading
(
X
List
*
args
)
void
_MatrixMul2DMultiTheading
(
Tensor
List
*
args
)
{
CheckNTErrors
(
args
->
count
==
2
,
"invalid argument number!"
);
IntList
*
indexArgs
=
(
IntList
*
)
args
->
GetItem
(
0
);
XList
*
matrixArgs
=
(
X
List
*
)
args
->
GetItem
(
1
);
TensorList
*
matrixArgs
=
(
Tensor
List
*
)
args
->
GetItem
(
1
);
CheckNTErrors
(
indexArgs
->
count
==
4
,
"invalid argument number!"
);
CheckNTErrors
(
matrixArgs
->
count
==
5
,
"invalid argument number!"
);
...
...
source/tensor/core/arithmetic/MatrixMul2DMultiTheading.h
查看文件 @
913e2251
...
...
@@ -30,7 +30,7 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
matrix multiplication for a block (x1,y1) - (x2,y2)
where (x1,y1) is the upper-left corner and (x2,y2) is the bottom-right corner
*/
void
_MatrixMul2DMultiTheading
(
X
List
*
args
);
void
_MatrixMul2DMultiTheading
(
Tensor
List
*
args
);
}
// namespace nts(NiuTrans.Tensor)
...
...
source/tensor/core/arithmetic/MatrixMulBatched.cpp
查看文件 @
913e2251
...
...
@@ -227,9 +227,9 @@ c_i = trans(a_i) * trans(b_i) * \alpha + c_i * \beta for each i in [0,count-1]
>> alpha - scalar
>> beta - scalar
*/
void
_MatrixMulBatchedCPU
(
const
X
List
*
a
,
MATRIX_TRANS_TYPE
transposedA
,
const
X
List
*
b
,
MATRIX_TRANS_TYPE
transposedB
,
X
List
*
c
,
DTYPE
alpha
,
DTYPE
beta
)
void
_MatrixMulBatchedCPU
(
const
Tensor
List
*
a
,
MATRIX_TRANS_TYPE
transposedA
,
const
Tensor
List
*
b
,
MATRIX_TRANS_TYPE
transposedB
,
Tensor
List
*
c
,
DTYPE
alpha
,
DTYPE
beta
)
{
CheckNTErrors
(
a
&&
b
&&
c
,
"Empty input lists!"
);
CheckNTErrors
(
a
->
count
==
b
->
count
&&
a
->
count
==
c
->
count
,
"Input lists must be of the same size!"
);
...
...
source/tensor/core/arithmetic/MatrixMulBatched.h
查看文件 @
913e2251
...
...
@@ -58,8 +58,8 @@ void _MatrixMulBatchedCPU(const XTensor * a, MATRIX_TRANS_TYPE transposedA, cons
matrix multiplication of the two tensors c = trans(a) * trans(b) * alpha + c * beta (for list inputs)
optimized for GPU
*/
void
_MatrixMulBatchedCPU
(
const
XList
*
a
,
MATRIX_TRANS_TYPE
transposedA
,
const
X
List
*
b
,
MATRIX_TRANS_TYPE
transposedB
,
X
List
*
c
,
DTYPE
alpha
=
(
DTYPE
)
1
.
0
,
DTYPE
beta
=
0
);
void
_MatrixMulBatchedCPU
(
const
TensorList
*
a
,
MATRIX_TRANS_TYPE
transposedA
,
const
Tensor
List
*
b
,
MATRIX_TRANS_TYPE
transposedB
,
Tensor
List
*
c
,
DTYPE
alpha
=
(
DTYPE
)
1
.
0
,
DTYPE
beta
=
0
);
/*
matrix multiplication of the two tensors (return an XTensor structure) c = trans(a) * trans(b) * alpha
...
...
source/tensor/core/arithmetic/XTensorBLAS.cu
查看文件 @
913e2251
...
...
@@ -201,9 +201,9 @@ void _CudaBLASMatrixMULBatchedStrided(cublasHandle_t * handle,
matrix multiplication via cuda version BLAS
*/
void _CudaBLASMatrixMULList(cublasHandle_t * handle,
const
X
List * a, MATRIX_TRANS_TYPE transposedA,
const
X
List * b, MATRIX_TRANS_TYPE transposedB,
X
List * c,
const
Tensor
List * a, MATRIX_TRANS_TYPE transposedA,
const
Tensor
List * b, MATRIX_TRANS_TYPE transposedB,
Tensor
List * c,
int count, DTYPE alpha, DTYPE beta)
{
CheckNTErrors((a && b && c), "Empty input lists!");
...
...
source/tensor/core/arithmetic/XTensorBLAS.h
查看文件 @
913e2251
...
...
@@ -56,8 +56,8 @@ void _CudaBLASMatrixMULBatchedStrided(cublasHandle_t * handle,
DTYPE
alpha
=
(
DTYPE
)
1
.
0
,
DTYPE
beta
=
1
.
0
);
/* matrix multiplication in batch mode via cuda version BLAS */
void
_CudaBLASMatrixMULList
(
cublasHandle_t
*
handle
,
const
X
List
*
a
,
MATRIX_TRANS_TYPE
transposedA
,
const
XList
*
b
,
MATRIX_TRANS_TYPE
transposedB
,
X
List
*
c
,
void
_CudaBLASMatrixMULList
(
cublasHandle_t
*
handle
,
const
Tensor
List
*
a
,
MATRIX_TRANS_TYPE
transposedA
,
const
TensorList
*
b
,
MATRIX_TRANS_TYPE
transposedB
,
Tensor
List
*
c
,
int
count
,
DTYPE
alpha
=
(
DTYPE
)
1
.
0
,
DTYPE
beta
=
1
.
0
);
#endif
...
...
source/tensor/core/math/Normalize.cpp
查看文件 @
913e2251
...
...
@@ -138,7 +138,7 @@ XTensor Normalize(const XTensor &input, int dim, const XTensor &mean, const XTen
_Normalize
(
&
input
,
&
output
,
dim
,
&
mean
,
&
var
,
&
a
,
&
b
,
epsilon
);
/* tensor connections */
X
List
list
(
5
);
Tensor
List
list
(
5
);
list
.
Add
((
XTensor
*
)
&
input
);
list
.
Add
((
XTensor
*
)
&
mean
);
list
.
Add
((
XTensor
*
)
&
var
);
...
...
source/tensor/core/movement/CopyIndexed.cpp
查看文件 @
913e2251
...
...
@@ -227,7 +227,7 @@ XTensor CopyIndexed(const XTensor & s, int dim,
/* call _CopyIndexed function */
_CopyIndexed
(
&
s
,
&
t
,
dim
,
&
srcIndex
,
&
tgtIndex
,
copyNum
);
X
List
list
(
3
);
Tensor
List
list
(
3
);
list
.
Add
((
XTensor
*
)
&
s
);
list
.
Add
((
XTensor
*
)
&
srcIndex
);
list
.
Add
((
XTensor
*
)
&
tgtIndex
);
...
...
source/tensor/core/shape/Concatenate.cpp
查看文件 @
913e2251
...
...
@@ -37,7 +37,7 @@ or "Merge" by means of the tensor shapes
>> big - the resulting tensor
>> dim - which dimension we perform the concatenation
*/
void
_Concatenate
(
const
X
List
*
smalls
,
XTensor
*
big
,
int
dim
)
void
_Concatenate
(
const
Tensor
List
*
smalls
,
XTensor
*
big
,
int
dim
)
{
bool
uniform
=
true
;
for
(
int
i
=
1
;
i
<
smalls
->
count
;
i
++
)
{
...
...
@@ -66,7 +66,7 @@ or "Merge" by means of the tensor shapes
>> dim - which dimension we perform the concatenation
<< return - the tensor of concatenating a list of tensors along a given dimension
*/
XTensor
Concatenate
(
const
X
List
&
smalls
,
int
dim
)
XTensor
Concatenate
(
const
Tensor
List
&
smalls
,
int
dim
)
{
CheckNTErrors
(
smalls
.
count
>
0
,
"Empty list!"
);
CheckNTErrors
(
dim
>=
0
,
"Illegal dimension to concatenate!"
);
...
...
@@ -147,7 +147,7 @@ concatenate two tensors along a given dimension
*/
void
_Concatenate
(
const
XTensor
*
smallA
,
const
XTensor
*
smallB
,
XTensor
*
big
,
int
dim
)
{
X
List
smalls
(
2
);
Tensor
List
smalls
(
2
);
smalls
.
Add
((
XTensor
*
)
smallA
);
smalls
.
Add
((
XTensor
*
)
smallB
);
...
...
@@ -168,7 +168,7 @@ XTensor Concatenate(const XTensor &smallA, const XTensor &smallB, int dim)
{
CheckNTErrors
(
dim
>=
0
,
"Illegal dimension to concatenate!"
);
X
List
smalls
(
2
);
Tensor
List
smalls
(
2
);
smalls
.
Add
((
XTensor
*
)
&
smallA
);
smalls
.
Add
((
XTensor
*
)
&
smallB
);
...
...
source/tensor/core/shape/Concatenate.h
查看文件 @
913e2251
...
...
@@ -31,7 +31,7 @@ concatenate a list of tensors along a given dimension
Note that this is actually a wrapper that selects
"ConcatenateSolely" or "Merge" by means of the tensor shapes
*/
void
_Concatenate
(
const
X
List
*
smalls
,
XTensor
*
big
,
int
dim
);
void
_Concatenate
(
const
Tensor
List
*
smalls
,
XTensor
*
big
,
int
dim
);
/*
concatenate a list of tensors along a given dimension (return an XTensor structure)
...
...
@@ -39,7 +39,7 @@ make a new tensor to keep the result and return it
Note that this is actually a wrapper that selects
"ConcatenateSolely" or "Merge" by means of the tensor shapes
*/
XTensor
Concatenate
(
const
X
List
&
smalls
,
int
dim
);
XTensor
Concatenate
(
const
Tensor
List
&
smalls
,
int
dim
);
/* concatenate two tensors along a given dimension */
void
_Concatenate
(
const
XTensor
*
smallA
,
const
XTensor
*
smallB
,
XTensor
*
big
,
int
dim
);
...
...
source/tensor/core/shape/ConcatenateSolely.cpp
查看文件 @
913e2251
...
...
@@ -34,7 +34,7 @@ concatenate a list of tensors along a given dimension
>> big - the resulting tensor
>> dim - which dimension we perform the concatenation
*/
void
_ConcatenateSolely
(
const
X
List
*
smalls
,
XTensor
*
big
,
int
dim
)
void
_ConcatenateSolely
(
const
Tensor
List
*
smalls
,
XTensor
*
big
,
int
dim
)
{
CheckNTErrors
(
big
->
order
>
dim
&&
dim
>=
0
,
"Illegal dimension to concatenate!"
);
...
...
@@ -85,7 +85,7 @@ void _ConcatenateSolely(const XList * smalls, XTensor * big, int dim)
}
}
else
{
CharList
*
sourceArrays
=
new
Cha
rList
(
smalls
->
count
);
StrList
*
sourceArrays
=
new
St
rList
(
smalls
->
count
);
int
*
blockSizes
=
new
int
[
smalls
->
count
];
for
(
int
i
=
0
;
i
<
smalls
->
count
;
i
++
)
{
XTensor
*
tensor
=
(
XTensor
*
)
smalls
->
GetItem
(
i
);
...
...
source/tensor/core/shape/ConcatenateSolely.h
查看文件 @
913e2251
...
...
@@ -27,7 +27,7 @@
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* concatenate a list of tensors along a given dimension */
void
_ConcatenateSolely
(
const
X
List
*
smalls
,
XTensor
*
big
,
int
dim
);
void
_ConcatenateSolely
(
const
Tensor
List
*
smalls
,
XTensor
*
big
,
int
dim
);
}
// namespace nts(NiuTrans.Tensor)
...
...
source/tensor/core/shape/Merge.cpp
查看文件 @
913e2251
...
...
@@ -206,7 +206,7 @@ merge small tensors into a big tensor
>> big - the merged tensor (for return)
>> whereToMerge - the merging operation is along with which dimension
*/
void
_Merge
(
const
X
List
*
smalls
,
XTensor
*
big
,
int
whereToMerge
)
void
_Merge
(
const
Tensor
List
*
smalls
,
XTensor
*
big
,
int
whereToMerge
)
{
whereToMerge
=
(
whereToMerge
<
0
?
big
->
order
-
1
:
whereToMerge
);
...
...
@@ -322,7 +322,7 @@ make a new tensor to keep the result and return it
>> whereToMerge - the merging operation is along with which dimension
<< return - the big tensor merged by small tensors
*/
XTensor
Merge
(
const
X
List
&
smalls
,
int
whereToMerge
)
XTensor
Merge
(
const
Tensor
List
&
smalls
,
int
whereToMerge
)
{
XTensor
*
tensor
=
smalls
.
GetItem
(
0
);
int
order
=
tensor
->
order
;
...
...
@@ -375,7 +375,7 @@ XTensor Merge(const XTensor &smallA, const XTensor &smallB, int whereToMerge)
XTensor
big
(
order
,
dimSize
,
smallA
.
dataType
,
dr
,
smallA
.
devID
,
smallA
.
mem
);
big
.
SetTMPFlag
();
X
List
smalls
(
2
);
Tensor
List
smalls
(
2
);
smalls
.
Add
((
XTensor
*
)
&
smallA
);
smalls
.
Add
((
XTensor
*
)
&
smallB
);
...
...
source/tensor/core/shape/Merge.h
查看文件 @
913e2251
...
...
@@ -34,10 +34,10 @@ void _Merge(const XTensor * s, XTensor * t, int whereToMerge, int leadingDim = -
XTensor
Merge
(
const
XTensor
&
s
,
int
whereToMerge
,
int
leadingDim
=
-
1
);
/* merge small tensors into a big tensor */
void
_Merge
(
const
X
List
*
smalls
,
XTensor
*
big
,
int
whereToMerge
);
void
_Merge
(
const
Tensor
List
*
smalls
,
XTensor
*
big
,
int
whereToMerge
);
/* merge small tensors into a big tensor (return an XTensor structure) */
XTensor
Merge
(
const
X
List
&
smalls
,
int
whereToMerge
);
XTensor
Merge
(
const
Tensor
List
&
smalls
,
int
whereToMerge
);
/* merge two tensors into a big tensor (return an XTensor structure) */
XTensor
Merge
(
const
XTensor
&
smallA
,
const
XTensor
&
smallB
,
int
whereToMerge
);
...
...
source/tensor/core/shape/MergeBlockLists.cpp
查看文件 @
913e2251
...
...
@@ -34,7 +34,7 @@ merge data by blocks
>> target - target data array
>> myMem - memory pool
*/
void
_MergeBlockLists
(
const
CharList
*
sourceList
,
int
*
blockSizes
,
int
blockNum
,
void
*
target
,
XMem
*
myMem
)
void
_MergeBlockLists
(
const
StrList
*
sourceList
,
int
*
blockSizes
,
int
blockNum
,
void
*
target
,
XMem
*
myMem
)
{
if
(
myMem
!=
NULL
&&
myMem
->
devID
>=
0
)
{
#ifdef USE_CUDA
...
...
source/tensor/core/shape/MergeBlockLists.cu
查看文件 @
913e2251
...
...
@@ -71,7 +71,7 @@ merge data by blocks (cuda version)
>> target - target data array
>> myMem - the memory pool
*/
void _CudaMergeBlockLists(const
CharList
* sourceList, int * blockSizes, int blockNum, void * target, XMem * myMem)
void _CudaMergeBlockLists(const
StrList
* sourceList, int * blockSizes, int blockNum, void * target, XMem * myMem)
{
CheckNTErrors((myMem != NULL), "No memory pool!");
CheckNTErrors((myMem->devID >= 0), "Wrong device to run!");
...
...
source/tensor/core/shape/MergeBlockLists.cuh
查看文件 @
913e2251
...
...
@@ -30,10 +30,10 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
/* copy a number of blocks (of different sizes) to target positions */
__global__
void KernelCopyBlockLists(DTYPE *
* sourceList, int * sourceBlockSizes, int sourceBlockNum, DTYPE ** targetList
);
void KernelCopyBlockLists(DTYPE *
sourceList[], int * sourceBlockSizes, int sourceBlockNum, DTYPE * targetList[]
);
/* merge data by blocks (cuda version) */
void _CudaMergeBlockLists(const
CharList
* sourceList, int * blockSizes, int blockNum, void * target, XMem * myMem);
void _CudaMergeBlockLists(const
StrList
* sourceList, int * blockSizes, int blockNum, void * target, XMem * myMem);
#endif // USE_CUDA
...
...
source/tensor/core/shape/MergeBlockLists.h
查看文件 @
913e2251
...
...
@@ -27,7 +27,7 @@
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* merge data by blocks */
void
_MergeBlockLists
(
const
CharList
*
sourceList
,
int
*
blockSizes
,
int
blockNum
,
void
*
target
,
XMem
*
myMem
);
void
_MergeBlockLists
(
const
StrList
*
sourceList
,
int
*
blockSizes
,
int
blockNum
,
void
*
target
,
XMem
*
myMem
);
}
// namespace nts(NiuTrans.Tensor)
...
...
source/tensor/core/shape/Split.cpp
查看文件 @
913e2251
...
...
@@ -209,7 +209,7 @@ split a big tensor into small tensors
>> whereToSplit - which dimension of the tensor is to split
>> splitNum - how many splits
*/
void
_Split
(
const
XTensor
*
big
,
X
List
*
smalls
,
int
whereToSplit
,
int
splitNum
)
void
_Split
(
const
XTensor
*
big
,
Tensor
List
*
smalls
,
int
whereToSplit
,
int
splitNum
)
{
CheckNTErrors
((
smalls
!=
NULL
),
"Invalid list!"
);
CheckNTErrors
((
smalls
->
count
==
splitNum
),
"Unmatched tensors!"
);
...
...
@@ -340,7 +340,7 @@ split a big tensor into small tensors
>> whereToSplit - which dimension of the tensor is to split
>> splitNum - how many splits
*/
void
Split
(
const
XTensor
&
big
,
X
List
&
smalls
,
int
whereToSplit
,
int
splitNum
)
void
Split
(
const
XTensor
&
big
,
Tensor
List
&
smalls
,
int
whereToSplit
,
int
splitNum
)
{
CheckNTErrors
(
big
.
GetDim
(
whereToSplit
)
%
splitNum
==
0
,
"Wrong splitNum!"
);
...
...
source/tensor/core/shape/Split.h
查看文件 @
913e2251
...
...
@@ -42,13 +42,13 @@ e.g., (M, N) -> (M, N/3, 3)
XTensor
Split
(
const
XTensor
&
s
,
int
whereToSplit
,
int
splitNum
);
/* split a big tensor into small tensors */
void
_Split
(
const
XTensor
*
big
,
X
List
*
smalls
,
int
whereToSplit
,
int
splitNum
);
void
_Split
(
const
XTensor
*
big
,
Tensor
List
*
smalls
,
int
whereToSplit
,
int
splitNum
);
/*
split a big tensor into small tensors (return a
X
List structure)
split a big tensor into small tensors (return a
Tensor
List structure)
make a new list to keep the result and return it
*/
void
Split
(
const
XTensor
&
big
,
X
List
&
smalls
,
int
whereToSplit
,
int
splitNum
);
void
Split
(
const
XTensor
&
big
,
Tensor
List
&
smalls
,
int
whereToSplit
,
int
splitNum
);
}
// namespace nts(NiuTrans.Tensor)
...
...
source/tensor/core/shape/Unsqueeze.cpp
查看文件 @
913e2251
...
...
@@ -78,7 +78,7 @@ void _Unsqueeze(const XTensor * a, XTensor * b, int dim, int dSize)
#endif
}
else
{
CharList
*
sourceArrays
=
new
Cha
rList
(
blockNumB
);
StrList
*
sourceArrays
=
new
St
rList
(
blockNumB
);
int
*
blockSizes
=
new
int
[
blockNumB
];
for
(
int
i
=
0
;
i
<
blockNumA
;
i
++
)
{
...
...
source/tensor/core/sort/Sort.cpp
查看文件 @
913e2251
...
...
@@ -114,7 +114,7 @@ void Sort(XTensor & a, XTensor & b, XTensor & index, int dim)
_Sort
(
&
a
,
&
b
,
&
index
,
dim
);
/* tensor connections */
X
List
list
(
2
);
Tensor
List
list
(
2
);
list
.
Add
(
&
b
);
list
.
Add
(
&
index
);
XLink
::
MakeLink
(
&
a
,
&
list
,
SORT_SORT
);
...
...
source/tensor/core/sort/TopK.cpp
查看文件 @
913e2251
...
...
@@ -128,7 +128,7 @@ void TopK(XTensor &a, XTensor &b, XTensor &index, int dim, int k)
_TopK
(
&
a
,
&
b
,
&
index
,
dim
,
k
);
/* tensor connection */
X
List
list
(
2
);
Tensor
List
list
(
2
);
list
.
Add
(
&
b
);
list
.
Add
(
&
index
);
XLink
::
MakeLink
(
&
a
,
&
list
,
SORT_TOPK
);
...
...
source/tensor/core/utilities/FlushToMem.cpp
查看文件 @
913e2251
...
...
@@ -31,7 +31,7 @@ flush a list of XTensor to GPU memory
>> devID - target GPU id
>> GPUMem - memory pool for the GPU
*/
void
CPUToGPUFlush
(
X
List
*
mList
,
int
devID
,
XMem
*
GPUMem
)
void
CPUToGPUFlush
(
Tensor
List
*
mList
,
int
devID
,
XMem
*
GPUMem
)
{
#ifdef USE_CUDA
CudaCPUToGPUFlush
(
mList
,
devID
,
GPUMem
);
...
...
source/tensor/core/utilities/FlushToMem.cu
查看文件 @
913e2251
...
...
@@ -32,7 +32,7 @@ flush a list of XTensor to GPU memory
>> devID - target GPU id
>> GPUMem - memory pool for the GPU
*/
void CudaCPUToGPUFlush(
X
List * mList, int devID, XMem * GPUMem)
void CudaCPUToGPUFlush(
Tensor
List * mList, int devID, XMem * GPUMem)
{
if (mList == NULL || mList->count == 0)
return;
...
...
source/tensor/core/utilities/FlushToMem.cuh
查看文件 @
913e2251
...
...
@@ -29,7 +29,7 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
#ifdef USE_CUDA
/* flush a list of XTensor to GPU memory */
void CudaCPUToGPUFlush(
X
List * mList, int devID, XMem * GPUMem);
void CudaCPUToGPUFlush(
Tensor
List * mList, int devID, XMem * GPUMem);
/* copy the data from GPU memory to CPU memory */
void CudaGPUToCPUFlush(XTensor * tensor);
...
...
source/tensor/core/utilities/FlushToMem.h
查看文件 @
913e2251
...
...
@@ -27,7 +27,7 @@
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* flush a list of XTensor to GPU memory */
void
CPUToGPUFlush
(
X
List
*
mList
,
int
devID
,
XMem
*
GPUMem
);
void
CPUToGPUFlush
(
Tensor
List
*
mList
,
int
devID
,
XMem
*
GPUMem
);
/* copy the data from GPU memory to CPU memory */
void
GPUToCPUFlush
(
XTensor
*
tensor
);
...
...
source/tensor/core/utilities/XMatrixSegment.cpp
查看文件 @
913e2251
...
...
@@ -51,7 +51,7 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
CheckNTErrors
(
jobNum
!=
0
,
"TODO!"
);
/* argument list of the jobs */
XList
*
jobArgList
=
new
X
List
(
argNum
);
TensorList
*
jobArgList
=
new
Tensor
List
(
argNum
);
va_list
ap
;
va_start
(
ap
,
argNum
);
...
...
@@ -62,13 +62,13 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
va_end
(
ap
);
/* prepare the neccesary argument list for parallel processing */
XList
*
jobs
=
new
X
List
(
jobNum
);
XList
*
args
=
new
X
List
(
jobNum
);
TensorList
*
jobs
=
new
Tensor
List
(
jobNum
);
TensorList
*
args
=
new
Tensor
List
(
jobNum
);
int
*
inde
x
List
=
new
int
[
jobNum
*
4
*
4
];
int
*
inde
Tensor
List
=
new
int
[
jobNum
*
4
*
4
];
/* segment the matrix into blocks */
int
nblock
=
SegmentTensor2D
(
rowNum
,
colNum
,
jobNum
,
inde
x
List
);
int
nblock
=
SegmentTensor2D
(
rowNum
,
colNum
,
jobNum
,
inde
Tensor
List
);
/*
assign jobs
...
...
@@ -78,8 +78,8 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
*/
for
(
int
i
=
0
;
i
<
jobNum
;
i
++
)
{
IntList
*
indexArgs
=
new
IntList
(
4
);
XList
*
blockArgs
=
new
X
List
(
argNum
);
int
*
blockIndex
=
inde
x
List
+
i
*
4
;
TensorList
*
blockArgs
=
new
Tensor
List
(
argNum
);
int
*
blockIndex
=
inde
Tensor
List
+
i
*
4
;
indexArgs
->
Add
(
blockIndex
[
0
]);
indexArgs
->
Add
(
blockIndex
[
1
]);
...
...
@@ -106,9 +106,9 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
parallelRunner
->
Run
(
jobs
,
args
);
/* free the memory */
delete
[]
inde
x
List
;
delete
[]
inde
Tensor
List
;
for
(
int
i
=
0
;
i
<
args
->
count
;
i
++
)
{
XList
*
blockArgs
=
(
X
List
*
)
args
->
GetItem
(
i
);
TensorList
*
blockArgs
=
(
Tensor
List
*
)
args
->
GetItem
(
i
);
delete
blockArgs
;
}
delete
args
;
...
...
@@ -154,7 +154,7 @@ int SegmentTensor2D(int rowNum, int colNum, int blockNum, int * blockIndex)
int
xMax
=
rowNum
-
1
;
int
yMax
=
colNum
-
1
;
int
nblock
=
0
,
nitem
=
0
;
int
*
inde
x
List
=
blockIndex
;
int
*
inde
Tensor
List
=
blockIndex
;
int
xSegNum
=
int
((
float
)
rowNum
/
colSize
);
int
ySegNum
=
int
((
float
)
colNum
/
rowSize
);
...
...
@@ -175,7 +175,7 @@ int SegmentTensor2D(int rowNum, int colNum, int blockNum, int * blockIndex)
x2
=
step
-
1
;
y2
=
yMax
;
while
(
x2
<=
xMax
)
{
int
*
blockIndex
=
inde
x
List
+
nblock
*
4
;
int
*
blockIndex
=
inde
Tensor
List
+
nblock
*
4
;
blockIndex
[
0
]
=
x1
;
blockIndex
[
1
]
=
y1
;
blockIndex
[
2
]
=
x2
;
blockIndex
[
3
]
=
y2
;
nblock
++
;
...
...
@@ -201,7 +201,7 @@ int SegmentTensor2D(int rowNum, int colNum, int blockNum, int * blockIndex)
x2
=
xMax
;
y2
=
step
-
1
;
while
(
y2
<=
yMax
)
{
int
*
blockIndex
=
inde
x
List
+
nblock
*
4
;
int
*
blockIndex
=
inde
Tensor
List
+
nblock
*
4
;
blockIndex
[
0
]
=
x1
;
blockIndex
[
1
]
=
y1
;
blockIndex
[
2
]
=
x2
;
blockIndex
[
3
]
=
y2
;
nblock
++
;
...
...
@@ -241,7 +241,7 @@ int SegmentTensor2D(int rowNum, int colNum, int blockNum, int * blockIndex)
}
while
(
y2
<=
yMax
)
{
int
*
blockIndex
=
inde
x
List
+
nblock
*
4
;
int
*
blockIndex
=
inde
Tensor
List
+
nblock
*
4
;
blockIndex
[
0
]
=
x1
;
blockIndex
[
1
]
=
y1
;
blockIndex
[
2
]
=
x2
;
blockIndex
[
3
]
=
y2
;
nblock
++
;
...
...
source/tensor/test/TConcatenate.cpp
查看文件 @
913e2251
...
...
@@ -30,7 +30,7 @@ In this case, 2 * (2, 1) -> (2, 2), dim=1.
bool
TestConcatenate1
()
{
/* create list */
XList
*
sList
=
new
X
List
();
TensorList
*
sList
=
new
Tensor
List
();
/* a source tensor of size (2, 1) */
int
sOrder1
=
2
;
...
...
@@ -157,7 +157,7 @@ In this case, 2 * (2, 1) -> (4, 1), dim=0.
bool
TestConcatenate2
()
{
/* create list */
XList
*
sList
=
new
X
List
();
TensorList
*
sList
=
new
Tensor
List
();
/* a source tensor of size (2, 1) */
int
sOrder1
=
2
;
...
...
@@ -286,7 +286,7 @@ In this case, (2, 1) + (2, 2) -> (2, 3), dim=1.
bool
TestConcatenate3
()
{
/* create list */
XList
*
sList
=
new
X
List
();
TensorList
*
sList
=
new
Tensor
List
();
/* a source tensor of size (2, 1) */
int
sOrder1
=
2
;
...
...
source/tensor/test/TConcatenateSolely.cpp
查看文件 @
913e2251
...
...
@@ -31,7 +31,7 @@ In this case, 2 * (2, 1) -> (2, 2), dim=1.
bool
TestConcatenateSolely1
()
{
/* create list */
XList
*
sList
=
new
X
List
();
TensorList
*
sList
=
new
Tensor
List
();
/* a source tensor of size (2, 1) */
int
sOrder1
=
2
;
...
...
@@ -154,7 +154,7 @@ In this case, 2 * (2, 1) -> (4, 1), dim=0.
bool
TestConcatenateSolely2
()
{
/* create list */
XList
*
sList
=
new
X
List
();
TensorList
*
sList
=
new
Tensor
List
();
/* a source tensor of size (2, 1) */
int
sOrder1
=
2
;
...
...
@@ -279,7 +279,7 @@ In this case, (2, 1) + (2, 2) -> (2, 3), dim=1.
bool
TestConcatenateSolely3
()
{
/* create list */
XList
*
sList
=
new
X
List
();
TensorList
*
sList
=
new
Tensor
List
();
/* a source tensor of size (2, 1) */
int
sOrder1
=
2
;
...
...
source/tensor/test/TMerge.cpp
查看文件 @
913e2251
...
...
@@ -246,7 +246,7 @@ In this case, 2 * (2, 4) -> (4, 4), whereToMerge=0.
bool
TestMerge3
()
{
/* create list */
XList
*
smallList
=
new
X
List
();
TensorList
*
smallList
=
new
Tensor
List
();
/* a small tensor of size (2, 4) */
int
sOrder
=
2
;
...
...
@@ -364,7 +364,7 @@ In this case, 2 * (2, 4) -> (2, 8), whereToMerge=1.
bool
TestMerge4
()
{
/* create list */
XList
*
smallList
=
new
X
List
();
TensorList
*
smallList
=
new
Tensor
List
();
/* a small tensor of size (2, 4) */
int
sOrder
=
2
;
...
...
source/tensor/test/TSplit.cpp
查看文件 @
913e2251
...
...
@@ -222,8 +222,8 @@ In this case, (3, 4) -> 2 * (3, 2) , whereToSplit=1, splitNum=2.
bool
TestSplit3
()
{
/* create list */
XList
*
tList
=
new
X
List
();
X
List
tUserList
;
TensorList
*
tList
=
new
Tensor
List
();
Tensor
List
tUserList
;
/* a source tensor of size (3, 4) */
int
sOrder
=
2
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论