Merged
fix(pooling): 修复 max_pool3_d geir example 在 ascend950 上运行失败问题 #13463
陈晨Add on 19 days ago
fix(pooling): 修复 max_pool3_d geir example 在 ascend950 上运行失败问题 #13463
Merged
Total: 2 files changed+36-38
| @@ -40,10 +40,11 @@ using std::vector; | |||
| 40 | #define ADD_INPUT(inputIndex, inputName, inputDtype, inputShape) \ | 40 | #define ADD_INPUT(inputIndex, inputName, inputDtype, inputShape) \ |
| 41 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ | 41 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ |
| 42 | auto placeholder##inputIndex = op::Data("placeholder" + inputIndex).set_attr_index(0); \ | 42 | auto placeholder##inputIndex = op::Data("placeholder" + inputIndex).set_attr_index(0); \ |
| 43 | - TensorDesc placeholder##inputIndex##_desc = TensorDesc(ge::Shape(placeholder##inputIndex##_shape), FORMAT_ND, \ | 43 | + TensorDesc placeholder##inputIndex##_desc = TensorDesc(ge::Shape(placeholder##inputIndex##_shape), FORMAT_NDHWC, \ |
| 44 | inputDtype); \ | 44 | inputDtype); \ |
| 45 | placeholder##inputIndex##_desc.SetPlacement(ge::kPlacementHost); \ | 45 | placeholder##inputIndex##_desc.SetPlacement(ge::kPlacementHost); \ |
| 46 | - placeholder##inputIndex##_desc.SetFormat(FORMAT_ND); \ | 46 | + placeholder##inputIndex##_desc.SetFormat(FORMAT_NDHWC); \ |
| 47 | + placeholder##inputIndex##_desc.SetOriginFormat(FORMAT_NDHWC); \ | ||
| 47 | Tensor tensor_placeholder##inputIndex; \ | 48 | Tensor tensor_placeholder##inputIndex; \ |
| 48 | ret = GenOnesData(placeholder##inputIndex##_shape, tensor_placeholder##inputIndex, placeholder##inputIndex##_desc, \ | 49 | ret = GenOnesData(placeholder##inputIndex##_shape, tensor_placeholder##inputIndex, placeholder##inputIndex##_desc, \ |
| 49 | inputDtype, 2); \ | 50 | inputDtype, 2); \ |
| @@ -52,6 +53,7 @@ using std::vector; | |||
| 52 | return FAILED; \ | 53 | return FAILED; \ |
| 53 | } \ | 54 | } \ |
| 54 | placeholder##inputIndex.update_input_desc_x(placeholder##inputIndex##_desc); \ | 55 | placeholder##inputIndex.update_input_desc_x(placeholder##inputIndex##_desc); \ |
| 56 | + placeholder##inputIndex.update_output_desc_y(placeholder##inputIndex##_desc); \ | ||
| 55 | input.push_back(tensor_placeholder##inputIndex); \ | 57 | input.push_back(tensor_placeholder##inputIndex); \ |
| 56 | graph.AddOp(placeholder##inputIndex); \ | 58 | graph.AddOp(placeholder##inputIndex); \ |
| 57 | add1.set_input_##inputName(placeholder##inputIndex); \ | 59 | add1.set_input_##inputName(placeholder##inputIndex); \ |
| @@ -78,8 +80,10 @@ using std::vector; | |||
| 78 | add1.update_input_desc_##inputName(placeholder##inputIndex##_desc); \ | 80 | add1.update_input_desc_##inputName(placeholder##inputIndex##_desc); \ |
| 79 | inputs.push_back(placeholder##inputIndex) | 81 | inputs.push_back(placeholder##inputIndex) |
| 80 | 82 | ||
| 81 | -#define ADD_OUTPUT(outputIndex, outputName, outputDtype, outputShape) \ | 83 | +#define ADD_OUTPUT(outputIndex, outputName, outputDtype, outputShape) \ |
| 82 | - TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ | 84 | + TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_NDHWC, outputDtype); \ |
| 85 | + outputName##outputIndex##_desc.SetFormat(FORMAT_NDHWC); \ | ||
| 86 | + outputName##outputIndex##_desc.SetOriginFormat(FORMAT_NDHWC); \ | ||
| 83 | add1.update_output_desc_##outputName(outputName##outputIndex##_desc) | 87 | add1.update_output_desc_##outputName(outputName##outputIndex##_desc) |
| 84 | 88 | ||
| 85 | #define LOG_PRINT(message, ...) \ | 89 | #define LOG_PRINT(message, ...) \ |
| @@ -179,7 +183,7 @@ int CreateOppInGraph(DataType inDtype, std::vector<ge::Tensor>& input, std::vect | |||
| 179 | Status ret = SUCCESS; | 183 | Status ret = SUCCESS; |
| 180 | // 自定义代码:添加单算子定义到图中 | 184 | // 自定义代码:添加单算子定义到图中 |
| 181 | auto add1 = op::MaxPool3D("max_pool3_d"); | 185 | auto add1 = op::MaxPool3D("max_pool3_d"); |
| 182 | - vector<vector<int64_t>> shapes = {{4, 1, 4, 4, 6}, {4, 1, 1, 3, 6}}; | 186 | + vector<vector<int64_t>> shapes = {{4, 4, 4, 4, 6}, {4, 1, 1, 3, 6}}; |
| 183 | vector<vector<int64_t>> attrs = {{1, 2, 3, 2, 1}, {1, 4, 4, 1, 1}, {0, 0, 0, 0, 0, 0}}; | 187 | vector<vector<int64_t>> attrs = {{1, 2, 3, 2, 1}, {1, 4, 4, 1, 1}, {0, 0, 0, 0, 0, 0}}; |
| 184 | 188 | ||
| 185 | ADD_INPUT(1, x, inDtype, shapes[0]); | 189 | ADD_INPUT(1, x, inDtype, shapes[0]); |
| @@ -188,6 +192,7 @@ int CreateOppInGraph(DataType inDtype, std::vector<ge::Tensor>& input, std::vect | |||
| 188 | ADD_INPUT_ATTR(strides, attrs[1]); | 192 | ADD_INPUT_ATTR(strides, attrs[1]); |
| 189 | ADD_INPUT_ATTR(padding, "CALCULATED"); | 193 | ADD_INPUT_ATTR(padding, "CALCULATED"); |
| 190 | ADD_INPUT_ATTR(pads, attrs[2]); | 194 | ADD_INPUT_ATTR(pads, attrs[2]); |
| 195 | + ADD_INPUT_ATTR(data_format, "NDHWC"); | ||
| 191 | outputs.push_back(add1); | 196 | outputs.push_back(add1); |
| 192 | // 添加完毕 | 197 | // 添加完毕 |
| 193 | return SUCCESS; | 198 | return SUCCESS; |
| @@ -26,47 +26,42 @@ | |||
| 26 | #include "array_ops.h" | 26 | #include "array_ops.h" |
| 27 | #include "ge_ir_build.h" | 27 | #include "ge_ir_build.h" |
| 28 | 28 | ||
| 29 | +#include "experiment_ops.h" | ||
| 29 | #include "nn_other.h" | 30 | #include "nn_other.h" |
| 30 | #include "../op_graph/max_pool3_d_proto.h" | 31 | #include "../op_graph/max_pool3_d_proto.h" |
| 31 | 32 | ||
| 32 | #define FAILED -1 | 33 | #define FAILED -1 |
| 33 | #define SUCCESS 0 | 34 | #define SUCCESS 0 |
| 34 | -#define C0_SIZE 16 // NDC1HWC0 物理格式中 C0 分块大小,FP16/FP32 在 910B 上为 16 | ||
| 35 | - | ||
| 36 | -// 由 NDHWC 5D 原始形状 (N, D, H, W, C) 计算 NDC1HWC0 6D 存储形状 (N, D, C1, H, W, C0) | ||
| 37 | -#define GET_NDC1HWC0_SHAPE(varName, ndhwcShape) \ | ||
| 38 | - int64_t varName##_c1 = (ndhwcShape[4] + C0_SIZE - 1) / C0_SIZE; \ | ||
| 39 | - vector<int64_t> varName = {ndhwcShape[0], ndhwcShape[1], varName##_c1, ndhwcShape[2], ndhwcShape[3], C0_SIZE} | ||
| 40 | 35 | ||
| 41 | using namespace ge; | 36 | using namespace ge; |
| 42 | using std::map; | 37 | using std::map; |
| 43 | using std::string; | 38 | using std::string; |
| 44 | using std::vector; | 39 | using std::vector; |
| 45 | -#define ADD_INPUT(inputIndex, inputName, inputDtype, inputShape) \ | 40 | +#define ADD_INPUT(inputIndex, inputName, inputDtype, inputShape) \ |
| 46 | - vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ | 41 | + vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ |
| 47 | - GET_NDC1HWC0_SHAPE(placeholder##inputIndex##_storage_shape, placeholder##inputIndex##_shape); \ | 42 | + auto placeholder##inputIndex = op::Data("placeholder" + inputIndex).set_attr_index(0); \ |
| 48 | - auto placeholder##inputIndex = op::Data("placeholder" #inputIndex).set_attr_index(0); \ | 43 | + TensorDesc placeholder##inputIndex##_desc = TensorDesc(ge::Shape(placeholder##inputIndex##_shape), FORMAT_NDHWC, \ |
| 49 | - TensorDesc placeholder##inputIndex##_desc = TensorDesc(ge::Shape(placeholder##inputIndex##_storage_shape), \ | 44 | + inputDtype); \ |
| 50 | - FORMAT_NDC1HWC0, inputDtype); \ | 45 | + placeholder##inputIndex##_desc.SetPlacement(ge::kPlacementHost); \ |
| 51 | - placeholder##inputIndex##_desc.SetOriginShape(ge::Shape(placeholder##inputIndex##_shape)); \ | 46 | + placeholder##inputIndex##_desc.SetFormat(FORMAT_NDHWC); \ |
| 52 | - placeholder##inputIndex##_desc.SetOriginFormat(FORMAT_NDHWC); \ | 47 | + placeholder##inputIndex##_desc.SetOriginFormat(FORMAT_NDHWC); \ |
| 53 | - placeholder##inputIndex##_desc.SetPlacement(ge::kPlacementHost); \ | 48 | + Tensor tensor_placeholder##inputIndex; \ |
| 54 | - Tensor tensor_placeholder##inputIndex; \ | 49 | + ret = GenOnesData(placeholder##inputIndex##_shape, tensor_placeholder##inputIndex, placeholder##inputIndex##_desc, \ |
| 55 | - ret = GenOnesData(placeholder##inputIndex##_storage_shape, tensor_placeholder##inputIndex, \ | 50 | + inputDtype, 2); \ |
| 56 | - placeholder##inputIndex##_desc, inputDtype, 2); \ | 51 | + if (ret != SUCCESS) { \ |
| 57 | - if (ret != SUCCESS) { \ | 52 | + printf("%s - ERROR - [XIR]: Generate input data failed\n", GetTime().c_str()); \ |
| 58 | - printf("%s - ERROR - [XIR]: Generate input data failed\n", GetTime().c_str()); \ | 53 | + return FAILED; \ |
| 59 | - return FAILED; \ | 54 | + } \ |
| 60 | - } \ | 55 | + placeholder##inputIndex.update_input_desc_x(placeholder##inputIndex##_desc); \ |
| 61 | - placeholder##inputIndex.update_input_desc_x(placeholder##inputIndex##_desc); \ | 56 | + placeholder##inputIndex.update_output_desc_y(placeholder##inputIndex##_desc); \ |
| 62 | - input.push_back(tensor_placeholder##inputIndex); \ | 57 | + input.push_back(tensor_placeholder##inputIndex); \ |
| 63 | - graph.AddOp(placeholder##inputIndex); \ | 58 | + graph.AddOp(placeholder##inputIndex); \ |
| 64 | - add1.set_input_##inputName(placeholder##inputIndex); \ | 59 | + add1.set_input_##inputName(placeholder##inputIndex); \ |
| 65 | inputs.push_back(placeholder##inputIndex) | 60 | inputs.push_back(placeholder##inputIndex) |
| 66 | 61 | ||
| 67 | #define ADD_CONST_INPUT(inputIndex, inputName, inputDtype, inputShape) \ | 62 | #define ADD_CONST_INPUT(inputIndex, inputName, inputDtype, inputShape) \ |
| 68 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ | 63 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ |
| 69 | - auto placeholder##inputIndex = op::Const("placeholder" #inputIndex); \ | 64 | + auto placeholder##inputIndex = op::Const("placeholder" + inputIndex); \ |
| 70 | TensorDesc placeholder##inputIndex##_desc = TensorDesc(ge::Shape(placeholder##inputIndex##_shape), FORMAT_ND, \ | 65 | TensorDesc placeholder##inputIndex##_desc = TensorDesc(ge::Shape(placeholder##inputIndex##_shape), FORMAT_ND, \ |
| 71 | inputDtype); \ | 66 | inputDtype); \ |
| 72 | placeholder##inputIndex##_desc.SetPlacement(ge::kPlacementHost); \ | 67 | placeholder##inputIndex##_desc.SetPlacement(ge::kPlacementHost); \ |
| @@ -86,11 +81,8 @@ using std::vector; | |||
| 86 | inputs.push_back(placeholder##inputIndex) | 81 | inputs.push_back(placeholder##inputIndex) |
| 87 | 82 | ||
| 88 | #define ADD_OUTPUT(outputIndex, outputName, outputDtype, outputShape) \ | 83 | #define ADD_OUTPUT(outputIndex, outputName, outputDtype, outputShape) \ |
| 89 | - vector<int64_t> outputName##outputIndex##_shape = outputShape; \ | 84 | + TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_NDHWC, outputDtype); \ |
| 90 | - GET_NDC1HWC0_SHAPE(outputName##outputIndex##_storage_shape, outputName##outputIndex##_shape); \ | 85 | + outputName##outputIndex##_desc.SetFormat(FORMAT_NDHWC); \ |
| 91 | - TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputName##outputIndex##_storage_shape), \ | ||
| 92 | - FORMAT_NDC1HWC0, outputDtype); \ | ||
| 93 | - outputName##outputIndex##_desc.SetOriginShape(ge::Shape(outputName##outputIndex##_shape)); \ | ||
| 94 | outputName##outputIndex##_desc.SetOriginFormat(FORMAT_NDHWC); \ | 86 | outputName##outputIndex##_desc.SetOriginFormat(FORMAT_NDHWC); \ |
| 95 | add1.update_output_desc_##outputName(outputName##outputIndex##_desc) | 87 | add1.update_output_desc_##outputName(outputName##outputIndex##_desc) |
| 96 | 88 | ||
| @@ -191,7 +183,7 @@ int CreateOppInGraph(DataType inDtype, std::vector<ge::Tensor>& input, std::vect | |||
| 191 | Status ret = SUCCESS; | 183 | Status ret = SUCCESS; |
| 192 | // 自定义代码:添加单算子定义到图中 | 184 | // 自定义代码:添加单算子定义到图中 |
| 193 | auto add1 = op::MaxPool3D("max_pool3_d"); | 185 | auto add1 = op::MaxPool3D("max_pool3_d"); |
| 194 | - vector<vector<int64_t>> shapes = {{4, 1, 4, 4, 6}, {4, 1, 1, 3, 6}}; | 186 | + vector<vector<int64_t>> shapes = {{4, 4, 4, 4, 6}, {4, 1, 1, 3, 6}}; |
| 195 | vector<vector<int64_t>> attrs = {{1, 2, 3, 2, 1}, {1, 4, 4, 1, 1}, {0, 0, 0, 0, 0, 0}}; | 187 | vector<vector<int64_t>> attrs = {{1, 2, 3, 2, 1}, {1, 4, 4, 1, 1}, {0, 0, 0, 0, 0, 0}}; |
| 196 | 188 | ||
| 197 | ADD_INPUT(1, x, inDtype, shapes[0]); | 189 | ADD_INPUT(1, x, inDtype, shapes[0]); |
| @@ -200,6 +192,7 @@ int CreateOppInGraph(DataType inDtype, std::vector<ge::Tensor>& input, std::vect | |||
| 200 | ADD_INPUT_ATTR(strides, attrs[1]); | 192 | ADD_INPUT_ATTR(strides, attrs[1]); |
| 201 | ADD_INPUT_ATTR(padding, "CALCULATED"); | 193 | ADD_INPUT_ATTR(padding, "CALCULATED"); |
| 202 | ADD_INPUT_ATTR(pads, attrs[2]); | 194 | ADD_INPUT_ATTR(pads, attrs[2]); |
| 195 | + ADD_INPUT_ATTR(data_format, "NDHWC"); | ||
| 203 | outputs.push_back(add1); | 196 | outputs.push_back(add1); |
| 204 | // 添加完毕 | 197 | // 添加完毕 |
| 205 | return SUCCESS; | 198 | return SUCCESS; |