Skip to content

Commit a5952cf

Browse files
committed
Merge branch 'remove_eigen_deps' into 'incubate/lite'
[LITE][ARM] Remove Eigen deps of ARM See merge request inference/paddlelite!87
2 parents 42f2580 + d1bef47 commit a5952cf

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

paddle/fluid/lite/arm/math/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ if (NOT HAS_ARM_MATH_LIB_DIR)
7878
gemv_arm_int8.cc
7979
conv3x3s1_direct_int8.cc
8080
conv3x3s2_direct_int8.cc
81-
DEPS ${lite_kernel_deps} eigen3 framework_proto_lite)
81+
DEPS ${lite_kernel_deps} framework_proto_lite)
8282
endif()

paddle/fluid/lite/core/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ endif()
2929
lite_cc_library(op_registry_lite SRCS op_registry.cc DEPS framework_proto_lite)
3030
lite_cc_library(scope_lite SRCS scope.cc DEPS ${tensor_lite})
3131
lite_cc_library(cpu_info_lite SRCS cpu_info.cc)
32+
33+
if (LITE_WITH_ARM)
34+
lite_cc_library(context_lite SRCS context.cc DEPS ${tensor_lite} any_lite cpu_info_lite CL_DEPS cl_helper)
35+
else()
3236
lite_cc_library(context_lite SRCS context.cc DEPS ${tensor_lite} any_lite cpu_info_lite eigen3 CL_DEPS cl_helper)
37+
endif()
3338
lite_cc_library(kernel_lite SRCS kernel.cc DEPS context_lite type_system target_wrapper_lite any_lite op_params_lite framework_proto_lite ${tensor_lite})
3439
lite_cc_library(op_lite SRCS op_lite.cc DEPS scope_lite op_registry_lite target_wrapper_lite kernel_lite
3540
cpp_op_desc_lite ${tensor_lite})

paddle/fluid/lite/kernels/arm/fc_compute_test.cc

+33-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@ namespace lite {
2828
namespace kernels {
2929
namespace arm {
3030

31+
#define A(i, j) a[i * lda + j]
32+
#define B(i, j) b[i * ldb + j]
33+
#define C(i, j) c[i * ldc + j]
34+
35+
template <typename T>
36+
void gemm_bias(const T* a, const int M, const int K, const T* b, const int K_,
37+
const int N, T* biases, T* c) {
38+
EXPECT_TRUE(K_ == K && M > 0 && N > 0 && K > 0);
39+
EXPECT_TRUE(a && b && c);
40+
const int lda = K;
41+
const int ldb = N;
42+
const int ldc = N;
43+
for (int m = 0; m < M; ++m) {
44+
for (int n = 0; n < N; ++n) {
45+
C(m, n) = 0.0f;
46+
for (int k = 0; k < K; ++k) {
47+
C(m, n) += A(m, k) * B(k, n);
48+
}
49+
}
50+
}
51+
if (biases) {
52+
for (int m = 0; m < M; ++m) {
53+
for (int n = 0; n < N; ++n) {
54+
C(m, n) += biases[n];
55+
}
56+
}
57+
}
58+
}
59+
3160
template <typename T>
3261
void FillData(T* a, const int n, const T lower = static_cast<T>(-2.f),
3362
const T upper = static_cast<T>(2.f)) {
@@ -103,8 +132,8 @@ TEST(fc_arm, compare_test) {
103132
fc.PrepareForRun();
104133
fc.Run();
105134

106-
lite::arm::math::fc_compute_eigen(x_data, m, k, w_data, k, n, b_data,
107-
ref_data);
135+
gemm_bias<T>(x_data, m, k, w_data, k, n, b_data, ref_data);
136+
108137
for (int i = 0; i < out.dims().production(); i++) {
109138
EXPECT_NEAR(out_data[i], ref_data[i], 1e-3);
110139
}
@@ -158,8 +187,8 @@ TEST(fc_arm, num_col_dims) {
158187
fc.PrepareForRun();
159188
fc.Run();
160189

161-
lite::arm::math::fc_compute_eigen(x_data, 2, 3, w_data, 3, 4, b_data,
162-
ref_data);
190+
gemm_bias<T>(x_data, 2, 3, w_data, 3, 4, b_data, ref_data);
191+
163192
for (int i = 0; i < out.dims().production(); i++) {
164193
EXPECT_NEAR(out_data[i], ref_data[i], 1e-3);
165194
}

paddle/fluid/lite/kernels/arm/mul_compute_test.cc

+26-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ namespace lite {
2828
namespace kernels {
2929
namespace arm {
3030

31+
#define A(i, j) a[i * lda + j]
32+
#define B(i, j) b[i * ldb + j]
33+
#define C(i, j) c[i * ldc + j]
34+
35+
template <typename T>
36+
void mul_gemm(const T* a, const int M, const int K, const T* b, const int K_,
37+
const int N, T* c) {
38+
EXPECT_TRUE(K_ == K && M > 0 && N > 0 && K > 0);
39+
EXPECT_TRUE(a && b && c);
40+
const int lda = K;
41+
const int ldb = N;
42+
const int ldc = N;
43+
for (int m = 0; m < M; ++m) {
44+
for (int n = 0; n < N; ++n) {
45+
C(m, n) = 0.0f;
46+
for (int k = 0; k < K; ++k) {
47+
C(m, n) += A(m, k) * B(k, n);
48+
}
49+
}
50+
}
51+
}
52+
3153
template <typename T>
3254
void FillData(T* a, const int n, const T lower = static_cast<T>(-2.f),
3355
const T upper = static_cast<T>(2.f)) {
@@ -91,8 +113,8 @@ TEST(mul_arm, compare_test) {
91113

92114
mul.Run();
93115

94-
lite::arm::math::mul_compute_eigen(x_data, m, k, y_data, k, n,
95-
ref_data);
116+
mul_gemm<T>(x_data, m, k, y_data, k, n, ref_data);
117+
96118
for (int i = 0; i < out.dims().production(); i++) {
97119
EXPECT_NEAR(out_data[i], ref_data[i], 1e-3);
98120
}
@@ -138,7 +160,8 @@ TEST(mul_arm, num_col_dims) {
138160

139161
mul.Run();
140162

141-
lite::arm::math::mul_compute_eigen(x_data, 2, 12, y_data, 12, 5, ref_data);
163+
mul_gemm<T>(x_data, 2, 12, y_data, 12, 5, ref_data);
164+
142165
for (int i = 0; i < out.dims().production(); i++) {
143166
EXPECT_NEAR(out_data[i], ref_data[i], 1e-3);
144167
}

0 commit comments

Comments
 (0)