PawelGlomski-Intel commented on a change in pull request #20757: URL: https://github.com/apache/incubator-mxnet/pull/20757#discussion_r781071113
########## File path: src/operator/nn/dnnl/dnnl_split-inl.h ########## @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file dnnl_split-inl.h + */ + +#ifndef MXNET_OPERATOR_NN_DNNL_DNNL_SPLIT_INL_H_ +#define MXNET_OPERATOR_NN_DNNL_DNNL_SPLIT_INL_H_ + +#if MXNET_USE_ONEDNN == 1 +#include <vector> + +#include "./dnnl_base-inl.h" +#include "./dnnl_ops-inl.h" + +namespace mxnet { +namespace op { + +using split_fwd_t = dnnl::reorder; +using split_fwd_pd_t = dnnl::reorder::primitive_desc; + +class DNNLSplitFwd { + public: + struct Tensors { + Tensors(const NDArray& input, const std::vector<NDArray>& outputs); + + const NDArray& input; + const std::vector<NDArray>& outputs; + }; + + static DNNLSplitFwd GetCached(const SplitParam& param, Review comment: ```suggestion static DNNLSplitFwd& GetCached(const SplitParam& param, ``` ########## File path: src/operator/nn/dnnl/dnnl_split.cc ########## @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file dnnl_split.cc + */ + +#if MXNET_USE_ONEDNN == 1 + +#include "../../tensor/matrix_op-inl.h" +#include "./dnnl_split-inl.h" + +namespace mxnet { +namespace op { + +bool SupportDNNLSplit(const NDArray& input) { + static const std::set<int> supported_dtypes = { + mshadow::kFloat32, mshadow::kBfloat16, mshadow::kInt32, mshadow::kInt8, mshadow::kUint8}; + return supported_dtypes.count(input.dtype()); +} + +void DNNLSplitForward(const nnvm::NodeAttrs& attrs, + const OpContext& ctx, + const std::vector<NDArray>& inputs, + const std::vector<OpReqType>& req, + const std::vector<NDArray>& outputs) { + const SplitParam& param = dmlc::get<SplitParam>(attrs.parsed); + const auto tensors = DNNLSplitFwd::Tensors(inputs[0], outputs); + + const auto& ishape = tensors.input.shape(); + const int split_axis = param.axis >= 0 ? param.axis : param.axis + ishape.ndim(); + const mxnet::TShape split_pts = + (param.sections > 0) ? GetSplitIndices(tensors.input.shape(), split_axis, param.sections) : + param.indices; + + const auto fwd = DNNLSplitFwd::GetCached(param, tensors, split_pts, split_axis); Review comment: ```suggestion const auto& fwd = DNNLSplitFwd::GetCached(param, tensors, split_pts, split_axis); ``` ########## File path: src/operator/nn/dnnl/dnnl_split.cc ########## @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file dnnl_split.cc + */ + +#if MXNET_USE_ONEDNN == 1 + +#include "../../tensor/matrix_op-inl.h" +#include "./dnnl_split-inl.h" + +namespace mxnet { +namespace op { + +bool SupportDNNLSplit(const NDArray& input) { + static const std::set<int> supported_dtypes = { + mshadow::kFloat32, mshadow::kBfloat16, mshadow::kInt32, mshadow::kInt8, mshadow::kUint8}; + return supported_dtypes.count(input.dtype()); +} + +void DNNLSplitForward(const nnvm::NodeAttrs& attrs, + const OpContext& ctx, + const std::vector<NDArray>& inputs, + const std::vector<OpReqType>& req, + const std::vector<NDArray>& outputs) { + const SplitParam& param = dmlc::get<SplitParam>(attrs.parsed); + const auto tensors = DNNLSplitFwd::Tensors(inputs[0], outputs); + + const auto& ishape = tensors.input.shape(); + const int split_axis = param.axis >= 0 ? param.axis : param.axis + ishape.ndim(); + const mxnet::TShape split_pts = + (param.sections > 0) ? GetSplitIndices(tensors.input.shape(), split_axis, param.sections) : + param.indices; + + const auto fwd = DNNLSplitFwd::GetCached(param, tensors, split_pts, split_axis); + fwd.Execute(tensors, split_pts, split_axis, req); +} + +DNNLSplitFwd::Tensors::Tensors(const NDArray& input, const std::vector<NDArray>& outputs) + : input(input), outputs(outputs) {} + +typedef ParamOpSign<SplitParam> DNNLSplitSignature; + +DNNLSplitFwd DNNLSplitFwd::GetCached(const SplitParam& param, Review comment: ```suggestion DNNLSplitFwd& DNNLSplitFwd::GetCached(const SplitParam& param, ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
