From d8d4e512f0a43b9ee8c5f03fb447001f90f688f4 Mon Sep 17 00:00:00 2001 From: co63oc Date: Wed, 3 Apr 2024 11:44:59 +0800 Subject: [PATCH] Rename mkldnn onednn in paddle/cinn (#63199) --- paddle/cinn/hlir/op/nn.cc | 22 +++++++++---------- paddle/cinn/hlir/pe/nn.cc | 12 +++++----- paddle/cinn/hlir/pe/nn.h | 4 ++-- paddle/cinn/runtime/cpu/CMakeLists.txt | 4 ++-- .../cpu/{mkldnn_math.cc => onednn_math.cc} | 12 +++++----- .../cpu/{mkldnn_math.h => onednn_math.h} | 4 ++-- ...kldnn_math_test.cc => onednn_math_test.cc} | 6 ++--- paddle/cinn/runtime/cpu/use_extern_funcs.h | 2 +- 8 files changed, 33 insertions(+), 33 deletions(-) rename paddle/cinn/runtime/cpu/{mkldnn_math.cc => onednn_math.cc} (96%) rename paddle/cinn/runtime/cpu/{mkldnn_math.h => onednn_math.h} (95%) rename paddle/cinn/runtime/cpu/{mkldnn_math_test.cc => onednn_math_test.cc} (96%) diff --git a/paddle/cinn/hlir/op/nn.cc b/paddle/cinn/hlir/op/nn.cc index 2b1ce342e0810..3816b864f1eed 100644 --- a/paddle/cinn/hlir/op/nn.cc +++ b/paddle/cinn/hlir/op/nn.cc @@ -167,7 +167,7 @@ std::shared_ptr StrategyForConv2d( int groups = 1; std::string key = ""; std::string conv_type = ""; - bool use_mkldnn = false; + bool use_onednn = false; if (attrs.attr_store.find("padding") != attrs.attr_store.end()) { padding = absl::get>(attrs.attr_store.at("padding")); } @@ -183,8 +183,8 @@ std::shared_ptr StrategyForConv2d( if (attrs.attr_store.find("groups") != attrs.attr_store.end()) { groups = absl::get(attrs.attr_store.at("groups")); } - if (attrs.attr_store.find("use_mkldnn") != attrs.attr_store.end()) { - use_mkldnn = absl::get(attrs.attr_store.at("use_mkldnn")); + if (attrs.attr_store.find("use_onednn") != attrs.attr_store.end()) { + use_onednn = absl::get(attrs.attr_store.at("use_onednn")); } if (attrs.attr_store.find("key") != attrs.attr_store.end()) { key = absl::get(attrs.attr_store.at("key")); @@ -231,7 +231,7 @@ std::shared_ptr StrategyForConv2d( // A is input: [N, C, H, W], B is filter: [C_out, C_in/group, // filter_h, filter_w] if (target.arch == Target::Arch::X86) { - if (groups == 1 && !use_mkldnn) { + if (groups == 1 && !use_onednn) { out = pe::Conv2d_NCHW_5D(A.as_tensor_ref(), B.as_tensor_ref(), padding[0], @@ -245,7 +245,7 @@ std::shared_ptr StrategyForConv2d( target); } else { #ifdef CINN_WITH_DNNL - out = pe::Conv2d_NCHW_MKLDNN(A.as_tensor_ref(), + out = pe::Conv2d_NCHW_ONEDNN(A.as_tensor_ref(), B.as_tensor_ref(), padding[0], padding[1], @@ -1912,12 +1912,12 @@ std::shared_ptr StrategyForSoftmax( const std::vector> &output_shapes, const Target &target) { int axis = -1; - bool use_mkldnn = false; + bool use_onednn = false; if (attrs.attr_store.count("axis")) { axis = absl::get(attrs.attr_store.at("axis")); } - if (attrs.attr_store.count("use_mkldnn")) { - use_mkldnn = absl::get(attrs.attr_store.at("use_mkldnn")); + if (attrs.attr_store.count("use_onednn")) { + use_onednn = absl::get(attrs.attr_store.at("use_onednn")); } framework::CINNCompute softmax_compute( [=](lang::Args args, lang::RetValue *ret) { @@ -1942,8 +1942,8 @@ std::shared_ptr StrategyForSoftmax( pack_args[pack_args.size() - 1].operator std::string(); #ifdef CINN_WITH_DNNL - if (use_mkldnn) { - out = pe::SoftmaxMKLDNN(A, new_axis, tensor_name); + if (use_onednn) { + out = pe::SoftmaxONEDNN(A, new_axis, tensor_name); } else { out = pe::Softmax(A, new_axis, tensor_name); } @@ -2043,7 +2043,7 @@ std::vector> InferLayoutForSoftmax( CHECK_EQ(input_layouts.size(), 1U) << "The input's layout size is not 1! Please check again."; if (input_shapes[0].size() > 4) { - // input tensor needs to be transformed back to NCHW for mkldnn + // input tensor needs to be transformed back to NCHW for onednn return {{"NCHW", "NCHW"}, {"NCHW"}}; } return {{input_layouts[0], input_layouts[0]}, input_layouts}; diff --git a/paddle/cinn/hlir/pe/nn.cc b/paddle/cinn/hlir/pe/nn.cc index 9e48b26ae9392..48bbda538351b 100644 --- a/paddle/cinn/hlir/pe/nn.cc +++ b/paddle/cinn/hlir/pe/nn.cc @@ -652,7 +652,7 @@ std::vector Conv2d_NCHWc(const ir::Tensor &input, } #ifdef CINN_WITH_DNNL -std::vector Conv2d_NCHW_MKLDNN(const ir::Tensor &input, +std::vector Conv2d_NCHW_ONEDNN(const ir::Tensor &input, const ir::Tensor &weights, int pad_h, int pad_w, @@ -674,7 +674,7 @@ std::vector Conv2d_NCHW_MKLDNN(const ir::Tensor &input, auto call = Compute( {Expr(1)}, [=]() -> Expr { - return lang::CallExtern("cinn_cpu_mkldnn_conv2d_nchw_fp32", + return lang::CallExtern("cinn_cpu_onednn_conv2d_nchw_fp32", { Expr(input->shape[0]), // batch_size Expr(input->shape[1]), // c_in @@ -694,7 +694,7 @@ std::vector Conv2d_NCHW_MKLDNN(const ir::Tensor &input, weights // weights }); }, - UniqName("conv2d_nchw_mkldnn_out")); + UniqName("conv2d_nchw_onednn_out")); auto out = call->TupleGet(0); out->WithBuffer(input->type()); return {out, call}; @@ -1020,11 +1020,11 @@ std::vector Softmax(const ir::Tensor &A, } #ifdef CINN_WITH_DNNL -std::vector SoftmaxMKLDNN(const ir::Tensor &A, +std::vector SoftmaxONEDNN(const ir::Tensor &A, int axis, const std::string &output_name) { CHECK_LE(A->shape.size(), 4U) - << "Input's dimension of mkldnn softmax op is less than 4! Please check."; + << "Input's dimension of onednn softmax op is less than 4! Please check."; if (axis == -1) { axis = A->shape.size() - 1; } @@ -1036,7 +1036,7 @@ std::vector SoftmaxMKLDNN(const ir::Tensor &A, auto call = Compute( {Expr(1)}, [=]() -> Expr { - return lang::CallExtern("cinn_cpu_mkldnn_softmax_fp32", + return lang::CallExtern("cinn_cpu_onednn_softmax_fp32", { shape[0], // batch_size shape[1], // c_in diff --git a/paddle/cinn/hlir/pe/nn.h b/paddle/cinn/hlir/pe/nn.h index 32e2db2dc38f7..c3cc860e657bc 100755 --- a/paddle/cinn/hlir/pe/nn.h +++ b/paddle/cinn/hlir/pe/nn.h @@ -179,7 +179,7 @@ std::vector Conv2d_NCHWc( const cinn::common::Target &target = cinn::common::DefaultHostTarget()); #ifdef CINN_WITH_DNNL -std::vector Conv2d_NCHW_MKLDNN( +std::vector Conv2d_NCHW_ONEDNN( const ir::Tensor &input, const ir::Tensor &weights, int pad_h, @@ -333,7 +333,7 @@ std::vector Softmax( const std::string &output_name = UniqName("T_softmax_out")); #ifdef CINN_WITH_DNNL -std::vector SoftmaxMKLDNN( +std::vector SoftmaxONEDNN( const ir::Tensor &A, int axis = -1, const std::string &output_name = UniqName("T_softmax_out")); diff --git a/paddle/cinn/runtime/cpu/CMakeLists.txt b/paddle/cinn/runtime/cpu/CMakeLists.txt index 72fa5f51bb0ca..0971d5a95dbae 100644 --- a/paddle/cinn/runtime/cpu/CMakeLists.txt +++ b/paddle/cinn/runtime/cpu/CMakeLists.txt @@ -5,7 +5,7 @@ gather_srcs(cinnapi_src SRCS host_intrinsics.cc thread_backend.cc) if(WITH_MKL_CBLAS) gather_srcs(cinnapi_src SRCS mkl_math.cc cblas.cc) if(WITH_MKLDNN) - gather_srcs(cinnapi_src SRCS mkldnn_math.cc) + gather_srcs(cinnapi_src SRCS onednn_math.cc) endif() endif() @@ -16,7 +16,7 @@ if(WITH_MKL_CBLAS) endif() if(WITH_MKLDNN) - cinn_cc_test(test_mkldnn_math SRCS mkldnn_math_test.cc mkldnn_math.cc DEPS + cinn_cc_test(test_onednn_math SRCS onednn_math_test.cc onednn_math.cc DEPS cinncore) endif() endif() diff --git a/paddle/cinn/runtime/cpu/mkldnn_math.cc b/paddle/cinn/runtime/cpu/onednn_math.cc similarity index 96% rename from paddle/cinn/runtime/cpu/mkldnn_math.cc rename to paddle/cinn/runtime/cpu/onednn_math.cc index f20e56e32f1e6..66af7029d7e58 100644 --- a/paddle/cinn/runtime/cpu/mkldnn_math.cc +++ b/paddle/cinn/runtime/cpu/onednn_math.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/cinn/runtime/cpu/mkldnn_math.h" +#include "paddle/cinn/runtime/cpu/onednn_math.h" #include @@ -25,7 +25,7 @@ using dnnl::memory; using tag = memory::format_tag; using dt = memory::data_type; -void cinn_cpu_mkldnn_softmax_fp32(int batch, +void cinn_cpu_onednn_softmax_fp32(int batch, int channel, int h, int w, @@ -75,7 +75,7 @@ void cinn_cpu_mkldnn_softmax_fp32(int batch, engine_stream.wait(); } -void cinn_cpu_mkldnn_conv2d_nchw_fp32(int batch_size, +void cinn_cpu_onednn_conv2d_nchw_fp32(int batch_size, int c_in, int input_h, int input_w, @@ -157,7 +157,7 @@ void cinn_cpu_mkldnn_conv2d_nchw_fp32(int batch_size, cpu_stream.wait(); } -CINN_REGISTER_HELPER(cinn_cpu_mkldnn) { +CINN_REGISTER_HELPER(cinn_cpu_onednn) { using namespace cinn; // NOLINT using backends::FunctionProto; auto host_target = cinn::common::DefaultHostTarget(); @@ -195,7 +195,7 @@ CINN_REGISTER_HELPER(cinn_cpu_mkldnn) { return shape; }; - REGISTER_EXTERN_FUNC_HELPER(cinn_cpu_mkldnn_conv2d_nchw_fp32, host_target) + REGISTER_EXTERN_FUNC_HELPER(cinn_cpu_onednn_conv2d_nchw_fp32, host_target) .SetRetType() .AddInputType() // batch_size .AddInputType() // c_in @@ -217,7 +217,7 @@ CINN_REGISTER_HELPER(cinn_cpu_mkldnn) { .SetShapeInference(inference_shape_conv2d_nchw) .End(); - REGISTER_EXTERN_FUNC_HELPER(cinn_cpu_mkldnn_softmax_fp32, host_target) + REGISTER_EXTERN_FUNC_HELPER(cinn_cpu_onednn_softmax_fp32, host_target) .SetRetType() .AddInputType() // batch_size .AddInputType() // c_in diff --git a/paddle/cinn/runtime/cpu/mkldnn_math.h b/paddle/cinn/runtime/cpu/onednn_math.h similarity index 95% rename from paddle/cinn/runtime/cpu/mkldnn_math.h rename to paddle/cinn/runtime/cpu/onednn_math.h index 9a37d13d57865..7d95b6461b0a9 100644 --- a/paddle/cinn/runtime/cpu/mkldnn_math.h +++ b/paddle/cinn/runtime/cpu/onednn_math.h @@ -21,7 +21,7 @@ // define some C APIs extern "C" { -void cinn_cpu_mkldnn_softmax_fp32(int batch, +void cinn_cpu_onednn_softmax_fp32(int batch, int channel, int h, int w, @@ -29,7 +29,7 @@ void cinn_cpu_mkldnn_softmax_fp32(int batch, cinn_buffer_t* inputs, cinn_buffer_t* out); -void cinn_cpu_mkldnn_conv2d_nchw_fp32(int batch_size, +void cinn_cpu_onednn_conv2d_nchw_fp32(int batch_size, int c_in, int input_h, int input_w, diff --git a/paddle/cinn/runtime/cpu/mkldnn_math_test.cc b/paddle/cinn/runtime/cpu/onednn_math_test.cc similarity index 96% rename from paddle/cinn/runtime/cpu/mkldnn_math_test.cc rename to paddle/cinn/runtime/cpu/onednn_math_test.cc index 15574a9028042..eb10e0ff1b4e4 100644 --- a/paddle/cinn/runtime/cpu/mkldnn_math_test.cc +++ b/paddle/cinn/runtime/cpu/onednn_math_test.cc @@ -42,7 +42,7 @@ cinn_buffer_t *CreateBuffer(const std::vector shape, return cinn::common::BufferBuilder(Float(32), shape).set_zero().Build(); } -TEST(cinn_cpu_mkldnn_conv2d_nchw_fp32, test) { +TEST(cinn_cpu_onednn_conv2d_nchw_fp32, test) { int n(1); int c_in(3); int i_h(224); @@ -65,7 +65,7 @@ TEST(cinn_cpu_mkldnn_conv2d_nchw_fp32, test) { auto call = Compute( {Expr(1)}, [=]() -> Expr { - return lang::CallExtern("cinn_cpu_mkldnn_conv2d_nchw_fp32", + return lang::CallExtern("cinn_cpu_onednn_conv2d_nchw_fp32", { Expr(n), // batch_size Expr(c_in), // c_in @@ -85,7 +85,7 @@ TEST(cinn_cpu_mkldnn_conv2d_nchw_fp32, test) { weights.tensor() // weights }); }, - "cinn_cpu_mkldnn_conv2d_nchw_fp32"); + "cinn_cpu_onednn_conv2d_nchw_fp32"); auto out = call->TupleGet(0); out->WithBuffer(Float(32)); diff --git a/paddle/cinn/runtime/cpu/use_extern_funcs.h b/paddle/cinn/runtime/cpu/use_extern_funcs.h index e708864f5b36a..4c65e5ff30501 100644 --- a/paddle/cinn/runtime/cpu/use_extern_funcs.h +++ b/paddle/cinn/runtime/cpu/use_extern_funcs.h @@ -21,7 +21,7 @@ CINN_USE_REGISTER(host_intrinsics) CINN_USE_REGISTER(mkl_math) CINN_USE_REGISTER(cinn_cpu_mkl) #ifdef CINN_WITH_DNNL -CINN_USE_REGISTER(cinn_cpu_mkldnn) +CINN_USE_REGISTER(cinn_cpu_onednn) #endif #endif CINN_USE_REGISTER(cinn_backend_parallel)