You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
graphengine/ge/host_kernels/broadcast_args_kernel.cc

84 lines
2.8 KiB

5 years ago
/**
* Copyright 2020 Huawei Technologies Co., Ltd
5 years ago
*
* 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.
*/
#include "host_kernels/broadcast_args_kernel.h"
5 years ago
#include <vector>
#include "common/op/ge_op_utils.h"
#include "common/types.h"
#include "common/util.h"
#include "framework/common/ge_inner_error_codes.h"
#include "graph/common/bcast.h"
#include "graph/passes/pass_utils.h"
#include "inc/kernel_factory.h"
namespace ge {
namespace {
const size_t kBCastArgsInputsSize = 2;
const size_t kBCastArgsOutputsSize = 1;
} // namespace
Status BroadcastArgsKernel::Compute(const OpDescPtr op_desc_ptr, const std::vector<ConstGeTensorPtr> &input,
std::vector<GeTensorPtr> &v_output) {
GELOGD("BroadcastArgsKernel in");
if (op_desc_ptr == nullptr) {
GELOGE(PARAM_INVALID, "Parameter's invalid, Input opDescPtr is nullptr.");
return PARAM_INVALID;
}
// check input size
bool size_check =
4 years ago
(op_desc_ptr->GetAllInputsDesc().size() != kBCastArgsInputsSize || input.size() != kBCastArgsInputsSize ||
op_desc_ptr->GetAllOutputsDesc().size() != kBCastArgsOutputsSize);
5 years ago
if (size_check) {
4 years ago
GELOGW("input/output size error. InDesc size:%zu,"
"OutDesc size:%zu, in size:%zu ",
op_desc_ptr->GetAllInputsDesc().size(), op_desc_ptr->GetAllOutputsDesc().size(), input.size());
5 years ago
return NOT_CHANGED;
}
vector<int64_t> x1_dims;
vector<int64_t> x2_dims;
const auto &op_in_desc = op_desc_ptr->MutableInputDesc(0);
GE_CHECK_NOTNULL(op_in_desc);
DataType data_type = op_in_desc->GetDataType();
5 years ago
bool result = (OpUtils::GetShapeDataFromConstTensor(input[0], data_type, x1_dims) == SUCCESS) &&
(OpUtils::GetShapeDataFromConstTensor(input[1], data_type, x2_dims) == SUCCESS);
if (!result) {
GELOGE(PARAM_INVALID, "GetShapeDataFromConstTensor fail.");
return PARAM_INVALID;
}
BCast bcast;
Status ret = bcast.GenerateBcastInfo(x1_dims, x2_dims);
if (ret != SUCCESS) {
GELOGE(ret, "GenerateBcastInfo fail.");
return ret;
}
vector<int64_t> bcast_dims = bcast.GetOutputShape();
ret = PassUtils::ConstructTensorDescWithData(op_desc_ptr->GetOutputDesc(0), bcast_dims, v_output);
if (ret != SUCCESS) {
GELOGE(ret, "BroadcastArgs kernel construct tensor desc fail");
return ret;
}
return SUCCESS;
}
REGISTER_KERNEL(BROADCASTARGS, BroadcastArgsKernel);
} // namespace ge