已合并
fix: 拦截不支持ScalarData的codegen输入(#161) #1209
fix: 拦截不支持ScalarData的codegen输入(#161) #1209
已合并
zqmin创建于 7月6日
共 2 个文件变更+103-2
@@ -14,6 +14,11 @@
14 14 
15namespace af {15namespace af {
16namespace ascir {16namespace ascir {
17+namespace {
18+bool IsScalarInputType(const std::string &node_type) {
19+ return node_type == "Scalar" || node_type == "ScalarData";
20+}
21+} // namespace
17 22 
18bool OnlySecondInputSupportScalar(const std::vector<bool> &is_scalar_list) {23bool OnlySecondInputSupportScalar(const std::vector<bool> &is_scalar_list) {
19 GE_ASSERT_EQ(is_scalar_list.size(), 2UL);24 GE_ASSERT_EQ(is_scalar_list.size(), 2UL);
@@ -213,7 +218,7 @@ Status ValidateShapeConsistencyWithSingleOutput(const AscNode &node, const Broad
213bool IsNodeHasScalarInput(const AscNode &node) {218bool IsNodeHasScalarInput(const AscNode &node) {
214 AscNodeInputs node_inputs = node.inputs;219 AscNodeInputs node_inputs = node.inputs;
215 for (size_t i = 0; i < node_inputs().size(); i++) {220 for (size_t i = 0; i < node_inputs().size(); i++) {
216- if (node.GetInDataNodes().at(i)->GetType() == "Scalar") {221+ if (IsScalarInputType(node.GetInDataNodes().at(i)->GetType())) {
217 return true;222 return true;
218 }223 }
219 }224 }
@@ -221,7 +226,7 @@ bool IsNodeHasScalarInput(const AscNode &node) {
221}226}
222 227 
223bool IsNodeFirstInputScalar(const AscNode &node) {228bool IsNodeFirstInputScalar(const AscNode &node) {
224- return node.GetInDataNodes().at(0)->GetType() == "Scalar";229+ return IsScalarInputType(node.GetInDataNodes().at(0)->GetType());
225}230}
226} // namespace ascir231} // namespace ascir
227} // namespace af232} // namespace af
@@ -32,6 +32,51 @@ namespace {
32std::string ToString(const af::Expression &e) {32std::string ToString(const af::Expression &e) {
33 return std::string(e.Serialize().get());33 return std::string(e.Serialize().get());
34}34}
35+ 
36+void SetGlobalOutput(const af::AscNodePtr &node, uint32_t tensor_id) {
37+ node->outputs[0].attr.mem.alloc_type = af::AllocType::kAllocTypeGlobal;
38+ node->outputs[0].attr.mem.tensor_id = tensor_id;
39+}
40+ 
41+void SetScalarLikeQueueOutput(const af::AscNodePtr &node, const af::Axis &axis, const af::Expression &repeat,
42+ uint32_t tensor_id, uint32_t queue_id) {
43+ auto &attr = node->outputs[0].attr;
44+ attr.axis = {axis.id};
45+ attr.vectorized_axis = {axis.id};
46+ attr.vectorized_strides = {af::ops::Zero};
47+ attr.repeats = {repeat};
48+ attr.strides = {af::ops::Zero};
49+ attr.mem.alloc_type = af::AllocType::kAllocTypeQueue;
50+ attr.mem.tensor_id = tensor_id;
51+ attr.que.id = queue_id;
52+ attr.mem.reuse_id = 0;
53+ attr.que.depth = 2;
54+ attr.que.buf_num = 2;
55+ attr.opt.merge_scope = af::kIdNone;
56+}
57+ 
58+void SetVectorQueueOutput(const af::AscNodePtr &node, const af::Axis &axis, const af::Expression &repeat,
59+ af::Position position, uint32_t tensor_id, uint32_t queue_id) {
60+ auto &attr = node->outputs[0].attr;
61+ attr.axis = {axis.id};
62+ attr.vectorized_axis = {axis.id};
63+ attr.vectorized_strides = {af::ops::One};
64+ attr.repeats = {repeat};
65+ attr.strides = {af::ops::One};
66+ attr.mem.position = position;
67+ attr.mem.alloc_type = af::AllocType::kAllocTypeQueue;
68+ attr.mem.tensor_id = tensor_id;
69+ attr.que.id = queue_id;
70+ attr.opt.merge_scope = af::kIdNone;
71+}
72+ 
73+void SetVectorInputQueueOutput(const af::AscNodePtr &node, const af::Axis &axis, const af::Expression &repeat,
74+ uint32_t tensor_id, uint32_t queue_id) {
75+ SetVectorQueueOutput(node, axis, repeat, af::Position::kPositionVecIn, tensor_id, queue_id);
76+ node->outputs[0].attr.mem.reuse_id = 0;
77+ node->outputs[0].attr.que.depth = 2;
78+ node->outputs[0].attr.que.buf_num = 2;
79+}
35} // namespace80} // namespace
36 81 
37TEST(CodegenKernel, Kernel_DynamicInputDtypeCheck) {82TEST(CodegenKernel, Kernel_DynamicInputDtypeCheck) {
@@ -443,6 +488,57 @@ TEST(CodegenKernel, Kernel_DynamicShapeConsistencyCheckValid) {
443 EXPECT_EQ(ret, af::SUCCESS);488 EXPECT_EQ(ret, af::SUCCESS);
444}489}
445 490 
491+TEST(CodegenKernel, Kernel_BitwiseAndScalarDataInputInvalidCheck) {
492+ af::AscGraph graph("test_graph");
493+ const af::Expression s0 = graph.CreateSizeVar(8);
494+ auto z0 = graph.CreateAxis("z0", s0);
495+ 
496+ af::ascir_op::Data x_op("x", graph);
497+ x_op.ir_attr.SetIndex(0);
498+ af::ascir_op::ScalarData scalar_op("scalar", graph);
499+ scalar_op.ir_attr.SetIndex(1);
500+ 
501+ af::ascir_op::Load load_op("load");
502+ af::ascir_op::BitwiseAnd bitwise_and_op("bitwise_and");
503+ af::ascir_op::Store store_op("store");
504+ af::ascir_op::Output y_op("y");
505+ y_op.ir_attr.SetIndex(0);
506+ 
507+ x_op.y.dtype = ge::DT_UINT8;
508+ scalar_op.y.dtype = ge::DT_UINT8;
509+ load_op.x = x_op.y;
510+ load_op.y.dtype = ge::DT_UINT8;
511+ bitwise_and_op.x1 = load_op.y;
512+ bitwise_and_op.x2 = scalar_op.y;
513+ bitwise_and_op.y.dtype = ge::DT_UINT8;
514+ store_op.x = bitwise_and_op.y;
515+ store_op.y.dtype = ge::DT_UINT8;
516+ y_op.x = store_op.y;
517+ y_op.y.dtype = ge::DT_UINT8;
518+ 
519+ auto x = graph.FindNode("x");
520+ auto scalar = graph.FindNode("scalar");
521+ auto load = graph.FindNode("load");
522+ auto bitwise_and = graph.FindNode("bitwise_and");
523+ auto store = graph.FindNode("store");
524+ ASSERT_NE(x, nullptr);
525+ ASSERT_NE(scalar, nullptr);
526+ ASSERT_NE(load, nullptr);
527+ ASSERT_NE(bitwise_and, nullptr);
528+ ASSERT_NE(store, nullptr);
529+ 
530+ SetGlobalOutput(x, 0);
531+ SetScalarLikeQueueOutput(scalar, z0, s0, 1, 0);
532+ SetVectorInputQueueOutput(load, z0, s0, 2, 1);
533+ 
534+ bitwise_and->attr.api.unit = af::ComputeUnit::kUnitVector;
535+ SetVectorQueueOutput(bitwise_and, z0, s0, af::Position::kPositionVecOut, 3, 2);
536+ SetGlobalOutput(store, 4);
537+ 
538+ auto ret = CheckGraphValidity(graph);
539+ EXPECT_NE(ret, af::SUCCESS);
540+}
541+ 
446TEST(CodegenKernel, Kernel_StaticShapeVecAxisConsistencyInValidCheck) {542TEST(CodegenKernel, Kernel_StaticShapeVecAxisConsistencyInValidCheck) {
447 af::AscGraph graph("test_graph");543 af::AscGraph graph("test_graph");
448 const af::Expression s0 = graph.CreateSizeVar(3);544 const af::Expression s0 = graph.CreateSizeVar(3);