Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions paddle/fluid/inference/api/paddle_analysis_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,13 +869,13 @@ struct PD_INFER_DECL AnalysisConfig {
/// \brief Turn on OneDNN.
///
///
void EnableONEDNN();
void EnableMKLDNN(); // deprecated

///
/// \brief Turn down OneDNN.
///
///
void DisableONEDNN();
void DisableMKLDNN(); // deprecated

///
/// \brief Set the cache capacity of different input shapes for OneDNN.
Expand All @@ -885,14 +885,37 @@ struct PD_INFER_DECL AnalysisConfig {
///
/// \param capacity The cache capacity.
///
void SetOnednnCacheCapacity(int capacity);
void SetMkldnnCacheCapacity(int capacity); // deprecated

///
/// \brief A boolean state telling whether to use the OneDNN.
///
/// \return bool Whether to use the OneDNN.
///
bool mkldnn_enabled() const { return use_onednn_; }

///
/// \brief Turn on OneDNN.
///
///
void EnableONEDNN();

///
/// \brief Turn down OneDNN.
///
///
void DisableONEDNN();

///
/// \brief Set the cache capacity of different input shapes for OneDNN.
/// Default value 0 means not caching any shape.
/// Please see MKL-DNN Data Caching Design Document:
/// https://github.com/PaddlePaddle/FluidDoc/blob/develop/doc/fluid/design/mkldnn/caching/caching.md
///
/// \param capacity The cache capacity.
///
void SetOnednnCacheCapacity(int capacity);

///
/// \brief Set the number of cpu math library threads.
///
Expand Down Expand Up @@ -921,6 +944,14 @@ struct PD_INFER_DECL AnalysisConfig {
///
/// \param op_list The operator type list.
///
void SetMKLDNNOp(std::unordered_set<std::string> op_list) { // deprecated
onednn_enabled_op_types_ = op_list;
}
///
/// \brief Specify the operator type list to use OneDNN acceleration.
///
/// \param op_list The operator type list.
///
void SetONEDNNOp(std::unordered_set<std::string> op_list) {
onednn_enabled_op_types_ = op_list;
}
Expand All @@ -945,6 +976,11 @@ struct PD_INFER_DECL AnalysisConfig {
///
void EnableMkldnnBfloat16();

///
/// \brief Turn off OneDNN fc passes.
///
void DisableMkldnnFcPasses(); // deprecated

///
/// \brief Turn off OneDNN fc passes.
///
Expand Down
3 changes: 3 additions & 0 deletions paddle/fluid/inference/api/paddle_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include "paddle_tensor.h" // NOLINT
/*! \namespace paddle
*/
#define ONEDNN_UPDATE_WARNING(api) \
"Warning: The api is deprecated since version 3.x, please use onednn " \
"api " #api "."
namespace paddle {

using PaddleDType = paddle_infer::DataType;
Expand Down
22 changes: 21 additions & 1 deletion paddle/fluid/inference/api/paddle_pass_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <algorithm>
#include <sstream>

#include "paddle/fluid/inference/api/paddle_api.h"
namespace paddle {

void PaddlePassBuilder::AppendPass(const std::string &pass_type) {
Expand Down Expand Up @@ -317,6 +317,10 @@ void GpuPassStrategy::EnableCUDNN() {
use_cudnn_ = true;
}

void GpuPassStrategy::EnableMKLDNN() {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(EnableONEDNN);
EnableONEDNN();
}
void GpuPassStrategy::EnableONEDNN() {
LOG(ERROR) << "GPU not support MKLDNN yet";
}
Expand All @@ -329,6 +333,10 @@ void GpuPassStrategy::EnableMkldnnInt8() {
LOG(ERROR) << "GPU not support MKL-DNN int8";
}

void GpuPassStrategy::DisableMkldnnFcPasses() {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(DisableOnednnFcPasses);
DisableOnednnFcPasses();
}
void GpuPassStrategy::DisableOnednnFcPasses() {
LOG(ERROR) << "GPU not support MKL-DNN fc";
}
Expand All @@ -343,6 +351,10 @@ CpuPassStrategy::CpuPassStrategy() : PassStrategy({}) {

void CpuPassStrategy::EnableCUDNN() { LOG(ERROR) << "CPU not support cuDNN"; }

void CpuPassStrategy::EnableMKLDNN() {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(EnableONEDNN);
EnableONEDNN();
}
void CpuPassStrategy::EnableONEDNN() {
// TODO(Superjomn) Consider the way to mix CPU with GPU.
#ifdef PADDLE_WITH_DNNL
Expand Down Expand Up @@ -389,6 +401,10 @@ void CpuPassStrategy::EnableONEDNN() {
#endif
}

void CpuPassStrategy::DisableMKLDNN() {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(DisableONEDNN);
DisableONEDNN();
}
void CpuPassStrategy::DisableONEDNN() {
ClearPasses();
passes_.assign(CpuBasicPasses.begin(), CpuBasicPasses.end());
Expand Down Expand Up @@ -475,6 +491,10 @@ void CpuPassStrategy::EnableMkldnnInt8() {
#endif
}

void CpuPassStrategy::DisableMkldnnFcPasses() {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(DisableOnednnFcPasses);
DisableOnednnFcPasses();
}
void CpuPassStrategy::DisableOnednnFcPasses() {
#ifdef PADDLE_WITH_DNNL
if (!disable_onednn_fc_passes_) {
Expand Down
36 changes: 31 additions & 5 deletions paddle/fluid/inference/api/paddle_pass_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,28 @@ class PD_INFER_DECL PassStrategy : public PaddlePassBuilder {
/// \brief Enable the use of OneDNN.
/// The OneDNN control exists in both CPU and GPU mode, because there can
/// still be some CPU kernels running in GPU mode.
virtual void EnableONEDNN() {}
virtual void EnableMKLDNN() {} // deprecated

/// \brief Disable the use of OneDNN.
virtual void DisableONEDNN() {}
virtual void DisableMKLDNN() {} // deprecated

/// \brief Enable OneDNN bfloat16.
virtual void EnableMkldnnBfloat16() {}

/// \brief Enable OneDNN int8.
virtual void EnableMkldnnInt8() {}

/// \brief Disable OneDNN fc passes.
virtual void DisableMkldnnFcPasses() {} // deprecated

/// \brief Enable the use of OneDNN.
/// The OneDNN control exists in both CPU and GPU mode, because there can
/// still be some CPU kernels running in GPU mode.
virtual void EnableONEDNN() {}

/// \brief Disable the use of OneDNN.
virtual void DisableONEDNN() {}

/// \brief Disable OneDNN fc passes.
virtual void DisableOnednnFcPasses() {}

Expand Down Expand Up @@ -211,17 +222,26 @@ class PD_INFER_DECL CpuPassStrategy : public PassStrategy {
void EnableCUDNN() override;

/// \brief Enable the use of OneDNN.
void EnableONEDNN() override;
void EnableMKLDNN() override; // deprecated

/// \brief Disable the use of OneDNN.
void DisableONEDNN() override;
void DisableMKLDNN() override; // deprecated

/// \brief Enable OneDNN bfloat16.
void EnableMkldnnBfloat16() override;

/// \brief Enable OneDNN int8.
void EnableMkldnnInt8() override;

/// \brief Disable OneDNN fc passes.
void DisableMkldnnFcPasses() override; // deprecated

/// \brief Enable the use of OneDNN.
void EnableONEDNN() override;

/// \brief Disable the use of OneDNN.
void DisableONEDNN() override;

/// \brief Disable OneDNN fc passes.
void DisableOnednnFcPasses() override;

Expand Down Expand Up @@ -257,14 +277,20 @@ class PD_INFER_DECL GpuPassStrategy : public PassStrategy {
void EnableCUDNN() override;

/// \brief Not supported in GPU mode yet.
void EnableONEDNN() override;
void EnableMKLDNN() override; // deprecated

/// \brief Not supported in GPU mode yet.
void EnableMkldnnBfloat16() override;

/// \brief Not supported in GPU mode yet.
void EnableMkldnnInt8() override;

/// \brief Disable OneDNN fc passes.
void DisableMkldnnFcPasses() override;

/// \brief Not supported in GPU mode yet.
void EnableONEDNN() override;

/// \brief Disable OneDNN fc passes.
void DisableOnednnFcPasses() override;

Expand Down
12 changes: 9 additions & 3 deletions paddle/fluid/inference/capi/paddle_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,20 @@ typedef struct PD_MaxInputShape {
PADDLE_CAPI_EXPORT extern void PD_SwitchIrDebug(PD_AnalysisConfig* config,
bool x);

PADDLE_CAPI_EXPORT extern void PD_EnableONEDNN(PD_AnalysisConfig* config);
PADDLE_CAPI_EXPORT extern void PD_EnableMKLDNN(
PD_AnalysisConfig* config); // deprecated

PADDLE_CAPI_EXPORT extern void PD_SetOnednnCacheCapacity(
PD_AnalysisConfig* config, int capacity);
PADDLE_CAPI_EXPORT extern void PD_SetMkldnnCacheCapacity(
PD_AnalysisConfig* config, int capacity); // deprecated

PADDLE_CAPI_EXPORT extern bool PD_MkldnnEnabled(
const PD_AnalysisConfig* config);

PADDLE_CAPI_EXPORT extern void PD_EnableONEDNN(PD_AnalysisConfig* config);

PADDLE_CAPI_EXPORT extern void PD_SetOnednnCacheCapacity(
PD_AnalysisConfig* config, int capacity);

PADDLE_CAPI_EXPORT extern void PD_SetCpuMathLibraryNumThreads(
PD_AnalysisConfig* config, int cpu_math_library_num_threads);

Expand Down
8 changes: 8 additions & 0 deletions paddle/fluid/inference/capi/pd_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ void PD_SwitchIrDebug(PD_AnalysisConfig* config, bool x) {
config->config.SwitchIrDebug(x);
}

void PD_EnableMKLDNN(PD_AnalysisConfig* config) {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(PD_EnableONEDNN);
PD_EnableONEDNN(config);
}
void PD_EnableONEDNN(PD_AnalysisConfig* config) {
PADDLE_ENFORCE_NOT_NULL(
config,
Expand All @@ -285,6 +289,10 @@ void PD_EnableONEDNN(PD_AnalysisConfig* config) {
config->config.EnableONEDNN();
}

void PD_SetMkldnnCacheCapacity(PD_AnalysisConfig* config, int capacity) {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(PD_SetOnednnCacheCapacity);
PD_SetOnednnCacheCapacity(config, capacity);
}
void PD_SetOnednnCacheCapacity(PD_AnalysisConfig* config, int capacity) {
PADDLE_ENFORCE_NOT_NULL(
config,
Expand Down
11 changes: 11 additions & 0 deletions paddle/fluid/inference/capi_exp/pd_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,21 @@ void PD_ConfigSwitchIrDebug(__pd_keep PD_Config* pd_config, PD_Bool x) {
CHECK_AND_CONVERT_PD_CONFIG;
config->SwitchIrDebug(x);
}

void PD_ConfigEnableMKLDNN(__pd_keep PD_Config* pd_config) {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(PD_ConfigEnableONEDNN);
PD_ConfigEnableONEDNN(pd_config);
}
void PD_ConfigEnableONEDNN(__pd_keep PD_Config* pd_config) {
CHECK_AND_CONVERT_PD_CONFIG;
config->EnableONEDNN();
}

void PD_ConfigSetMkldnnCacheCapacity(__pd_keep PD_Config* pd_config,
int32_t capacity) {
LOG(WARNING) << ONEDNN_UPDATE_WARNING(PD_ConfigSetOnednnCacheCapacity);
PD_ConfigSetOnednnCacheCapacity(pd_config, capacity);
}
void PD_ConfigSetOnednnCacheCapacity(__pd_keep PD_Config* pd_config,
int32_t capacity) {
CHECK_AND_CONVERT_PD_CONFIG;
Expand Down
18 changes: 18 additions & 0 deletions paddle/fluid/inference/capi_exp/pd_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,13 @@ PADDLE_CAPI_EXPORT extern void PD_ConfigSwitchIrDebug(
///
/// \param[in] pd_config config
///
PADDLE_CAPI_EXPORT extern void PD_ConfigEnableMKLDNN(
__pd_keep PD_Config* pd_config); // deprecated
///
/// \brief Turn on OneDNN.
///
/// \param[in] pd_config config
///
PADDLE_CAPI_EXPORT extern void PD_ConfigEnableONEDNN(
__pd_keep PD_Config* pd_config);
///
Expand All @@ -515,6 +522,17 @@ PADDLE_CAPI_EXPORT extern void PD_ConfigEnableONEDNN(
/// \param[in] pd_config config
/// \param[in] capacity The cache capacity.
///
PADDLE_CAPI_EXPORT extern void PD_ConfigSetMkldnnCacheCapacity(
__pd_keep PD_Config* pd_config, int32_t capacity); // deprecated
///
/// \brief Set the cache capacity of different input shapes for OneDNN.
/// Default value 0 means not caching any shape.
/// Please see MKL-DNN Data Caching Design Document:
/// https://github.com/PaddlePaddle/FluidDoc/blob/develop/doc/fluid/design/mkldnn/caching/caching.md
///
/// \param[in] pd_config config
/// \param[in] capacity The cache capacity.
///
PADDLE_CAPI_EXPORT extern void PD_ConfigSetOnednnCacheCapacity(
__pd_keep PD_Config* pd_config, int32_t capacity);
///
Expand Down