/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. Licensed 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. */ #ifdef PADDLE_WITH_XPU #include "paddle/fluid/operators/split_op.h" #include #include #include "paddle/fluid/platform/device/xpu/xpu_header.h" namespace paddle { namespace operators { using Tensor = framework::Tensor; template class SplitXPUKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { auto* input = ctx.Input("X"); auto output = ctx.MultiOutput("Out"); int num = ctx.Attr("num"); std::vector sections = ctx.Attr>("sections"); int axis = ctx.Attr("axis"); auto& dev_ctx = ctx.template device_context(); auto in_dims = input->dims(); auto input_shape = framework::vectorize(in_dims); std::vector split_lists; std::vector out_ptrs; auto outs_number = output.size(); std::vector outs_dims = UpdateOutsDims(true, true, in_dims, num, sections, axis, outs_number); for (size_t i = 0; i < output.size(); ++i) { output[i]->Resize(outs_dims[i]); out_ptrs.push_back(output[i]->mutable_data(ctx.GetPlace())); split_lists.push_back(output[i]->dims()[axis]); } int r = xpu::split(dev_ctx.x_context(), input->data(), out_ptrs, input_shape, split_lists, axis); PADDLE_ENFORCE_EQ( r, XPU_SUCCESS, platform::errors::External("XPU split kernel return wrong value[%d %s]", r, XPUAPIErrorMsg[r])); } }; } // namespace operators } // namespace paddle namespace ops = paddle::operators; REGISTER_OP_XPU_KERNEL( split, ops::SplitXPUKernel, ops::SplitXPUKernel); #endif