Closed
fix(normalize_bbox): 修复FP16大除数精度并补齐推导校验 #13275
raoliang_sacAdd on 21 days agoClosed at 18 days ago
fix(normalize_bbox): 修复FP16大除数精度并补齐推导校验 #13275
Closed
raoliang_sacAdd on 21 days agoClosed at 18 days ago
Total: 13 files changed+259-91
@@ -5,11 +5,11 @@
5| 产品 | 是否支持 |5| 产品 | 是否支持 |
6| :----------------------------------------- | :------: |6| :----------------------------------------- | :------: |
7| <term>Ascend 950PR&950DT系列产品</term> | √ |7| <term>Ascend 950PR&950DT系列产品</term> | √ |
8-| <term>Atlas A3系列产品</term>| × |8+| <term>Atlas A3系列产品</term>| √ |
9-| <term>Atlas A2系列产品</term> | × |9+| <term>Atlas A2系列产品</term> | √ |
10-| <term>Atlas 200I/500 A2推理产品</term> | × |10+| <term>Atlas 200I/500 A2推理产品</term> | √ |
11-| <term>Atlas推理系列产品</term> | × |11+| <term>Atlas推理系列产品</term> | √ |
12-| <term>Atlas训练系列产品</term> | × |12+| <term>Atlas训练系列产品</term> | √ |
13 13 
14## 功能说明14## 功能说明
15 15 
@@ -37,12 +37,6 @@
37| y | 输出 | 换算后的相对坐标,shape和数据类型与`boxes`一致。 | FLOAT、FLOAT16 | ND |37| y | 输出 | 换算后的相对坐标,shape和数据类型与`boxes`一致。 | FLOAT、FLOAT16 | ND |
38| reversed_box | 可选属性 | 指定`boxes`的坐标轴位置,默认值为false。 | BOOL | - |38| reversed_box | 可选属性 | 指定`boxes`的坐标轴位置,默认值为false。 | BOOL | - |
39 39 
40-### 产品差异说明
41- 
42-| 产品 | 静态shape能力 | 动态shape能力 | shape/rank及空Tensor限制 |
43-| --- | --- | --- | --- |
44-| <term>Ascend 950PR&950DT系列产品</term> | 输入、输出均为ND | 支持动态shape和动态rank,输入、输出均为ND | `boxes`的rank为2~8;支持batch或非坐标维为0的空Tensor,坐标维必须为4 |
45- 
46## 约束说明40## 约束说明
47 41 
48- `shape_hw`的batch必须与`boxes`的batch一致。42- `shape_hw`的batch必须与`boxes`的batch一致。
@@ -62,6 +56,6 @@
62 56 
63本算子不提供aclnn单算子接口,通过图引擎(Graph Engine,GE)图模式调用。57本算子不提供aclnn单算子接口,通过图引擎(Graph Engine,GE)图模式调用。
64 58 
65-| 调用方式 | 调用样例 | 说明 |59+| 调用方式 | 样例代码 | 说明 |
66| --- | --- | --- |60| --- | --- | --- |
67| GE图模式 | [test_geir_normalize_bbox.cpp](examples/arch35/test_geir_normalize_bbox.cpp) | 通过[NormalizeBBox算子IR](op_graph/normalize_bbox_proto.h)构图并调用算子。 |61| GE图模式 | [test_geir_normalize_bbox.cpp](examples/arch35/test_geir_normalize_bbox.cpp) | 通过[NormalizeBBox算子IR](op_graph/normalize_bbox_proto.h)构图并调用算子。 |
@@ -21,15 +21,28 @@
21namespace ops {21namespace ops {
22namespace {22namespace {
23constexpr size_t INPUT_BOXES_IDX = 0;23constexpr size_t INPUT_BOXES_IDX = 0;
24+constexpr size_t INPUT_SHAPE_HW_IDX = 1;
24constexpr size_t OUTPUT_Y_IDX = 0;25constexpr size_t OUTPUT_Y_IDX = 0;
25} // namespace26} // namespace
26 27 
27-static ge::graphStatus NormalizeBBoxInferDataType(gert::InferDataTypeContext* context)28+ge::graphStatus NormalizeBBoxInferDataType(gert::InferDataTypeContext* context)
28{29{
30+ if (context == nullptr) {
31+ return ge::GRAPH_FAILED;
32+ }
29 OP_LOGD(context, "NormalizeBBoxInferDataType enter");33 OP_LOGD(context, "NormalizeBBoxInferDataType enter");
30- context->SetOutputDataType(OUTPUT_Y_IDX, context->GetInputDataType(INPUT_BOXES_IDX));34+ const auto boxesDtype = context->GetInputDataType(INPUT_BOXES_IDX);
35+ OP_CHECK_IF(boxesDtype != ge::DT_FLOAT16 && boxesDtype != ge::DT_FLOAT,
36+ OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(context->GetNodeName(), "boxes", Ops::Base::ToString(boxesDtype),
37+ "only float16 and float32 are supported"),
38+ return ge::GRAPH_FAILED);
39+ OP_CHECK_IF(context->GetInputDataType(INPUT_SHAPE_HW_IDX) != ge::DT_INT32,
40+ OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(
41+ context->GetNodeName(), "shape_hw",
42+ Ops::Base::ToString(context->GetInputDataType(INPUT_SHAPE_HW_IDX)), "only int32 is supported"),
43+ return ge::GRAPH_FAILED);
31 OP_LOGD(context, "NormalizeBBoxInferDataType end");44 OP_LOGD(context, "NormalizeBBoxInferDataType end");
32- return ge::GRAPH_SUCCESS;45+ return context->SetOutputDataType(OUTPUT_Y_IDX, boxesDtype);
33}46}
34 47 
35IMPL_OP(NormalizeBBox).InferDataType(NormalizeBBoxInferDataType);48IMPL_OP(NormalizeBBox).InferDataType(NormalizeBBoxInferDataType);
@@ -21,14 +21,70 @@
21using namespace ge;21using namespace ge;
22namespace ops {22namespace ops {
23static constexpr size_t INPUT_BOXES_IDX = 0;23static constexpr size_t INPUT_BOXES_IDX = 0;
24+static constexpr size_t INPUT_SHAPE_HW_IDX = 1;
24static constexpr size_t OUTPUT_Y_IDX = 0;25static constexpr size_t OUTPUT_Y_IDX = 0;
26+static constexpr size_t MAX_BOXES_RANK = 8;
27+ 
28+static ge::graphStatus CheckNormalizeBBoxShapes(gert::InferShapeContext* context, const gert::Shape& boxesShape,
29+ const gert::Shape& shapeHwShape)
30+{
31+ const bool unknownBoxesRank = Ops::Base::IsUnknownRank(boxesShape);
32+ const bool unknownHwRank = Ops::Base::IsUnknownRank(shapeHwShape);
33+ if (!unknownHwRank) {
34+ OP_CHECK_IF(shapeHwShape.GetDimNum() != 2,
35+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(
36+ context->GetNodeName(), "shape_hw", std::to_string(shapeHwShape.GetDimNum()), "rank must be 2"),
37+ return ge::GRAPH_FAILED);
38+ const auto width = shapeHwShape.GetDim(1);
39+ OP_CHECK_IF(width >= 0 && width != 3,
40+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(context->GetNodeName(), "shape_hw",
41+ Ops::Base::ToString(shapeHwShape), "dimension 1 must be 3"),
42+ return ge::GRAPH_FAILED);
43+ }
44+ if (!unknownBoxesRank) {
45+ const auto rank = boxesShape.GetDimNum();
46+ OP_CHECK_IF(rank < 2 || rank > MAX_BOXES_RANK,
47+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context->GetNodeName(), "boxes", std::to_string(rank),
48+ "rank must be in [2, 8]"),
49+ return ge::GRAPH_FAILED);
50+ const auto* attrs = context->GetAttrs();
51+ const auto* reversed = attrs == nullptr ? nullptr : attrs->GetAttrPointer<bool>(0);
52+ const size_t coordinateAxis = reversed != nullptr && *reversed ? 1 : rank - 1;
53+ const auto coordinateSize = boxesShape.GetDim(coordinateAxis);
54+ OP_CHECK_IF(
55+ coordinateSize >= 0 && coordinateSize != 4,
56+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(context->GetNodeName(), "boxes", Ops::Base::ToString(boxesShape),
57+ "coordinate dimension must be 4"),
58+ return ge::GRAPH_FAILED);
59+ }
60+ if (!unknownBoxesRank && !unknownHwRank) {
61+ const auto boxesBatch = boxesShape.GetDim(0);
62+ const auto hwBatch = shapeHwShape.GetDim(0);
63+ OP_CHECK_IF(boxesBatch >= 0 && hwBatch >= 0 && boxesBatch != hwBatch,
64+ OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(
65+ context->GetNodeName(), "boxes, shape_hw",
66+ Ops::Base::ToString(boxesShape) + ", " + Ops::Base::ToString(shapeHwShape),
67+ "batch dimensions must match"),
68+ return ge::GRAPH_FAILED);
69+ }
70+ return ge::GRAPH_SUCCESS;
71+}
25 72 
26static ge::graphStatus NormalizeBBoxInferShape(gert::InferShapeContext* context)73static ge::graphStatus NormalizeBBoxInferShape(gert::InferShapeContext* context)
27{74{
75+ if (context == nullptr) {
76+ return ge::GRAPH_FAILED;
77+ }
28 OP_LOGD(context, "Begin to do NormalizeBBoxInferShape");78 OP_LOGD(context, "Begin to do NormalizeBBoxInferShape");
29 79 
30 const gert::Shape* boxesShape = context->GetInputShape(INPUT_BOXES_IDX);80 const gert::Shape* boxesShape = context->GetInputShape(INPUT_BOXES_IDX);
31 OP_CHECK_NULL_WITH_CONTEXT(context, boxesShape);81 OP_CHECK_NULL_WITH_CONTEXT(context, boxesShape);
82+ const gert::Shape* shapeHwShape = context->GetInputShape(INPUT_SHAPE_HW_IDX);
83+ OP_CHECK_NULL_WITH_CONTEXT(context, shapeHwShape);
84+ const auto shapeStatus = CheckNormalizeBBoxShapes(context, *boxesShape, *shapeHwShape);
85+ if (shapeStatus != ge::GRAPH_SUCCESS) {
86+ return shapeStatus;
87+ }
32 gert::Shape* yShape = context->GetOutputShape(OUTPUT_Y_IDX);88 gert::Shape* yShape = context->GetOutputShape(OUTPUT_Y_IDX);
33 OP_CHECK_NULL_WITH_CONTEXT(context, yShape);89 OP_CHECK_NULL_WITH_CONTEXT(context, yShape);
34 if (Ops::Base::IsUnknownRank(*boxesShape)) {90 if (Ops::Base::IsUnknownRank(*boxesShape)) {
@@ -224,11 +224,13 @@ ge::graphStatus NormalizeBBoxTilingForRegbase::GetShapeAttrsInfo()
224ge::graphStatus NormalizeBBoxTilingForRegbase::ComputeTileLen()224ge::graphStatus NormalizeBBoxTilingForRegbase::ComputeTileLen()
225{225{
226 uint64_t divisorBlocks = reversedBox_ ? 2 : 1;226 uint64_t divisorBlocks = reversedBox_ ? 2 : 1;
227- uint64_t ubBufFactor = 2 + 2 + divisorBlocks;227+ const uint64_t computeDtypeSize = sizeof(float);
228+ const uint64_t computeBytesPerElem = boxesDType_ == ge::DT_FLOAT16 ? computeDtypeSize : 0;
229+ const uint64_t ubBytesPerElem = 4 * boxesDtypeSize_ + divisorBlocks * computeDtypeSize + computeBytesPerElem;
228 uint64_t blockAlignElems = VREPEAT_SIZE / boxesDtypeSize_;230 uint64_t blockAlignElems = VREPEAT_SIZE / boxesDtypeSize_;
229 uint64_t tileLen = 0;231 uint64_t tileLen = 0;
230 if (ubSize_ > UB_RESERVE) {232 if (ubSize_ > UB_RESERVE) {
231- tileLen = (ubSize_ - UB_RESERVE) / (ubBufFactor * boxesDtypeSize_);233+ tileLen = (ubSize_ - UB_RESERVE) / ubBytesPerElem;
232 }234 }
233 tileLen = tileLen / blockAlignElems * blockAlignElems;235 tileLen = tileLen / blockAlignElems * blockAlignElems;
234 if (tileLen > MAX_TILE_LEN) {236 if (tileLen > MAX_TILE_LEN) {
@@ -241,9 +243,10 @@ ge::graphStatus NormalizeBBoxTilingForRegbase::ComputeTileLen()
241 tilingData_.boxesBufferBytes = tileLen * boxesDtypeSize_;243 tilingData_.boxesBufferBytes = tileLen * boxesDtypeSize_;
242 tilingData_.shapeBufferBytes = BLOCK_SIZE;244 tilingData_.shapeBufferBytes = BLOCK_SIZE;
243 tilingData_.hwCastBufferBytes = BLOCK_SIZE * 2;245 tilingData_.hwCastBufferBytes = BLOCK_SIZE * 2;
244- tilingData_.divisorBufferBytes = tileLen * boxesDtypeSize_ * divisorBlocks;246+ tilingData_.divisorBufferBytes = tileLen * computeDtypeSize * divisorBlocks;
245 const uint64_t requiredUb = UB_RESERVE + tilingData_.boxesBufferBytes * 2 * 2 + tilingData_.shapeBufferBytes +247 const uint64_t requiredUb = UB_RESERVE + tilingData_.boxesBufferBytes * 2 * 2 + tilingData_.shapeBufferBytes +
246- tilingData_.hwCastBufferBytes + tilingData_.divisorBufferBytes;248+ tilingData_.hwCastBufferBytes + tilingData_.divisorBufferBytes +
249+ tileLen * computeBytesPerElem;
247 OP_CHECK_IF(requiredUb > ubSize_,250 OP_CHECK_IF(requiredUb > ubSize_,
248 OP_LOGE(opName_, "UB is too small: required=%luB available=%luB.", requiredUb, ubSize_),251 OP_LOGE(opName_, "UB is too small: required=%luB available=%luB.", requiredUb, ubSize_),
249 return ge::GRAPH_FAILED);252 return ge::GRAPH_FAILED);
@@ -32,18 +32,12 @@ constexpr int64_t NB_BLOCK_SIZE = 32;
32constexpr int64_t NB_VREPEAT_SIZE = 256;32constexpr int64_t NB_VREPEAT_SIZE = 256;
33constexpr int64_t NB_DOUBLE_BUFFER = 2;33constexpr int64_t NB_DOUBLE_BUFFER = 2;
34constexpr uint64_t NB_ODD_LANE_MASK = 0xAAAAAAAAAAAAAAAAULL; // odd lanes (x-system coords) -> w34constexpr uint64_t NB_ODD_LANE_MASK = 0xAAAAAAAAAAAAAAAAULL; // odd lanes (x-system coords) -> w
35-constexpr int64_t NB_MASK_ELEM_WIDTH = 128; // mask Duplicate covers 128 CompT elements per repeat35+constexpr int64_t NB_MASK_ELEM_WIDTH = 128; // divisor coverage alignment (two fp32 repeats)
36constexpr size_t NB_MASK_WORD_COUNT = 2;36constexpr size_t NB_MASK_WORD_COUNT = 2;
37constexpr uint8_t NB_DUPLICATE_REPEAT_COUNT = 1;37constexpr uint8_t NB_DUPLICATE_REPEAT_COUNT = 1;
38constexpr uint8_t NB_DUPLICATE_BLOCK_STRIDE = 1;38constexpr uint8_t NB_DUPLICATE_BLOCK_STRIDE = 1;
39constexpr uint8_t NB_DUPLICATE_REPEAT_STRIDE = 8;39constexpr uint8_t NB_DUPLICATE_REPEAT_STRIDE = 8;
40 40 
41-// Compute type: boxes dtype is half or float, Div runs in-place (CompT == T).
42-template <typename T>
43-struct DivCompute {
44- using Type = T;
45-};
46- 
47template <typename T, bool reversedBox>41template <typename T, bool reversedBox>
48class NormalizeBBoxKernel {42class NormalizeBBoxKernel {
49public:43public:
@@ -52,7 +46,8 @@ public:
52 __aicore__ inline void Init(GM_ADDR boxes, GM_ADDR shape_hw, GM_ADDR y);46 __aicore__ inline void Init(GM_ADDR boxes, GM_ADDR shape_hw, GM_ADDR y);
53 __aicore__ inline void Process();47 __aicore__ inline void Process();
54 48 
55- using CompT = typename DivCompute<T>::Type;49+ // Keep int32 image dimensions in fp32, including dimensions above 65504.
50+ using CompT = float;
56 51 
57private:52private:
58 __aicore__ inline void LoadHW(int64_t b, CompT& h, CompT& w);53 __aicore__ inline void LoadHW(int64_t b, CompT& h, CompT& w);
@@ -82,8 +77,9 @@ private:
82 TQue<QuePosition::VECIN, NB_DOUBLE_BUFFER> boxesInQue_;77 TQue<QuePosition::VECIN, NB_DOUBLE_BUFFER> boxesInQue_;
83 TQue<QuePosition::VECOUT, NB_DOUBLE_BUFFER> boxesOutQue_;78 TQue<QuePosition::VECOUT, NB_DOUBLE_BUFFER> boxesOutQue_;
84 TQue<QuePosition::VECIN, 1> shapeInQue_; // shape_hw 3 int32 per batch79 TQue<QuePosition::VECIN, 1> shapeInQue_; // shape_hw 3 int32 per batch
85- TBuf<TPosition::VECCALC> hwCastBuf_; // int32 -> f32 [-> half] scratch for h/w80+ TBuf<TPosition::VECCALC> hwCastBuf_; // int32 -> f32 scratch for h/w
86 TBuf<TPosition::VECCALC> divisorBuf_; // divisor block(s), in CompT81 TBuf<TPosition::VECCALC> divisorBuf_; // divisor block(s), in CompT
82+ TBuf<TPosition::VECCALC> computeBuf_; // fp16 boxes -> fp32 division scratch
87 83 
88 GlobalTensor<T> boxesGm_;84 GlobalTensor<T> boxesGm_;
89 GlobalTensor<T> yGm_;85 GlobalTensor<T> yGm_;
@@ -126,14 +122,15 @@ __aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::Init(GM_ADDR boxes,
126 tpipe_.InitBuffer(boxesInQue_, NB_DOUBLE_BUFFER, tiling_.boxesBufferBytes);122 tpipe_.InitBuffer(boxesInQue_, NB_DOUBLE_BUFFER, tiling_.boxesBufferBytes);
127 tpipe_.InitBuffer(boxesOutQue_, NB_DOUBLE_BUFFER, tiling_.boxesBufferBytes);123 tpipe_.InitBuffer(boxesOutQue_, NB_DOUBLE_BUFFER, tiling_.boxesBufferBytes);
128 tpipe_.InitBuffer(shapeInQue_, 1, tiling_.shapeBufferBytes); // 3 int32 fits in one 32B block124 tpipe_.InitBuffer(shapeInQue_, 1, tiling_.shapeBufferBytes); // 3 int32 fits in one 32B block
129- tpipe_.InitBuffer(hwCastBuf_, tiling_.hwCastBufferBytes); // f32 + half scratch125+ tpipe_.InitBuffer(hwCastBuf_, tiling_.hwCastBufferBytes);
130 // divisor is in CompT: normal needs 1 full-width block; reversed needs divH + divW (2 blocks)126 // divisor is in CompT: normal needs 1 full-width block; reversed needs divH + divW (2 blocks)
131 tpipe_.InitBuffer(divisorBuf_, tiling_.divisorBufferBytes);127 tpipe_.InitBuffer(divisorBuf_, tiling_.divisorBufferBytes);
128+ if constexpr (std::is_same_v<T, half>) {
129+ tpipe_.InitBuffer(computeBuf_, tileLen_ * sizeof(CompT));
130+ }
132}131}
133 132 
134-// Load shape_hw[b] = [h, w, *] (int32) -> Cast to CompT scalars h, w.133+// Load shape_hw[b] = [h, w, *] without narrowing the int32 dimensions to fp16.
135-// CompT is float for float and half for half. The divisor is built in CompT, so
136-// the whole divide runs in CompT (cast chain: int32->f32->[f16 for half boxes]->divide).
137template <typename T, bool reversedBox>134template <typename T, bool reversedBox>
138__aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::LoadHW(int64_t b, CompT& h, CompT& w)135__aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::LoadHW(int64_t b, CompT& h, CompT& w)
139{136{
@@ -149,21 +146,10 @@ __aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::LoadHW(int64_t b, Co
149 PipeBarrier<PIPE_V>();146 PipeBarrier<PIPE_V>();
150 147 
151 event_t eventVS = static_cast<event_t>(GetTPipePtr()->FetchEventID(HardEvent::V_S));148 event_t eventVS = static_cast<event_t>(GetTPipePtr()->FetchEventID(HardEvent::V_S));
152- if constexpr (std::is_same_v<CompT, half>) {149+ SetFlag<HardEvent::V_S>(eventVS);
153- LocalTensor<half> hwHalf = hwCastBuf_.Get<half>()[16]; // separate 32B block (byte 32)150+ WaitFlag<HardEvent::V_S>(eventVS);
154- Cast(hwHalf, hwF32, RoundMode::CAST_RINT, 3); // float32 -> half151+ h = hwF32.GetValue(0);
155- PipeBarrier<PIPE_V>();152+ w = hwF32.GetValue(1);
156- SetFlag<HardEvent::V_S>(eventVS);
157- WaitFlag<HardEvent::V_S>(eventVS);
158- h = hwHalf.GetValue(0);
159- w = hwHalf.GetValue(1);
160- } else {
161- // CompT == float: read h/w directly as float
162- SetFlag<HardEvent::V_S>(eventVS);
163- WaitFlag<HardEvent::V_S>(eventVS);
164- h = hwF32.GetValue(0);
165- w = hwF32.GetValue(1);
166- }
167 shapeInQue_.FreeTensor(shapeLocal);153 shapeInQue_.FreeTensor(shapeLocal);
168}154}
169 155 
@@ -176,10 +162,8 @@ __aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::BuildDivisorNormal(c
176 Duplicate(divisor, h, divWidth); // all lanes = h162 Duplicate(divisor, h, divWidth); // all lanes = h
177 PipeBarrier<PIPE_V>();163 PipeBarrier<PIPE_V>();
178 // overwrite odd lanes (x-system coords) with w via masked Duplicate.164 // overwrite odd lanes (x-system coords) with w via masked Duplicate.
179- // DAV_3510 Vector lane count is dtype-dependent: 128 for 2-byte (half), 64 for 4-byte (float).165+ // Each 256B repeat holds 64 fp32 divisors and uses the first 64 mask bits.
180- // mask[2] has 128 bits, but only the first 64 are effective for 4-byte CompT on 3510,166+ // Fill every repeat separately so all odd lanes receive the width.
181- // so elements 64+ would keep h instead of w if we used a single 128-element repeat.
182- // Process in chunks of 256/sizeof(CompT) elements (64 for float, 128 for half) to cover all dtypes.
183 constexpr int32_t maskElemWidth = NB_VREPEAT_SIZE / static_cast<int32_t>(sizeof(CompT));167 constexpr int32_t maskElemWidth = NB_VREPEAT_SIZE / static_cast<int32_t>(sizeof(CompT));
184 uint64_t mask[NB_MASK_WORD_COUNT] = {NB_ODD_LANE_MASK, NB_ODD_LANE_MASK};168 uint64_t mask[NB_MASK_WORD_COUNT] = {NB_ODD_LANE_MASK, NB_ODD_LANE_MASK};
185 for (int32_t off = 0; off < divWidth; off += maskElemWidth) {169 for (int32_t off = 0; off < divWidth; off += maskElemWidth) {
@@ -198,7 +182,7 @@ __aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::BuildConstBlock(cons
198}182}
199 183 
200// CopyIn one tile -> Div by divisor -> CopyOut.184// CopyIn one tile -> Div by divisor -> CopyOut.
201-// half/float: Div runs directly in T (CompT == T).185+// fp16 inputs are widened before division and rounded once on output.
202template <typename T, bool reversedBox>186template <typename T, bool reversedBox>
203__aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::CopyDivide(int64_t gmOffset, int64_t processLen,187__aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::CopyDivide(int64_t gmOffset, int64_t processLen,
204 const LocalTensor<CompT>& divisor)188 const LocalTensor<CompT>& divisor)
@@ -211,7 +195,16 @@ __aicore__ inline void NormalizeBBoxKernel<T, reversedBox>::CopyDivide(int64_t g
211 195 
212 boxesIn = boxesInQue_.template DeQue<T>();196 boxesIn = boxesInQue_.template DeQue<T>();
213 LocalTensor<T> boxesOut = boxesOutQue_.template AllocTensor<T>();197 LocalTensor<T> boxesOut = boxesOutQue_.template AllocTensor<T>();
214- Div(boxesOut, boxesIn, divisor, static_cast<int32_t>(processLen));198+ if constexpr (std::is_same_v<T, half>) {
199+ LocalTensor<CompT> compute = computeBuf_.Get<CompT>();
200+ Cast(compute, boxesIn, RoundMode::CAST_NONE, static_cast<int32_t>(processLen));
201+ PipeBarrier<PIPE_V>();
202+ Div(compute, compute, divisor, static_cast<int32_t>(processLen));
203+ PipeBarrier<PIPE_V>();
204+ Cast(boxesOut, compute, RoundMode::CAST_RINT, static_cast<int32_t>(processLen));
205+ } else {
206+ Div(boxesOut, boxesIn, divisor, static_cast<int32_t>(processLen));
207+ }
215 boxesInQue_.FreeTensor(boxesIn);208 boxesInQue_.FreeTensor(boxesIn);
216 boxesOutQue_.EnQue(boxesOut);209 boxesOutQue_.EnQue(boxesOut);
217 210 
@@ -41,7 +41,7 @@ struct NormalizeBBoxTilingData {
41 int64_t shapeElements; // shape_hw 总元素数(batch*3)41 int64_t shapeElements; // shape_hw 总元素数(batch*3)
42 uint64_t boxesBufferBytes; // boxes input/output 各 queue 单 buffer 字节数42 uint64_t boxesBufferBytes; // boxes input/output 各 queue 单 buffer 字节数
43 uint64_t shapeBufferBytes; // shape_hw queue 字节数43 uint64_t shapeBufferBytes; // shape_hw queue 字节数
44- uint64_t hwCastBufferBytes; // int32->fp32/half 临时 buffer 字节数44+ uint64_t hwCastBufferBytes; // int32->fp32 临时 buffer 字节数
45 uint64_t divisorBufferBytes; // divisor buffer 字节数45 uint64_t divisorBufferBytes; // divisor buffer 字节数
46};46};
47#pragma pack(pop)47#pragma pack(pop)
@@ -11,10 +11,9 @@
11 11 
12"""NormalizeBBox kernel/GEIR golden (TestSpec multi-path form).12"""NormalizeBBox kernel/GEIR golden (TestSpec multi-path form).
13 13 
14-The mathematical golden uses Torch tensor composition and honors TTK Promote:14+The mathematical reference preserves TTK Promote and performs at least fp32
15-it computes in the dtype presented by the framework and never narrows a promoted15+division, so int32 image dimensions are never narrowed to fp16. The independent
16-fp64/fp32 input. The independent third-party compose mirrors the arch35 kernel's16+GPU composition follows the formula rather than reproducing kernel casts.
17-dtype-dependent int32 -> fp32 [-> fp16] divisor construction and division path.
18"""17"""
19 18 
20import numpy as np19import numpy as np
@@ -73,6 +72,8 @@ def _compute(boxes, shape_hw, reversed_box=False):
73 active reference precision and never cuts a promoted input back down.72 active reference precision and never cuts a promoted input back down.
74 """73 """
75 boxes_tensor = _as_tensor(boxes)74 boxes_tensor = _as_tensor(boxes)
75+ if boxes_tensor.dtype == torch.float16:
76+ boxes_tensor = boxes_tensor.to(torch.float32)
76 shape_tensor = _as_tensor(shape_hw)77 shape_tensor = _as_tensor(shape_hw)
77 78 
78 batch = boxes_tensor.shape[0]79 batch = boxes_tensor.shape[0]
@@ -108,7 +109,7 @@ def _numpy_outputs(outputs, output_dtypes=None):
108 109 
109 110 
110class _NormalizeBBoxCompose:111class _NormalizeBBoxCompose:
111- """Independent Torch compose matching the arch35 kernel operation order."""112+ """Independent GPU reference for coordinate normalization."""
112 113 
113 def __init__(self, reversed_box=False, **kwargs):114 def __init__(self, reversed_box=False, **kwargs):
114 self.reversed_box = _resolve_reversed_box(reversed_box, kwargs)115 self.reversed_box = _resolve_reversed_box(reversed_box, kwargs)
@@ -121,14 +122,9 @@ class _NormalizeBBoxCompose:
121 f"got {output_dtype}"122 f"got {output_dtype}"
122 )123 )
123 124 
124- # NormalizeBBoxKernel::LoadHW, line for line at dtype level:125+ # Image dimensions may exceed the finite fp16 range even when the
125- # shape input is int32, then Cast int32 -> fp32, and fp16 boxes take one126+ # normalized coordinates are representable. Divide before narrowing.
126- # additional Cast fp32 -> fp16 before Div; fp32 boxes stay in fp32.127+ hw_compute = shape_hw.to(dtype=torch.float32)
127- shape_i32 = shape_hw.to(dtype=torch.int32)
128- hw_f32 = shape_i32.to(dtype=torch.float32)
129- hw_compute = (
130- hw_f32.to(dtype=torch.float16) if output_dtype == torch.float16 else hw_f32
131- )
132 height = hw_compute[:, 0]128 height = hw_compute[:, 0]
133 width = hw_compute[:, 1]129 width = hw_compute[:, 1]
134 divisor4 = torch.stack((height, width, height, width), dim=1)130 divisor4 = torch.stack((height, width, height, width), dim=1)
@@ -141,8 +137,7 @@ class _NormalizeBBoxCompose:
141 divisor_shape = (batch,) + (1,) * (rank - 2) + (4,)137 divisor_shape = (batch,) + (1,) * (rank - 2) + (4,)
142 divisor = torch.reshape(divisor4, divisor_shape)138 divisor = torch.reshape(divisor4, divisor_shape)
143 139 
144- # NormalizeBBoxKernel::CopyDivide performs Div directly in boxes dtype.140+ output = torch.div(boxes.to(torch.float32), divisor)
145- output = torch.div(boxes, divisor)
146 return [output.to(dtype=output_dtype)]141 return [output.to(dtype=output_dtype)]
147 142 
148 143 
@@ -168,6 +163,7 @@ def normalize_bbox_golden(boxes, shape_hw, reversed_box=False, **kwargs):
168 input_is_tensor = isinstance(boxes, torch.Tensor)163 input_is_tensor = isinstance(boxes, torch.Tensor)
169 reversed_value = _resolve_reversed_box(reversed_box, kwargs)164 reversed_value = _resolve_reversed_box(reversed_box, kwargs)
170 output = _compute(boxes, shape_hw, reversed_value)[0]165 output = _compute(boxes, shape_hw, reversed_value)[0]
166+ output = output.to(dtype=_as_tensor(boxes).dtype)
171 if input_is_tensor:167 if input_is_tensor:
172 return output168 return output
173 return output.detach().cpu().numpy()169 return output.detach().cpu().numpy()
@@ -0,0 +1,9 @@
1+testcase_name,op_name,input_shapes,input_dtypes,input_formats,output_shapes,output_dtypes,output_formats,input_ori_shapes,input_ori_formats,output_ori_shapes,output_ori_formats,attributes,input_data_ranges,is_enabled,remark
2+nb_float16_normal,normalize_bbox,"((2, 3, 4), (2, 3))","('float16', 'int32')","('ND', 'ND')","((2, 3, 4),)","('float16',)","('ND',)","((2, 3, 4), (2, 3))","('ND', 'ND')","((2, 3, 4),)","('ND',)",{'reversed_box': False},"((-30, 100), (10, 200))",TRUE,
3+nb_float16_reversed,normalize_bbox,"((2, 4, 7), (2, 3))","('float16', 'int32')","('ND', 'ND')","((2, 4, 7),)","('float16',)","('ND',)","((2, 4, 7), (2, 3))","('ND', 'ND')","((2, 4, 7),)","('ND',)",{'reversed_box': True},"((-30, 100), (10, 200))",TRUE,
4+nb_float32_normal,normalize_bbox,"((2, 3, 4), (2, 3))","('float32', 'int32')","('ND', 'ND')","((2, 3, 4),)","('float32',)","('ND',)","((2, 3, 4), (2, 3))","('ND', 'ND')","((2, 3, 4),)","('ND',)",{'reversed_box': False},"((-30, 100), (10, 200))",TRUE,
5+nb_float32_rank8,normalize_bbox,"((1, 1, 2, 1, 1, 1, 1, 4), (1, 3))","('float32', 'int32')","('ND', 'ND')","((1, 1, 2, 1, 1, 1, 1, 4),)","('float32',)","('ND',)","((1, 1, 2, 1, 1, 1, 1, 4), (1, 3))","('ND', 'ND')","((1, 1, 2, 1, 1, 1, 1, 4),)","('ND',)",{'reversed_box': False},"((-20, 20), (11, 200))",TRUE,
6+nb_float16_large_hw,normalize_bbox,"((1, 3, 4), (1, 3))","('float16', 'int32')","('ND', 'ND')","((1, 3, 4),)","('float16',)","('ND',)","((1, 3, 4), (1, 3))","('ND', 'ND')","((1, 3, 4),)","('ND',)",{'reversed_box': False},"((1000, 1000), (65536, 65536))",TRUE,int32 divisor above float16 range; expected 1000/65536
7+nb_float32_large_hw,normalize_bbox,"((1, 3, 4), (1, 3))","('float32', 'int32')","('ND', 'ND')","((1, 3, 4),)","('float32',)","('ND',)","((1, 3, 4), (1, 3))","('ND', 'ND')","((1, 3, 4),)","('ND',)",{'reversed_box': False},"((1000, 1000), (65536, 65536))",TRUE,int32 divisor above float16 range; expected 1000/65536
8+nb_float16_split_num_tail,normalize_bbox,"((1, 1027, 4), (1, 3))","('float16', 'int32')","('ND', 'ND')","((1, 1027, 4),)","('float16',)","('ND',)","((1, 1027, 4), (1, 3))","('ND', 'ND')","((1, 1027, 4),)","('ND',)",{'reversed_box': False},"((-20, 20), (3, 233))",TRUE,
9+nb_float32_empty_num,normalize_bbox,"((2, 4, 0), (2, 3))","('float32', 'int32')","('ND', 'ND')","((2, 4, 0),)","('float32',)","('ND',)","((2, 4, 0), (2, 3))","('ND', 'ND')","((2, 4, 0),)","('ND',)",{'reversed_box': True},"((1, 2), (10, 200))",TRUE,
@@ -10,4 +10,5 @@
10 10 
11# 显式声明子目录,避免 file(GLOB) 对新增目录不敏感导致静默跳过编译11# 显式声明子目录,避免 file(GLOB) 对新增目录不敏感导致静默跳过编译
12add_subdirectory(op_host)12add_subdirectory(op_host)
13+add_subdirectory(op_graph)
13add_subdirectory(framework)14add_subdirectory(framework)
@@ -0,0 +1,11 @@
1+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3+# CANN Open Software License Agreement Version 2.0 (the "License").
4+# Please refer to the License for details. You may not use this file except in compliance with the License.
5+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
6+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
7+# See LICENSE in the root of the software repository for the full text of the License.
8+ 
9+if(UT_TEST_ALL OR OP_GRAPH_UT)
10+ add_modules_ut_sources(HOSTNAME ${OP_GRAPH_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
11+endif()
@@ -0,0 +1,44 @@
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+#include <gtest/gtest.h>
12+#include "base/context_builder/op_infer_datatype_context_builder.h"
13+ 
14+namespace ops {
15+ge::graphStatus NormalizeBBoxInferDataType(gert::InferDataTypeContext* context);
16+}
17+ 
18+TEST(NormalizeBBoxGraphInfer, validates_both_input_dtypes)
19+{
20+ struct Case {
21+ ge::DataType boxes;
22+ ge::DataType shapeHw;
23+ bool valid;
24+ };
25+ const Case cases[] = {
26+ {ge::DT_FLOAT16, ge::DT_INT32, true}, {ge::DT_FLOAT, ge::DT_INT32, true}, {ge::DT_BF16, ge::DT_INT32, false},
27+ {ge::DT_BOOL, ge::DT_INT32, false}, {ge::DT_INT32, ge::DT_INT32, false}, {ge::DT_FLOAT, ge::DT_BF16, false},
28+ {ge::DT_FLOAT, ge::DT_BOOL, false}, {ge::DT_FLOAT, ge::DT_FLOAT, false},
29+ };
30+ for (const auto& item : cases) {
31+ SCOPED_TRACE(static_cast<int>(item.boxes));
32+ gert::OpInferDataTypeContextBuilder builder;
33+ builder.OpType("NormalizeBBox").OpName("normalize_bbox_dtype_check").IONum(2, 1);
34+ builder.InputTensorDesc(0, item.boxes, ge::FORMAT_ND, ge::FORMAT_ND);
35+ builder.InputTensorDesc(1, item.shapeHw, ge::FORMAT_ND, ge::FORMAT_ND);
36+ builder.OutputTensorDesc(0, ge::FORMAT_ND, ge::FORMAT_ND);
37+ auto holder = builder.Build();
38+ ASSERT_NE(holder.GetContext(), nullptr);
39+ EXPECT_EQ(ops::NormalizeBBoxInferDataType(holder.GetContext()),
40+ item.valid ? ge::GRAPH_SUCCESS : ge::GRAPH_FAILED);
41+ if (item.valid)
42+ EXPECT_EQ(holder.GetContext()->GetOutputDataType(0), item.boxes);
43+ }
44+}
@@ -10,16 +10,7 @@
10 10 
11/*!11/*!
12 * \file test_normalize_bbox_infershape.cpp12 * \file test_normalize_bbox_infershape.cpp
13- * \brief NormalizeBBox InferShape UT (iteration-1 core path)13+ * \brief NormalizeBBox shape validation and propagation tests.
14- *
15- * Coverage:
16- * - InferShape: y.shape == boxes.shape for normal (batch,num,4) and reversed (batch,4,num) layouts
17- *
18- * InferDataType (y.dtype == boxes.dtype) now lives in
19- * op_graph/normalize_bbox_graph_infer.cpp: it is a graph-only deliverable. The op_graph
20- * UT module links graph_plugin_obj only and has no access to the tests/ut/common
21- * infershape fakers, so it is not covered here -- same as every other op in this repo
22- * that keeps InferDataType in op_graph (bn_infer_grad / lp_norm_update / in_infer_v2).
23 */14 */
24 15 
25#include <gtest/gtest.h>16#include <gtest/gtest.h>
@@ -28,6 +19,7 @@
28#include "infershape_test_util.h"19#include "infershape_test_util.h"
29#include "kernel_run_context_facker.h"20#include "kernel_run_context_facker.h"
30#include "log/log.h"21#include "log/log.h"
22+#include "base/context_builder/op_infer_shape_context_builder.h"
31 23 
32class NormalizeBBoxProto : public testing::Test {24class NormalizeBBoxProto : public testing::Test {
33protected:25protected:
@@ -70,6 +62,7 @@ TEST_F(NormalizeBBoxProto, normalize_bbox_infershape_reversed_layout)
70 auto holder = gert::InferShapeContextFaker()62 auto holder = gert::InferShapeContextFaker()
71 .NodeIoNum(2, 1)63 .NodeIoNum(2, 1)
72 .IrInstanceNum({1, 1})64 .IrInstanceNum({1, 1})
65+ .NodeAttrs({{"reversed_box", Ops::NN::AnyValue::CreateFrom<bool>(true)}})
73 .InputShapes({&boxesShape, &shapeHwShape})66 .InputShapes({&boxesShape, &shapeHwShape})
74 .OutputShapes({&yShape})67 .OutputShapes({&yShape})
75 .Build();68 .Build();
@@ -145,12 +138,6 @@ TEST_F(NormalizeBBoxProto, normalize_bbox_infershape_unknown_rank)
145 ASSERT_EQ(Ops::Base::ToString(*context->GetOutputShape(0)), "[-2]");138 ASSERT_EQ(Ops::Base::ToString(*context->GetOutputShape(0)), "[-2]");
146}139}
147 140 
148-// ============================================================================================
149-// Iteration-3: round out InferShape (layout) coverage.
150-// InferShape copies boxes->y verbatim (layout/dtype agnostic). dtype *rejection* lives
151-// in the host tiling layer, NOT in the proto layer.
152-// ============================================================================================
153- 
154// InferShape: reversed large layout (batch, 4, num) preserved verbatim141// InferShape: reversed large layout (batch, 4, num) preserved verbatim
155TEST_F(NormalizeBBoxProto, normalize_bbox_infershape_reversed_large_shape)142TEST_F(NormalizeBBoxProto, normalize_bbox_infershape_reversed_large_shape)
156{143{
@@ -164,6 +151,7 @@ TEST_F(NormalizeBBoxProto, normalize_bbox_infershape_reversed_large_shape)
164 auto holder = gert::InferShapeContextFaker()151 auto holder = gert::InferShapeContextFaker()
165 .NodeIoNum(2, 1)152 .NodeIoNum(2, 1)
166 .IrInstanceNum({1, 1})153 .IrInstanceNum({1, 1})
154+ .NodeAttrs({{"reversed_box", Ops::NN::AnyValue::CreateFrom<bool>(true)}})
167 .InputShapes({&boxesShape, &shapeHwShape})155 .InputShapes({&boxesShape, &shapeHwShape})
168 .OutputShapes({&yShape})156 .OutputShapes({&yShape})
169 .Build();157 .Build();
@@ -172,3 +160,56 @@ TEST_F(NormalizeBBoxProto, normalize_bbox_infershape_reversed_large_shape)
172 auto context = holder.GetContext<gert::InferShapeContext>();160 auto context = holder.GetContext<gert::InferShapeContext>();
173 ASSERT_EQ(Ops::Base::ToString(*context->GetOutputShape(0)), "[8, 4, 4096]");161 ASSERT_EQ(Ops::Base::ToString(*context->GetOutputShape(0)), "[8, 4, 4096]");
174}162}
163+ 
164+TEST_F(NormalizeBBoxProto, rejects_known_invalid_shapes_and_preserves_dynamic_shapes)
165+{
166+ struct Case {
167+ std::vector<int64_t> boxes;
168+ std::vector<int64_t> shapeHw;
169+ bool reversed;
170+ bool valid;
171+ };
172+ const std::vector<Case> cases = {
173+ {{4}, {4, 3}, false, false},
174+ {{1, 1, 1, 1, 1, 1, 1, 1, 4}, {1, 3}, false, false},
175+ {{2, 3, 4}, {6}, false, false},
176+ {{2, 3, 4}, {2, 1, 3}, false, false},
177+ {{2, 3, 4}, {2, 2}, false, false},
178+ {{2, 3, 4}, {3, 3}, false, false},
179+ {{2, 3, 3}, {2, 3}, false, false},
180+ {{2, 3, 4}, {2, 3}, true, false},
181+ {{-1, -1, 4}, {-1, 3}, false, true},
182+ {{2, 3, -1}, {2, 3}, false, true},
183+ {{-2}, {-2}, false, true},
184+ {{2, 0, 4}, {2, 3}, false, true},
185+ {{1, 1, 1, 1, 1, 1, 1, 4}, {1, 3}, false, true},
186+ };
187+ const auto* impl = gert::OpImplRegistry::GetInstance().GetOpImpl("NormalizeBBox");
188+ ASSERT_NE(impl, nullptr);
189+ ASSERT_NE(impl->infer_shape, nullptr);
190+ for (size_t index = 0; index < cases.size(); ++index) {
191+ SCOPED_TRACE(index);
192+ const auto& item = cases[index];
193+ gert::StorageShape boxesShape, hwShape;
194+ for (size_t i = 0; i < item.boxes.size(); ++i) {
195+ boxesShape.MutableOriginShape().AppendDim(item.boxes[i]);
196+ boxesShape.MutableStorageShape().AppendDim(item.boxes[i]);
197+ }
198+ for (size_t i = 0; i < item.shapeHw.size(); ++i) {
199+ hwShape.MutableOriginShape().AppendDim(item.shapeHw[i]);
200+ hwShape.MutableStorageShape().AppendDim(item.shapeHw[i]);
201+ }
202+ gert::Tensor boxes(boxesShape, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, ge::DT_FLOAT);
203+ gert::Tensor hw(hwShape, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, ge::DT_INT32);
204+ gert::OpInferShapeContextBuilder builder;
205+ builder.OpType("NormalizeBBox").OpName("normalize_bbox_shape_check").IONum(2, 1);
206+ builder.InputTensors({&boxes, &hw}).AppendAttr(item.reversed);
207+ builder.OutputTensorDesc(0, ge::DT_FLOAT, ge::FORMAT_ND, ge::FORMAT_ND);
208+ auto holder = builder.Build();
209+ ASSERT_NE(holder.GetContext(), nullptr);
210+ EXPECT_EQ(impl->infer_shape(holder.GetContext()), item.valid ? ge::GRAPH_SUCCESS : ge::GRAPH_FAILED);
211+ if (item.valid) {
212+ EXPECT_EQ(*holder.GetContext()->GetOutputShape(0), boxesShape.GetOriginShape());
213+ }
214+ }
215+}
@@ -703,7 +703,8 @@ TEST_F(NormalizeBBoxTiling, tiling_tilelen_ub_budget_capped)
703 703 
704// Additional op_host branch coverage.704// Additional op_host branch coverage.
705// Constants mirrored from normalize_bbox_regbase_tiling.cpp:705// Constants mirrored from normalize_bbox_regbase_tiling.cpp:
706-// UB_RESERVE=32*1024=32768, UB_BUF_FACTOR=5(normal)/6(reversed), VREPEAT_SIZE=256,706+// UB_RESERVE=32*1024=32768, VREPEAT_SIZE=256,
707+// per-element UB: fp32=20/24B, fp16=16/20B (normal/reversed),
707// MAX_TILE_LEN=8192.708// MAX_TILE_LEN=8192.
708// blockAlignElems = VREPEAT_SIZE/dsize -> fp32:64, fp16:128 (also the tileLen floor clamp).709// blockAlignElems = VREPEAT_SIZE/dsize -> fp32:64, fp16:128 (also the tileLen floor clamp).
709// Covered branches:710// Covered branches:
@@ -731,18 +732,24 @@ TEST_F(NormalizeBBoxTiling, tiling_fail_platform_zero_ubsize)
731}732}
732 733 
733// ---- tileLen minimum viable UB: reserve + explicit minimum buffers --------------------------734// ---- tileLen minimum viable UB: reserve + explicit minimum buffers --------------------------
734-// Normal fp32/fp16 both need 1376B beyond UB_RESERVE at their minimum 256B-repeat tile:735+// Minimum tiles use 1024B for boxes queues and 96B for image dimensions.
735-// boxes queues 1024B + shape 32B + cast 64B + divisor 256B.736+// FP32 adds a 256B divisor; FP16 adds a 512B divisor and 512B fp32 compute buffer.
736TEST_F(NormalizeBBoxTiling, tiling_tilelen_small_ub_clamp_to_blockalign)737TEST_F(NormalizeBBoxTiling, tiling_tilelen_small_ub_clamp_to_blockalign)
737{738{
738 constexpr uint64_t kUbReserve = 32u * 1024u;739 constexpr uint64_t kUbReserve = 32u * 1024u;
739- constexpr uint64_t kMinimumBuffers = 1376u;740+ constexpr uint64_t kMinimumFp32Buffers = 1376u;
740- auto f32 = RunTiling({1, 4096, 4}, {1, 3}, NORMAL_LAYOUT, ge::DT_FLOAT, CORE_NUM, kUbReserve + kMinimumBuffers);741+ constexpr uint64_t kMinimumFp16Buffers = 2144u;
741- auto f16 = RunTiling({1, 4096, 4}, {1, 3}, NORMAL_LAYOUT, ge::DT_FLOAT16, CORE_NUM, kUbReserve + kMinimumBuffers);742+ auto f32 = RunTiling({1, 4096, 4}, {1, 3}, NORMAL_LAYOUT, ge::DT_FLOAT, CORE_NUM, kUbReserve + kMinimumFp32Buffers);
743+ auto f16 = RunTiling({1, 4096, 4}, {1, 3}, NORMAL_LAYOUT, ge::DT_FLOAT16, CORE_NUM,
744+ kUbReserve + kMinimumFp16Buffers);
742 ASSERT_EQ(f32.status, ge::GRAPH_SUCCESS);745 ASSERT_EQ(f32.status, ge::GRAPH_SUCCESS);
743 ASSERT_EQ(f16.status, ge::GRAPH_SUCCESS);746 ASSERT_EQ(f16.status, ge::GRAPH_SUCCESS);
744 EXPECT_EQ(f32.tilingData.tileLen, 64u); // clamped to blockAlignElems (fp32)747 EXPECT_EQ(f32.tilingData.tileLen, 64u); // clamped to blockAlignElems (fp32)
745 EXPECT_EQ(f16.tilingData.tileLen, 128u); // clamped to blockAlignElems (fp16)748 EXPECT_EQ(f16.tilingData.tileLen, 128u); // clamped to blockAlignElems (fp16)
749+ EXPECT_EQ(f16.tilingData.divisorBufferBytes, 512u);
750+ const auto insufficient = RunTiling({1, 4096, 4}, {1, 3}, NORMAL_LAYOUT, ge::DT_FLOAT16, CORE_NUM,
751+ kUbReserve + kMinimumFp16Buffers - 1);
752+ EXPECT_EQ(insufficient.status, ge::GRAPH_FAILED);
746}753}
747 754 
748// ---- UB below the reserved/runtime requirement must be rejected -----------------------------755// ---- UB below the reserved/runtime requirement must be rejected -----------------------------