Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2d84c6ea
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2d84c6ea
编写于
10月 31, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove SparseMatrix in mobile inference.
上级
a5494fa8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
174 addition
and
0 deletion
+174
-0
paddle/capi/Matrix.cpp
paddle/capi/Matrix.cpp
+8
-0
paddle/capi/matrix.h
paddle/capi/matrix.h
+2
-0
paddle/math/BaseMatrix.cu
paddle/math/BaseMatrix.cu
+47
-0
paddle/math/CMakeLists.txt
paddle/math/CMakeLists.txt
+13
-0
paddle/math/CpuSparseMatrix.h
paddle/math/CpuSparseMatrix.h
+57
-0
paddle/math/SparseMatrix.h
paddle/math/SparseMatrix.h
+47
-0
未找到文件。
paddle/capi/Matrix.cpp
浏览文件 @
2d84c6ea
...
...
@@ -81,6 +81,7 @@ paddle_error paddle_matrix_get_shape(paddle_matrix mat,
paddle_matrix
paddle_matrix_create_sparse
(
uint64_t
height
,
uint64_t
width
,
uint64_t
nnz
,
bool
isBinary
,
bool
useGpu
)
{
#ifndef PADDLE_MOBILE_INFERENCE
auto
ptr
=
new
paddle
::
capi
::
CMatrix
();
ptr
->
mat
=
paddle
::
Matrix
::
createSparseMatrix
(
height
,
...
...
@@ -91,6 +92,9 @@ paddle_matrix paddle_matrix_create_sparse(
false
,
useGpu
);
return
ptr
;
#else
return
nullptr
;
#endif
}
paddle_error
paddle_matrix_sparse_copy_from
(
paddle_matrix
mat
,
...
...
@@ -100,6 +104,7 @@ paddle_error paddle_matrix_sparse_copy_from(paddle_matrix mat,
uint64_t
colSize
,
float
*
valueArray
,
uint64_t
valueSize
)
{
#ifndef PADDLE_MOBILE_INFERENCE
if
(
mat
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
cast
(
mat
);
if
(
rowArray
==
nullptr
||
colArray
==
nullptr
||
...
...
@@ -120,4 +125,7 @@ paddle_error paddle_matrix_sparse_copy_from(paddle_matrix mat,
}
else
{
return
kPD_NOT_SUPPORTED
;
}
#else
return
kPD_NOT_SUPPORTED
;
#endif
}
paddle/capi/matrix.h
浏览文件 @
2d84c6ea
...
...
@@ -48,6 +48,7 @@ PD_API paddle_matrix paddle_matrix_create(uint64_t height,
* @param isBinary is binary (either 1 or 0 in matrix) or not.
* @param useGpu is using GPU or not.
* @return paddle_matrix.
* @note Mobile inference does not support this interface.
*/
PD_API
paddle_matrix
paddle_matrix_create_sparse
(
uint64_t
height
,
uint64_t
width
,
uint64_t
nnz
,
bool
isBinary
,
bool
useGpu
);
...
...
@@ -110,6 +111,7 @@ PD_API paddle_error paddle_matrix_get_shape(paddle_matrix mat,
* NULL if the matrix is binary.
* @param [in] valueSize length of value array. Zero if the matrix is binary.
* @return paddle_error
* @note Mobile inference does not support this interface.
*/
PD_API
paddle_error
paddle_matrix_sparse_copy_from
(
paddle_matrix
mat
,
int
*
rowArray
,
...
...
paddle/math/BaseMatrix.cu
浏览文件 @
2d84c6ea
...
...
@@ -1902,5 +1902,52 @@ void BaseMatrixT<real>::sumOfProducts(BaseMatrixT& b,
}
template
class
BaseMatrixT
<
real
>;
#ifndef PADDLE_MOBILE_INFERENCE
template
class
BaseMatrixT
<
int
>;
#else
template
<
>
void
BaseMatrixT
<
int
>::
zero
()
{
applyUnary
(
unary
::
Zero
<
int
>
());
}
template
<
>
void
BaseMatrixT
<
int
>::
assign
(
int
p
)
{
applyUnary
(
unary
::
Assign
<
int
>
(
p
));
}
template
<
>
void
BaseMatrixT
<
int
>::
isEqualTo
(
BaseMatrixT
&
b
,
int
value
)
{
applyBinary
(
binary
::
IsEqual
<
int
>
(
value
),
b
);
}
template
<
>
void
BaseMatrixT
<
int
>::
neg
()
{
applyUnary
(
unary
::
Neg
<
int
>
());
}
template
<
>
void
BaseMatrixT
<
int
>::
abs2
()
{
applyUnary
(
unary
::
Abs
<
int
>
());
}
template
<
>
void
BaseMatrixT
<
int
>::
add
(
int
p
)
{
applyUnary
(
unary
::
Add
<
int
>
(
p
));
}
template
<
>
void
BaseMatrixT
<
int
>::
add
(
int
p1
,
int
p2
)
{
applyUnary
(
unary
::
Add2
<
int
>
(
p1
,
p2
));
}
template
<
>
void
BaseMatrixT
<
int
>::
applyL1
(
int
learningRate
,
int
decayRate
)
{
applyUnary
(
unary
::
ApplyL1
<
int
>
(
learningRate
*
decayRate
));
}
#endif
}
// namespace paddle
paddle/math/CMakeLists.txt
浏览文件 @
2d84c6ea
...
...
@@ -25,6 +25,19 @@ else()
message
(
STATUS
"Compile with MKLDNNMatrix"
)
endif
()
if
(
MOBILE_INFERENCE
)
list
(
REMOVE_ITEM MATH_SOURCES
${
CMAKE_CURRENT_SOURCE_DIR
}
/SIMDFunctions.cpp
)
# Remove sparse
list
(
REMOVE_ITEM MATH_HEADERS
${
CMAKE_CURRENT_SOURCE_DIR
}
/CpuSparseMatrix.h
${
CMAKE_CURRENT_SOURCE_DIR
}
/SparseMatrix.h
${
CMAKE_CURRENT_SOURCE_DIR
}
/SparseRowMatrix.h
)
list
(
REMOVE_ITEM MATH_SOURCES
${
CMAKE_CURRENT_SOURCE_DIR
}
/CpuSparseMatrix.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/SparseMatrix.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/SparseRowMatrix.cpp
)
endif
()
set
(
MATH_SOURCES
"
${
PADDLE_SOURCE_DIR
}
/paddle/math/BaseMatrix.cu"
"
${
PADDLE_SOURCE_DIR
}
/paddle/math/TrainingAlgorithmOp.cu"
...
...
paddle/math/CpuSparseMatrix.h
浏览文件 @
2d84c6ea
...
...
@@ -13,6 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#ifndef PADDLE_MOBILE_INFERENCE
#include <cstddef>
#include "Matrix.h"
...
...
@@ -309,3 +312,57 @@ private:
using
Matrix
::
subMatrix
;
};
}
// namespace paddle
#else
#include "Matrix.h"
namespace
paddle
{
class
CpuSparseMatrix
:
public
Matrix
{
public:
CpuSparseMatrix
(
size_t
height
,
size_t
width
,
size_t
nnz
,
/* used to allocate space */
SparseValueType
valueType
=
FLOAT_VALUE
,
SparseFormat
format
=
SPARSE_CSR
,
bool
trans
=
false
)
:
Matrix
(
NULL
,
height
,
width
,
trans
,
false
)
{}
CpuSparseMatrix
(
real
*
data
,
int
*
rows
,
int
*
cols
,
size_t
height
,
size_t
width
,
size_t
nnz
,
SparseValueType
valueType
,
SparseFormat
format
,
bool
trans
)
:
Matrix
(
NULL
,
height
,
width
,
trans
,
false
)
{}
real
*
getValue
()
const
{
return
nullptr
;
}
size_t
getColStartIdx
(
size_t
i
)
const
{
return
0
;
}
size_t
getRowStartIdx
(
size_t
i
)
const
{
return
0
;
}
size_t
getColNum
(
size_t
i
)
const
{
return
0
;
}
int
*
getRowCols
(
size_t
i
)
const
{
return
nullptr
;
}
CpuSparseMatrixPtr
getTmpSparseMatrix
(
size_t
height
,
size_t
width
)
{
return
nullptr
;
}
void
resize
(
size_t
newHeight
,
size_t
newWidth
,
size_t
newNnz
,
/* used to allocate space */
SparseValueType
valueType
,
SparseFormat
format
)
{}
void
resize
(
size_t
newHeight
,
size_t
newWidth
)
{}
MatrixPtr
getTranspose
()
{
return
nullptr
;
}
void
setRow
(
size_t
row
,
size_t
colNum
,
const
unsigned
int
*
cols
,
const
real
*
values
)
{}
};
}
// namespace paddle
#endif
paddle/math/SparseMatrix.h
浏览文件 @
2d84c6ea
...
...
@@ -13,6 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#ifndef PADDLE_MOBILE_INFERENCE
#include <cstddef>
#include "CpuSparseMatrix.h"
#include "Matrix.h"
...
...
@@ -237,3 +240,47 @@ private:
};
}
// namespace paddle
#else
#include "CpuSparseMatrix.h"
namespace
paddle
{
class
GpuSparseMatrix
:
public
Matrix
{
public:
GpuSparseMatrix
(
size_t
height
,
size_t
width
,
size_t
nnz
,
/* used to allocate space */
SparseValueType
valueType
=
FLOAT_VALUE
,
SparseFormat
format_
=
SPARSE_CSR
,
bool
trans
=
false
)
:
Matrix
(
NULL
,
height
,
width
,
trans
,
false
)
{}
GpuSparseMatrix
(
real
*
value
,
int
*
rows
,
int
*
cols
,
size_t
height
,
size_t
width
,
size_t
nnz
,
SparseValueType
valueType
,
SparseFormat
format
,
bool
trans
)
:
Matrix
(
NULL
,
height
,
width
,
trans
,
true
)
{}
void
resize
(
size_t
newHeight
,
size_t
newWidth
,
size_t
newNnz
,
/* used to allocate space */
SparseValueType
valueType
,
SparseFormat
format
)
{}
void
resize
(
size_t
newHeight
,
size_t
newWidth
)
{}
MatrixPtr
getTranspose
()
{
return
nullptr
;
}
void
setRow
(
size_t
row
,
size_t
colNum
,
const
unsigned
int
*
cols
,
const
real
*
values
)
{}
};
}
// namespace paddle
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录