Skip to content

Commit 6a14f52

Browse files
committed
Remove SharedCpuMatrix in mobile inference.
1 parent 2d84c6e commit 6a14f52

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

paddle/math/Matrix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ void GpuMatrix::addSharedBias(Matrix& b, real scale) {
451451
}
452452

453453
void GpuMatrix::collectBias(Matrix& a, real scale) {
454+
#ifdef PADDLE_WITH_CUDA
454455
CHECK_EQ(getHeight(), (size_t)1);
455456
CHECK_EQ(width_, a.getWidth());
456457
GpuSparseMatrix* sMatPtr = dynamic_cast<GpuSparseMatrix*>(&a);
@@ -461,6 +462,7 @@ void GpuMatrix::collectBias(Matrix& a, real scale) {
461462
hl_sparse_matrix_s A_d = sMatPtr->sMatrix_.get();
462463
hl_sparse_matrix_column_sum(data, A_d, sMatPtr->getHeight(), width_, scale);
463464
}
465+
#endif
464466
}
465467

466468
void GpuMatrix::collectSharedBias(Matrix& a, real scale) {
@@ -552,6 +554,7 @@ void GpuMatrix::mul(const GpuSparseMatrix& a,
552554
const GpuMatrix& b,
553555
real scaleAB,
554556
real scaleT) {
557+
#ifdef PADDLE_WITH_CUDA
555558
CHECK(isContiguous());
556559
CHECK(b.isContiguous());
557560
CHECK(b.useGpu_ == true) << "Matrix type are not equal";
@@ -578,12 +581,14 @@ void GpuMatrix::mul(const GpuSparseMatrix& a,
578581
b.height_,
579582
scaleAB,
580583
scaleT);
584+
#endif
581585
}
582586

583587
void GpuMatrix::mul(const GpuMatrix& a,
584588
const GpuSparseMatrix& b,
585589
real scaleAB,
586590
real scaleT) {
591+
#ifdef PADDLE_WITH_CUDA
587592
CHECK(isContiguous());
588593
CHECK(a.isContiguous());
589594
CHECK(a.useGpu_ == true) << "Matrix type are not equal";
@@ -622,6 +627,7 @@ void GpuMatrix::mul(const GpuMatrix& a,
622627
scaleAB,
623628
scaleT);
624629
}
630+
#endif
625631
}
626632

627633
/* this = a*b */
@@ -1548,6 +1554,7 @@ void GpuMatrix::bilinearBackward(const Matrix& out,
15481554
}
15491555

15501556
void GpuMatrix::multiBinaryLabelCrossEntropy(Matrix& output, Matrix& label) {
1557+
#ifdef PADDLE_WITH_CUDA
15511558
GpuMatrix* outputPtr = dynamic_cast<GpuMatrix*>(&output);
15521559
auto labelPtr = dynamic_cast<GpuSparseMatrix*>(&label);
15531560

@@ -1563,9 +1570,11 @@ void GpuMatrix::multiBinaryLabelCrossEntropy(Matrix& output, Matrix& label) {
15631570
hl_sparse_matrix_s mat_d = labelPtr->sMatrix_.get();
15641571
hl_matrix_multi_binary_cross_entropy(
15651572
output_d, entropy_d, mat_d, height_, outputPtr->width_);
1573+
#endif
15661574
}
15671575

15681576
void GpuMatrix::multiBinaryLabelCrossEntropyBp(Matrix& output, Matrix& label) {
1577+
#ifdef PADDLE_WITH_CUDA
15691578
GpuMatrix* outputPtr = dynamic_cast<GpuMatrix*>(&output);
15701579
auto labelPtr = dynamic_cast<GpuSparseMatrix*>(&label);
15711580

@@ -1581,6 +1590,7 @@ void GpuMatrix::multiBinaryLabelCrossEntropyBp(Matrix& output, Matrix& label) {
15811590
hl_sparse_matrix_s mat_d = labelPtr->sMatrix_.get();
15821591
hl_matrix_multi_binary_cross_entropy_bp(
15831592
output_d, grad_d, mat_d, height_, width_);
1593+
#endif
15841594
}
15851595

15861596
void GpuMatrix::vol2Col(real* dataSrc,
@@ -3226,6 +3236,7 @@ template void CpuMatrix::mul<CpuMatrix, CacheRowCpuMatrix>(CpuSparseMatrix* a,
32263236
real scaleAB,
32273237
real scaleT);
32283238

3239+
#ifndef PADDLE_MOBILE_INFERENCE
32293240
void SharedCpuMatrix::mul(CpuSparseMatrix* a,
32303241
CpuMatrix* b,
32313242
real scaleAB,
@@ -3354,6 +3365,7 @@ void SharedCpuMatrix::initBlock(int blockNum) {
33543365
}
33553366
}
33563367

3368+
#endif
33573369
/* Add a (column) vector b to matrix a, column by column */
33583370
void CpuMatrix::addColumnVector(const Matrix& b) {
33593371
BaseMatrix::addColVector(const_cast<Matrix&>(b));

paddle/math/Matrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,7 @@ class CpuMatrix : public Matrix {
20652065
};
20662066

20672067
class SharedCpuMatrix : public CpuMatrix {
2068+
#ifndef PADDLE_MOBILE_INFERENCE
20682069
public:
20692070
/* blockNum is number of partitions of the matrix */
20702071
SharedCpuMatrix(int blockNum, size_t height, size_t width, bool trans = false)
@@ -2111,6 +2112,7 @@ class SharedCpuMatrix : public CpuMatrix {
21112112
ThreadLocal<CpuMatrixPtr> localBuf_;
21122113
ThreadLocal<std::vector<int>> localBufRows_;
21132114
ThreadLocal<std::vector<int>> blockSeq_;
2115+
#endif
21142116
};
21152117

21162118
typedef struct { unsigned int col; } sparse_non_value_t;

0 commit comments

Comments
 (0)