Skip to content

Commit 924e53b

Browse files
authored
Update the Anakin interfaces for content-dnn and MLU, test=release/1.5 (#18028)
* Update the Anakin interfaces for content-dnn and MLU (#17890) * update anakin-engine interfaces for content-dnn test=develop * support only-gpu mode of Anakin modify eltwise parse test=develop * modification for thread-safe test=develop * Integrated template instance test=develop * increase template parameters test=develop * support MLU predictor test=develop * update anakin cmake files test=develop * update TargetWrapper::set_device * update the initialization of anakin subgraph test=develop * use the default constructor of base class test=develop * modify the access level of anakin engine (#18015) test=develop * fix ci test cmake test=develop
1 parent b5556f2 commit 924e53b

40 files changed

+819
-352
lines changed

cmake/anakin_subgraph.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
if(NOT WITH_GPU)
2-
return()
3-
endif()
4-
51
set(ANAKIN_ROOT "/usr" CACHE PATH "ANAKIN ROOT")
62
find_path(ANAKIN_INCLUDE_DIR anakin_config.h
73
PATHS ${ANAKIN_ROOT} ${ANAKIN_ROOT}/include
@@ -16,9 +12,7 @@ find_library(ANAKIN_LIBRARY NAMES libanakin_saber_common.so libanakin.so
1612
DOC "Path to ANAKIN library.")
1713

1814
if(ANAKIN_INCLUDE_DIR AND ANAKIN_LIBRARY)
19-
if(WITH_DSO)
2015
set(ANAKIN_FOUND ON)
21-
endif(WITH_DSO)
2216
else()
2317
set(ANAKIN_FOUND OFF)
2418
endif()
@@ -31,3 +25,8 @@ if(ANAKIN_FOUND)
3125
link_directories(${ANAKIN_ROOT})
3226
add_definitions(-DPADDLE_WITH_ANAKIN)
3327
endif()
28+
29+
if(ANAKIN_FOUND AND WITH_GPU AND WITH_DSO)
30+
message(STATUS "Compile with anakin subgraph.")
31+
set(ANAKIN_SUBGRAPH ON)
32+
endif()

paddle/fluid/framework/ir/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pass_library(fillconstant_elementwisemul_fuse inference)
7777
pass_library(shuffle_channel_detect_pass inference)
7878
pass_library(delete_quant_dequant_op_pass inference)
7979

80-
if(ANAKIN_FOUND)
80+
if(ANAKIN_SUBGRAPH)
8181
pass_library(simplify_anakin_priorbox_detection_out_pass inference)
8282
endif()
8383

paddle/fluid/inference/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (TENSORRT_FOUND)
1717
add_subdirectory(tensorrt)
1818
endif()
1919

20-
if (ANAKIN_FOUND)
20+
if (ANAKIN_SUBGRAPH)
2121
add_subdirectory(anakin)
2222
endif()
2323

@@ -43,11 +43,15 @@ if(WITH_MKLDNN)
4343
endif()
4444

4545
set(STATIC_INFERENCE_APIS paddle_fluid_api paddle_inference_api analysis_predictor)
46+
if (ANAKIN_FOUND)
47+
set(ANAKIN_SHARED_INFERENCE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/api/api_anakin_engine.cc)
48+
endif()
4649
set(SHARED_INFERENCE_SRCS
4750
io.cc ${CMAKE_CURRENT_SOURCE_DIR}/api/api.cc ${CMAKE_CURRENT_SOURCE_DIR}/api/api_impl.cc
4851
${CMAKE_CURRENT_SOURCE_DIR}/api/analysis_predictor.cc
4952
${mkldnn_quantizer_src}
50-
${CMAKE_CURRENT_SOURCE_DIR}/api/details/zero_copy_tensor.cc)
53+
${CMAKE_CURRENT_SOURCE_DIR}/api/details/zero_copy_tensor.cc
54+
${ANAKIN_SHARED_INFERENCE_SRCS})
5155

5256
if(WIN32)
5357
sep_library(paddle_fluid DEPS ${fluid_modules} ${STATIC_INFERENCE_APIS} zero_copy_tensor reset_tensor_array

paddle/fluid/inference/anakin/convert/elementwise.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void ElementwiseMulOpConverter<TargetT, PrecisionT>::operator()(
6060
auto op_name = op_desc.Type() + ":" + op_desc.Output("Out").front();
6161

6262
this->engine_->AddOp(op_name, "Eltwise", {x_name, y_name}, {out_name});
63-
std::string elementwise_type = "Prod";
63+
std::string elementwise_type = "Mul";
6464
this->engine_->template AddOpAttr<std::string>(op_name, "type",
6565
elementwise_type);
6666
std::vector<float> coeff = {1.0, 1.0};

paddle/fluid/inference/anakin/convert/op_converter.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ template class AnakinOpConverter<::anakin::saber::NV,
153153
::anakin::Precision::FP32>;
154154
template class AnakinOpConverter<::anakin::saber::NV,
155155
::anakin::Precision::INT8>;
156-
156+
#ifdef ANAKIN_X86_PLACE
157157
template class AnakinOpConverter<::anakin::saber::X86,
158158
::anakin::Precision::FP32>;
159159
template class AnakinOpConverter<::anakin::saber::X86,
160160
::anakin::Precision::INT8>;
161+
#endif
161162
} // namespace anakin
162163
} // namespace inference
163164
} // namespace paddle
@@ -203,16 +204,16 @@ template class AnakinOpConverter<::anakin::saber::X86,
203204
CPU, ::anakin::saber::X86, precision_type__, \
204205
::anakin::Precision::precision_type__)
205206

206-
#ifdef PADDLE_WITH_CUDA
207+
#if defined(PADDLE_WITH_CUDA) && defined(ANAKIN_X86_PLACE)
207208
#define REGISTER_ANAKIN_OP_CONVERTER(op_type__, Converter__) \
208209
REGISTER_CUDA_ANAKIN_OP_CONVERTER(op_type__, Converter__, FP32); \
209210
REGISTER_CUDA_ANAKIN_OP_CONVERTER(op_type__, Converter__, INT8); \
210211
REGISTER_CPU_ANAKIN_OP_CONVERTER(op_type__, Converter__, FP32); \
211212
REGISTER_CPU_ANAKIN_OP_CONVERTER(op_type__, Converter__, INT8)
212-
#else
213-
#define REGISTER_ANAKIN_OP_CONVERTER(op_type__, Converter__) \
214-
REGISTER_CPU_ANAKIN_OP_CONVERTER(op_type__, Converter__, FP32); \
215-
REGISTER_CPU_ANAKIN_OP_CONVERTER(op_type__, Converter__, INT8)
213+
#elif defined(PADDLE_WITH_CUDA)
214+
#define REGISTER_ANAKIN_OP_CONVERTER(op_type__, Converter__) \
215+
REGISTER_CUDA_ANAKIN_OP_CONVERTER(op_type__, Converter__, FP32); \
216+
REGISTER_CUDA_ANAKIN_OP_CONVERTER(op_type__, Converter__, INT8)
216217
#endif
217218

218219
#define USE_ANAKIN_CONVERTER_BASE(op_type__, place_type__, precision_type__) \
@@ -221,12 +222,16 @@ template class AnakinOpConverter<::anakin::saber::X86,
221222
__attribute__((unused)) = \
222223
Touch_anakin_##op_type__##_##place_type__##_##precision_type__();
223224

225+
#if defined(PADDLE_WITH_CUDA) && defined(ANAKIN_X86_PLACE)
226+
#define USE_ANAKIN_CONVERTER(op_type__) \
227+
USE_ANAKIN_CONVERTER_BASE(op_type__, CUDA, FP32) \
228+
USE_ANAKIN_CONVERTER_BASE(op_type__, CPU, FP32)
229+
#define USE_INT8_ANAKIN_CONVERTER(op_type__) \
230+
USE_ANAKIN_CONVERTER_BASE(op_type__, CUDA, INT8) \
231+
USE_ANAKIN_CONVERTER_BASE(op_type__, CPU, INT8)
232+
#elif defined(PADDLE_WITH_CUDA)
224233
#define USE_ANAKIN_CONVERTER(op_type__) \
225234
USE_ANAKIN_CONVERTER_BASE(op_type__, CUDA, FP32)
226235
#define USE_INT8_ANAKIN_CONVERTER(op_type__) \
227236
USE_ANAKIN_CONVERTER_BASE(op_type__, CUDA, INT8)
228-
229-
#define USE_CPU_ANAKIN_CONVERTER(op_type__) \
230-
USE_ANAKIN_CONVERTER_BASE(op_type__, CPU, FP32)
231-
#define USE_CPU_INT8_ANAKIN_CONVERTER(op_type__) \
232-
USE_ANAKIN_CONVERTER_BASE(op_type__, CPU, INT8)
237+
#endif

paddle/fluid/inference/anakin/convert/test_activation_op.cc

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,6 @@ TEST(swish_op, gpu) {
7777
}
7878
#endif
7979

80-
/*
81-
TEST(sigm_op, cpu) {
82-
platform::CPUPlace cpu_place;
83-
platform::CPUDeviceContext ctx(cpu_place);
84-
test_activation_op<::anakin::saber::X86>("sigmoid", ctx, false);
85-
}
86-
87-
TEST(tanh_op, cpu) {
88-
platform::CPUPlace cpu_place;
89-
platform::CPUDeviceContext ctx(cpu_place);
90-
test_activation_op<::anakin::saber::X86>("tanh", ctx, false);
91-
}
92-
93-
TEST(relu6_op, cpu) {
94-
platform::CPUPlace cpu_place;
95-
platform::CPUDeviceContext ctx(cpu_place);
96-
test_activation_op<::anakin::saber::X86>("relu6", ctx, false);
97-
}
98-
99-
TEST(swish_op, cpu) {
100-
platform::CPUPlace cpu_place;
101-
platform::CPUDeviceContext ctx(cpu_place);
102-
test_activation_op<::anakin::saber::X86>("swish", ctx, false);
103-
}
104-
*/
105-
10680
} // namespace anakin
10781
} // namespace inference
10882
} // namespace paddle
@@ -112,13 +86,7 @@ USE_OP(tanh);
11286
USE_OP(relu6);
11387
USE_OP(swish);
11488

115-
USE_CPU_ANAKIN_CONVERTER(sigmoid);
116-
USE_CPU_ANAKIN_CONVERTER(tanh);
117-
USE_CPU_ANAKIN_CONVERTER(relu6);
118-
USE_CPU_ANAKIN_CONVERTER(swish);
119-
#ifdef PADDLE_WITH_CUDA
12089
USE_ANAKIN_CONVERTER(sigmoid);
12190
USE_ANAKIN_CONVERTER(tanh);
12291
USE_ANAKIN_CONVERTER(relu6);
12392
USE_ANAKIN_CONVERTER(swish);
124-
#endif

paddle/fluid/inference/anakin/convert/test_affine_channel_op.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,16 @@ TEST(affine_channel_op, gpu) {
5757
test_affine_channel_op<::anakin::saber::NV>(ctx, true);
5858
}
5959
#endif
60-
60+
#ifdef ANAKIN_X86_PLACE
6161
TEST(affine_channel_op, cpu) {
6262
platform::CPUPlace cpu_place;
6363
platform::CPUDeviceContext ctx(cpu_place);
6464
test_affine_channel_op<::anakin::saber::X86>(ctx, false);
6565
}
66-
66+
#endif
6767
} // namespace anakin
6868
} // namespace inference
6969
} // namespace paddle
7070

7171
USE_OP(affine_channel);
72-
USE_CPU_ANAKIN_CONVERTER(affine_channel);
73-
#ifdef PADDLE_WITH_CUDA
7472
USE_ANAKIN_CONVERTER(affine_channel);
75-
#endif

paddle/fluid/inference/anakin/convert/test_batch_norm_op.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,15 @@ TEST(batch_norm_op, gpu) {
7373
test_batchnorm_op<::anakin::saber::NV>(ctx, true);
7474
}
7575
#endif
76-
76+
#ifdef ANAKIN_X86_PLACE
7777
TEST(batch_norm_op, cpu) {
7878
platform::CPUPlace cpu_place;
7979
platform::CPUDeviceContext ctx(cpu_place);
8080
test_batchnorm_op<::anakin::saber::X86>(ctx, false);
8181
}
82-
82+
#endif
8383
} // namespace anakin
8484
} // namespace inference
8585
} // namespace paddle
8686
USE_OP(batch_norm);
87-
USE_CPU_ANAKIN_CONVERTER(batch_norm);
88-
89-
#ifdef PADDLE_WITH_CUDA
9087
USE_ANAKIN_CONVERTER(batch_norm);
91-
#endif

paddle/fluid/inference/anakin/convert/test_concat_op.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ TEST(concat_op, gpu) {
5353
test_concat_op<::anakin::saber::NV>(ctx, true);
5454
}
5555
#endif
56-
56+
#ifdef ANAKIN_X86_PLACE
5757
TEST(concat_op, cpu) {
5858
platform::CPUPlace cpu_place;
5959
platform::CPUDeviceContext ctx(cpu_place);
6060
test_concat_op<::anakin::saber::X86>(ctx, false);
6161
}
62-
62+
#endif
6363
} // namespace anakin
6464
} // namespace inference
6565
} // namespace paddle
6666
USE_OP(concat);
67-
USE_CPU_ANAKIN_CONVERTER(concat);
68-
69-
#ifdef PADDLE_WITH_CUDA
7067
USE_ANAKIN_CONVERTER(concat);
71-
#endif

paddle/fluid/inference/anakin/convert/test_conv2d_op.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,16 @@ TEST(conv2d_op, gpu) {
6060
test_conv2d_op<::anakin::saber::NV>(ctx, true);
6161
}
6262
#endif
63-
63+
#ifdef ANAKIN_X86_PLACE
6464
TEST(conv2d_op, cpu) {
6565
platform::CPUPlace cpu_place;
6666
platform::CPUDeviceContext ctx(cpu_place);
6767
test_conv2d_op<::anakin::saber::X86>(ctx, false);
6868
}
69-
69+
#endif
7070
} // namespace anakin
7171
} // namespace inference
7272
} // namespace paddle
7373

7474
USE_OP(conv2d);
75-
USE_CPU_ANAKIN_CONVERTER(conv2d);
76-
77-
#ifdef PADDLE_WITH_CUDA
7875
USE_ANAKIN_CONVERTER(conv2d);
79-
#endif

0 commit comments

Comments
 (0)