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
6d05d6c8
Commit
6d05d6c8
authored
Jul 23, 2019
by
张裕浩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean code, remove variable useBLAS and useCUDA permanently.
parent
1f71eb10
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
217 行增加
和
185 行删除
+217
-185
source/tensor/XBLAS.h
+0
-59
source/tensor/XGlobal.cpp
+0
-2
source/tensor/XGlobal.h
+2
-2
source/tensor/core/reduce/VectorBuffer.cpp
+172
-0
source/tensor/core/reduce/VectorBuffer.h
+43
-122
没有找到文件。
source/tensor/XBLAS.h
查看文件 @
6d05d6c8
...
...
@@ -34,7 +34,6 @@ namespace nts{
/* some of the code below is from OpenBLAS (https://github.com/xianyi/OpenBLAS) */
//#define OPENBLAS
#define OPENBLAS_CONST const
typedef
int
BLASINT
;
...
...
@@ -141,64 +140,6 @@ extern "C" int XBLAS_GET_CORE_NUM();
/* get the parallelization type used by OpenBLAS */
//extern "C" int (*XBLAS_GET_PARALLEL_TYPE)(void);
/* linux systems */
#ifndef _WIN32
/* cblas functions that are imported from the lib. See cblas.h in OpenBlas for more information */
extern
"C"
void
cblas_sgemm
(
OPENBLAS_CONST
enum
CBLAS_ORDER
Order
,
OPENBLAS_CONST
enum
CBLAS_TRANSPOSE
TransA
,
OPENBLAS_CONST
enum
CBLAS_TRANSPOSE
TransB
,
OPENBLAS_CONST
BLASINT
M
,
OPENBLAS_CONST
BLASINT
N
,
OPENBLAS_CONST
BLASINT
K
,
OPENBLAS_CONST
float
alpha
,
OPENBLAS_CONST
float
*
A
,
OPENBLAS_CONST
BLASINT
lda
,
OPENBLAS_CONST
float
*
B
,
OPENBLAS_CONST
BLASINT
ldb
,
OPENBLAS_CONST
float
beta
,
float
*
C
,
OPENBLAS_CONST
BLASINT
ldc
);
extern
"C"
void
cblas_dgemm
(
OPENBLAS_CONST
enum
CBLAS_ORDER
Order
,
OPENBLAS_CONST
enum
CBLAS_TRANSPOSE
TransA
,
OPENBLAS_CONST
enum
CBLAS_TRANSPOSE
TransB
,
OPENBLAS_CONST
BLASINT
M
,
OPENBLAS_CONST
BLASINT
N
,
OPENBLAS_CONST
BLASINT
K
,
OPENBLAS_CONST
double
alpha
,
OPENBLAS_CONST
double
*
A
,
OPENBLAS_CONST
BLASINT
lda
,
OPENBLAS_CONST
double
*
B
,
OPENBLAS_CONST
BLASINT
ldb
,
OPENBLAS_CONST
double
beta
,
double
*
C
,
OPENBLAS_CONST
BLASINT
ldc
);
extern
"C"
void
cblas_sger
(
OPENBLAS_CONST
enum
CBLAS_ORDER
order
,
OPENBLAS_CONST
BLASINT
M
,
OPENBLAS_CONST
BLASINT
N
,
OPENBLAS_CONST
float
alpha
,
OPENBLAS_CONST
float
*
X
,
OPENBLAS_CONST
BLASINT
incX
,
OPENBLAS_CONST
float
*
Y
,
OPENBLAS_CONST
BLASINT
incY
,
float
*
A
,
OPENBLAS_CONST
BLASINT
lda
);
extern
"C"
void
cblas_dger
(
OPENBLAS_CONST
enum
CBLAS_ORDER
order
,
OPENBLAS_CONST
BLASINT
M
,
OPENBLAS_CONST
BLASINT
N
,
OPENBLAS_CONST
double
alpha
,
OPENBLAS_CONST
double
*
X
,
OPENBLAS_CONST
BLASINT
incX
,
OPENBLAS_CONST
double
*
Y
,
OPENBLAS_CONST
BLASINT
incY
,
double
*
A
,
OPENBLAS_CONST
BLASINT
lda
);
extern
"C"
void
cblas_saxpy
(
OPENBLAS_CONST
BLASINT
n
,
OPENBLAS_CONST
float
a
,
OPENBLAS_CONST
float
*
x
,
OPENBLAS_CONST
BLASINT
incx
,
OPENBLAS_CONST
float
*
y
,
OPENBLAS_CONST
BLASINT
incy
);
extern
"C"
void
cblas_daxpy
(
OPENBLAS_CONST
BLASINT
n
,
OPENBLAS_CONST
double
a
,
OPENBLAS_CONST
double
*
x
,
OPENBLAS_CONST
BLASINT
incx
,
OPENBLAS_CONST
double
*
y
,
OPENBLAS_CONST
BLASINT
incy
);
#endif
#if defined(OPENBLAS)
/* better control of multi-threading */
extern
"C"
void
openblas_set_num_threads
(
int
num_threads
);
extern
"C"
void
goto_set_num_threads
(
int
num_threads
);
//extern "C" int openblas_get_num_threads(void);
extern
"C"
int
openblas_get_num_procs
(
void
);
extern
"C"
void
cblas_saxpy
(
OPENBLAS_CONST
BLASINT
n
,
OPENBLAS_CONST
float
a
,
OPENBLAS_CONST
float
*
x
,
OPENBLAS_CONST
BLASINT
incx
,
OPENBLAS_CONST
float
*
y
,
OPENBLAS_CONST
BLASINT
incy
);
extern
"C"
void
cblas_daxpy
(
OPENBLAS_CONST
BLASINT
n
,
OPENBLAS_CONST
double
a
,
OPENBLAS_CONST
double
*
x
,
OPENBLAS_CONST
BLASINT
incx
,
OPENBLAS_CONST
double
*
y
,
OPENBLAS_CONST
BLASINT
incy
);
//extern "C" char* openblas_get_config(void);
//extern "C" char* openblas_get_corename(void);
//extern "C" int openblas_get_parallel(void);
#endif
#if defined(MKL)
/* better control of multi-threading */
//_Mkl_Api(void,MKL_Set_Num_Threads,(int nth))
//_Mkl_Api(int,MKL_Get_Max_Threads,(void))
//extern "C" void MKL_Set_Num_Threads(int num_threads);
//extern "C" int MKL_Get_Max_Threads();
//extern "C" void cblas_saxpy(OPENBLAS_CONST BLASINT n, OPENBLAS_CONST float a, OPENBLAS_CONST float *x, OPENBLAS_CONST BLASINT incx, OPENBLAS_CONST float *y, OPENBLAS_CONST BLASINT incy);
//#define mkl_set_num_threads MKL_Set_Num_Threads
//#define mkl_get_max_num_threads MKL_Get_Max_Threads
//extern "C" void mkl_set_num_threads(int num_threads);
//extern "C" void omp_set_num_threads(int num_threads);
//extern "C" int mkl_get_max_num_threads();
#endif
#if defined(CUDA_BLAS)
...
...
source/tensor/XGlobal.cpp
查看文件 @
6d05d6c8
...
...
@@ -50,8 +50,6 @@ int CONST_MINUSONE = -1;
bool
CONST_TRUE
=
true
;
int
verboseLevel
=
0
;
bool
useBLAS
=
false
;
bool
useCUDA
=
false
;
FILE
*
tmpLog
=
NULL
;
double
myTime
=
0
;
...
...
source/tensor/XGlobal.h
查看文件 @
6d05d6c8
...
...
@@ -135,8 +135,6 @@ extern bool CONST_TRUE;
#define NIUTRANSNNDEBUG
extern
int
verboseLevel
;
extern
bool
useBLAS
;
extern
bool
useCUDA
;
#define FFLUSH(FILEH) \
{ \
...
...
@@ -158,8 +156,10 @@ extern bool useCUDA;
/* BLAS interfaces */
#ifdef DOUBELPRICSION
#define GEMM XBLAS_DGEMM
#define AXPY XBLAS_DAXPY
#else
#define GEMM XBLAS_SGEMM
#define AXPY XBLAS_SAXPY
#endif
extern
void
InitGlobalAll
();
...
...
source/tensor/core/reduce/VectorBuffer.cpp
0 → 100644
查看文件 @
6d05d6c8
/* NiuTrans.Tensor - an open-source tensor library
* Copyright (C) 2017, Natural Language Processing Lab, Northestern University.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Created by: ZHANG Yuhao (email: zhangyuhao@stu.neu.edu.cn) 2019-07-23
*/
#include "VectorBuffer.h"
namespace
nts
{
/* data size for each buffer */
int
VectorBuffer
::
size
()
{
return
32
/
sizeof
(
DTYPE
);
}
/* constructor */
VectorBuffer
::
VectorBuffer
()
{
}
/*
constructor
initial values with val
*/
VectorBuffer
::
VectorBuffer
(
DTYPE
val
)
{
for
(
int
i
=
0
;
i
!=
size
();
i
++
)
{
values
[
i
]
=
val
;
}
}
/* load data */
VectorBuffer
VectorBuffer
::
loadu
(
const
DTYPE
*
ptr
,
bool
isExp
,
DTYPE
power
,
DTYPE
*
bias
)
{
int
count
=
32
/
sizeof
(
DTYPE
);
VectorBuffer
vec
;
if
(
isExp
)
{
if
(
bias
==
NULL
)
{
if
(
power
==
(
DTYPE
)
1.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
*
(
ptr
+
i
));
}
}
else
if
(
power
==
(
DTYPE
)
2.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
((
*
(
ptr
+
i
))
*
(
*
(
ptr
+
i
)));
}
}
else
if
(
power
==
(
DTYPE
)
0.5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
sqrt
(
*
(
ptr
+
i
)));
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
pow
(
*
(
ptr
+
i
),
power
));
}
}
}
/*is bias == NULL*/
else
{
if
(
power
==
(
DTYPE
)
1.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
*
(
ptr
+
i
)
-
bias
[
i
]);
}
}
else
if
(
power
==
(
DTYPE
)
2.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
DTYPE
value
=
*
(
ptr
+
i
)
-
bias
[
i
];
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
value
*
value
);
}
}
else
if
(
power
==
(
DTYPE
)
0.5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
sqrt
(
*
(
ptr
+
i
)
-
bias
[
i
]));
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
pow
(
*
(
ptr
+
i
)
-
bias
[
i
],
power
));
}
}
}
}
//isExp
else
{
if
(
bias
==
NULL
)
{
if
(
power
==
(
DTYPE
)
1.0
)
{
memcpy
(
vec
.
values
,
ptr
,
count
*
sizeof
(
DTYPE
));
}
else
if
(
power
==
(
DTYPE
)
2.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
*
(
ptr
+
i
))
*
(
*
(
ptr
+
i
));
}
}
else
if
(
power
==
(
DTYPE
)
0.5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
sqrt
(
*
(
ptr
+
i
));
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
pow
(
*
(
ptr
+
i
),
power
);
}
}
}
// if bias == NULL
else
{
if
(
power
==
(
DTYPE
)
1.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
*
(
ptr
+
i
)
-
bias
[
i
];
}
}
else
if
(
power
==
(
DTYPE
)
2.0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
DTYPE
value
=
*
(
ptr
+
i
)
-
bias
[
i
];
vec
.
values
[
i
]
=
value
*
value
;
}
}
else
if
(
power
==
(
DTYPE
)
0.5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
sqrt
(
*
(
ptr
+
i
)
-
bias
[
i
]);
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
pow
(
*
(
ptr
+
i
)
-
bias
[
i
],
power
);
}
}
}
}
return
vec
;
}
/* overloading [] */
const
DTYPE
&
VectorBuffer
::
operator
[](
int
idx
)
const
{
return
values
[
idx
];
}
/* overloading + */
VectorBuffer
VectorBuffer
::
operator
+
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
a
[
i
]
+
this
->
values
[
i
];
}
return
*
this
;
}
/* conculte the max of two buffer */
VectorBuffer
VectorBuffer
::
maxData
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
MAX
(
a
[
i
],
this
->
values
[
i
]);
}
return
*
this
;
}
}
/* end of the nts (NiuTrans.Tensor) namespace */
\ No newline at end of file
source/tensor/core/reduce/VectorBuffer.h
查看文件 @
6d05d6c8
/* NiuTrans.Tensor - an open-source tensor library
* Copyright (C) 2017, Natural Language Processing Lab, Northestern University.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Created by: ZHANG Yuhao (email: zhangyuhao@stu.neu.edu.cn) 2019-07-23
*/
#include <cstring>
#include <cmath>
#include "../../XGlobal.h"
namespace
nts
{
class
VectorBuffer
{
private
:
/* buffer for concluter */
DTYPE
values
[
32
/
sizeof
(
DTYPE
)]
=
{
0
};
public
:
static
int
size
()
{
return
32
/
sizeof
(
DTYPE
);
}
VectorBuffer
()
{}
VectorBuffer
(
DTYPE
val
)
{
for
(
int
i
=
0
;
i
!=
size
();
i
++
)
{
values
[
i
]
=
val
;
}
}
static
VectorBuffer
loadu
(
const
DTYPE
*
ptr
,
bool
isExp
=
false
,
DTYPE
power
=
(
DTYPE
)
1
.
0
F
,
DTYPE
*
bias
=
NULL
)
{
int
count
=
32
/
sizeof
(
DTYPE
);
VectorBuffer
vec
;
if
(
isExp
)
{
if
(
bias
==
NULL
)
{
if
(
power
==
(
DTYPE
)
1
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
*
(
ptr
+
i
));
}
}
else
if
(
power
==
(
DTYPE
)
2
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
((
*
(
ptr
+
i
))
*
(
*
(
ptr
+
i
)));
}
}
else
if
(
power
==
(
DTYPE
)
0
.
5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
sqrt
(
*
(
ptr
+
i
)));
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
pow
(
*
(
ptr
+
i
),
power
));
}
}
}
/*is bias == NULL*/
else
{
if
(
power
==
(
DTYPE
)
1
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
*
(
ptr
+
i
)
-
bias
[
i
]);
}
}
else
if
(
power
==
(
DTYPE
)
2
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
DTYPE
value
=
*
(
ptr
+
i
)
-
bias
[
i
];
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
value
*
value
);
}
}
else
if
(
power
==
(
DTYPE
)
0
.
5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
sqrt
(
*
(
ptr
+
i
)
-
bias
[
i
]));
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
exp
(
pow
(
*
(
ptr
+
i
)
-
bias
[
i
],
power
));
}
}
}
}
//isExp
else
{
if
(
bias
==
NULL
)
{
if
(
power
==
(
DTYPE
)
1
.
0
)
{
memcpy
(
vec
.
values
,
ptr
,
count
*
sizeof
(
DTYPE
));
}
else
if
(
power
==
(
DTYPE
)
2
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
*
(
ptr
+
i
))
*
(
*
(
ptr
+
i
));
}
}
else
if
(
power
==
(
DTYPE
)
0
.
5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
sqrt
(
*
(
ptr
+
i
));
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
pow
(
*
(
ptr
+
i
),
power
);
}
}
}
// if bias == NULL
else
{
if
(
power
==
(
DTYPE
)
1
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
*
(
ptr
+
i
)
-
bias
[
i
];
}
}
else
if
(
power
==
(
DTYPE
)
2
.
0
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
DTYPE
value
=
*
(
ptr
+
i
)
-
bias
[
i
];
vec
.
values
[
i
]
=
value
*
value
;
}
}
else
if
(
power
==
(
DTYPE
)
0
.
5
)
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
sqrt
(
*
(
ptr
+
i
)
-
bias
[
i
]);
}
}
else
{
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
pow
(
*
(
ptr
+
i
)
-
bias
[
i
],
power
);
}
}
}
}
return
vec
;
}
const
DTYPE
&
operator
[](
int
idx
)
const
{
return
values
[
idx
];
}
inline
VectorBuffer
operator
+
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
a
[
i
]
+
this
->
values
[
i
];
}
return
*
this
;
}
inline
VectorBuffer
maxData
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
MAX
(
a
[
i
],
this
->
values
[
i
]);
}
return
*
this
;
}
/* data size for each buffer */
static
int
size
();
/* constructor */
VectorBuffer
();
/* constructor */
VectorBuffer
(
DTYPE
val
);
/* load data */
static
VectorBuffer
loadu
(
const
DTYPE
*
ptr
,
bool
isExp
=
false
,
DTYPE
power
=
(
DTYPE
)
1
.
0
F
,
DTYPE
*
bias
=
NULL
);
/* overloading [] */
const
DTYPE
&
operator
[](
int
idx
)
const
;
/* overloading + */
VectorBuffer
operator
+
(
const
VectorBuffer
&
a
);
/* conculte the max of two buffer */
VectorBuffer
maxData
(
const
VectorBuffer
&
a
);
};
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论