Merged
fix(lamb_next_right): 修正空 Tensor tiling data 有效长度 #14193
陈思Add on 11 days ago
fix(lamb_next_right): 修正空 Tensor tiling data 有效长度 #14193
Merged
Total: 10 files changed+429-37
| @@ -74,15 +74,22 @@ ge::graphStatus LambApplyWeightAssignTiling::DoOpTiling() | |||
| 74 | // 直接成功。 | 74 | // 直接成功。 |
| 75 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); | 75 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); |
| 76 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { | 76 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { |
| 77 | + // schMode=1 reads this layout for both fp16 and fp32. Serialize | ||
| 78 | + // the structure size, not the caller's potentially 2 MB capacity. | ||
| 79 | + using EmptyTilingData = BroadcastBaseTilingData< | ||
| 80 | + LambApplyWeightAssignOp::LambApplyWeightAssignCompute<float, float>::OpDag>; | ||
| 77 | auto emptyRawTiling = context_->GetRawTilingData(); | 81 | auto emptyRawTiling = context_->GetRawTilingData(); |
| 78 | - if (emptyRawTiling != nullptr && emptyRawTiling->GetData() != nullptr) { | 82 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyRawTiling); |
| 79 | - size_t emptyCap = emptyRawTiling->GetCapacity(); | 83 | + auto emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); |
| 80 | - uint8_t* emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); | 84 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyPtr); |
| 81 | - for (size_t emptyIdx = 0; emptyIdx < emptyCap; ++emptyIdx) { | 85 | + OP_CHECK_IF( |
| 82 | - emptyPtr[emptyIdx] = 0; | 86 | + emptyRawTiling->GetCapacity() < sizeof(EmptyTilingData), |
| 83 | - } | 87 | + OP_LOGE(context_->GetNodeName(), "Tiling data capacity is smaller than the empty tiling structure."), |
| 84 | - emptyRawTiling->SetDataSize(emptyCap); | 88 | + return ge::GRAPH_FAILED); |
| 89 | + for (size_t emptyIdx = 0; emptyIdx < sizeof(EmptyTilingData); ++emptyIdx) { | ||
| 90 | + emptyPtr[emptyIdx] = 0; | ||
| 85 | } | 91 | } |
| 92 | + emptyRawTiling->SetDataSize(sizeof(EmptyTilingData)); | ||
| 86 | size_t* emptyWs = context_->GetWorkspaceSizes(1); | 93 | size_t* emptyWs = context_->GetWorkspaceSizes(1); |
| 87 | if (emptyWs != nullptr) { | 94 | if (emptyWs != nullptr) { |
| 88 | emptyWs[0] = 0; | 95 | emptyWs[0] = 0; |
Moptim/lamb_apply_weight_assign/tests/ut/op_host/arch35/test_lamb_apply_weight_assign_tiling.cpp+92-0
| @@ -8,6 +8,8 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | +#include <algorithm> | ||
| 12 | +#include <cstring> | ||
| 11 | #include <iostream> | 13 | #include <iostream> |
| 12 | #include <vector> | 14 | #include <vector> |
| 13 | #include <gtest/gtest.h> | 15 | #include <gtest/gtest.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include "platform/platform_infos_def.h" | 21 | #include "platform/platform_infos_def.h" |
| 20 | #include "ut_op_util.h" | 22 | #include "ut_op_util.h" |
| 21 | #include "optim/lamb_apply_weight_assign/op_host/arch35/lamb_apply_weight_assign_tiling_arch35.h" | 23 | #include "optim/lamb_apply_weight_assign/op_host/arch35/lamb_apply_weight_assign_tiling_arch35.h" |
| 24 | +#include "optim/lamb_apply_weight_assign/op_kernel/arch35/lamb_apply_weight_assign_dag.h" | ||
| 25 | +#include "atvoss/broadcast/broadcast_base_struct.h" | ||
| 22 | 26 | ||
| 23 | using namespace ut_util; | 27 | using namespace ut_util; |
| 24 | using namespace std; | 28 | using namespace std; |
| @@ -278,3 +282,91 @@ TEST_F(LambApplyWeightAssignTilingTest, lamb_apply_weight_assign_tiling_test_inv | |||
| 278 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); | 282 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); |
| 279 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); | 283 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); |
| 280 | } | 284 | } |
| 285 | + | ||
| 286 | +namespace { | ||
| 287 | +using EmptyTilingData = Ops::Base::BroadcastBaseTilingData< | ||
| 288 | + LambApplyWeightAssignOp::LambApplyWeightAssignCompute<float, float>::OpDag>; | ||
| 289 | + | ||
| 290 | +void CheckEmptyTilingBuffer(gert::TilingData* data, ge::DataType dtype, ge::graphStatus expected) | ||
| 291 | +{ | ||
| 292 | + gert::StorageShape emptyShape = {{0}, {0}}; | ||
| 293 | + auto workspace = gert::ContinuousVector::Create<size_t>(1); | ||
| 294 | + auto* ws = reinterpret_cast<gert::ContinuousVector*>(workspace.get()); | ||
| 295 | + ASSERT_NE(ws, nullptr); | ||
| 296 | + optiling::LambApplyWeightAssignCompileInfo compileInfo; | ||
| 297 | + fe::PlatFormInfos platformInfo; | ||
| 298 | + platformInfo.Init(); | ||
| 299 | + auto faker = gert::TilingContextFaker(); | ||
| 300 | + faker.SetOpType("LambApplyWeightAssign") | ||
| 301 | + .NodeIoNum(5, 1) | ||
| 302 | + .InputShapes(std::vector<gert::StorageShape*>(5, &emptyShape)) | ||
| 303 | + .OutputShapes(std::vector<gert::StorageShape*>(1, &emptyShape)) | ||
| 304 | + .CompileInfo(&compileInfo) | ||
| 305 | + .PlatformInfo(&platformInfo) | ||
| 306 | + .TilingData(data) | ||
| 307 | + .Workspace(ws); | ||
| 308 | + for (int32_t i = 0; i < 5; ++i) { | ||
| 309 | + faker.NodeInputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 310 | + } | ||
| 311 | + for (int32_t i = 0; i < 1; ++i) { | ||
| 312 | + faker.NodeOutputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 313 | + } | ||
| 314 | + auto holder = faker.Build(); | ||
| 315 | + auto* context = holder.GetContext<gert::TilingContext>(); | ||
| 316 | + ASSERT_NE(context, nullptr); | ||
| 317 | + context->SetBlockDim(7); | ||
| 318 | + context->SetTilingKey(99); | ||
| 319 | + context->GetWorkspaceSizes(1)[0] = 123; | ||
| 320 | + optiling::LambApplyWeightAssignTiling tiling(context); | ||
| 321 | + ASSERT_EQ(tiling.DoTiling(), expected); | ||
| 322 | + if (expected == ge::GRAPH_SUCCESS) { | ||
| 323 | + EXPECT_EQ(context->GetBlockDim(), 1); | ||
| 324 | + EXPECT_EQ(context->GetTilingKey(), GET_TPL_TILING_KEY(1)); | ||
| 325 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 0); | ||
| 326 | + ASSERT_NE(data, nullptr); | ||
| 327 | + EXPECT_EQ(data->GetDataSize(), sizeof(EmptyTilingData)); | ||
| 328 | + } else { | ||
| 329 | + EXPECT_EQ(context->GetBlockDim(), 7); | ||
| 330 | + EXPECT_EQ(context->GetTilingKey(), 99); | ||
| 331 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 123); | ||
| 332 | + if (data != nullptr) { | ||
| 333 | + EXPECT_EQ(data->GetDataSize(), 0); | ||
| 334 | + } | ||
| 335 | + } | ||
| 336 | + if (data != nullptr && data->GetData() != nullptr) { | ||
| 337 | + const auto* bytes = static_cast<const uint8_t*>(data->GetData()); | ||
| 338 | + const size_t initialized = expected == ge::GRAPH_SUCCESS ? sizeof(EmptyTilingData) : 0; | ||
| 339 | + EXPECT_TRUE(std::all_of(bytes, bytes + initialized, [](uint8_t byte) { return byte == 0; })); | ||
| 340 | + EXPECT_TRUE( | ||
| 341 | + std::all_of(bytes + initialized, bytes + data->GetCapacity(), [](uint8_t byte) { return byte == 0x5a; })); | ||
| 342 | + } | ||
| 343 | +} | ||
| 344 | +} // namespace | ||
| 345 | + | ||
| 346 | +TEST_F(LambApplyWeightAssignTilingTest, empty_tiling_buffer_capacity_boundaries) | ||
| 347 | +{ | ||
| 348 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 349 | + for (size_t capacity : {size_t(0), size_t(1), sizeof(EmptyTilingData) - 1, sizeof(EmptyTilingData), | ||
| 350 | + sizeof(EmptyTilingData) + 16, size_t(2 * 1024 * 1024)}) { | ||
| 351 | + SCOPED_TRACE(testing::Message() << "dtype=" << dtype << ", capacity=" << capacity); | ||
| 352 | + auto buffer = gert::TilingData::CreateCap(capacity); | ||
| 353 | + ASSERT_NE(buffer, nullptr); | ||
| 354 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 355 | + std::memset(data->GetData(), 0x5a, capacity); | ||
| 356 | + CheckEmptyTilingBuffer(data, dtype, | ||
| 357 | + capacity < sizeof(EmptyTilingData) ? ge::GRAPH_FAILED : ge::GRAPH_SUCCESS); | ||
| 358 | + } | ||
| 359 | + } | ||
| 360 | +} | ||
| 361 | + | ||
| 362 | +TEST_F(LambApplyWeightAssignTilingTest, empty_tiling_rejects_null_buffers) | ||
| 363 | +{ | ||
| 364 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 365 | + CheckEmptyTilingBuffer(nullptr, dtype, ge::GRAPH_FAILED); | ||
| 366 | + auto buffer = gert::TilingData::CreateCap(sizeof(EmptyTilingData)); | ||
| 367 | + ASSERT_NE(buffer, nullptr); | ||
| 368 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 369 | + data->Init(sizeof(EmptyTilingData), nullptr); | ||
| 370 | + CheckEmptyTilingBuffer(data, dtype, ge::GRAPH_FAILED); | ||
| 371 | + } | ||
| 372 | +} | ||
| @@ -89,15 +89,21 @@ ge::graphStatus LambNextRightTiling::DoOpTiling() | |||
| 89 | // 直接成功。 | 89 | // 直接成功。 |
| 90 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); | 90 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); |
| 91 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { | 91 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { |
| 92 | + // schMode=1 reads this layout for both fp16 and fp32. Serialize | ||
| 93 | + // the structure size, not the caller's potentially 2 MB capacity. | ||
| 94 | + using EmptyTilingData = BroadcastBaseTilingData<LambNextRightOp::LambNextRightCompute<float, float>::OpDag>; | ||
| 92 | auto emptyRawTiling = context_->GetRawTilingData(); | 95 | auto emptyRawTiling = context_->GetRawTilingData(); |
| 93 | - if (emptyRawTiling != nullptr && emptyRawTiling->GetData() != nullptr) { | 96 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyRawTiling); |
| 94 | - size_t emptyCap = emptyRawTiling->GetCapacity(); | 97 | + auto emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); |
| 95 | - uint8_t* emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); | 98 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyPtr); |
| 96 | - for (size_t emptyIdx = 0; emptyIdx < emptyCap; ++emptyIdx) { | 99 | + OP_CHECK_IF( |
| 97 | - emptyPtr[emptyIdx] = 0; | 100 | + emptyRawTiling->GetCapacity() < sizeof(EmptyTilingData), |
| 98 | - } | 101 | + OP_LOGE(context_->GetNodeName(), "Tiling data capacity is smaller than the empty tiling structure."), |
| 99 | - emptyRawTiling->SetDataSize(emptyCap); | 102 | + return ge::GRAPH_FAILED); |
| 103 | + for (size_t emptyIdx = 0; emptyIdx < sizeof(EmptyTilingData); ++emptyIdx) { | ||
| 104 | + emptyPtr[emptyIdx] = 0; | ||
| 100 | } | 105 | } |
| 106 | + emptyRawTiling->SetDataSize(sizeof(EmptyTilingData)); | ||
| 101 | size_t* emptyWs = context_->GetWorkspaceSizes(1); | 107 | size_t* emptyWs = context_->GetWorkspaceSizes(1); |
| 102 | if (emptyWs != nullptr) { | 108 | if (emptyWs != nullptr) { |
| 103 | emptyWs[0] = 0; | 109 | emptyWs[0] = 0; |
| @@ -60,8 +60,8 @@ struct LambNextRightCompute { | |||
| 60 | using Recip = Bind<Vec::Cast<U, T, 0>, InRecip>; | 60 | using Recip = Bind<Vec::Cast<U, T, 0>, InRecip>; |
| 61 | using Eps = Bind<Vec::Cast<U, T, 0>, InEps>; | 61 | using Eps = Bind<Vec::Cast<U, T, 0>, InEps>; |
| 62 | 62 | ||
| 63 | - // next_v = v*b2 + g^2*(1-b2) | 63 | + // next_v = v*b2 + (g*(1-b2))*g: multiply the coefficient before squaring. |
| 64 | - using NextV = Bind<Vec::Add<U>, Bind<Vec::Mul<U>, V, B2>, Bind<Vec::Mul<U>, Bind<Vec::Mul<U>, G, G>, OmB2>>; | 64 | + using NextV = Bind<Vec::Add<U>, Bind<Vec::Mul<U>, V, B2>, Bind<Vec::Mul<U>, Bind<Vec::Mul<U>, G, OmB2>, G>>; |
| 65 | // y2 = sqrt(next_v * recip) + eps | 65 | // y2 = sqrt(next_v * recip) + eps |
| 66 | using Y2 = Bind<Vec::Add<U>, Bind<SqrtFtzFalse<U>, Bind<Vec::Mul<U>, NextV, Recip>>, Eps>; | 66 | using Y2 = Bind<Vec::Add<U>, Bind<SqrtFtzFalse<U>, Bind<Vec::Mul<U>, NextV, Recip>>, Eps>; |
| 67 | 67 | ||
| @@ -98,9 +98,8 @@ def lamb_next_right_golden( | |||
| 98 | dt = input_square.dtype | 98 | dt = input_square.dtype |
| 99 | g, v = _t(input_square), _t(input_mul2) | 99 | g, v = _t(input_square), _t(input_mul2) |
| 100 | b2, omb2, recip, eps = _scalars(mul2_x, mul3_x, truediv1_recip, add2_y) | 100 | b2, omb2, recip, eps = _scalars(mul2_x, mul3_x, truediv1_recip, add2_y) |
| 101 | - # 两步(先乘后加)拼接,不用 addcmul 的融合形式:后者可能走 FMA 单次舍入,与算子定义的 | 101 | + # 与内核一致:先 g*omb2 再乘 g,避免 g*g 提前溢出;保持分步乘加,不引入 FMA。 |
| 102 | - # 「Muls 再 Add」两步舍入不是同一个运算序列。golden 要如实转写定义。 | 102 | + next_v = v * b2 + (g * omb2) * g |
| 103 | - next_v = v * b2 + (g * g) * omb2 | ||
| 104 | y2 = torch.sqrt(next_v * recip) + eps | 103 | y2 = torch.sqrt(next_v * recip) + eps |
| 105 | _shape = _decl_shape( | 104 | _shape = _decl_shape( |
| 106 | input_square, input_mul2, mul2_x, mul3_x, truediv1_recip, add2_y | 105 | input_square, input_mul2, mul2_x, mul3_x, truediv1_recip, add2_y |
| @@ -111,7 +110,7 @@ def lamb_next_right_golden( | |||
| 111 | # ---------------------------------------------------------------------------- | 110 | # ---------------------------------------------------------------------------- |
| 112 | # TTK 新版 spec 注册(kernel 通路): 在保留原 golden 的基础上补三方标杆能力。 | 111 | # TTK 新版 spec 注册(kernel 通路): 在保留原 golden 的基础上补三方标杆能力。 |
| 113 | # golden = CPU 真值,如实转写算子定义(两步拼接,不用融合算子) | 112 | # golden = CPU 真值,如实转写算子定义(两步拼接,不用融合算子) |
| 114 | -# third_party= 三方标杆,用 torch 的自然形式(含融合算子)在设备侧跑,供 cross_check 比对 | 113 | +# third_party= 三方标杆,用 torch 分步乘加在设备侧跑,供 cross_check 比对 |
| 115 | # ---------------------------------------------------------------------------- | 114 | # ---------------------------------------------------------------------------- |
| 116 | _TOL_KERNEL = { | 115 | _TOL_KERNEL = { |
| 117 | "float32": {"standard": "cross_check", "level": "L1"}, | 116 | "float32": {"standard": "cross_check", "level": "L1"}, |
| @@ -184,9 +183,8 @@ class _LambNextRightCompose: | |||
| 184 | b2, omb2, recip, eps = ( | 183 | b2, omb2, recip, eps = ( |
| 185 | _tp_s(v_) for v_ in (mul2_x, mul3_x, truediv1_recip, add2_y) | 184 | _tp_s(v_) for v_ in (mul2_x, mul3_x, truediv1_recip, add2_y) |
| 186 | ) | 185 | ) |
| 187 | - # 与内核同运算序列: dag.h:46 `Add(Mul(V,B2), Mul(Mul(G,G),OmB2))` —— 先 g*g, | 186 | + # 与内核一致:先 g*omb2,再乘 g,最后与 v*b2 相加;不使用融合乘加。 |
| 188 | - # 再乘 omb2, 最后相加, 四次舍入。不能用 addcmul(FMA 单次舍入会让竞品凭空更准)。 | 187 | + next_v = v * b2 + (g * omb2) * g |
| 189 | - next_v = v * b2 + (g * g) * omb2 | ||
| 190 | y2 = torch.sqrt(next_v * recip) + eps | 188 | y2 = torch.sqrt(next_v * recip) + eps |
| 191 | _shape = _decl_shape( | 189 | _shape = _decl_shape( |
| 192 | input_square, input_mul2, mul2_x, mul3_x, truediv1_recip, add2_y | 190 | input_square, input_mul2, mul2_x, mul3_x, truediv1_recip, add2_y |
| @@ -8,6 +8,8 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | +#include <algorithm> | ||
| 12 | +#include <cstring> | ||
| 11 | #include <iostream> | 13 | #include <iostream> |
| 12 | #include <vector> | 14 | #include <vector> |
| 13 | #include <gtest/gtest.h> | 15 | #include <gtest/gtest.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include "platform/platform_infos_def.h" | 21 | #include "platform/platform_infos_def.h" |
| 20 | #include "ut_op_util.h" | 22 | #include "ut_op_util.h" |
| 21 | #include "optim/lamb_next_right/op_host/arch35/lamb_next_right_tiling_arch35.h" | 23 | #include "optim/lamb_next_right/op_host/arch35/lamb_next_right_tiling_arch35.h" |
| 24 | +#include "optim/lamb_next_right/op_kernel/arch35/lamb_next_right_dag.h" | ||
| 25 | +#include "atvoss/broadcast/broadcast_base_struct.h" | ||
| 22 | 26 | ||
| 23 | using namespace ut_util; | 27 | using namespace ut_util; |
| 24 | using namespace std; | 28 | using namespace std; |
| @@ -294,3 +298,90 @@ TEST_F(LambNextRightTilingTest, lamb_next_right_tiling_test_invalid_dtype) | |||
| 294 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); | 298 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); |
| 295 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); | 299 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); |
| 296 | } | 300 | } |
| 301 | + | ||
| 302 | +namespace { | ||
| 303 | +using EmptyTilingData = Ops::Base::BroadcastBaseTilingData<LambNextRightOp::LambNextRightCompute<float, float>::OpDag>; | ||
| 304 | + | ||
| 305 | +void CheckEmptyTilingBuffer(gert::TilingData* data, ge::DataType dtype, ge::graphStatus expected) | ||
| 306 | +{ | ||
| 307 | + gert::StorageShape emptyShape = {{0}, {0}}; | ||
| 308 | + auto workspace = gert::ContinuousVector::Create<size_t>(1); | ||
| 309 | + auto* ws = reinterpret_cast<gert::ContinuousVector*>(workspace.get()); | ||
| 310 | + ASSERT_NE(ws, nullptr); | ||
| 311 | + optiling::LambNextRightCompileInfo compileInfo; | ||
| 312 | + fe::PlatFormInfos platformInfo; | ||
| 313 | + platformInfo.Init(); | ||
| 314 | + auto faker = gert::TilingContextFaker(); | ||
| 315 | + faker.SetOpType("LambNextRight") | ||
| 316 | + .NodeIoNum(6, 2) | ||
| 317 | + .InputShapes(std::vector<gert::StorageShape*>(6, &emptyShape)) | ||
| 318 | + .OutputShapes(std::vector<gert::StorageShape*>(2, &emptyShape)) | ||
| 319 | + .CompileInfo(&compileInfo) | ||
| 320 | + .PlatformInfo(&platformInfo) | ||
| 321 | + .TilingData(data) | ||
| 322 | + .Workspace(ws); | ||
| 323 | + for (int32_t i = 0; i < 6; ++i) { | ||
| 324 | + faker.NodeInputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 325 | + } | ||
| 326 | + for (int32_t i = 0; i < 2; ++i) { | ||
| 327 | + faker.NodeOutputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 328 | + } | ||
| 329 | + auto holder = faker.Build(); | ||
| 330 | + auto* context = holder.GetContext<gert::TilingContext>(); | ||
| 331 | + ASSERT_NE(context, nullptr); | ||
| 332 | + context->SetBlockDim(7); | ||
| 333 | + context->SetTilingKey(99); | ||
| 334 | + context->GetWorkspaceSizes(1)[0] = 123; | ||
| 335 | + optiling::LambNextRightTiling tiling(context); | ||
| 336 | + ASSERT_EQ(tiling.DoTiling(), expected); | ||
| 337 | + if (expected == ge::GRAPH_SUCCESS) { | ||
| 338 | + EXPECT_EQ(context->GetBlockDim(), 1); | ||
| 339 | + EXPECT_EQ(context->GetTilingKey(), GET_TPL_TILING_KEY(1)); | ||
| 340 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 0); | ||
| 341 | + ASSERT_NE(data, nullptr); | ||
| 342 | + EXPECT_EQ(data->GetDataSize(), sizeof(EmptyTilingData)); | ||
| 343 | + } else { | ||
| 344 | + EXPECT_EQ(context->GetBlockDim(), 7); | ||
| 345 | + EXPECT_EQ(context->GetTilingKey(), 99); | ||
| 346 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 123); | ||
| 347 | + if (data != nullptr) { | ||
| 348 | + EXPECT_EQ(data->GetDataSize(), 0); | ||
| 349 | + } | ||
| 350 | + } | ||
| 351 | + if (data != nullptr && data->GetData() != nullptr) { | ||
| 352 | + const auto* bytes = static_cast<const uint8_t*>(data->GetData()); | ||
| 353 | + const size_t initialized = expected == ge::GRAPH_SUCCESS ? sizeof(EmptyTilingData) : 0; | ||
| 354 | + EXPECT_TRUE(std::all_of(bytes, bytes + initialized, [](uint8_t byte) { return byte == 0; })); | ||
| 355 | + EXPECT_TRUE( | ||
| 356 | + std::all_of(bytes + initialized, bytes + data->GetCapacity(), [](uint8_t byte) { return byte == 0x5a; })); | ||
| 357 | + } | ||
| 358 | +} | ||
| 359 | +} // namespace | ||
| 360 | + | ||
| 361 | +TEST_F(LambNextRightTilingTest, empty_tiling_buffer_capacity_boundaries) | ||
| 362 | +{ | ||
| 363 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 364 | + for (size_t capacity : {size_t(0), size_t(1), sizeof(EmptyTilingData) - 1, sizeof(EmptyTilingData), | ||
| 365 | + sizeof(EmptyTilingData) + 16, size_t(2 * 1024 * 1024)}) { | ||
| 366 | + SCOPED_TRACE(testing::Message() << "dtype=" << dtype << ", capacity=" << capacity); | ||
| 367 | + auto buffer = gert::TilingData::CreateCap(capacity); | ||
| 368 | + ASSERT_NE(buffer, nullptr); | ||
| 369 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 370 | + std::memset(data->GetData(), 0x5a, capacity); | ||
| 371 | + CheckEmptyTilingBuffer(data, dtype, | ||
| 372 | + capacity < sizeof(EmptyTilingData) ? ge::GRAPH_FAILED : ge::GRAPH_SUCCESS); | ||
| 373 | + } | ||
| 374 | + } | ||
| 375 | +} | ||
| 376 | + | ||
| 377 | +TEST_F(LambNextRightTilingTest, empty_tiling_rejects_null_buffers) | ||
| 378 | +{ | ||
| 379 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 380 | + CheckEmptyTilingBuffer(nullptr, dtype, ge::GRAPH_FAILED); | ||
| 381 | + auto buffer = gert::TilingData::CreateCap(sizeof(EmptyTilingData)); | ||
| 382 | + ASSERT_NE(buffer, nullptr); | ||
| 383 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 384 | + data->Init(sizeof(EmptyTilingData), nullptr); | ||
| 385 | + CheckEmptyTilingBuffer(data, dtype, ge::GRAPH_FAILED); | ||
| 386 | + } | ||
| 387 | +} | ||
| @@ -93,15 +93,22 @@ ge::graphStatus LambUpdateWithLrTiling::DoOpTiling() | |||
| 93 | // 直接成功。 | 93 | // 直接成功。 |
| 94 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); | 94 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); |
| 95 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { | 95 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { |
| 96 | + // schMode=1 reads this layout for both fp16 and fp32. Serialize | ||
| 97 | + // the structure size, not the caller's potentially 2 MB capacity. | ||
| 98 | + using EmptyTilingData = BroadcastBaseTilingData< | ||
| 99 | + LambUpdateWithLrOp::LambUpdateWithLrCompute<float, float>::OpDag>; | ||
| 96 | auto emptyRawTiling = context_->GetRawTilingData(); | 100 | auto emptyRawTiling = context_->GetRawTilingData(); |
| 97 | - if (emptyRawTiling != nullptr && emptyRawTiling->GetData() != nullptr) { | 101 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyRawTiling); |
| 98 | - size_t emptyCap = emptyRawTiling->GetCapacity(); | 102 | + auto emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); |
| 99 | - uint8_t* emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); | 103 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyPtr); |
| 100 | - for (size_t emptyIdx = 0; emptyIdx < emptyCap; ++emptyIdx) { | 104 | + OP_CHECK_IF( |
| 101 | - emptyPtr[emptyIdx] = 0; | 105 | + emptyRawTiling->GetCapacity() < sizeof(EmptyTilingData), |
| 102 | - } | 106 | + OP_LOGE(context_->GetNodeName(), "Tiling data capacity is smaller than the empty tiling structure."), |
| 103 | - emptyRawTiling->SetDataSize(emptyCap); | 107 | + return ge::GRAPH_FAILED); |
| 108 | + for (size_t emptyIdx = 0; emptyIdx < sizeof(EmptyTilingData); ++emptyIdx) { | ||
| 109 | + emptyPtr[emptyIdx] = 0; | ||
| 104 | } | 110 | } |
| 111 | + emptyRawTiling->SetDataSize(sizeof(EmptyTilingData)); | ||
| 105 | size_t* emptyWs = context_->GetWorkspaceSizes(1); | 112 | size_t* emptyWs = context_->GetWorkspaceSizes(1); |
| 106 | if (emptyWs != nullptr) { | 113 | if (emptyWs != nullptr) { |
| 107 | emptyWs[0] = 0; | 114 | emptyWs[0] = 0; |
| @@ -8,6 +8,8 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | +#include <algorithm> | ||
| 12 | +#include <cstring> | ||
| 11 | #include <iostream> | 13 | #include <iostream> |
| 12 | #include <vector> | 14 | #include <vector> |
| 13 | #include <gtest/gtest.h> | 15 | #include <gtest/gtest.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include "platform/platform_infos_def.h" | 21 | #include "platform/platform_infos_def.h" |
| 20 | #include "ut_op_util.h" | 22 | #include "ut_op_util.h" |
| 21 | #include "optim/lamb_update_with_lr/op_host/arch35/lamb_update_with_lr_tiling_arch35.h" | 23 | #include "optim/lamb_update_with_lr/op_host/arch35/lamb_update_with_lr_tiling_arch35.h" |
| 24 | +#include "optim/lamb_update_with_lr/op_kernel/arch35/lamb_update_with_lr_dag.h" | ||
| 25 | +#include "atvoss/broadcast/broadcast_base_struct.h" | ||
| 22 | 26 | ||
| 23 | using namespace ut_util; | 27 | using namespace ut_util; |
| 24 | using namespace std; | 28 | using namespace std; |
| @@ -314,3 +318,91 @@ TEST_F(LambUpdateWithLrTilingTest, lamb_update_with_lr_tiling_test_invalid_dtype | |||
| 314 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); | 318 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); |
| 315 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); | 319 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); |
| 316 | } | 320 | } |
| 321 | + | ||
| 322 | +namespace { | ||
| 323 | +using EmptyTilingData = Ops::Base::BroadcastBaseTilingData< | ||
| 324 | + LambUpdateWithLrOp::LambUpdateWithLrCompute<float, float>::OpDag>; | ||
| 325 | + | ||
| 326 | +void CheckEmptyTilingBuffer(gert::TilingData* data, ge::DataType dtype, ge::graphStatus expected) | ||
| 327 | +{ | ||
| 328 | + gert::StorageShape emptyShape = {{0}, {0}}; | ||
| 329 | + auto workspace = gert::ContinuousVector::Create<size_t>(1); | ||
| 330 | + auto* ws = reinterpret_cast<gert::ContinuousVector*>(workspace.get()); | ||
| 331 | + ASSERT_NE(ws, nullptr); | ||
| 332 | + optiling::LambUpdateWithLrCompileInfo compileInfo; | ||
| 333 | + fe::PlatFormInfos platformInfo; | ||
| 334 | + platformInfo.Init(); | ||
| 335 | + auto faker = gert::TilingContextFaker(); | ||
| 336 | + faker.SetOpType("LambUpdateWithLr") | ||
| 337 | + .NodeIoNum(9, 1) | ||
| 338 | + .InputShapes(std::vector<gert::StorageShape*>(9, &emptyShape)) | ||
| 339 | + .OutputShapes(std::vector<gert::StorageShape*>(1, &emptyShape)) | ||
| 340 | + .CompileInfo(&compileInfo) | ||
| 341 | + .PlatformInfo(&platformInfo) | ||
| 342 | + .TilingData(data) | ||
| 343 | + .Workspace(ws); | ||
| 344 | + for (int32_t i = 0; i < 9; ++i) { | ||
| 345 | + faker.NodeInputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 346 | + } | ||
| 347 | + for (int32_t i = 0; i < 1; ++i) { | ||
| 348 | + faker.NodeOutputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 349 | + } | ||
| 350 | + auto holder = faker.Build(); | ||
| 351 | + auto* context = holder.GetContext<gert::TilingContext>(); | ||
| 352 | + ASSERT_NE(context, nullptr); | ||
| 353 | + context->SetBlockDim(7); | ||
| 354 | + context->SetTilingKey(99); | ||
| 355 | + context->GetWorkspaceSizes(1)[0] = 123; | ||
| 356 | + optiling::LambUpdateWithLrTiling tiling(context); | ||
| 357 | + ASSERT_EQ(tiling.DoTiling(), expected); | ||
| 358 | + if (expected == ge::GRAPH_SUCCESS) { | ||
| 359 | + EXPECT_EQ(context->GetBlockDim(), 1); | ||
| 360 | + EXPECT_EQ(context->GetTilingKey(), GET_TPL_TILING_KEY(1)); | ||
| 361 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 0); | ||
| 362 | + ASSERT_NE(data, nullptr); | ||
| 363 | + EXPECT_EQ(data->GetDataSize(), sizeof(EmptyTilingData)); | ||
| 364 | + } else { | ||
| 365 | + EXPECT_EQ(context->GetBlockDim(), 7); | ||
| 366 | + EXPECT_EQ(context->GetTilingKey(), 99); | ||
| 367 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 123); | ||
| 368 | + if (data != nullptr) { | ||
| 369 | + EXPECT_EQ(data->GetDataSize(), 0); | ||
| 370 | + } | ||
| 371 | + } | ||
| 372 | + if (data != nullptr && data->GetData() != nullptr) { | ||
| 373 | + const auto* bytes = static_cast<const uint8_t*>(data->GetData()); | ||
| 374 | + const size_t initialized = expected == ge::GRAPH_SUCCESS ? sizeof(EmptyTilingData) : 0; | ||
| 375 | + EXPECT_TRUE(std::all_of(bytes, bytes + initialized, [](uint8_t byte) { return byte == 0; })); | ||
| 376 | + EXPECT_TRUE( | ||
| 377 | + std::all_of(bytes + initialized, bytes + data->GetCapacity(), [](uint8_t byte) { return byte == 0x5a; })); | ||
| 378 | + } | ||
| 379 | +} | ||
| 380 | +} // namespace | ||
| 381 | + | ||
| 382 | +TEST_F(LambUpdateWithLrTilingTest, empty_tiling_buffer_capacity_boundaries) | ||
| 383 | +{ | ||
| 384 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 385 | + for (size_t capacity : {size_t(0), size_t(1), sizeof(EmptyTilingData) - 1, sizeof(EmptyTilingData), | ||
| 386 | + sizeof(EmptyTilingData) + 16, size_t(2 * 1024 * 1024)}) { | ||
| 387 | + SCOPED_TRACE(testing::Message() << "dtype=" << dtype << ", capacity=" << capacity); | ||
| 388 | + auto buffer = gert::TilingData::CreateCap(capacity); | ||
| 389 | + ASSERT_NE(buffer, nullptr); | ||
| 390 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 391 | + std::memset(data->GetData(), 0x5a, capacity); | ||
| 392 | + CheckEmptyTilingBuffer(data, dtype, | ||
| 393 | + capacity < sizeof(EmptyTilingData) ? ge::GRAPH_FAILED : ge::GRAPH_SUCCESS); | ||
| 394 | + } | ||
| 395 | + } | ||
| 396 | +} | ||
| 397 | + | ||
| 398 | +TEST_F(LambUpdateWithLrTilingTest, empty_tiling_rejects_null_buffers) | ||
| 399 | +{ | ||
| 400 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 401 | + CheckEmptyTilingBuffer(nullptr, dtype, ge::GRAPH_FAILED); | ||
| 402 | + auto buffer = gert::TilingData::CreateCap(sizeof(EmptyTilingData)); | ||
| 403 | + ASSERT_NE(buffer, nullptr); | ||
| 404 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 405 | + data->Init(sizeof(EmptyTilingData), nullptr); | ||
| 406 | + CheckEmptyTilingBuffer(data, dtype, ge::GRAPH_FAILED); | ||
| 407 | + } | ||
| 408 | +} | ||
| @@ -89,15 +89,22 @@ ge::graphStatus LambUpdateWithLrV2Tiling::DoOpTiling() | |||
| 89 | // 直接成功。 | 89 | // 直接成功。 |
| 90 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); | 90 | auto emptyTensorOutShape0 = context_->GetOutputShape(0); |
| 91 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { | 91 | if (emptyTensorOutShape0 != nullptr && emptyTensorOutShape0->GetStorageShape().GetShapeSize() == 0) { |
| 92 | + // schMode=1 reads this layout for both fp16 and fp32. Serialize | ||
| 93 | + // the structure size, not the caller's potentially 2 MB capacity. | ||
| 94 | + using EmptyTilingData = BroadcastBaseTilingData< | ||
| 95 | + LambUpdateWithLrV2Op::LambUpdateWithLrV2Compute<float, float>::OpDag>; | ||
| 92 | auto emptyRawTiling = context_->GetRawTilingData(); | 96 | auto emptyRawTiling = context_->GetRawTilingData(); |
| 93 | - if (emptyRawTiling != nullptr && emptyRawTiling->GetData() != nullptr) { | 97 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyRawTiling); |
| 94 | - size_t emptyCap = emptyRawTiling->GetCapacity(); | 98 | + auto emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); |
| 95 | - uint8_t* emptyPtr = static_cast<uint8_t*>(emptyRawTiling->GetData()); | 99 | + OP_CHECK_NULL_WITH_CONTEXT(context_, emptyPtr); |
| 96 | - for (size_t emptyIdx = 0; emptyIdx < emptyCap; ++emptyIdx) { | 100 | + OP_CHECK_IF( |
| 97 | - emptyPtr[emptyIdx] = 0; | 101 | + emptyRawTiling->GetCapacity() < sizeof(EmptyTilingData), |
| 98 | - } | 102 | + OP_LOGE(context_->GetNodeName(), "Tiling data capacity is smaller than the empty tiling structure."), |
| 99 | - emptyRawTiling->SetDataSize(emptyCap); | 103 | + return ge::GRAPH_FAILED); |
| 104 | + for (size_t emptyIdx = 0; emptyIdx < sizeof(EmptyTilingData); ++emptyIdx) { | ||
| 105 | + emptyPtr[emptyIdx] = 0; | ||
| 100 | } | 106 | } |
| 107 | + emptyRawTiling->SetDataSize(sizeof(EmptyTilingData)); | ||
| 101 | size_t* emptyWs = context_->GetWorkspaceSizes(1); | 108 | size_t* emptyWs = context_->GetWorkspaceSizes(1); |
| 102 | if (emptyWs != nullptr) { | 109 | if (emptyWs != nullptr) { |
| 103 | emptyWs[0] = 0; | 110 | emptyWs[0] = 0; |
| @@ -8,6 +8,8 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | +#include <algorithm> | ||
| 12 | +#include <cstring> | ||
| 11 | #include <iostream> | 13 | #include <iostream> |
| 12 | #include <vector> | 14 | #include <vector> |
| 13 | #include <gtest/gtest.h> | 15 | #include <gtest/gtest.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include "platform/platform_infos_def.h" | 21 | #include "platform/platform_infos_def.h" |
| 20 | #include "ut_op_util.h" | 22 | #include "ut_op_util.h" |
| 21 | #include "optim/lamb_update_with_lr_v2/op_host/arch35/lamb_update_with_lr_v2_tiling_arch35.h" | 23 | #include "optim/lamb_update_with_lr_v2/op_host/arch35/lamb_update_with_lr_v2_tiling_arch35.h" |
| 24 | +#include "optim/lamb_update_with_lr_v2/op_kernel/arch35/lamb_update_with_lr_v2_dag.h" | ||
| 25 | +#include "atvoss/broadcast/broadcast_base_struct.h" | ||
| 22 | 26 | ||
| 23 | using namespace ut_util; | 27 | using namespace ut_util; |
| 24 | using namespace std; | 28 | using namespace std; |
| @@ -294,3 +298,91 @@ TEST_F(LambUpdateWithLrV2TilingTest, lamb_update_with_lr_v2_tiling_test_invalid_ | |||
| 294 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); | 298 | tiling_context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); |
| 295 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); | 299 | EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_FAILED); |
| 296 | } | 300 | } |
| 301 | + | ||
| 302 | +namespace { | ||
| 303 | +using EmptyTilingData = Ops::Base::BroadcastBaseTilingData< | ||
| 304 | + LambUpdateWithLrV2Op::LambUpdateWithLrV2Compute<float, float>::OpDag>; | ||
| 305 | + | ||
| 306 | +void CheckEmptyTilingBuffer(gert::TilingData* data, ge::DataType dtype, ge::graphStatus expected) | ||
| 307 | +{ | ||
| 308 | + gert::StorageShape emptyShape = {{0}, {0}}; | ||
| 309 | + auto workspace = gert::ContinuousVector::Create<size_t>(1); | ||
| 310 | + auto* ws = reinterpret_cast<gert::ContinuousVector*>(workspace.get()); | ||
| 311 | + ASSERT_NE(ws, nullptr); | ||
| 312 | + optiling::LambUpdateWithLrV2CompileInfo compileInfo; | ||
| 313 | + fe::PlatFormInfos platformInfo; | ||
| 314 | + platformInfo.Init(); | ||
| 315 | + auto faker = gert::TilingContextFaker(); | ||
| 316 | + faker.SetOpType("LambUpdateWithLrV2") | ||
| 317 | + .NodeIoNum(7, 1) | ||
| 318 | + .InputShapes(std::vector<gert::StorageShape*>(7, &emptyShape)) | ||
| 319 | + .OutputShapes(std::vector<gert::StorageShape*>(1, &emptyShape)) | ||
| 320 | + .CompileInfo(&compileInfo) | ||
| 321 | + .PlatformInfo(&platformInfo) | ||
| 322 | + .TilingData(data) | ||
| 323 | + .Workspace(ws); | ||
| 324 | + for (int32_t i = 0; i < 7; ++i) { | ||
| 325 | + faker.NodeInputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 326 | + } | ||
| 327 | + for (int32_t i = 0; i < 1; ++i) { | ||
| 328 | + faker.NodeOutputTd(i, dtype, ge::FORMAT_ND, ge::FORMAT_ND); | ||
| 329 | + } | ||
| 330 | + auto holder = faker.Build(); | ||
| 331 | + auto* context = holder.GetContext<gert::TilingContext>(); | ||
| 332 | + ASSERT_NE(context, nullptr); | ||
| 333 | + context->SetBlockDim(7); | ||
| 334 | + context->SetTilingKey(99); | ||
| 335 | + context->GetWorkspaceSizes(1)[0] = 123; | ||
| 336 | + optiling::LambUpdateWithLrV2Tiling tiling(context); | ||
| 337 | + ASSERT_EQ(tiling.DoTiling(), expected); | ||
| 338 | + if (expected == ge::GRAPH_SUCCESS) { | ||
| 339 | + EXPECT_EQ(context->GetBlockDim(), 1); | ||
| 340 | + EXPECT_EQ(context->GetTilingKey(), GET_TPL_TILING_KEY(1)); | ||
| 341 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 0); | ||
| 342 | + ASSERT_NE(data, nullptr); | ||
| 343 | + EXPECT_EQ(data->GetDataSize(), sizeof(EmptyTilingData)); | ||
| 344 | + } else { | ||
| 345 | + EXPECT_EQ(context->GetBlockDim(), 7); | ||
| 346 | + EXPECT_EQ(context->GetTilingKey(), 99); | ||
| 347 | + EXPECT_EQ(context->GetWorkspaceSizes(1)[0], 123); | ||
| 348 | + if (data != nullptr) { | ||
| 349 | + EXPECT_EQ(data->GetDataSize(), 0); | ||
| 350 | + } | ||
| 351 | + } | ||
| 352 | + if (data != nullptr && data->GetData() != nullptr) { | ||
| 353 | + const auto* bytes = static_cast<const uint8_t*>(data->GetData()); | ||
| 354 | + const size_t initialized = expected == ge::GRAPH_SUCCESS ? sizeof(EmptyTilingData) : 0; | ||
| 355 | + EXPECT_TRUE(std::all_of(bytes, bytes + initialized, [](uint8_t byte) { return byte == 0; })); | ||
| 356 | + EXPECT_TRUE( | ||
| 357 | + std::all_of(bytes + initialized, bytes + data->GetCapacity(), [](uint8_t byte) { return byte == 0x5a; })); | ||
| 358 | + } | ||
| 359 | +} | ||
| 360 | +} // namespace | ||
| 361 | + | ||
| 362 | +TEST_F(LambUpdateWithLrV2TilingTest, empty_tiling_buffer_capacity_boundaries) | ||
| 363 | +{ | ||
| 364 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 365 | + for (size_t capacity : {size_t(0), size_t(1), sizeof(EmptyTilingData) - 1, sizeof(EmptyTilingData), | ||
| 366 | + sizeof(EmptyTilingData) + 16, size_t(2 * 1024 * 1024)}) { | ||
| 367 | + SCOPED_TRACE(testing::Message() << "dtype=" << dtype << ", capacity=" << capacity); | ||
| 368 | + auto buffer = gert::TilingData::CreateCap(capacity); | ||
| 369 | + ASSERT_NE(buffer, nullptr); | ||
| 370 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 371 | + std::memset(data->GetData(), 0x5a, capacity); | ||
| 372 | + CheckEmptyTilingBuffer(data, dtype, | ||
| 373 | + capacity < sizeof(EmptyTilingData) ? ge::GRAPH_FAILED : ge::GRAPH_SUCCESS); | ||
| 374 | + } | ||
| 375 | + } | ||
| 376 | +} | ||
| 377 | + | ||
| 378 | +TEST_F(LambUpdateWithLrV2TilingTest, empty_tiling_rejects_null_buffers) | ||
| 379 | +{ | ||
| 380 | + for (auto dtype : {ge::DT_FLOAT16, ge::DT_FLOAT}) { | ||
| 381 | + CheckEmptyTilingBuffer(nullptr, dtype, ge::GRAPH_FAILED); | ||
| 382 | + auto buffer = gert::TilingData::CreateCap(sizeof(EmptyTilingData)); | ||
| 383 | + ASSERT_NE(buffer, nullptr); | ||
| 384 | + auto* data = reinterpret_cast<gert::TilingData*>(buffer.get()); | ||
| 385 | + data->Init(sizeof(EmptyTilingData), nullptr); | ||
| 386 | + CheckEmptyTilingBuffer(data, dtype, ge::GRAPH_FAILED); | ||
| 387 | + } | ||
| 388 | +} | ||