|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097 |
- /**
- * Copyright 2021 Huawei Technologies Co., Ltd
- *
- * 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.
- */
-
- /*!
- * \file util.cpp
- * \brief
- */
- #include "util.h"
- #include <string>
- #include <vector>
- #include <map>
- #include <functional>
- #include <algorithm>
- #include "./error_util.h"
- #include "op_common_util.h"
- #include "graph/utils/type_utils.h"
- #include "axis_util.h"
-
- namespace ge {
-
- bool GetInputDataType(const ge::DataType& data_type, const std::vector<ge::DataType>& supportList) {
- std::vector<ge::DataType>::const_iterator supportIter = find(supportList.begin(), supportList.end(), data_type);
- if (supportIter == supportList.end()) {
- return false;
- }
- return true;
- }
-
- bool CheckInputDtypeAndShape(const Operator& op, const std::map<std::string, std::vector<DataType>>& inputTensorMap) {
- auto iter = inputTensorMap.begin();
- auto first_name = iter->first;
- auto first_shape_dims = op.GetInputDesc(iter->first).GetShape().GetDims();
- auto first_input_dtype = op.GetInputDesc(iter->first).GetDataType();
- for (; iter != inputTensorMap.end(); ++iter) {
- const TensorDesc input_desc = op.GetInputDesc(iter->first);
- // check input dtype
- auto input_type = input_desc.GetDataType();
- if (input_type != first_input_dtype) {
- OP_LOGE(op.GetName().c_str(), "the op type of param %s must equal with param %s", iter->first.c_str(),
- first_name.c_str());
- return false;
- }
- auto dims = input_desc.GetShape().GetDims();
- if (dims != first_shape_dims) {
- OP_LOGE(op.GetName().c_str(), "the op shape of param %s must equal with param %s", iter->first.c_str(),
- first_name.c_str());
- return false;
- }
- }
- return true;
- }
-
- bool CheckInputDataType(const Operator& op, const std::string& input_name,
- const std::vector<ge::DataType>& support_list) {
- bool valid = false;
- DataType input_type = op.GetInputDesc(input_name).GetDataType();
- do {
- const auto& found_list = find(support_list.begin(), support_list.end(), input_type);
-
- if (found_list == support_list.end()) {
- break;
- }
-
- const auto& found_map = DTYPE_STR_MAP.find(input_type);
- if (found_map == DTYPE_STR_MAP.end()) {
- break;
- }
-
- valid = true;
- } while (0);
-
- if (!valid) {
- OpsInputDtypeErrReport(op.GetName(), input_name, DebugString(support_list), ConcatString(input_type));
- OP_LOGE(op.GetName().c_str(), "The op do not support the dtype %s",
- ge::TypeUtils::DataTypeToSerialString(input_type).c_str());
- return false;
- }
-
- return true;
- }
-
- bool CheckTwoInputDtypeSame(const Operator& op, const string& input_name1, const string& input_name2) {
- auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_desc == nullptr || op_desc->MutableInputDesc(input_name1) == nullptr ||
- op_desc->MutableInputDesc(input_name2) == nullptr,
- OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
-
- DataType input_type_x1 = op_desc->MutableInputDesc(input_name1)->GetDataType();
- DataType input_type_x2 = op_desc->MutableInputDesc(input_name2)->GetDataType();
- if (input_type_x1 != input_type_x2) {
- OpsTwoInputDtypeErrReport(op.GetName(), input_name1, input_name2, ConcatString(input_type_x1),
- ConcatString(input_type_x2));
- OP_LOGE(op.GetName().c_str(), "The %s op dtype is not same, type1:%s, type2:%s", op.GetName().c_str(),
- ge::TypeUtils::DataTypeToSerialString(input_type_x1).c_str(),
- ge::TypeUtils::DataTypeToSerialString(input_type_x2).c_str());
- return false;
- }
-
- return true;
- }
-
- bool CheckInputDtypeSame(const Operator& op, std::vector<std::string>& input_tensors) {
- auto first_name = input_tensors.begin();
- auto first_input_dtype = op.GetInputDesc(*first_name).GetDataType();
- for (const string& input_name : input_tensors) {
- const TensorDesc input_desc = op.GetInputDesc(input_name);
- auto input_dtype = input_desc.GetDataType();
- if (input_dtype != first_input_dtype) {
- OP_LOGE(op.GetName().c_str(), "the op type of param %s must equal with param %s", input_name.c_str(),
- (*first_name).c_str());
- return false;
- }
- }
- return true;
- }
-
- bool CheckInputsShapeDtypeSame(const Operator& op, const std::vector<std::string>& input_names) {
- auto first_input_name = input_names.begin();
- auto first_input_des = op.GetInputDesc(*first_input_name);
- auto input_name = first_input_name;
- for (++input_name; input_name != input_names.end(); ++input_name) {
- auto input_des = op.GetInputDesc(*first_input_name);
-
- if (input_des.GetDataType() != first_input_des.GetDataType() ||
- input_des.GetShape().GetDims() != first_input_des.GetShape().GetDims()) {
- OpsAttrValueErrReport(
- op.GetName(), ConcatString(input_name->c_str(), "'s dtype and shape"),
- ConcatString("same as", first_input_name->c_str(), "[", first_input_des.GetDataType(), "]", "[",
- DebugString(first_input_des.GetShape().GetDims()), "]"),
- ConcatString("[", input_des.GetDataType(), "]", "[", DebugString(input_des.GetShape().GetDims()), "]"));
- OP_LOGE(op.GetName().c_str(), "the dtype and shape of param %s must be same as param %s",
- first_input_name->c_str(), input_name->c_str());
- return false;
- }
- }
-
- return true;
- }
-
- bool InferShapeAndTypeTwoInOneOutBroadcast(Operator& op, const string& input_name1, const string& input_name2,
- const string& output_name, bool& is_dynamic) {
- auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_desc == nullptr || op_desc->MutableOutputDesc(output_name) == nullptr||
- op_desc->MutableInputDesc(input_name1) == nullptr || op_desc->MutableInputDesc(input_name2) == nullptr,
- OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
-
- DataType input_dtype = op_desc->MutableInputDesc(input_name1)->GetDataType();
-
- // output Desc
- GeTensorDescPtr tensordesc_output = op_desc->MutableOutputDesc(output_name);
- tensordesc_output->SetDataType(input_dtype);
-
- ge::GeShape shapeX = op_desc->MutableInputDesc(input_name1)->GetShape();
- ge::GeShape shapeY = op_desc->MutableInputDesc(input_name2)->GetShape();
- OP_LOGI(op.GetName().c_str(), "shape %s: %s, shape %s: %s.", input_name1.c_str(), to_string(shapeX).c_str(),
- input_name2.c_str(), to_string(shapeY).c_str());
- std::vector<int64_t> dimsX = shapeX.GetDims();
- std::vector<int64_t> dimsY = shapeY.GetDims();
- // swap based on shape size
- if (dimsX.size() < dimsY.size()) {
- std::vector<int64_t> dimsTmp = dimsX;
- dimsX = dimsY;
- dimsY = dimsTmp;
- }
-
- std::vector<int64_t> dimVec;
- // unknown rank
- if (IsUnknownRankShape(dimsX) || IsUnknownRankShape(dimsY)) {
- tensordesc_output->SetShape(ge::GeShape(UNKNOWN_RANK));
- OP_LOGI(op.GetName().c_str(), "output shape is: %s, output dtype is:%d.", to_string(ge::Shape(UNKNOWN_RANK)).c_str(),
- input_dtype);
- is_dynamic = false;
- return true;
- }
-
- // pad 1 for small shape
- if (dimsX.size() != dimsY.size()) {
- int dec = dimsX.size() - dimsY.size();
- for (int i = 0; i < dec; i++) {
- dimsY.insert(dimsY.begin(), (int64_t)1);
- }
- }
-
- // when not dynamic case, do infer shape only
- if (!IsUnknown(dimsY) && !IsUnknown(dimsX)) {
- for (size_t i = 0; i < dimsX.size(); i++) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dims = (dimsY[i] == 0 || dimsX[i] == 0) ? 0 : dims;
- dimVec.push_back(dims);
- }
- tensordesc_output->SetShape(ge::GeShape(dimVec));
- is_dynamic = false;
- return true;
- }
-
- // dynamic case
- for (size_t i = 0; i < dimsX.size(); i++) {
- CHECK((dimsX[i] != dimsY[i]) && (dimsX[i] != 1) && (dimsY[i] != 1) && (dimsX[i] != -1) && (dimsY[i] != -1),
- OpsInputShapeBroadcastErrReport(op.GetName(), input_name1, input_name2, ConcatString(dimsX[i]),
- ConcatString(dimsY[i]));
- OP_LOGE(op.GetName().c_str(), "The %s's dimensions does not match the broadcast rule(%lu %lu).",
- op.GetName().c_str(), dimsX[i], dimsY[i]),
- return false);
-
- if ((dimsX[i] == -1) && (dimsY[i] != -1)) {
- if (dimsY[i] > 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- } else if (dimsY[i] == 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- dimVec[i] = -1;
- } else if ((dimsY[i] == 0) || (dimsX[i] == 0)) {
- dimVec.push_back(0);
- }
- } else if ((dimsX[i] != -1) && (dimsY[i] == -1)) {
- if (dimsX[i] > 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- } else if (dimsX[i] == 0) {
- dimVec.push_back(0);
- } else if (dimsX[i] == 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- dimVec[i] = -1;
- }
- } else {
- if ((dimsX[i] == -1) && (dimsY[i] == -1)) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- dimVec[i] = -1;
- } else {
- if (dimsY[i] == 0 || dimsX[i] == 0) {
- dimVec.push_back(0);
- } else {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- }
- }
- }
- }
- ge::GeShape outputShape = ge::GeShape(dimVec);
- tensordesc_output->SetShape(outputShape);
-
- OP_LOGI(op.GetName().c_str(), "output shape is: %s, output dtype is:%s.", to_string(outputShape).c_str(),
- ge::TypeUtils::DataTypeToSerialString(input_dtype).c_str());
- is_dynamic = IsUnknown(dimVec);
-
- if (is_dynamic) {
- if (!InferShapeRangeTwoInOneOutBroadcase(op, input_name1, input_name2, output_name)) {
- return false;
- }
- }
- return true;
- }
-
- bool InferShapeAndTypeTwoInOneOutBroadcast(Operator& op, const string& input_name1, const string& input_name2,
- const string& output_name) {
- auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_desc == nullptr || op_desc->MutableInputDesc(input_name1) == nullptr ||
- op_desc->MutableOutputDesc(output_name) == nullptr || op_desc->MutableInputDesc(input_name2) == nullptr,
- OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
-
- DataType input_dtype = op_desc->MutableInputDesc(input_name1)->GetDataType();
-
- GeTensorDescPtr tensordesc_output = op_desc->MutableOutputDesc(output_name);
-
- ge::GeShape shapeX = op_desc->MutableInputDesc(input_name1)->GetShape();
- ge::GeShape shapeY = op_desc->MutableInputDesc(input_name2)->GetShape();
- OP_LOGI(op.GetName().c_str(), "shape %s: %s, shape %s: %s.", input_name1.c_str(), to_string(shapeX).c_str(),
- input_name2.c_str(), to_string(shapeY).c_str());
- std::vector<int64_t> dimsX = shapeX.GetDims();
- std::vector<int64_t> dimsY = shapeY.GetDims();
- // swap based on shape size
- if (dimsX.size() < dimsY.size()) {
- std::vector<int64_t> dimsTmp = dimsX;
- dimsX = dimsY;
- dimsY = dimsTmp;
- }
-
- std::vector<int64_t> dimVec;
-
- // unknown rank
- if (IsUnknownRankShape(dimsX) || IsUnknownRankShape(dimsY)) {
- tensordesc_output->SetShape(ge::GeShape(UNKNOWN_RANK));
- tensordesc_output->SetDataType(input_dtype);
- OP_LOGI(op.GetName().c_str(), "output shape is: %s, output dtype is:%d.", to_string(ge::Shape(UNKNOWN_RANK)).c_str(),
- input_dtype);
- return true;
- }
-
- // pad 1 for small shape
- if (dimsX.size() != dimsY.size()) {
- int dec = dimsX.size() - dimsY.size();
- for (int i = 0; i < dec; i++) {
- dimsY.insert(dimsY.begin(), (int64_t)1);
- }
- }
-
- for (size_t i = 0; i < dimsX.size(); i++) {
- CHECK((dimsX[i] != dimsY[i]) && (dimsX[i] != 1) && (dimsY[i] != 1) && (dimsX[i] != -1) && (dimsY[i] != -1),
- OpsInputShapeBroadcastErrReport(op.GetName(), input_name1, input_name2, ConcatString(dimsX[i]),
- ConcatString(dimsY[i]));
- OP_LOGE(op.GetName().c_str(), "The %s's dimensions does not match the broadcast rule(%lu %lu).",
- op.GetName().c_str(), dimsX[i], dimsY[i]),
- return false);
-
- if ((dimsX[i] == -1) && (dimsY[i] != -1)) {
- if (dimsY[i] > 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- } else if (dimsY[i] == 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- dimVec[i] = -1;
- } else if ((dimsY[i] == 0) || (dimsX[i] == 0)) {
- dimVec.push_back(0);
- }
- } else if ((dimsX[i] != -1) && (dimsY[i] == -1)) {
- if (dimsX[i] > 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- } else if (dimsX[i] == 0) {
- dimVec.push_back(0);
- } else if (dimsX[i] == 1) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- dimVec[i] = -1;
- }
- } else {
- if ((dimsX[i] == -1) && (dimsY[i] == -1)) {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- dimVec[i] = -1;
- } else {
- if (dimsY[i] == 0 || dimsX[i] == 0) {
- dimVec.push_back(0);
- } else {
- int64_t dims = dimsX[i] > dimsY[i] ? dimsX[i] : dimsY[i];
- dimVec.push_back(dims);
- }
- }
- }
- }
- ge::GeShape outputShape = ge::GeShape(dimVec);
-
- tensordesc_output->SetShape(outputShape);
- tensordesc_output->SetDataType(input_dtype);
- OP_LOGI(op.GetName().c_str(), "output shape is: %s, output dtype is:%s.", to_string(outputShape).c_str(),
- ge::TypeUtils::DataTypeToSerialString(input_dtype).c_str());
-
- return true;
- }
-
- bool InferShapeRangeTwoInOneOutBroadcase(Operator& op, const string& input_name1, const string& input_name2,
- const string& output_name) {
- auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_desc == nullptr || op_desc->MutableInputDesc(input_name1) == nullptr ||
- op_desc->MutableOutputDesc(output_name) == nullptr || op_desc->MutableInputDesc(input_name2) == nullptr,
- OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
-
- ge::GeShape shape_x = op_desc->MutableInputDesc(input_name1)->GetShape();
- ge::GeShape shape_y = op_desc->MutableInputDesc(input_name2)->GetShape();
-
- std::vector<int64_t> dims_x = shape_x.GetDims();
- std::vector<int64_t> dims_y = shape_y.GetDims();
-
- std::vector<std::pair<int64_t, int64_t>> shape_range_x;
- op_desc->MutableInputDesc(input_name1)->GetShapeRange(shape_range_x);
- std::vector<std::pair<int64_t, int64_t>> shape_range_y;
- op_desc->MutableInputDesc(input_name2)->GetShapeRange(shape_range_y);
-
- MakeUpShapeRange(dims_x, shape_range_x);
- MakeUpShapeRange(dims_y, shape_range_y);
-
- ge::GeShape shape_out = op_desc->MutableOutputDesc(output_name)->GetShape();
- std::vector<int64_t> dims_out = shape_out.GetDims();
- size_t size_shape_out = dims_out.size();
-
- std::vector<std::pair<int64_t, int64_t>> out_range;
-
- if (!IsUnknownRankShape(dims_out)) {
- // shape switch by shape dim size
- if (dims_x.size() < dims_y.size()) {
- std::vector<int64_t> dims_tmp = dims_x;
- dims_x = dims_y;
- dims_y = dims_tmp;
-
- std::vector<std::pair<int64_t, int64_t>> range_temp = shape_range_x;
- shape_range_x = shape_range_y;
- shape_range_y = range_temp;
- }
-
- while (dims_x.size() > shape_range_y.size()) {
- shape_range_y.insert(shape_range_y.begin(), std::pair<int64_t, int64_t>(1, 1));
- }
-
- for (size_t i = 0; i < size_shape_out; i++) {
- if (dims_out[i] != -1) {
- out_range.push_back(std::pair<int64_t, int64_t>(dims_out[i], dims_out[i]));
- continue;
- }
- if (i < shape_range_x.size() && i < shape_range_y.size()) {
- if (shape_range_x[i].second == -1 && shape_range_y[i].second == 1) {
- out_range.push_back(std::pair<int64_t, int64_t>(1, -1));
- } else if (shape_range_x[i].second == 1 && shape_range_y[i].second == -1) {
- out_range.push_back(std::pair<int64_t, int64_t>(1, -1));
- } else if (shape_range_x[i].first == 1 || shape_range_y[i].first == 1) {
- // one shape size maybe 1, so will support boardcast
- // first_range == max first
- int64_t first_range = std::max(shape_range_x[i].first, shape_range_y[i].first);
- int64_t second_range = shape_range_x[i].first == 1 ? shape_range_y[i].second : shape_range_x[i].second;
- if (shape_range_x[i].first == 1 && shape_range_y[i].first == 1) {
- second_range = std::max(shape_range_x[i].second, shape_range_y[i].second);
- second_range = (shape_range_x[i].second == -1 || shape_range_y[i].second == -1) ? -1 : second_range;
- }
- out_range.push_back(std::pair<int64_t, int64_t>(first_range, second_range));
- } else {
- // no 1 in range.first, mean no boardcast for range
- // get intersect range
- int64_t first_range = std::max(shape_range_x[i].first, shape_range_y[i].first);
- int64_t second_range = std::min(shape_range_x[i].second, shape_range_y[i].second);
- second_range = (shape_range_x[i].second == -1 || shape_range_y[i].second == -1)
- ? std::max(shape_range_x[i].second, shape_range_y[i].second)
- : second_range;
- out_range.push_back(std::pair<int64_t, int64_t>(first_range, second_range));
- }
- }
- }
- }
-
- GeTensorDescPtr tensor_out = op_desc->MutableOutputDesc(output_name);
- tensor_out->SetShapeRange(out_range);
-
- return true;
- }
-
- bool GetInputDataType(const ge::DataType& dataType, const std::vector<ge::DataType>& supportList, std::string& dType) {
- std::vector<ge::DataType>::const_iterator supportIter = find(supportList.begin(), supportList.end(), dataType);
- if (supportIter == supportList.end()) {
- return false;
- }
-
- std::map<ge::DataType, std::string>::const_iterator totalIter = DTYPE_STR_MAP.find(dataType);
- if (totalIter == DTYPE_STR_MAP.end()) {
- return false;
- }
-
- dType = totalIter->second;
- return true;
- }
-
- bool CheckInputDataType(const Operator& op, std::string* data_type, const std::string& input_name,
- const std::vector<ge::DataType>& supportList) {
- DataType input_type = op.GetInputDesc(input_name).GetDataType();
- if (false == GetInputDataType(input_type, supportList, *data_type)) {
- LOG_ERROR("[ERROR]op [%s] [%s] do not supported dtype [%s]!\n", op.GetName().c_str(), input_name.c_str(),
- data_type->c_str());
- return false;
- }
- return true;
- }
-
- bool GetConstValue(const ge::Operator& op, const std::string& key_name, float& attr_value) {
- if (ge::GRAPH_SUCCESS != op.GetAttr(key_name, attr_value)) {
- LOG_ERROR("[ERROR]op [%s] GetOpAttr [%s] failed!\n", op.GetName().c_str(), key_name.c_str());
- return false;
- }
- return true;
- }
-
- bool GetConstValue(const ge::Operator& op, const std::string& key_name, int64_t& attr_value) {
- if (ge::GRAPH_SUCCESS != op.GetAttr(key_name, attr_value)) {
- LOG_ERROR("[ERROR]op [%s] GetOpAttr [%s] failed!\n", op.GetName().c_str(), key_name.c_str());
- return false;
- }
- return true;
- }
-
- bool GetConstValue(const ge::Operator& op, const std::string& key_name, bool& attr_value) {
- if (ge::GRAPH_SUCCESS != op.GetAttr(key_name, attr_value)) {
- LOG_ERROR("[ERROR]op [%s] GetOpAttr [%s] failed!\n", op.GetName().c_str(), key_name.c_str());
- return false;
- }
- return true;
- }
-
- bool GetConstValue(const ge::Operator& op, const std::string& key_name, std::vector<int32_t>& attr_value) {
- if (ge::GRAPH_SUCCESS != op.GetAttr(key_name, attr_value)) {
- LOG_ERROR("[ERROR]op [%s] GetOpAttr [%s] failed!\n", op.GetName().c_str(), key_name.c_str());
- return false;
- }
- return true;
- }
-
- template <typename T>
- static std::vector<int64_t> GetConstIntData(const uint8_t* const_data, size_t data_size) {
- size_t size = data_size / sizeof(T);
- std::vector<int64_t> result(size);
- T* data = (T*)const_data;
- for (size_t i = 0; i < size; i++) {
- result[i] = *(data + i);
- }
-
- return result;
- }
-
- bool GetConstIntData(const Tensor& data, DataType data_type, std::vector<int64_t>& const_values) {
- using namespace std::placeholders;
- const std::map<DataType, std::function<std::vector<int64_t>(const uint8_t*, size_t)>> type_call_map = {
- {DT_INT8, std::bind(GetConstIntData<int8_t>, _1, _2)},
- {DT_INT16, std::bind(GetConstIntData<int16_t>, _1, _2)},
- {DT_INT32, std::bind(GetConstIntData<int32_t>, _1, _2)},
- {DT_INT64, std::bind(GetConstIntData<int64_t>, _1, _2)},
- };
-
- auto found = type_call_map.find(data_type);
- if (found == type_call_map.end()) {
- USER_GE_LOGE("[ERROR]GetConstIntData is not support data_type[%s]!",
- ge::TypeUtils::DataTypeToSerialString(data_type).c_str());
- return false;
- }
-
- const_values = found->second(data.GetData(), data.GetSize());
-
- return true;
- }
-
- bool GetConstValue(const Operator& op, const Tensor& const_tensor, const DataType& dtype,
- std::vector<int64_t>& const_data) {
- size_t size = 0;
- CHECK(dtype != ge::DT_INT32 && dtype != ge::DT_INT64,
- OP_LOGE(op.GetName().c_str(), "not support this type"), return false);
- if (dtype == ge::DT_INT32) {
- int32_t* const_data_ptr = (int32_t*)const_tensor.GetData();
- size = const_tensor.GetSize() / sizeof(int32_t);
- for (size_t i = 0; i < size; ++i) {
- const_data.push_back((int32_t)((*(const_data_ptr + i))));
- OP_LOGD(op.GetName().c_str(), "const data int32 fusion pass ====== %d", (int32_t)(*(const_data_ptr + i)));
- }
- } else if (dtype == ge::DT_INT64) {
- int64_t* const_data_ptr = (int64_t*)const_tensor.GetData();
- size = const_tensor.GetSize() / sizeof(int64_t);
- for (size_t i = 0; i < size; ++i) {
- const_data.push_back(((int64_t)(*(const_data_ptr + i))));
- OP_LOGD(op.GetName().c_str(), "const data int64 fusion pass ====== %d", (int64_t)(*(const_data_ptr + i)));
- }
- }
- return true;
- }
-
- bool GetConstValue(const Operator& op, const GeTensorPtr& const_tensor,
- const DataType& dtype, std::vector<int64_t>& const_data) {
- size_t size = const_tensor->GetData().GetSize();
- void* data_ptr = (void*)const_tensor->GetData().GetData();
- CHECK(data_ptr == nullptr, OP_LOGE(op.GetName().c_str(), "data is null."), return false);
-
- CHECK(dtype != ge::DT_INT32 && dtype != ge::DT_INT64,
- OP_LOGE(op.GetName().c_str(), "const not support this type"), return false);
- if (dtype == ge::DT_INT32){
- int32_t* const_data_ptr = reinterpret_cast<int32_t*>(data_ptr);
- size = size / sizeof(int32_t);
- for (size_t i=0; i < size; i++) {
- const_data.push_back((int64_t)((int32_t) ((*(const_data_ptr + i)))));
- }
- } else if (dtype == ge::DT_INT64) {
- int64_t* const_data_ptr = reinterpret_cast<int64_t*>(data_ptr);
- size = size / sizeof(int64_t);
- for (size_t i=0; i < size; i++) {
- const_data.push_back((int64_t)((int64_t) ((*(const_data_ptr + i)))));
- }
- }
- return true;
- }
-
- bool GetScalerValue(const Operator& op, const Tensor& const_tensor, const DataType& dtype, std::int64_t& const_data) {
- if (dtype == ge::DT_INT32) {
- int32_t* const_data_ptr = (int32_t*)const_tensor.GetData();
- const_data = (int32_t)(*const_data_ptr);
- } else if (dtype == ge::DT_INT64) {
- int64_t* const_data_ptr = (int64_t*)const_tensor.GetData();
- const_data = (int64_t)(*const_data_ptr);
- } else {
- OP_LOGE(op.GetName().c_str(), "not support this type");
- return false;
- }
- return true;
- }
-
- string to_string(const vector<int64_t>& shape) {
- return ops::to_string(shape);
- }
-
- std::string to_string(const ge::Shape& shape) {
- return to_string(shape.GetDims());
- }
-
- std::string to_string(const ge::GeShape& shape) {
- return to_string(shape.GetDims());
- }
-
- std::string to_string(const vector<pair<int64_t, int64_t>>& ranges) {
- return ops::to_string(ranges);
- }
-
- bool DynamicShapeInfer::CatchFormatAndShape() {
- inputs = op_desc->GetAllInputName();
- outputs = op_desc->GetAllOutputName();
- GeTensorDescPtr tensor_desc_input, tensor_desc_output;
-
- // get and save current input shape&format, and assign origin ones to them
- std::string input_name;
- for (map<std::string, uint32_t>::iterator it = inputs.begin(); it != inputs.end(); it++) {
- input_name = it->first;
- tensor_desc_input = op_desc->MutableInputDesc(input_name);
- if (tensor_desc_input == nullptr) {
- continue;
- }
- Format curr_format = tensor_desc_input->GetFormat();
-
- map_format.insert(std::pair<std::string, Format>(input_name, curr_format));
- map_dtype.insert(std::pair<std::string, DataType>(input_name, tensor_desc_input->GetDataType()));
-
- if (tensor_desc_input->GetOriginFormat() == curr_format) {
- continue;
- }
- tensor_desc_input->SetFormat(tensor_desc_input->GetOriginFormat());
- tensor_desc_input->SetShape(tensor_desc_input->GetOriginShape());
- }
-
- // get and save current output shape&format, and assign origin ones to them
- std::string output_name;
- for (map<std::string, uint32_t>::iterator it = outputs.begin(); it != outputs.end(); it++) {
- output_name = it->first;
- tensor_desc_output = op_desc->MutableOutputDesc(output_name);
- if (tensor_desc_output == nullptr) {
- continue;
- }
- Format curr_format = tensor_desc_output->GetFormat();
-
- map_format.insert(std::pair<std::string, Format>(output_name, curr_format));
- map_dtype.insert(std::pair<std::string, DataType>(output_name, tensor_desc_output->GetDataType()));
-
- if (tensor_desc_output->GetOriginFormat() == curr_format) {
- continue;
- }
- tensor_desc_output->SetFormat(tensor_desc_output->GetOriginFormat());
- }
-
- return true;
- }
-
- bool DynamicShapeInfer::UpdateFormatAndShape() {
- const int64_t opImplType = EN_IMPL_CUSTOM_TBE;
- GeTensorDescPtr tensor_desc_input, tensor_desc_output;
- // assign output's after infershape to origin shape
- for (map<std::string, uint32_t>::iterator it = outputs.begin(); it != outputs.end(); it++) {
- tensor_desc_output = op_desc->MutableOutputDesc(it->first);
- if (tensor_desc_output == nullptr) {
- continue;
- }
- tensor_desc_output->SetOriginShape(tensor_desc_output->GetShape());
- }
-
- // transfer input's origin shape to current shape
- Format ori_input_format, cur_input_format;
- GeShape ori_infer_shape, current_shape;
- std::string input_name;
- for (map<std::string, uint32_t>::iterator it = inputs.begin(); it != inputs.end(); it++) {
- input_name = it->first;
- tensor_desc_input = op_desc->MutableInputDesc(input_name);
- if (tensor_desc_input == nullptr) {
- continue;
- }
- ori_input_format = tensor_desc_input->GetFormat();
- ori_infer_shape = tensor_desc_input->GetShape();
- cur_input_format = map_format[input_name];
-
- // print some info
- OP_LOGI(op.GetName().c_str(), "origin input shape %s is %s", input_name.c_str(),
- to_string(ori_infer_shape).c_str());
-
- ShapeAndFormat shapeAndFormatInfoInput = {ori_infer_shape, current_shape, ori_input_format,
- cur_input_format, map_dtype[input_name], opImplType};
- if (ori_input_format == cur_input_format) {
- // no need to transfer shape
- continue;
- } else {
- ShapeTransferAccordingToFormat* global_object = new ShapeTransferAccordingToFormat();
- CHECK(global_object == nullptr, OP_LOGE(op.GetName().c_str(), "new ShapeTransferAccordingToFormat failed."),
- return false);
- global_object->GetShapeAccordingToFormat(shapeAndFormatInfoInput);
-
- // print some info
- OP_LOGI(op.GetName().c_str(), "current input shape %s is %s", input_name.c_str(),
- to_string(current_shape).c_str());
-
- tensor_desc_input->SetFormat(cur_input_format);
- tensor_desc_input->SetShape(current_shape);
- delete global_object;
- }
- }
-
- // transfer output's origin shape to current shape
- Format ori_output_format, cur_output_format;
- GeShape ori_infer_out_shape, current_out_shape;
- std::string output_name;
- for (map<std::string, uint32_t>::iterator it = outputs.begin(); it != outputs.end(); it++) {
- output_name = it->first;
- tensor_desc_output = op_desc->MutableOutputDesc(output_name);
- if (tensor_desc_output == nullptr) {
- continue;
- }
- ori_output_format = tensor_desc_output->GetFormat();
- ori_infer_out_shape = tensor_desc_output->GetShape();
- cur_output_format = map_format[output_name];
-
- // print some info
- OP_LOGI(op.GetName().c_str(), "origin output shape %s is %s", output_name.c_str(),
- to_string(ori_infer_out_shape).c_str());
-
- ShapeAndFormat shapeAndFormatInfoOutput = {ori_infer_out_shape, current_out_shape, ori_output_format,
- cur_output_format, map_dtype[output_name], opImplType};
- if (ori_output_format == cur_output_format) {
- // no need to transfer shape
- continue;
- } else {
- ShapeTransferAccordingToFormat* global_object = new ShapeTransferAccordingToFormat();
- CHECK(global_object == nullptr, OP_LOGE(op.GetName().c_str(), "new ShapeTransferAccordingToFormat failed."),
- return false);
- global_object->GetShapeAccordingToFormat(shapeAndFormatInfoOutput);
-
- // print some info
- OP_LOGI(op.GetName().c_str(), "current output shape %s is %s", output_name.c_str(),
- to_string(current_out_shape).c_str());
-
- tensor_desc_output->SetFormat(cur_output_format);
- tensor_desc_output->SetShape(current_out_shape);
- delete global_object;
- }
- }
-
- return true;
- }
-
- bool IsEmptyTensor(const std::vector<int64_t>& dims) {
- if (dims.size() == 1 && dims[0] == 0) {
- return true;
- } else {
- return false;
- }
- }
-
- bool IsUnknownRank(const Operator& op, const std::string& tensor_name, const std::string& types) {
- auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_desc == nullptr, OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
- GeTensorDescPtr tensor_desc;
- if (types == "input") {
- tensor_desc = op_desc->MutableInputDesc(tensor_name);
- } else if (types == "output") {
- tensor_desc = op_desc->MutableOutputDesc(tensor_name);
- } else {
- OP_LOGE(op.GetName().c_str(), "invalid params of types to judge.");
- return false;
- }
-
- std::vector<int64_t> shape_vec = tensor_desc->GetShape().GetDims();
- if (shape_vec.size() == 1 && shape_vec[0] == -2) {
- return true;
- }
- return false;
- }
-
- bool IsUnknownRankShape(const std::vector<int64_t>& shape_vec) {
- if (shape_vec.size() == 1 && shape_vec[0] == -2) {
- return true;
- }
- return false;
- }
-
- bool IsUnKnownShape(const std::vector<int64_t>& shape_vec) {
- auto found = find(shape_vec.begin(), shape_vec.end(), -1);
- return found != shape_vec.end();
- }
-
- bool IsUnknown(const std::vector<int64_t>& shape_vec) {
- return (IsUnKnownShape(shape_vec) || IsUnknownRankShape(shape_vec));
- }
-
- bool IsUnknownShape(const Operator& op, const std::string& tensor_name, const std::string& types) {
- auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_desc == nullptr, OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
- GeTensorDescPtr tensor_desc;
- if (types == "input") {
- tensor_desc = op_desc->MutableInputDesc(tensor_name);
- } else if (types == "output") {
- tensor_desc = op_desc->MutableOutputDesc(tensor_name);
- } else {
- OP_LOGE(op.GetName().c_str(), "invalid params of types to judge.");
- return false;
- }
-
- std::vector<int64_t> shape_vec = tensor_desc->GetShape().GetDims();
- std::vector<int64_t>::iterator it_shape;
- it_shape = find(shape_vec.begin(), shape_vec.end(), -1);
- if (it_shape == shape_vec.end()) {
- return false;
- } else {
- return true;
- }
- }
-
- bool IsUnknownVec(std::vector<int64_t>& shape_vec) {
- std::vector<int64_t>::iterator it_shape;
- it_shape = find(shape_vec.begin(), shape_vec.end(), -1);
- if (it_shape == shape_vec.end()) {
- return false;
- } else {
- return true;
- }
- }
-
- void MakeUpShapeRange(const std::vector<int64_t>& shape, std::vector<std::pair<int64_t, int64_t>>& range) {
- if (IsUnknownRankShape(shape)) {
- return;
- }
-
- if (range.empty()) {
- for (size_t i = 0; i < shape.size(); i++) {
- if (shape[i] == -1) {
- range.push_back(std::pair<int64_t, int64_t>(1, -1));
- } else {
- range.push_back(std::pair<int64_t, int64_t>(shape[i], shape[i]));
- }
- }
- }
- }
-
- std::string DataTypeToStringDesc(const ge::DataType& dataType) {
- std::map<ge::DataType, std::string>::const_iterator totalIter = DTYPE_STR_MAP.find(dataType);
- if (totalIter == DTYPE_STR_MAP.end()) {
- return "UNDEFINED";
- }
- return totalIter->second;
- }
-
- bool OneInOneOutDynamicInfer(const Operator& op,
- const std::string& input_name,
- const std::vector<std::string>& output_name_list) {
- // get input desc
- auto op_info = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_info == nullptr, OP_LOGE(op.GetName().c_str(), "invalid OpDesc."), return false);
- auto input_desc = op_info->MutableInputDesc(input_name);
- vector<int64_t> input_shape = input_desc->MutableShape().GetDims();
- DataType input_dtype = input_desc->GetDataType();
-
- if (IsUnknown(input_shape)) {
- std::vector<std::pair<int64_t, int64_t>> input_range;
- input_desc->GetShapeRange(input_range);
- MakeUpShapeRange(input_shape, input_range);
-
- auto output_desc = op_info->MutableOutputDesc(0);
- for (const string& output_name : output_name_list) {
- output_desc = op_info->MutableOutputDesc(output_name);
- output_desc->SetShape(GeShape(input_shape));
- output_desc->SetOriginShape(GeShape(input_shape));
- output_desc->SetShapeRange(input_range);
- output_desc->SetDataType(input_dtype);
- }
- } else {
- auto output_desc = op_info->MutableOutputDesc(0);
- for (const string& output_name : output_name_list) {
- output_desc = op_info->MutableOutputDesc(output_name);
- output_desc->SetShape(GeShape(input_shape));
- output_desc->SetDataType(input_dtype);
- }
- }
- return true;
- }
-
- void FixShapeRangeWithDims(const std::vector<int64_t>& dims,
- std::vector<int64_t>& shape_1,
- std::vector<int64_t>& shape_2,
- std::vector<std::pair<int64_t, int64_t>>& range_1,
- std::vector<std::pair<int64_t, int64_t>>& range_2) {
- MakeUpShapeRange(shape_1, range_1);
- MakeUpShapeRange(shape_2, range_2);
- bool is_all_fix = dims.empty();
-
- if (shape_1 == UNKNOWN_RANK && shape_2 == UNKNOWN_RANK) {
- return;
- }
- if (shape_1 == UNKNOWN_RANK) {
- shape_1 = shape_2;
- range_1 = range_2;
- return;
- }
- if (shape_2 == UNKNOWN_RANK) {
- shape_2 = shape_1;
- range_2 = range_1;
- return;
- }
- if ((shape_1.size() != shape_2.size()) || (range_1.size() != range_2.size())) {
- return;
- }
- auto loop_size = is_all_fix ? shape_1.size() : dims.size();
- for (size_t i = 0; i < loop_size; i ++) {
- auto dim_num = is_all_fix ? i : dims[i];
- if (shape_1[dim_num] != -1) {
- shape_2[dim_num] = shape_1[dim_num];
- range_1[dim_num] = std::pair<int64_t, int64_t>(shape_1[dim_num], shape_1[dim_num]);
- range_2[dim_num] = std::pair<int64_t, int64_t>(shape_1[dim_num], shape_1[dim_num]);
- continue;
- }
- if (shape_2[dim_num] != -1) {
- shape_1[dim_num] = shape_2[dim_num];
- range_1[dim_num] = std::pair<int64_t, int64_t>(shape_2[dim_num], shape_2[dim_num]);
- range_2[dim_num] = std::pair<int64_t, int64_t>(shape_2[dim_num], shape_2[dim_num]);
- continue;
- }
- // both the dim in shape1 and shape2 are -1
- auto range_1_min = range_1[dim_num].first;
- auto range_2_min = range_2[dim_num].first;
- auto range_1_max = range_1[dim_num].second;
- auto range_2_max = range_2[dim_num].second;
- auto range_fisrt = range_1_min > range_2_min ? range_1_min : range_2_min;
- auto range_second_min = range_1_max > range_2_max ? range_2_max : range_1_max;
- auto range_second_max = range_1_max > range_2_max ? range_1_max : range_2_max;
- range_second_min = range_second_min == -1 ? range_second_max : range_second_min;
- range_1[dim_num] = std::pair<int64_t, int64_t>(range_fisrt, range_second_min);
- range_2[dim_num] = std::pair<int64_t, int64_t>(range_fisrt, range_second_min);
- }
- }
-
- bool TwoInOneOutDynamicInferNoBroadcast(Operator& op,
- const string& input1_name,
- const string& input2_name,
- const std::vector<string>& output_name_list) {
- // get input1 desc
- auto op_info = OpDescUtils::GetOpDescFromOperator(op);
- CHECK(op_info == nullptr || op_info->MutableInputDesc(input1_name) == nullptr ||
- op_info->MutableInputDesc(input2_name) == nullptr, OP_LOGE(op.GetName().c_str(), "invalid OpDesc."),
- return false);
- auto input1_desc = op_info->MutableInputDesc(input1_name);
- vector<int64_t> input1_shape = input1_desc->MutableShape().GetDims();
- DataType input_dtype = input1_desc->GetDataType();
-
- // get input2 desc
- auto input2_desc = op_info->MutableInputDesc(input2_name);
- vector<int64_t> input2_shape = input2_desc->MutableShape().GetDims();
-
- if (IsUnknown(input1_shape) || IsUnknown(input2_shape)) {
- std::vector<std::pair<int64_t, int64_t>> input1_range;
- input1_desc->GetShapeRange(input1_range);
- std::vector<std::pair<int64_t, int64_t>> input2_range;
- input2_desc->GetShapeRange(input2_range);
-
- vector<int64_t> dim_size = {};
- FixShapeRangeWithDims(dim_size, input1_shape, input2_shape, input1_range, input2_range);
-
- // update output desc
- auto output_desc = op_info->MutableOutputDesc(0);
- for (const string& output_name : output_name_list) {
- output_desc = op_info->MutableOutputDesc(output_name);
- output_desc->SetShape(GeShape(input1_shape));
- output_desc->SetOriginShape(GeShape(input1_shape));
- output_desc->SetShapeRange(input1_range);
- output_desc->SetDataType(input_dtype);
- }
- } else {
- auto output_desc = op_info->MutableOutputDesc(0);
- for (const string& output_name : output_name_list) {
- output_desc = op_info->MutableOutputDesc(output_name);
- output_desc->SetShape(GeShape(input1_shape));
- output_desc->SetDataType(input_dtype);
- }
- }
- return true;
- }
-
- bool SetScalarOutputDesc(const string& input, const string& output, OpDescPtr op_desc, GeShape& output_shape) {
- if (output_shape.IsScalar()) {
- auto td = op_desc->MutableOutputDesc(output);
- td->SetShape(output_shape);
- td->SetOriginShape(output_shape);
- td->SetDataType(op_desc->MutableInputDesc(input)->GetDataType());
- td->SetOriginDataType(op_desc->MutableInputDesc(input)->GetDataType());
- return true;
- } else {
- return false;
- }
- }
-
- namespace array_ops {
-
- bool CheckInt64MulOverflow(int64_t a, int64_t b) {
- if (a > 0) {
- if (b > 0) {
- if (a >(INT64_MAX / b)) {
- return false;
- }
- } else {
- if (b < (INT64_MIN / a)) {
- return false;
- }
- }
- } else {
- if (b > 0) {
- if (a < (INT64_MIN / b)) {
- return false;
- }
- } else {
- if ((a != 0) && (b < (INT64_MAX / a))) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- void ReshapeRangeInfer(const Operator &op, const std::vector<std::pair<int64_t, int64_t>>& x_range,
- int64_t& range_max) {
- for (const auto& ele : x_range) {
- if (ele.second < 0) {
- range_max = -1;
- return;
- }
-
- if (array_ops::CheckInt64MulOverflow(range_max, ele.second)) {
- range_max *= ele.second;
- } else {
- range_max = INT64_MAX;
- GE_OP_LOGW(op.GetName().c_str(), "Range Infer out of int64 max!Do set int64max!");
- return;
- }
- }
- }
-
- void ReshapeRangeInfer(const Operator &op, const std::vector<std::pair<int64_t, int64_t>>& x_range,
- std::vector<std::pair<int64_t, int64_t>>& y_range, GeShape& output_shape) {
- int64_t max_input_dims = 1;
- for (const auto& pair : x_range) {
- if (pair.second < 0) {
- max_input_dims = -1;
- break;
- }
- if (array_ops::CheckInt64MulOverflow(max_input_dims, pair.second)) {
- max_input_dims *= pair.second;
- } else {
- max_input_dims = INT64_MAX;
- GE_OP_LOGW(op.GetName().c_str(), "Range Infer out of int64 max!Do set int64max!");
- break;
- }
- }
-
- if (max_input_dims < 0) {
- for (const auto dim : output_shape.GetDims()) {
- if (dim < 0) {
- y_range.emplace_back(std::pair<int64_t, int64_t>(1, -1));
- } else {
- y_range.emplace_back(std::pair<int64_t, int64_t>(dim, dim));
- }
- }
- } else {
- int64_t left = max_input_dims;
- left = (left > INT32_MAX) ? INT32_MAX : left;
- for (const auto dim : output_shape.GetDims()) {
- if (dim < 0) {
- y_range.emplace_back(std::pair<int64_t, int64_t>(1, left));
- } else {
- y_range.emplace_back(std::pair<int64_t, int64_t>(dim, dim));
- if (dim != 0) {
- left = static_cast<int64_t>((static_cast<double>(left) + 0.5) / dim);
- }
- }
- }
- }
- }
-
- }
-
- } // namespace ge
-
|