Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License")
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : /* !
12 : * \file sparse_slice_tiling_arch35.cpp
13 : * \brief
14 : */
15 :
16 : #include <cmath>
17 : #include "sparse_slice_tiling_arch35.h"
18 : #include <graph/utils/type_utils.h>
19 : #include "log/log.h"
20 : #include "register/op_impl_registry.h"
21 : #include "register/tilingdata_base.h"
22 : #include "op_host/tiling_templates_registry.h"
23 : #include "op_host/tiling_util.h"
24 : #include "error_util.h"
25 :
26 : using namespace std;
27 : using namespace ge;
28 : using namespace Ops::NN::OpTiling;
29 :
30 : namespace optiling {
31 : const std::set<ge::DataType> INDICES_SUPPORT_DTYPE_SET = {ge::DT_INT64};
32 : const std::set<ge::DataType> VALUE_SUPPORT_DTYPE_SET = {ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_UINT8,
33 : ge::DT_INT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32,
34 : ge::DT_INT64, ge::DT_BOOL};
35 : constexpr int64_t DIGIT_ZERO = 0;
36 : constexpr int64_t DIGIT_ONE = 1;
37 : constexpr int64_t DIGIT_TWO = 2;
38 : constexpr int64_t DIGIT_THREE = 3;
39 : constexpr int64_t DIGIT_FOUR = 4;
40 : constexpr int64_t DIGIT_SIX = 6;
41 : constexpr int64_t DIGIT_SEVEN = 7;
42 : constexpr int64_t DIGIT_TWENTYFOUR = 24;
43 : constexpr int64_t DIGIT_TEN_THOUSAND = 10000;
44 : constexpr int64_t SIZE_OF_INT64 = 8;
45 : constexpr int64_t RESERVED_UB_SIZE = 8 * 1024;
46 : constexpr int64_t DOUBLE_BUFFER = 2;
47 : constexpr int64_t MAX_ITER_DIM = 32;
48 : constexpr int64_t WORKSPACE_SIZE_ALIGN = 512;
49 : constexpr int64_t SHAPE_IDX = 2;
50 : constexpr int64_t START_IDX = 3;
51 : constexpr int64_t SIZE_IDX = 4;
52 : constexpr uint64_t DCACHE_SIZE = 32UL * 1024UL;
53 : constexpr int64_t INDICES_NUM_MAX_SIMT = 19968;
54 :
55 : template <typename T>
56 : static void GetConstValueToShape(const gert::Tensor* tensor, size_t size, gert::Shape* shape)
57 : {
58 : const T* value = tensor->GetData<T>();
59 : shape->SetDimNum(size);
60 : for (size_t i = 0; i < size; i++) {
61 : shape->SetDim(i, value[i]);
62 : }
63 : }
64 :
65 : bool SparseSliceTiling::UseSIMT()
66 : {
67 : bool rank2 = tilingParams.rankNumbers > DIGIT_TWO;
68 : bool dataSizeUB = tilingParams.valueNumbers * tilingParams.rankNumbers / tilingParams.totalCoreNum <=
69 : INDICES_NUM_MAX_SIMT;
70 : return rank2 && dataSizeUB;
71 : }
72 :
73 : ge::graphStatus SparseSliceTiling::GetShapeAttrsInfo()
74 : {
75 : OP_TILING_CHECK(CheckDtype() != ge::GRAPH_SUCCESS, OP_LOGE(context_->GetNodeName(), "Check datatype failed. "),
76 : return ge::GRAPH_FAILED);
77 : OP_TILING_CHECK(CheckShape() != ge::GRAPH_SUCCESS, OP_LOGE(context_->GetNodeName(), "Check shape failed. "),
78 : return ge::GRAPH_FAILED);
79 :
80 : return ge::GRAPH_SUCCESS;
81 : }
82 :
83 : ge::graphStatus SparseSliceTiling::GetPlatformInfo()
84 : {
85 : auto platformInfo = context_->GetPlatformInfo();
86 : OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo);
87 : auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo);
88 : tilingParams.totalCoreNum = ascendcPlatform.GetCoreNumAiv();
89 4 : OP_TILING_CHECK(
90 : (tilingParams.totalCoreNum <= 0),
91 : OP_LOGE(context_->GetNodeName(), "Failed to get core num, coreNum: %ld.", tilingParams.totalCoreNum),
92 : return ge::GRAPH_FAILED);
93 : uint64_t ubSize;
94 : ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);
95 : tilingParams.ubSize = static_cast<int64_t>(ubSize) - RESERVED_UB_SIZE;
96 4 : OP_TILING_CHECK((tilingParams.ubSize <= 0),
97 : OP_LOGE(context_->GetNodeName(), "Failed to get ub size, ubSize: %ld.", tilingParams.ubSize),
98 : return ge::GRAPH_FAILED);
99 : tilingParams.vfLen = Ops::Base::GetVRegSize(context_);
100 : tilingParams.workspaceSize = ascendcPlatform.GetLibApiWorkSpaceSize();
101 :
102 : return ge::GRAPH_SUCCESS;
103 : }
104 :
105 : bool SparseSliceTiling::IsCapable() { return true; }
106 :
107 : ge::graphStatus SparseSliceTiling::DoOpTiling()
108 : {
109 : ge::graphStatus res = SetTilingParams();
110 : OP_TILING_CHECK(res != ge::GRAPH_SUCCESS,
111 : OP_LOGE(context_->GetNodeName(), "SparseSliceTiling SetTilingParams Failed"), return res);
112 :
113 : SetTilingData();
114 : PrintTilingData();
115 :
116 : return ge::GRAPH_SUCCESS;
117 : }
118 :
119 : ge::graphStatus SparseSliceTiling::DoLibApiTiling() { return ge::GRAPH_SUCCESS; }
120 :
121 : ge::graphStatus SparseSliceTiling::GetWorkspaceSize() { return ge::GRAPH_SUCCESS; }
122 :
123 : ge::graphStatus SparseSliceTiling::PostTiling()
124 : {
125 : if (tilingData.GetDataSize() > context_->GetRawTilingData()->GetCapacity()) {
126 : OP_LOGD(context_->GetNodeName(), "Tiling DataSize Greater than capacity, please check.");
127 : return ge::GRAPH_FAILED;
128 : }
129 : tilingData.SaveToBuffer(context_->GetRawTilingData()->GetData(), context_->GetRawTilingData()->GetCapacity());
130 : context_->GetRawTilingData()->SetDataSize(tilingData.GetDataSize());
131 :
132 : OP_LOGD(nodeName.c_str(), "Tiling totalCoreNum is %lu.", tilingParams.totalCoreNum);
133 : context_->SetBlockDim(tilingParams.totalCoreNum);
134 :
135 : if (tilingParams.templateType == DIGIT_FOUR) {
136 : auto res = context_->SetLocalMemorySize(tilingParams.ubSize - DCACHE_SIZE);
137 : OP_LOGD(nodeName.c_str(), "SetLocalMemorySize ubSize = %lu, %d.", tilingParams.ubSize, res);
138 : }
139 :
140 : if (tilingParams.templateType == DIGIT_ONE || tilingParams.templateType == DIGIT_FOUR) {
141 : context_->SetScheduleMode(DIGIT_ONE);
142 : OP_LOGD(context_->GetNodeName(), "Set block sync batch mode.");
143 : }
144 :
145 : size_t* workspaces = context_->GetWorkspaceSizes(1);
146 : OP_CHECK_NULL_WITH_CONTEXT(context_, workspaces);
147 : OP_LOGD(nodeName.c_str(), "Tiling workspaceSize is %ld.", tilingParams.workspaceSize);
148 : auto workspaceSizeAlign = ((tilingParams.valueNumbers * sizeof(int8_t) + WORKSPACE_SIZE_ALIGN - 1) /
149 : WORKSPACE_SIZE_ALIGN) *
150 : WORKSPACE_SIZE_ALIGN +
151 : WORKSPACE_SIZE_ALIGN * 65;
152 : workspaces[0] = tilingParams.workspaceSize + workspaceSizeAlign;
153 :
154 : return ge::GRAPH_SUCCESS;
155 : }
156 :
157 : uint64_t SparseSliceTiling::GetTilingKey() const
158 : {
159 : int64_t tilingKey = tilingParams.tilingKey;
160 : OP_LOGD(nodeName.c_str(), "TilingKey is %lu.", tilingKey);
161 : return tilingKey;
162 : }
163 :
164 : // 非override函数
165 : ge::graphStatus SparseSliceTiling::CheckDtype()
166 : {
167 : auto indicesPtr = context_->GetInputDesc(0);
168 : OP_CHECK_NULL_WITH_CONTEXT(context_, indicesPtr);
169 : auto indicesDtype = indicesPtr->GetDataType();
170 : OP_TILING_CHECK(INDICES_SUPPORT_DTYPE_SET.count(indicesDtype) == 0,
171 : OP_LOGE_FOR_INVALID_DTYPE(context_->GetNodeName(), "x_indices",
172 : ge::TypeUtils::DataTypeToSerialString(indicesDtype), "DT_INT64"),
173 : return ge::GRAPH_FAILED);
174 :
175 : auto valuesPtr = context_->GetInputDesc(1);
176 : OP_CHECK_NULL_WITH_CONTEXT(context_, valuesPtr);
177 : auto valuesDtype = valuesPtr->GetDataType();
178 : OP_TILING_CHECK(
179 : VALUE_SUPPORT_DTYPE_SET.count(valuesDtype) == 0,
180 : OP_LOGE_FOR_INVALID_DTYPE(
181 : context_->GetNodeName(), "x_values", ge::TypeUtils::DataTypeToSerialString(valuesDtype),
182 : "DT_FLOAT, DT_FLOAT16, DT_BF16, DT_UINT8, DT_INT8, DT_INT16, DT_UINT16, DT_INT32, DT_INT64, DT_BOOL"),
183 : return ge::GRAPH_FAILED);
184 :
185 : auto shapePtr = context_->GetInputDesc(DIGIT_TWO);
186 : OP_CHECK_NULL_WITH_CONTEXT(context_, shapePtr);
187 : auto shapeDtype = shapePtr->GetDataType();
188 : OP_TILING_CHECK(INDICES_SUPPORT_DTYPE_SET.count(shapeDtype) == 0,
189 : OP_LOGE_FOR_INVALID_DTYPE(context_->GetNodeName(), "x_shape",
190 : ge::TypeUtils::DataTypeToSerialString(shapeDtype), "DT_INT64"),
191 : return ge::GRAPH_FAILED);
192 :
193 : auto startPtr = context_->GetInputDesc(DIGIT_THREE);
194 : OP_CHECK_NULL_WITH_CONTEXT(context_, startPtr);
195 : auto startDtype = startPtr->GetDataType();
196 : OP_TILING_CHECK(INDICES_SUPPORT_DTYPE_SET.count(startDtype) == 0,
197 : OP_LOGE_FOR_INVALID_DTYPE(context_->GetNodeName(), "x_start",
198 : ge::TypeUtils::DataTypeToSerialString(startDtype), "DT_INT64"),
199 : return ge::GRAPH_FAILED);
200 :
201 : auto sizePtr = context_->GetInputDesc(DIGIT_FOUR);
202 : OP_CHECK_NULL_WITH_CONTEXT(context_, sizePtr);
203 : auto sizeDtype = sizePtr->GetDataType();
204 : OP_TILING_CHECK(INDICES_SUPPORT_DTYPE_SET.count(sizeDtype) == 0,
205 : OP_LOGE_FOR_INVALID_DTYPE(context_->GetNodeName(), "x_size",
206 : ge::TypeUtils::DataTypeToSerialString(sizeDtype), "DT_INT64"),
207 : return ge::GRAPH_FAILED);
208 : return ge::GRAPH_SUCCESS;
209 : }
210 :
211 : ge::graphStatus SparseSliceTiling::CheckShape()
212 : {
213 : auto indicesPtr = context_->GetInputShape(0);
214 : auto indicesShape = indicesPtr->GetStorageShape();
215 : OP_TILING_CHECK(static_cast<int64_t>(indicesShape.GetDimNum()) != DIGIT_TWO,
216 : OP_LOGE_FOR_INVALID_SHAPEDIM(context_->GetNodeName(), "x_indices",
217 : std::to_string(static_cast<int64_t>(indicesShape.GetDimNum())),
218 : std::to_string(DIGIT_TWO)),
219 : return ge::GRAPH_FAILED);
220 : auto valueNumbers = static_cast<int64_t>(indicesShape.GetDim(0));
221 : auto rankNumbers = static_cast<int64_t>(indicesShape.GetDim(1));
222 : OP_TILING_CHECK(
223 : rankNumbers > DIGIT_TWENTYFOUR || rankNumbers < DIGIT_ONE,
224 : OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "x_indices[1]", std::to_string(rankNumbers),
225 : "The value of x_indices[1] must be in range [1, 24]"),
226 : return ge::GRAPH_FAILED);
227 : auto valuesPtr = context_->GetInputShape(1);
228 : auto valuesShape = valuesPtr->GetStorageShape();
229 : OP_TILING_CHECK(static_cast<int64_t>(valuesShape.GetDimNum()) != DIGIT_ONE,
230 : OP_LOGE_FOR_INVALID_SHAPEDIM(context_->GetNodeName(), "x_values",
231 : std::to_string(static_cast<int64_t>(valuesShape.GetDimNum())),
232 : std::to_string(DIGIT_ONE)),
233 : return ge::GRAPH_FAILED);
234 : auto actualValueNumbers = static_cast<int64_t>(valuesShape.GetDim(0));
235 : OP_TILING_CHECK(valueNumbers != actualValueNumbers,
236 : OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(
237 : context_->GetNodeName(), "x_values, x_indices",
238 : Ops::Base::ToString(valuesShape) + ", " + Ops::Base::ToString(indicesShape),
239 : "The shapes of x_values and x_indices must be the same"),
240 : return ge::GRAPH_FAILED);
241 : auto shapePtr = context_->GetInputShape(DIGIT_TWO);
242 : auto shapeShape = shapePtr->GetStorageShape();
243 : OP_TILING_CHECK(static_cast<int64_t>(shapeShape.GetDimNum()) != DIGIT_ONE,
244 : OP_LOGE_FOR_INVALID_SHAPEDIM(context_->GetNodeName(), "x_shape",
245 : std::to_string(static_cast<int64_t>(shapeShape.GetDimNum())),
246 : std::to_string(DIGIT_ONE)),
247 : return ge::GRAPH_FAILED);
248 : auto shapeRankNumbers = static_cast<int64_t>(shapeShape.GetDim(0));
249 : OP_TILING_CHECK(rankNumbers != shapeRankNumbers,
250 : OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(
251 : context_->GetNodeName(), "x_shape, x_indices",
252 : Ops::Base::ToString(shapeShape) + ", " + Ops::Base::ToString(indicesShape),
253 : "The shapes of x_shape and x_indices must be the same"),
254 : return ge::GRAPH_FAILED);
255 : auto startPtr = context_->GetInputShape(DIGIT_THREE);
256 : auto startShape = startPtr->GetStorageShape();
257 : OP_TILING_CHECK(
258 : startShape != shapeShape,
259 : OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context_->GetNodeName(), "x_start, x_shape",
260 : Ops::Base::ToString(startShape) + ", " + Ops::Base::ToString(shapeShape),
261 : "The shapes of x_start and x_shape must be the same"),
262 : return ge::GRAPH_FAILED);
263 : auto sizePtr = context_->GetInputShape(DIGIT_FOUR);
264 : auto sizeShape = sizePtr->GetStorageShape();
265 : OP_TILING_CHECK(
266 : sizeShape != shapeShape,
267 : OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context_->GetNodeName(), "x_size, x_shape",
268 : Ops::Base::ToString(sizeShape) + ", " + Ops::Base::ToString(shapeShape),
269 : "The shapes of x_size and x_shape must be the same"),
270 : return ge::GRAPH_FAILED);
271 : return ge::GRAPH_SUCCESS;
272 : }
273 :
274 : ge::graphStatus SparseSliceTiling::SetTilingParams()
275 : {
276 : auto indicesPtr = context_->GetInputShape(0);
277 : auto indicesShape = indicesPtr->GetStorageShape();
278 : tilingParams.valueNumbers = static_cast<int64_t>(indicesShape.GetDim(0));
279 : tilingParams.rankNumbers = static_cast<int64_t>(indicesShape.GetDim(1));
280 :
281 : auto valuesPtr = context_->GetInputDesc(1);
282 : auto valuesDtype = valuesPtr->GetDataType();
283 : int64_t valuesDataTypeSize = GetSizeByDataType(valuesDtype);
284 : OP_LOGD(context_->GetNodeName(), "The data type size of input values is %ld. ", valuesDataTypeSize);
285 :
286 : OP_TILING_CHECK(CalcYShape() != ge::GRAPH_SUCCESS, OP_LOGE(context_->GetNodeName(), "Calc y shape failed. "),
287 : return ge::GRAPH_FAILED);
288 : auto sizePerCalc = (tilingParams.rankNumbers * SIZE_OF_INT64 * DIGIT_SEVEN + valuesDataTypeSize * DIGIT_TWO) *
289 : DOUBLE_BUFFER;
290 :
291 : tilingParams.templateType = DIGIT_ONE;
292 : if (tilingParams.valueNumbers == DIGIT_ZERO) {
293 : tilingParams.templateType = DIGIT_TWO;
294 : OP_LOGD(context_->GetNodeName(), "Enters empty tensor template. (Number of input values is 0)");
295 : tilingParams.tilingKey = tilingParams.templateType * DIGIT_TEN_THOUSAND;
296 : tilingParams.valuePerUb = 0;
297 : tilingParams.valuePerCore = 0;
298 : tilingParams.usedCoreNum = 1;
299 : tilingParams.valuePerTail = 0;
300 : return ge::GRAPH_SUCCESS;
301 : } else if (tilingParams.IsEmptyYShape == true) {
302 : tilingParams.templateType = DIGIT_TWO;
303 : OP_LOGD(context_->GetNodeName(), "Enters empty tensor template. (Output shape implies empty tensor)");
304 : tilingParams.tilingKey = tilingParams.templateType * DIGIT_TEN_THOUSAND;
305 : tilingParams.valuePerUb = 0;
306 : tilingParams.valuePerCore = 0;
307 : tilingParams.usedCoreNum = 1;
308 : tilingParams.valuePerTail = 0;
309 : return ge::GRAPH_SUCCESS;
310 : } else if (UseSIMT()) {
311 : tilingParams.templateType = DIGIT_FOUR;
312 : }
313 :
314 : tilingParams.tilingKey = tilingParams.templateType * DIGIT_TEN_THOUSAND;
315 :
316 : tilingParams.valuePerUb = tilingParams.ubSize / sizePerCalc;
317 : tilingParams.valuePerCore = (tilingParams.valueNumbers + tilingParams.totalCoreNum - DIGIT_ONE) /
318 : tilingParams.totalCoreNum;
319 : tilingParams.usedCoreNum = (tilingParams.valueNumbers + tilingParams.valuePerCore - DIGIT_ONE) /
320 : tilingParams.valuePerCore;
321 : tilingParams.valuePerTail = tilingParams.valuePerCore * tilingParams.usedCoreNum == tilingParams.valueNumbers ?
322 : tilingParams.valuePerCore :
323 : tilingParams.valueNumbers % tilingParams.valuePerCore;
324 :
325 : return ge::GRAPH_SUCCESS;
326 : }
327 :
328 : void SparseSliceTiling::SetTilingData()
329 : {
330 : tilingData.set_usedCoreNum(tilingParams.usedCoreNum);
331 : tilingData.set_valueNumbers(tilingParams.valueNumbers);
332 : tilingData.set_rankNumbers(tilingParams.rankNumbers);
333 : tilingData.set_valuePerUb(tilingParams.valuePerUb);
334 : tilingData.set_valuePerCore(tilingParams.valuePerCore);
335 : tilingData.set_valuePerTail(tilingParams.valuePerTail);
336 : }
337 :
338 : void SparseSliceTiling::PrintTilingData()
339 : {
340 : OP_LOGD(context_->GetNodeName(),
341 : "PrintTilingData usedCoreNum: %ld, valueNumbers: %ld, rankNumbers: %ld, "
342 : "valuePerUb: %ld, valuePerCore: %ld, valuePerTail: %ld. ",
343 : tilingData.get_usedCoreNum(), tilingData.get_valueNumbers(), tilingData.get_rankNumbers(),
344 : tilingData.get_valuePerUb(), tilingData.get_valuePerCore(), tilingData.get_valuePerTail());
345 : }
346 :
347 : ge::graphStatus SparseSliceTiling::CalcYShape()
348 : {
349 : const gert::Tensor* shapeTensor = context_->GetInputTensor(DIGIT_TWO);
350 : const gert::Tensor* startTensor = context_->GetInputTensor(DIGIT_THREE);
351 : const gert::Tensor* sizeTensor = context_->GetInputTensor(DIGIT_FOUR);
352 : if (shapeTensor == nullptr || startTensor == nullptr || sizeTensor == nullptr) {
353 : OP_LOGD(context_->GetNodeName(), "INPUT TENSOR IS NULLPTR");
354 : return ge::GRAPH_FAILED;
355 : }
356 :
357 : const int64_t* shapeValue = shapeTensor->GetData<int64_t>();
358 : const int64_t* startValue = startTensor->GetData<int64_t>();
359 : const int64_t* sizeValue = sizeTensor->GetData<int64_t>();
360 : if (shapeValue == nullptr || startValue == nullptr || sizeValue == nullptr) {
361 : OP_LOGD(context_->GetNodeName(), "INPUT TENSOR VALUE IS NULLPTR");
362 : return ge::GRAPH_FAILED;
363 : }
364 :
365 : GetValueList(DIGIT_TWO, shapeTensor, tilingParams.rankNumbers, tilingParams.shape);
366 : GetValueList(DIGIT_THREE, startTensor, tilingParams.rankNumbers, tilingParams.start);
367 : GetValueList(DIGIT_FOUR, sizeTensor, tilingParams.rankNumbers, tilingParams.size);
368 :
369 : for (int64_t i = 0; i < tilingParams.rankNumbers; i++) {
370 : int64_t tmpShape = tilingParams.shape[i];
371 : int64_t tmpStart = tilingParams.start[i];
372 : int64_t tmpSize = tilingParams.size[i];
373 : int64_t tmpEndValue = tmpStart + tmpSize;
374 : int64_t tmpYShapeValue = tmpShape;
375 : if (tmpYShapeValue > tmpEndValue) {
376 : tmpYShapeValue = tmpEndValue;
377 : }
378 : tmpYShapeValue = tmpYShapeValue - tmpStart;
379 : if (tmpYShapeValue <= 0) {
380 : tmpYShapeValue = 0;
381 : tilingParams.IsEmptyYShape = true;
382 : }
383 : OP_LOGD(context_->GetNodeName(), "Print curent Y value %ld. ", tmpYShapeValue);
384 : tilingParams.yShapeOut[i] = tmpYShapeValue;
385 : tilingParams.sliceStart[i] = tmpStart;
386 : tilingParams.sliceEnd[i] = tmpEndValue;
387 : }
388 :
389 : tilingData.set_yShape(tilingParams.yShapeOut);
390 : tilingData.set_sliceStart(tilingParams.sliceStart);
391 : tilingData.set_sliceEnd(tilingParams.sliceEnd);
392 : OP_LOGD(context_->GetNodeName(), "Print Y shape is empty: %d. ", tilingParams.IsEmptyYShape);
393 : return ge::GRAPH_SUCCESS;
394 : }
395 :
396 : void SparseSliceTiling::GetValueList(size_t idx, const gert::Tensor* tensor, int64_t size, gert::Shape& valueList)
397 : {
398 : if (size > 0) {
399 : if (tensor->GetDataType() == ge::DT_INT64) {
400 : GetConstValueToShape<int64_t>(tensor, size, &valueList);
401 : OP_LOGD(context_->GetNodeName(), "GetConstValueToShape successfully");
402 : } else {
403 : OP_LOGD(context_->GetNodeName(), "input[%zu] data type is invalid: %d", idx, tensor->GetDataType());
404 : }
405 : }
406 : }
407 :
408 : static ge::graphStatus Tiling4SparseSlice(gert::TilingContext* context_)
409 : {
410 : OP_TILING_CHECK(context_ == nullptr, OP_LOGE("SparseSlice", "context_ should not be nullptr."),
411 : return ge::GRAPH_FAILED);
412 :
413 : if (IsRegbaseSocVersion(context_)) {
414 : SparseSliceTiling tiling(context_);
415 : ge::graphStatus status = tiling.DoTiling();
416 : return status;
417 : }
418 :
419 : return ge::GRAPH_FAILED;
420 : }
421 :
422 : ge::graphStatus TilingPrepare4SparseSlice(gert::TilingParseContext* context_)
423 : {
424 : auto compileInfo = GetCompileInfoPtr<SparseSliceCompileInfo>(context_);
425 : OP_CHECK_NULL_WITH_CONTEXT(context_, compileInfo);
426 : auto platformInfo = context_->GetPlatformInfo();
427 : OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo);
428 : auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo);
429 : compileInfo->coreNum = ascendcPlatform.GetCoreNumAiv();
430 : ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, compileInfo->ubSize);
431 : OP_TILING_CHECK((compileInfo->coreNum <= 0 || compileInfo->ubSize <= 0),
432 : OP_LOGE(context_->GetNodeName(), "SparseSlice GetHardwareInfo Failed, coreNum:%d, ubSize:%ld.",
433 : compileInfo->coreNum, compileInfo->ubSize),
434 : return ge::GRAPH_FAILED);
435 : OP_LOGD(context_->GetNodeName(), "GetCoreNum:%d, ubSize:%lu", compileInfo->coreNum, compileInfo->ubSize);
436 :
437 : return ge::GRAPH_SUCCESS;
438 : }
439 :
440 : IMPL_OP_OPTILING(SparseSlice)
441 : .Tiling(Tiling4SparseSlice)
442 : .TilingParse<SparseSliceCompileInfo>(TilingPrepare4SparseSlice)
443 : .TilingInputsDataDependency({SHAPE_IDX, START_IDX, SIZE_IDX});
444 : } // namespace optiling
|