已合并
fix(compressor): validate A3 cache mode and grad enabled #10624
qiansunchi159创建于 21 天前
fix(compressor): validate A3 cache mode and grad enabled #10624
已合并
qiansunchi159创建于 21 天前
3 个文件变更+109-23
@@ -87,6 +87,7 @@ ge::graphStatus CompressorTiling::ConvertContext(gert::TilingContext &context, C
87 compressorContext.cmpRatio = attrs->GetAttrPointer<int>(CMP_RATIO_ATTR_INDEX);87 compressorContext.cmpRatio = attrs->GetAttrPointer<int>(CMP_RATIO_ATTR_INDEX);
88 compressorContext.cacheMode = attrs->GetAttrPointer<int>(CACHE_MODE_ATTR_INDEX);88 compressorContext.cacheMode = attrs->GetAttrPointer<int>(CACHE_MODE_ATTR_INDEX);
89 compressorContext.stateCacheStrideDim0 = attrs->GetAttrPointer<int>(STATE_CACHE_STRIDE_DIM0_ATTR_INDEX);89 compressorContext.stateCacheStrideDim0 = attrs->GetAttrPointer<int>(STATE_CACHE_STRIDE_DIM0_ATTR_INDEX);
90+ compressorContext.gradEnabled = attrs->GetAttrPointer<bool>(GRAD_ENABLED_ATTR_INDEX);
90 91 
91 OP_CHECK_IF(92 OP_CHECK_IF(
92 context.GetWorkspaceSizes(1) == nullptr,93 context.GetWorkspaceSizes(1) == nullptr,
@@ -198,7 +199,10 @@ ge::graphStatus CompressorTiling::SetWorkSpaceInfo()
198 return ge::GRAPH_SUCCESS;199 return ge::GRAPH_SUCCESS;
199}200}
200 201 
201-ge::graphStatus CompressorTiling::SetScenarioInfo() { return ge::GRAPH_SUCCESS; }202+ge::graphStatus CompressorTiling::SetScenarioInfo()
203+{
204+ return ge::GRAPH_SUCCESS;
205+}
202 206 
203ge::graphStatus CompressorTiling::SetTemplateId()207ge::graphStatus CompressorTiling::SetTemplateId()
204{208{
@@ -403,7 +407,7 @@ ge::graphStatus CompressorTiling::CheckSinglePara() const
403 ge::GRAPH_SUCCESS != CheckSingleParaCuSeqlens() || ge::GRAPH_SUCCESS != CheckSingleParaSeqused() ||407 ge::GRAPH_SUCCESS != CheckSingleParaCuSeqlens() || ge::GRAPH_SUCCESS != CheckSingleParaSeqused() ||
404 ge::GRAPH_SUCCESS != CheckSingleParaStartPos() || ge::GRAPH_SUCCESS != CheckSingleParaCmpKv() ||408 ge::GRAPH_SUCCESS != CheckSingleParaStartPos() || ge::GRAPH_SUCCESS != CheckSingleParaCmpKv() ||
405 ge::GRAPH_SUCCESS != CheckSingleParaCmpRatio() || ge::GRAPH_SUCCESS != CheckSingleParaCoff() ||409 ge::GRAPH_SUCCESS != CheckSingleParaCmpRatio() || ge::GRAPH_SUCCESS != CheckSingleParaCoff() ||
406- ge::GRAPH_SUCCESS != CheckSingleParaCacheMode()) {410+ ge::GRAPH_SUCCESS != CheckSingleParaCacheMode() || ge::GRAPH_SUCCESS != CheckSingleParaGradEnabled()) {
407 return ge::GRAPH_FAILED;411 return ge::GRAPH_FAILED;
408 }412 }
409 return ge::GRAPH_SUCCESS;413 return ge::GRAPH_SUCCESS;
@@ -720,12 +724,23 @@ ge::graphStatus CompressorTiling::CheckSingleParaCoff() const
720 724 
721ge::graphStatus CompressorTiling::CheckSingleParaCacheMode() const725ge::graphStatus CompressorTiling::CheckSingleParaCacheMode() const
722{726{
727+ // A3 does not support the ring buffer mode (cache_mode=2).
723 if (ge::GRAPH_SUCCESS != CheckAttrValueSupport(context_->cacheMode, CACHE_MODE, CACHE_MODE_NAME)) {728 if (ge::GRAPH_SUCCESS != CheckAttrValueSupport(context_->cacheMode, CACHE_MODE, CACHE_MODE_NAME)) {
724 return ge::GRAPH_FAILED;729 return ge::GRAPH_FAILED;
725 }730 }
726 return ge::GRAPH_SUCCESS;731 return ge::GRAPH_SUCCESS;
727}732}
728 733 
734+ge::graphStatus CompressorTiling::CheckSingleParaGradEnabled() const
735+{
736+ // A3 only supports grad_enabled=false because arch22 has no backward-output path.
737+ OP_CHECK_IF(context_->gradEnabled != nullptr && *context_->gradEnabled,
738+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->opName, GRAD_ENABLED_NAME, "true",
739+ "grad_enabled only supports false"),
740+ return ge::GRAPH_FAILED);
741+ return ge::GRAPH_SUCCESS;
742+}
743+ 
729ge::graphStatus CompressorTiling::CheckRequiredParaExistence() const744ge::graphStatus CompressorTiling::CheckRequiredParaExistence() const
730{745{
731 if (CheckRequiredInOutExistence() != ge::GRAPH_SUCCESS || CheckRequiredAttrExistence() != ge::GRAPH_SUCCESS) {746 if (CheckRequiredInOutExistence() != ge::GRAPH_SUCCESS || CheckRequiredAttrExistence() != ge::GRAPH_SUCCESS) {
@@ -808,7 +823,10 @@ ge::graphStatus CompressorTiling::CheckRequiredAttrExistence() const
808 return ge::GRAPH_SUCCESS;823 return ge::GRAPH_SUCCESS;
809}824}
810 825 
811-ge::graphStatus CompressorTiling::CheckFeature() const { return ge::GRAPH_SUCCESS; }826+ge::graphStatus CompressorTiling::CheckFeature() const
827+{
828+ return ge::GRAPH_SUCCESS;
829+}
812 830 
813ge::graphStatus CompressorTiling::LogErrorShapeConsistency(const std::string &name, const gert::StorageShape *shape,831ge::graphStatus CompressorTiling::LogErrorShapeConsistency(const std::string &name, const gert::StorageShape *shape,
814 const uint32_t &dimNum, const std::string &subName,832 const uint32_t &dimNum, const std::string &subName,
@@ -58,6 +58,7 @@ constexpr uint32_t CMP_RATIO_ATTR_INDEX = 0;
58constexpr uint32_t COFF_ATTR_INDEX = 1;58constexpr uint32_t COFF_ATTR_INDEX = 1;
59constexpr uint32_t CACHE_MODE_ATTR_INDEX = 2;59constexpr uint32_t CACHE_MODE_ATTR_INDEX = 2;
60constexpr uint32_t STATE_CACHE_STRIDE_DIM0_ATTR_INDEX = 3;60constexpr uint32_t STATE_CACHE_STRIDE_DIM0_ATTR_INDEX = 3;
61+constexpr uint32_t GRAD_ENABLED_ATTR_INDEX = 4;
61 62 
62// OUTPUT63// OUTPUT
63constexpr uint32_t CMP_KV_OUTPUT_INDEX = 0;64constexpr uint32_t CMP_KV_OUTPUT_INDEX = 0;
@@ -92,6 +93,7 @@ static const std::string START_POS_NAME = "start_pos";
92static const std::string CMP_RATIO_NAME = "cmp_ratio";93static const std::string CMP_RATIO_NAME = "cmp_ratio";
93static const std::string COFF_NAME = "coff";94static const std::string COFF_NAME = "coff";
94static const std::string CACHE_MODE_NAME = "cache_mode";95static const std::string CACHE_MODE_NAME = "cache_mode";
96+static const std::string GRAD_ENABLED_NAME = "grad_enabled";
95static const std::string CMP_KV_NAME = "cmp_kv";97static const std::string CMP_KV_NAME = "cmp_kv";
96 98 
97static std::string DataTypeToSerialString(ge::DataType type);99static std::string DataTypeToSerialString(ge::DataType type);
@@ -207,6 +209,7 @@ const std::vector<int> CMP_RATIO{4, 128};
207const std::vector<int> CMP_RATIO{2, 4, 8, 16, 32, 64, 128};209const std::vector<int> CMP_RATIO{2, 4, 8, 16, 32, 64, 128};
208#endif210#endif
209const std::vector<uint32_t> HEAD_DIM{128, 512};211const std::vector<uint32_t> HEAD_DIM{128, 512};
212+// A3 only supports the linear state-cache buffer mode.
210const std::vector<int> CACHE_MODE{1};213const std::vector<int> CACHE_MODE{1};
211 214 
212enum class CACHE_MODE : uint8_t {215enum class CACHE_MODE : uint8_t {
@@ -234,6 +237,7 @@ struct CompressorContext {
234 const int *cmpRatio;237 const int *cmpRatio;
235 const int *cacheMode;238 const int *cacheMode;
236 const int *stateCacheStrideDim0;239 const int *stateCacheStrideDim0;
240+ const bool *gradEnabled;
237 TemplateId templateId;241 TemplateId templateId;
238 242 
239 ge::DataType dtype = ge::DT_BF16;243 ge::DataType dtype = ge::DT_BF16;
@@ -299,6 +303,7 @@ private:
299 ge::graphStatus CheckSingleParaCmpRatio() const;303 ge::graphStatus CheckSingleParaCmpRatio() const;
300 ge::graphStatus CheckSingleParaCoff() const;304 ge::graphStatus CheckSingleParaCoff() const;
301 ge::graphStatus CheckSingleParaCacheMode() const;305 ge::graphStatus CheckSingleParaCacheMode() const;
306+ ge::graphStatus CheckSingleParaGradEnabled() const;
302 ge::graphStatus CheckRequiredParaExistence() const;307 ge::graphStatus CheckRequiredParaExistence() const;
303 ge::graphStatus CheckRequiredInOutExistence() const;308 ge::graphStatus CheckRequiredInOutExistence() const;
304 ge::graphStatus CheckRequiredAttrExistence() const;309 ge::graphStatus CheckRequiredAttrExistence() const;
@@ -19,26 +19,25 @@
19using namespace std;19using namespace std;
20 20 
21// 构造版本21// 构造版本
22-std::string Compressor_tiling_A3SocInfo =22+std::string Compressor_tiling_A3SocInfo = "{\n"
23- "{\n"23+ " \"hardware_info\": {\n"
24- " \"hardware_info\": {\n"24+ " \"BT_SIZE\": 0,\n"
25- " \"BT_SIZE\": 0,\n"25+ " \"load3d_constraints\": \"1\",\n"
26- " \"load3d_constraints\": \"1\",\n"26+ " \"Intrinsic_fix_pipe_l0c2out\": false,\n"
27- " \"Intrinsic_fix_pipe_l0c2out\": false,\n"27+ " \"Intrinsic_data_move_l12ub\": true,\n"
28- " \"Intrinsic_data_move_l12ub\": true,\n"28+ " \"Intrinsic_data_move_l0c2ub\": true,\n"
29- " \"Intrinsic_data_move_l0c2ub\": true,\n"29+ " \"Intrinsic_data_move_out2l1_nd2nz\": false,\n"
30- " \"Intrinsic_data_move_out2l1_nd2nz\": false,\n"30+ " \"4096\": 196608,\n"
31- " \"4096\": 196608,\n"31+ " \"L2_SIZE\": 201326592,\n"
32- " \"L2_SIZE\": 201326592,\n"32+ " \"L1_SIZE\": 524288,\n"
33- " \"L1_SIZE\": 524288,\n"33+ " \"L0A_SIZE\": 65536,\n"
34- " \"L0A_SIZE\": 65536,\n"34+ " \"L0B_SIZE\": 65536,\n"
35- " \"L0B_SIZE\": 65536,\n"35+ " \"L0C_SIZE\": 131072,\n"
36- " \"L0C_SIZE\": 131072,\n"36+ " \"vector_core_cnt\": 40,\n"
37- " \"vector_core_cnt\": 40,\n"37+ " \"cube_core_cnt\": 20,\n"
38- " \"cube_core_cnt\": 20,\n"38+ " \"socVersion\": \"Ascend910_93\"\n"
39- " \"socVersion\": \"Ascend910_93\"\n"39+ " }\n"
40- " }\n"40+ "}";
41- "}";
42 41 
43// ====================================================================42// ====================================================================
44// BSH Layout Tiling Tests43// BSH Layout Tiling Tests
@@ -82,6 +81,7 @@ TEST_F(CompressorTilingArch22, test1)
82 {"coff", Ops::Transformer::AnyValue::CreateFrom<int64_t>(2)},81 {"coff", Ops::Transformer::AnyValue::CreateFrom<int64_t>(2)},
83 {"cache_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(1)},82 {"cache_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(1)},
84 {"state_cache_stride_dim0", Ops::Transformer::AnyValue::CreateFrom<int64_t>(262144)},83 {"state_cache_stride_dim0", Ops::Transformer::AnyValue::CreateFrom<int64_t>(262144)},
84+ {"grad_enabled", Ops::Transformer::AnyValue::CreateFrom<bool>(false)},
85 },85 },
86 &compileInfo, "Ascend910_93", Compressor_tiling_A3SocInfo, 4096);86 &compileInfo, "Ascend910_93", Compressor_tiling_A3SocInfo, 4096);
87 int64_t expectTilingKey = 32;87 int64_t expectTilingKey = 32;
@@ -357,6 +357,69 @@ TEST_F(CompressorTilingArch22, test6)
357// Error Cases — expected FAIL357// Error Cases — expected FAIL
358// ====================================================================358// ====================================================================
359 359 
360+// A3 does not support cache_mode=2 (ring buffer).
361+TEST_F(CompressorTilingArch22, test_cache_mode_ring_buffer_unsupported)
362+{
363+ optiling::CompressorCompileInfo compileInfo = {};
364+ gert::TilingContextPara tilingContextPara(
365+ "Compressor",
366+ {
367+ {{{2, 8, 4096}, {2, 8, 4096}}, ge::DT_BF16, ge::FORMAT_ND},
368+ {{{1024, 4096}, {1024, 4096}}, ge::DT_BF16, ge::FORMAT_ND},
369+ {{{1024, 4096}, {1024, 4096}}, ge::DT_BF16, ge::FORMAT_ND},
370+ {{{4, 128, 2048}, {4, 128, 2048}}, ge::DT_FLOAT, ge::FORMAT_ND},
371+ {{{4, 1024}, {4, 1024}}, ge::DT_FLOAT, ge::FORMAT_ND},
372+ {{{2, 8}, {2, 8}}, ge::DT_INT32, ge::FORMAT_ND},
373+ {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND},
374+ {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND},
375+ {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND},
376+ },
377+ {
378+ {{{2, 2, 512}, {2, 2, 512}}, ge::DT_BF16, ge::FORMAT_ND},
379+ {{{4, 128, 2048}, {4, 128, 2048}}, ge::DT_FLOAT, ge::FORMAT_ND},
380+ },
381+ {
382+ {"cmp_ratio", Ops::Transformer::AnyValue::CreateFrom<int64_t>(4)},
383+ {"coff", Ops::Transformer::AnyValue::CreateFrom<int64_t>(2)},
384+ {"cache_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(2)},
385+ {"state_cache_stride_dim0", Ops::Transformer::AnyValue::CreateFrom<int64_t>(262144)},
386+ },
387+ &compileInfo, "Ascend910_93", Compressor_tiling_A3SocInfo, 4096);
388+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, std::numeric_limits<uint64_t>::max());
389+}
390+ 
391+// A3 only supports grad_enabled=false.
392+TEST_F(CompressorTilingArch22, test_grad_enabled_unsupported)
393+{
394+ optiling::CompressorCompileInfo compileInfo = {};
395+ gert::TilingContextPara tilingContextPara(
396+ "Compressor",
397+ {
398+ {{{2, 8, 4096}, {2, 8, 4096}}, ge::DT_BF16, ge::FORMAT_ND},
399+ {{{1024, 4096}, {1024, 4096}}, ge::DT_BF16, ge::FORMAT_ND},
400+ {{{1024, 4096}, {1024, 4096}}, ge::DT_BF16, ge::FORMAT_ND},
401+ {{{4, 128, 2048}, {4, 128, 2048}}, ge::DT_FLOAT, ge::FORMAT_ND},
402+ {{{4, 1024}, {4, 1024}}, ge::DT_FLOAT, ge::FORMAT_ND},
403+ {{{2, 8}, {2, 8}}, ge::DT_INT32, ge::FORMAT_ND},
404+ {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND},
405+ {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND},
406+ {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND},
407+ },
408+ {
409+ {{{2, 2, 512}, {2, 2, 512}}, ge::DT_BF16, ge::FORMAT_ND},
410+ {{{4, 128, 2048}, {4, 128, 2048}}, ge::DT_FLOAT, ge::FORMAT_ND},
411+ },
412+ {
413+ {"cmp_ratio", Ops::Transformer::AnyValue::CreateFrom<int64_t>(4)},
414+ {"coff", Ops::Transformer::AnyValue::CreateFrom<int64_t>(2)},
415+ {"cache_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(1)},
416+ {"state_cache_stride_dim0", Ops::Transformer::AnyValue::CreateFrom<int64_t>(262144)},
417+ {"grad_enabled", Ops::Transformer::AnyValue::CreateFrom<bool>(true)},
418+ },
419+ &compileInfo, "Ascend910_93", Compressor_tiling_A3SocInfo, 4096);
420+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, std::numeric_limits<uint64_t>::max());
421+}
422+ 
360// Unsupported cmp_ratio=3423// Unsupported cmp_ratio=3
361TEST_F(CompressorTilingArch22, test7)424TEST_F(CompressorTilingArch22, test7)
362{425{