已合并
revert add_example #596
weinachuan创建于 2025年12月25日
revert add_example #596
已合并
共 17 个文件变更+28-658
| @@ -66,4 +66,4 @@ $$ | |||
| 66 | 66 | ||
| 67 | | 调用方式 | 调用样例 | 说明 | | 67 | | 调用方式 | 调用样例 | 说明 | |
| 68 | |--------------|------------------------------------------------------------------------|--------------------------------------------------------------| | 68 | |--------------|------------------------------------------------------------------------|--------------------------------------------------------------| |
| 69 | -| 图模式调用 | [test_geir_add_example](./examples/test_geir_add_example.cpp) | 通过[算子IR](./op_graph/add_example_proto.h)构图方式调用AddExample算子。 | | 69 | +| aclnn调用 | [test_aclnn_add_example](./examples/test_aclnn_add_example.cpp) | 通过直调的方式调用AddExample算子。 | |
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | -#include "aclnn_add_example.h" | 14 | +#include "aclnnop/aclnn_add_example.h" |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | do { \ | 17 | do { \ |
| @@ -97,21 +97,21 @@ int main() | |||
| 97 | aclTensor* selfX = nullptr; | 97 | aclTensor* selfX = nullptr; |
| 98 | void* selfXDeviceAddr = nullptr; | 98 | void* selfXDeviceAddr = nullptr; |
| 99 | std::vector<int64_t> selfXShape = {32, 4, 4, 4}; | 99 | std::vector<int64_t> selfXShape = {32, 4, 4, 4}; |
| 100 | - std::vector<float> selfXHostData(2048, 1); | 100 | + std::vector<float> selfXHostData(2048, 1); // 2048:创建包含32*4*4*4=2048个元素的向量 |
| 101 | ret = CreateAclTensor(selfXHostData, selfXShape, &selfXDeviceAddr, aclDataType::ACL_FLOAT, &selfX); | 101 | ret = CreateAclTensor(selfXHostData, selfXShape, &selfXDeviceAddr, aclDataType::ACL_FLOAT, &selfX); |
| 102 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 102 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 103 | 103 | ||
| 104 | aclTensor* selfY = nullptr; | 104 | aclTensor* selfY = nullptr; |
| 105 | void* selfYDeviceAddr = nullptr; | 105 | void* selfYDeviceAddr = nullptr; |
| 106 | std::vector<int64_t> selfYShape = {32, 4, 4, 4}; | 106 | std::vector<int64_t> selfYShape = {32, 4, 4, 4}; |
| 107 | - std::vector<float> selfYHostData(2048, 1); | 107 | + std::vector<float> selfYHostData(2048, 1); // 2048:创建包含32*4*4*4=2048个元素的向量 |
| 108 | ret = CreateAclTensor(selfYHostData, selfYShape, &selfYDeviceAddr, aclDataType::ACL_FLOAT, &selfY); | 108 | ret = CreateAclTensor(selfYHostData, selfYShape, &selfYDeviceAddr, aclDataType::ACL_FLOAT, &selfY); |
| 109 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 109 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 110 | 110 | ||
| 111 | aclTensor* out = nullptr; | 111 | aclTensor* out = nullptr; |
| 112 | void* outDeviceAddr = nullptr; | 112 | void* outDeviceAddr = nullptr; |
| 113 | std::vector<int64_t> outShape = {32, 4, 4, 4}; | 113 | std::vector<int64_t> outShape = {32, 4, 4, 4}; |
| 114 | - std::vector<float> outHostData(2048, 1); | 114 | + std::vector<float> outHostData(2048, 1); // 2048:创建包含32*4*4*4=2048个元素的向量 |
| 115 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 115 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| 116 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 116 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 117 | 117 | ||
| @@ -1,300 +0,0 @@ | |||
| 1 | -/** | ||
| 2 | - * Copyright (c) 2025 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 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | -using namespace ge; | ||
| 37 | -using std::map; | ||
| 38 | -using std::string; | ||
| 39 | -using std::vector; | ||
| 40 | - | ||
| 41 | - vector<int64_t> placeholder##intputIndex##_shape = inputShape; \ | ||
| 42 | - auto placeholder##intputIndex = op::Data("placeholder" + intputIndex).set_attr_index(0); \ | ||
| 43 | - TensorDesc placeholder##intputIndex##_desc = \ | ||
| 44 | - TensorDesc(ge::Shape(placeholder##intputIndex##_shape), FORMAT_ND, intputDtype); \ | ||
| 45 | - placeholder##intputIndex##_desc.SetPlacement(ge::kPlacementHost); \ | ||
| 46 | - placeholder##intputIndex##_desc.SetFormat(FORMAT_ND); \ | ||
| 47 | - Tensor tensor_placeholder##intputIndex; \ | ||
| 48 | - ret = GenOnesData(placeholder##intputIndex##_shape, \ | ||
| 49 | - tensor_placeholder##intputIndex, \ | ||
| 50 | - placeholder##intputIndex##_desc, \ | ||
| 51 | - intputDtype, \ | ||
| 52 | - 2); \ | ||
| 53 | - if (ret != SUCCESS) { \ | ||
| 54 | - printf("%s - ERROR - [XIR]: Generate input data failed\n", GetTime().c_str()); \ | ||
| 55 | - return FAILED; \ | ||
| 56 | - } \ | ||
| 57 | - placeholder##intputIndex.update_input_desc_x(placeholder##intputIndex##_desc); \ | ||
| 58 | - input.push_back(tensor_placeholder##intputIndex); \ | ||
| 59 | - graph.AddOp(placeholder##intputIndex); \ | ||
| 60 | - add1.set_input_##intputName(placeholder##intputIndex); \ | ||
| 61 | - inputs.push_back(placeholder##intputIndex); | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - vector<int64_t> placeholder##intputIndex##_shape = inputShape; \ | ||
| 65 | - auto placeholder##intputIndex = op::Const("placeholder" + intputIndex); \ | ||
| 66 | - TensorDesc placeholder##intputIndex##_desc = \ | ||
| 67 | - TensorDesc(ge::Shape(placeholder##intputIndex##_shape), FORMAT_ND, intputDtype); \ | ||
| 68 | - placeholder##intputIndex##_desc.SetPlacement(ge::kPlacementHost); \ | ||
| 69 | - placeholder##intputIndex##_desc.SetFormat(FORMAT_ND); \ | ||
| 70 | - Tensor tensor_placeholder##intputIndex; \ | ||
| 71 | - ret = GenOnesData(placeholder##intputIndex##_shape, \ | ||
| 72 | - tensor_placeholder##intputIndex, \ | ||
| 73 | - placeholder##intputIndex##_desc, \ | ||
| 74 | - intputDtype, \ | ||
| 75 | - 2); \ | ||
| 76 | - if (ret != SUCCESS) { \ | ||
| 77 | - printf("%s - ERROR - [XIR]: Generate input data failed\n", GetTime().c_str()); \ | ||
| 78 | - return FAILED; \ | ||
| 79 | - } \ | ||
| 80 | - placeholder##intputIndex.SetAttr("value", tensor_placeholder##intputIndex); \ | ||
| 81 | - placeholder##intputIndex.update_output_desc_y(placeholder##intputIndex##_desc); \ | ||
| 82 | - graph.AddOp(placeholder##intputIndex); \ | ||
| 83 | - add1.set_input_##intputName(placeholder##intputIndex); \ | ||
| 84 | - add1.update_input_desc_##intputName(placeholder##intputIndex##_desc); \ | ||
| 85 | - inputs.push_back(placeholder##intputIndex); | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - TensorDesc outputName##outputIndex##_desc = \ | ||
| 89 | - TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ | ||
| 90 | - add1.update_output_desc_##outputName(outputName##outputIndex##_desc); | ||
| 91 | - | ||
| 92 | -string GetTime() | ||
| 93 | -{ | ||
| 94 | - time_t timep; | ||
| 95 | - time(&timep); | ||
| 96 | - char tmp[64]; | ||
| 97 | - strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S,000", localtime(&timep)); | ||
| 98 | - return tmp; | ||
| 99 | -} | ||
| 100 | - | ||
| 101 | -uint32_t GetDataTypeSize(DataType dt) | ||
| 102 | -{ | ||
| 103 | - uint32_t dilation = 1; | ||
| 104 | - uint32_t oneByte = 1; | ||
| 105 | - uint32_t twoByte = 2; | ||
| 106 | - uint32_t fourByte = 4; | ||
| 107 | - uint32_t eightByte = 8; | ||
| 108 | - | ||
| 109 | - if (dt == ge::DT_FLOAT) { | ||
| 110 | - dilation = fourByte; | ||
| 111 | - } else if (dt == ge::DT_FLOAT16) { | ||
| 112 | - dilation = twoByte; | ||
| 113 | - } else if (dt == ge::DT_BF16) { | ||
| 114 | - dilation = twoByte; | ||
| 115 | - } else if (dt == ge::DT_INT16) { | ||
| 116 | - dilation = twoByte; | ||
| 117 | - } else if (dt == ge::DT_UINT16) { | ||
| 118 | - dilation = twoByte; | ||
| 119 | - } else if (dt == ge::DT_INT32) { | ||
| 120 | - dilation = fourByte; | ||
| 121 | - } else if (dt == ge::DT_UINT32) { | ||
| 122 | - dilation = fourByte; | ||
| 123 | - } else if (dt == ge::DT_INT64) { | ||
| 124 | - dilation = eightByte; | ||
| 125 | - } else if (dt == ge::DT_UINT64) { | ||
| 126 | - dilation = eightByte; | ||
| 127 | - } else if (dt == ge::DT_INT8) { | ||
| 128 | - dilation = oneByte; | ||
| 129 | - } | ||
| 130 | - return dilation; | ||
| 131 | -} | ||
| 132 | - | ||
| 133 | -int32_t GenOnesDataFloat32(vector<int64_t> shapes, Tensor &input_tensor, TensorDesc &input_tensor_desc, float value) | ||
| 134 | -{ | ||
| 135 | - input_tensor_desc.SetRealDimCnt(shapes.size()); | ||
| 136 | - size_t size = 1; | ||
| 137 | - for (uint32_t i = 0; i < shapes.size(); i++) { | ||
| 138 | - size *= shapes[i]; | ||
| 139 | - } | ||
| 140 | - uint32_t byteSizeFloat32 = 4; | ||
| 141 | - uint32_t data_len = size * byteSizeFloat32; | ||
| 142 | - float *pData = new (std::nothrow) float[size]; | ||
| 143 | - | ||
| 144 | - for (size_t i = 0; i < size; ++i) { | ||
| 145 | - *(pData + i) = value; | ||
| 146 | - } | ||
| 147 | - input_tensor = Tensor(input_tensor_desc, (uint8_t *)pData, data_len); | ||
| 148 | - return SUCCESS; | ||
| 149 | -} | ||
| 150 | - | ||
| 151 | -int32_t GenOnesData( | ||
| 152 | - vector<int64_t> shapes, Tensor &input_tensor, TensorDesc &input_tensor_desc, DataType data_type, int value) | ||
| 153 | -{ | ||
| 154 | - input_tensor_desc.SetRealDimCnt(shapes.size()); | ||
| 155 | - size_t size = 1; | ||
| 156 | - for (uint32_t i = 0; i < shapes.size(); i++) { | ||
| 157 | - size *= shapes[i]; | ||
| 158 | - } | ||
| 159 | - uint32_t data_len = size * GetDataTypeSize(data_type); | ||
| 160 | - int32_t *pData = new (std::nothrow) int32_t[data_len]; | ||
| 161 | - for (uint32_t i = 0; i < size; ++i) { | ||
| 162 | - *(pData + i) = value; | ||
| 163 | - } | ||
| 164 | - input_tensor = Tensor(input_tensor_desc, reinterpret_cast<uint8_t *>(pData), data_len); | ||
| 165 | - return SUCCESS; | ||
| 166 | -} | ||
| 167 | - | ||
| 168 | -int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) | ||
| 169 | -{ | ||
| 170 | - FILE *fp; | ||
| 171 | - fp = fopen(bin_file.c_str(), "w"); | ||
| 172 | - fwrite(inputData, sizeof(uint8_t), data_size, fp); | ||
| 173 | - fclose(fp); | ||
| 174 | - return SUCCESS; | ||
| 175 | -} | ||
| 176 | - | ||
| 177 | -int CreateOppInGraph(DataType inDtype, std::vector<ge::Tensor> &input, std::vector<Operator> &inputs, | ||
| 178 | - std::vector<Operator> &outputs, Graph &graph) | ||
| 179 | -{ | ||
| 180 | - Status ret = SUCCESS; | ||
| 181 | - // 自定义代码:添加单算子定义到图中 | ||
| 182 | - auto add1 = op::AddExample("add1"); | ||
| 183 | - std::vector<int64_t> xShape = {32,4,4,4}; | ||
| 184 | - ADD_INPUT(1, x1, inDtype, xShape); | ||
| 185 | - ADD_INPUT(2, x2, inDtype, xShape); | ||
| 186 | - | ||
| 187 | - ADD_OUTPUT(1, y, inDtype, xShape); | ||
| 188 | - | ||
| 189 | - outputs.push_back(add1); | ||
| 190 | - // 添加完毕 | ||
| 191 | - return SUCCESS; | ||
| 192 | -} | ||
| 193 | - | ||
| 194 | -int main(int argc, char *argv[]) | ||
| 195 | -{ | ||
| 196 | - const char *graph_name = "tc_ge_irrun_test"; | ||
| 197 | - Graph graph(graph_name); | ||
| 198 | - std::vector<ge::Tensor> input; | ||
| 199 | - | ||
| 200 | - printf("%s - INFO - [XIR]: Start to initialize ge using ge global options\n", GetTime().c_str()); | ||
| 201 | - std::map<AscendString, AscendString> global_options = {{"ge.exec.deviceId", "0"}, {"ge.graphRunMode", "1"}}; | ||
| 202 | - Status ret = ge::GEInitialize(global_options); | ||
| 203 | - if (ret != SUCCESS) { | ||
| 204 | - printf("%s - INFO - [XIR]: Initialize ge using ge global options failed\n", GetTime().c_str()); | ||
| 205 | - return FAILED; | ||
| 206 | - } | ||
| 207 | - printf("%s - INFO - [XIR]: Initialize ge using ge global options success\n", GetTime().c_str()); | ||
| 208 | - | ||
| 209 | - std::vector<Operator> inputs{}; | ||
| 210 | - std::vector<Operator> outputs{}; | ||
| 211 | - | ||
| 212 | - std::cout << argv[1] << std::endl; | ||
| 213 | - char *endptr; | ||
| 214 | - | ||
| 215 | - DataType inDtype = DT_FLOAT; | ||
| 216 | - | ||
| 217 | - std::cout << inDtype << std::endl; | ||
| 218 | - | ||
| 219 | - ret = CreateOppInGraph(inDtype, input, inputs, outputs, graph); | ||
| 220 | - if (ret != SUCCESS) { | ||
| 221 | - printf("%s - ERROR - [XIR]: Create ir session using build options failed\n", GetTime().c_str()); | ||
| 222 | - return FAILED; | ||
| 223 | - } | ||
| 224 | - | ||
| 225 | - if (!inputs.empty() && !outputs.empty()) { | ||
| 226 | - graph.SetInputs(inputs).SetOutputs(outputs); | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - std::map<AscendString, AscendString> build_options = { | ||
| 230 | - | ||
| 231 | - }; | ||
| 232 | - printf("%s - INFO - [XIR]: Start to create ir session using build options\n", GetTime().c_str()); | ||
| 233 | - ge::Session *session = new Session(build_options); | ||
| 234 | - | ||
| 235 | - if (session == nullptr) { | ||
| 236 | - printf("%s - ERROR - [XIR]: Create ir session using build options failed\n", GetTime().c_str()); | ||
| 237 | - return FAILED; | ||
| 238 | - } | ||
| 239 | - printf("%s - INFO - [XIR]: Create ir session using build options success\n", GetTime().c_str()); | ||
| 240 | - printf("%s - INFO - [XIR]: Start to add compute graph to ir session\n", GetTime().c_str()); | ||
| 241 | - | ||
| 242 | - std::map<AscendString, AscendString> graph_options = { | ||
| 243 | - | ||
| 244 | - }; | ||
| 245 | - uint32_t graph_id = 0; | ||
| 246 | - ret = session->AddGraph(graph_id, graph, graph_options); | ||
| 247 | - | ||
| 248 | - printf("%s - INFO - [XIR]: Session add ir compute graph to ir session success\n", GetTime().c_str()); | ||
| 249 | - printf("%s - INFO - [XIR]: dump graph to txt\n", GetTime().c_str()); | ||
| 250 | - std::string file_path = "./dump"; | ||
| 251 | - aclgrphDumpGraph(graph, file_path.c_str(), file_path.length()); | ||
| 252 | - printf("%s - INFO - [XIR]: Start to run ir compute graph\n", GetTime().c_str()); | ||
| 253 | - std::vector<ge::Tensor> output; | ||
| 254 | - ret = session->RunGraph(graph_id, input, output); | ||
| 255 | - if (ret != SUCCESS) { | ||
| 256 | - printf("%s - INFO - [XIR]: Run graph failed\n", GetTime().c_str()); | ||
| 257 | - delete session; | ||
| 258 | - GEFinalize(); | ||
| 259 | - return FAILED; | ||
| 260 | - } | ||
| 261 | - printf("%s - INFO - [XIR]: Session run ir compute graph success\n", GetTime().c_str()); | ||
| 262 | - | ||
| 263 | - int input_num = input.size(); | ||
| 264 | - for (int i = 0; i < input_num; i++) { | ||
| 265 | - std::cout << "input " << i << " dtype : " << input[i].GetTensorDesc().GetDataType() << std::endl; | ||
| 266 | - string input_file = "./tc_ge_irrun_test_0008_npu_input_" + std::to_string(i) + ".bin"; | ||
| 267 | - uint8_t *input_data_i = input[i].GetData(); | ||
| 268 | - int64_t input_shape = input[i].GetTensorDesc().GetShape().GetShapeSize(); | ||
| 269 | - std::cout << "this is " << i << "th input, input shape size =" << input_shape << std::endl; | ||
| 270 | - uint32_t data_size = input_shape * GetDataTypeSize(input[i].GetTensorDesc().GetDataType()); | ||
| 271 | - WriteDataToFile((const char *)input_file.c_str(), data_size, input_data_i); | ||
| 272 | - } | ||
| 273 | - | ||
| 274 | - int output_num = output.size(); | ||
| 275 | - for (int i = 0; i < output_num; i++) { | ||
| 276 | - std::cout << "output " << i << " dtype : " << output[i].GetTensorDesc().GetDataType() << std::endl; | ||
| 277 | - string output_file = "./tc_ge_irrun_test_0008_npu_output_" + std::to_string(i) + ".bin"; | ||
| 278 | - uint8_t *output_data_i = output[i].GetData(); | ||
| 279 | - int64_t output_shape = output[i].GetTensorDesc().GetShape().GetShapeSize(); | ||
| 280 | - std::cout << "this is " << i << "th output, output shape size =" << output_shape << std::endl; | ||
| 281 | - uint32_t data_size = output_shape * GetDataTypeSize(output[i].GetTensorDesc().GetDataType()); | ||
| 282 | - WriteDataToFile((const char *)output_file.c_str(), data_size, output_data_i); | ||
| 283 | - } | ||
| 284 | - | ||
| 285 | - ge::AscendString error_msg = ge::GEGetErrorMsgV2(); | ||
| 286 | - std::string error_str(error_msg.GetString()); | ||
| 287 | - std::cout << "Error message: " << error_str << std::endl; | ||
| 288 | - ge::AscendString warning_msg = ge::GEGetWarningMsgV2(); | ||
| 289 | - std::string warning_str(warning_msg.GetString()); | ||
| 290 | - std::cout << "Warning message: " << warning_str << std::endl; | ||
| 291 | - printf("%s - INFO - [XIR]: Precision is ok\n", GetTime().c_str()); | ||
| 292 | - printf("%s - INFO - [XIR]: Start to finalize ir graph session\n", GetTime().c_str()); | ||
| 293 | - ret = ge::GEFinalize(); | ||
| 294 | - if (ret != SUCCESS) { | ||
| 295 | - printf("%s - INFO - [XIR]: Finalize ir graph session failed\n", GetTime().c_str()); | ||
| 296 | - return FAILED; | ||
| 297 | - } | ||
| 298 | - printf("%s - INFO - [XIR]: Finalize ir graph session success\n", GetTime().c_str()); | ||
| 299 | - return SUCCESS; | ||
| 300 | -} | ||
| @@ -1,38 +0,0 @@ | |||
| 1 | -/** | ||
| 2 | - * Copyright (c) 2025 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 | -/*! | ||
| 12 | - * \file add_example_graph_infer.cpp | ||
| 13 | - * \brief add_example operater graph infer resource | ||
| 14 | - */ | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | -namespace ops { | ||
| 20 | -using namespace ge; | ||
| 21 | - | ||
| 22 | -static constexpr int64_t IDX_0 = 0; | ||
| 23 | - | ||
| 24 | -static ge::graphStatus InferDataTypeAddExample(gert::InferDataTypeContext* context) | ||
| 25 | -{ | ||
| 26 | - OP_LOGD(context->GetNodeName(), "Begin to do InferDataTypeAddExample"); | ||
| 27 | - | ||
| 28 | - // 设置输出的dtype | ||
| 29 | - ge::DataType sizeDtype = context->GetInputDataType(IDX_0); | ||
| 30 | - context->SetOutputDataType(IDX_0, sizeDtype); | ||
| 31 | - | ||
| 32 | - OP_LOGD(context->GetNodeName(), "End to do InferDataTypeAddExample"); | ||
| 33 | - return GRAPH_SUCCESS; | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -IMPL_OP(AddExample).InferDataType(InferDataTypeAddExample); | ||
| 37 | - | ||
| 38 | -}; // namespace ops | ||
The file is empty
| @@ -6,6 +6,13 @@ | |||
| 6 | # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | 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. | 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. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | -# ----------------------------------------------------------------------------------------------------------- | 9 | +# ---------------------------------------------------------------------------- |
| 10 | 10 | ||
| 11 | -add_modules_sources(OPTYPE add_example ACLNNTYPE aclnn) | 11 | +if (BUILD_OPEN_PROJECT) |
| 12 | + target_sources(op_host_aclnn PRIVATE | ||
| 13 | + add_example_def.cpp | ||
| 14 | + ) | ||
| 15 | + add_modules_sources(OPTYPE add_example ACLNNTYPE aclnn) | ||
| 16 | +else() | ||
| 17 | + add_modules_sources(OPTYPE add_example ACLNNTYPE aclnn) | ||
| 18 | +endif() | ||
| @@ -9,13 +9,14 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | /*! | 11 | /*! |
| 12 | - * \file add_example.cpp | 12 | + * \file add_example_def.cpp |
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | namespace ops { | 17 | namespace ops { |
| 18 | -class AddExample : public OpDef { | 18 | +class AddExample : public OpDef |
| 19 | +{ | ||
| 19 | public: | 20 | public: |
| 20 | explicit AddExample(const char* name) : OpDef(name) | 21 | explicit AddExample(const char* name) : OpDef(name) |
| 21 | { | 22 | { |
| @@ -47,6 +48,7 @@ public: | |||
| 47 | .PrecisionReduceFlag(true) | 48 | .PrecisionReduceFlag(true) |
| 48 | .ExtendCfgInfo("opFile.value", "add_example"); // 这里制定的值会对应到kernel入口文件名.cpp | 49 | .ExtendCfgInfo("opFile.value", "add_example"); // 这里制定的值会对应到kernel入口文件名.cpp |
| 49 | this->AICore().AddConfig("ascend910b", aicoreConfig); // 其他的soc版本补充部分配置项 | 50 | this->AICore().AddConfig("ascend910b", aicoreConfig); // 其他的soc版本补充部分配置项 |
| 51 | + this->AICore().AddConfig("ascend910_93", aicoreConfig); | ||
| 50 | } | 52 | } |
| 51 | }; | 53 | }; |
| 52 | OP_ADD(AddExample); // 添加算子信息库 | 54 | OP_ADD(AddExample); // 添加算子信息库 |
| @@ -17,12 +17,12 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | -#include "../op_kernel/add_example_tiling_data.h" | 20 | +#include "examples/add_example/op_kernel/add_example_tiling_data.h" |
| 21 | -#include "../op_kernel/add_example_tiling_key.h" | 21 | +#include "examples/add_example/op_kernel/add_example_tiling_key.h" |
| 22 | 22 | ||
| 23 | namespace optiling { | 23 | namespace optiling { |
| 24 | 24 | ||
| 25 | -using namespace Ops::Math::OpTiling; | 25 | +using namespace Ops::Transformer::OpTiling; |
| 26 | 26 | ||
| 27 | const uint32_t BLOCK_DIM = 8; | 27 | const uint32_t BLOCK_DIM = 8; |
| 28 | const int64_t TILE_NUM = 8; | 28 | const int64_t TILE_NUM = 8; |
| @@ -34,7 +34,8 @@ constexpr uint32_t INDEXONE = 1; | |||
| 34 | constexpr uint32_t INDEXTWO = 2; | 34 | constexpr uint32_t INDEXTWO = 2; |
| 35 | constexpr uint32_t INDEXTHREE = 3; | 35 | constexpr uint32_t INDEXTHREE = 3; |
| 36 | 36 | ||
| 37 | -struct AddExampleCompileInfo {}; | 37 | +struct AddExampleCompileInfo { |
| 38 | +}; | ||
| 38 | 39 | ||
| 39 | // 获取平台信息如ubSize, coreNum | 40 | // 获取平台信息如ubSize, coreNum |
| 40 | static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t& ubSize, int64_t& coreNum) | 41 | static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t& ubSize, int64_t& coreNum) |
| @@ -58,10 +58,9 @@ private: | |||
| 58 | template <typename T> | 58 | template <typename T> |
| 59 | __aicore__ inline void AddExample<T>::Init(GM_ADDR x, GM_ADDR y, GM_ADDR z, const AddExampleTilingData* tilingData) | 59 | __aicore__ inline void AddExample<T>::Init(GM_ADDR x, GM_ADDR y, GM_ADDR z, const AddExampleTilingData* tilingData) |
| 60 | { | 60 | { |
| 61 | - blockLength_ = (tilingData->totalLength + AscendC::GetBlockNum() - 1) / AscendC::GetBlockNum(); | 61 | + blockLength_ = tilingData->totalLength / AscendC::GetBlockNum(); |
| 62 | tileNum_ = tilingData->tileNum; | 62 | tileNum_ = tilingData->tileNum; |
| 63 | - tileLength_ = ((blockLength_ + tileNum_ - 1) / tileNum_ / BUFFER_NUM) ? | 63 | + tileLength_ = blockLength_ / tileNum_ / BUFFER_NUM; |
| 64 | - ((blockLength_ + tileNum_ - 1) / tileNum_ / BUFFER_NUM) : 1; | ||
| 65 | 64 | ||
| 66 | inputGMX.SetGlobalBuffer((__gm__ T*)x + blockLength_ * AscendC::GetBlockIdx(), blockLength_); | 65 | inputGMX.SetGlobalBuffer((__gm__ T*)x + blockLength_ * AscendC::GetBlockIdx(), blockLength_); |
| 67 | inputGMY.SetGlobalBuffer((__gm__ T*)y + blockLength_ * AscendC::GetBlockIdx(), blockLength_); | 66 | inputGMY.SetGlobalBuffer((__gm__ T*)y + blockLength_ * AscendC::GetBlockIdx(), blockLength_); |
| @@ -77,13 +76,8 @@ __aicore__ inline void AddExample<T>::CopyIn(int32_t progress) | |||
| 77 | { | 76 | { |
| 78 | AscendC::LocalTensor<T> xLocal = inputQueueX.AllocTensor<T>(); | 77 | AscendC::LocalTensor<T> xLocal = inputQueueX.AllocTensor<T>(); |
| 79 | AscendC::LocalTensor<T> yLocal = inputQueueY.AllocTensor<T>(); | 78 | AscendC::LocalTensor<T> yLocal = inputQueueY.AllocTensor<T>(); |
| 80 | - AscendC::DataCopyParams copyParams; | 79 | + AscendC::DataCopy(xLocal, inputGMX[progress * tileLength_], tileLength_); |
| 81 | - copyParams.blockCount = 1; | 80 | + AscendC::DataCopy(yLocal, inputGMY[progress * tileLength_], tileLength_); |
| 82 | - copyParams.blockLen = tileLength_ * sizeof(T); | ||
| 83 | - copyParams.srcStride = 0; | ||
| 84 | - copyParams.dstStride = 0; | ||
| 85 | - AscendC::DataCopyPad(xLocal, inputGMX[progress * tileLength_], copyParams, {false, 0, 0, 0}); | ||
| 86 | - AscendC::DataCopyPad(yLocal, inputGMY[progress * tileLength_], copyParams, {false, 0, 0, 0}); | ||
| 87 | inputQueueX.EnQue(xLocal); | 81 | inputQueueX.EnQue(xLocal); |
| 88 | inputQueueY.EnQue(yLocal); | 82 | inputQueueY.EnQue(yLocal); |
| 89 | } | 83 | } |
| @@ -92,12 +86,7 @@ template <typename T> | |||
| 92 | __aicore__ inline void AddExample<T>::CopyOut(int32_t progress) | 86 | __aicore__ inline void AddExample<T>::CopyOut(int32_t progress) |
| 93 | { | 87 | { |
| 94 | AscendC::LocalTensor<T> zLocal = outputQueueZ.DeQue<T>(); | 88 | AscendC::LocalTensor<T> zLocal = outputQueueZ.DeQue<T>(); |
| 95 | - AscendC::DataCopyParams copyParams; | 89 | + AscendC::DataCopy(outputGMZ[progress * tileLength_], zLocal, tileLength_); |
| 96 | - copyParams.blockCount = 1; | ||
| 97 | - copyParams.blockLen = tileLength_ * sizeof(T); | ||
| 98 | - copyParams.srcStride = 0; | ||
| 99 | - copyParams.dstStride = 0; | ||
| 100 | - AscendC::DataCopyPad(outputGMZ[progress * tileLength_], zLocal, copyParams); | ||
| 101 | outputQueueZ.FreeTensor(zLocal); | 90 | outputQueueZ.FreeTensor(zLocal); |
| 102 | } | 91 | } |
| 103 | 92 | ||
The file is empty
| @@ -1,16 +0,0 @@ | |||
| 1 | -# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | -# Copyright (c) 2025 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 13 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 14 | - add_subdirectory(${SUB_DIR}) | ||
| 15 | - endif() | ||
| 16 | -endforeach() | ||
| @@ -1,16 +0,0 @@ | |||
| 1 | -# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | -# Copyright (c) 2025 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 13 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 14 | - add_subdirectory(${SUB_DIR}) | ||
| 15 | - endif() | ||
| 16 | -endforeach() | ||
| @@ -1,20 +0,0 @@ | |||
| 1 | -# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | -# Copyright (c) 2025 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 | -if(UT_TEST_ALL OR OP_HOST_UT) | ||
| 12 | - add_modules_ut_sources(UT_NAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 13 | -endif() | ||
| 14 | - | ||
| 15 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
| @@ -1,73 +0,0 @@ | |||
| 1 | -/** | ||
| 2 | - * Copyright (c) 2025 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 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | -using namespace std; | ||
| 18 | -using namespace ge; | ||
| 19 | - | ||
| 20 | -class AddExampleTiling : public testing::Test { | ||
| 21 | -protected: | ||
| 22 | - static void SetUpTestCase() | ||
| 23 | - { | ||
| 24 | - std::cout << "AddExampleTiling SetUp" << std::endl; | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - static void TearDownTestCase() | ||
| 28 | - { | ||
| 29 | - std::cout << "AddExampleTiling TearDown" << std::endl; | ||
| 30 | - } | ||
| 31 | -}; | ||
| 32 | - | ||
| 33 | -std::map<std::string, std::string> soc_version_infos = {{"Short_SoC_version", "Ascend910B"}}; | ||
| 34 | - | ||
| 35 | -TEST_F(AddExampleTiling, add_example_0) { | ||
| 36 | - struct AddExampleCompileInfo {} compileInfo; | ||
| 37 | - gert::TilingContextPara tilingContextPara("AddExample", | ||
| 38 | - { | ||
| 39 | - {{{1, 2, 8, 16}, {1, 2, 8, 16}}, ge::DT_FLOAT, ge::FORMAT_ND}, // input tensor1 | ||
| 40 | - {{{1, 2, 8, 16}, {1, 2, 8, 16}}, ge::DT_FLOAT, ge::FORMAT_ND}, // input tensor2 | ||
| 41 | - }, | ||
| 42 | - { | ||
| 43 | - {{{1, 2, 8, 16}, {1, 2, 8, 16}}, ge::DT_FLOAT, ge::FORMAT_ND}, // output tensor | ||
| 44 | - }, | ||
| 45 | - { | ||
| 46 | - /* attrs */ | ||
| 47 | - }, | ||
| 48 | - &compileInfo); | ||
| 49 | - uint64_t expectTilingKey = 0; | ||
| 50 | - string expectTilingData = "256 8 "; | ||
| 51 | - std::vector<size_t> expectWorkspaces = {1024 * 1024 * 16}; | ||
| 52 | - ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -TEST_F(AddExampleTiling, add_example_1) { | ||
| 56 | - struct AddExampleCompileInfo {} compileInfo; | ||
| 57 | - gert::TilingContextPara tilingContextPara("AddExample", | ||
| 58 | - { | ||
| 59 | - {{{1, 2, 8, 16}, {1, 2, 8, 16}}, ge::DT_INT32, ge::FORMAT_ND}, // input tensor1 | ||
| 60 | - {{{1, 2, 8, 16}, {1, 2, 8, 16}}, ge::DT_INT32, ge::FORMAT_ND}, // input tensor2 | ||
| 61 | - }, | ||
| 62 | - { | ||
| 63 | - {{{1, 2, 8, 16}, {1, 2, 8, 16}}, ge::DT_INT32, ge::FORMAT_ND}, // output tensor | ||
| 64 | - }, | ||
| 65 | - { | ||
| 66 | - /* attrs */ | ||
| 67 | - }, | ||
| 68 | - &compileInfo); | ||
| 69 | - uint64_t expectTilingKey = 1; | ||
| 70 | - string expectTilingData = "256 8 "; | ||
| 71 | - std::vector<size_t> expectWorkspaces = {1024 * 1024 * 16}; | ||
| 72 | - ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 73 | -} | ||
| @@ -1,26 +0,0 @@ | |||
| 1 | -# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | -# Copyright (c) 2025 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 | -if (UT_TEST_ALL OR OP_KERNEL_UT) | ||
| 12 | - # 需要将Tiling依赖的文件添加到CMakeLists.txt中 | ||
| 13 | - # set(elewise_common_tiling_files | ||
| 14 | - # ${CANN_ROOT}/ops/built-in/op_tiling/runtime/elewise_tiling.cc | ||
| 15 | - # ) | ||
| 16 | - # 算子自己的tiling文件路径 | ||
| 17 | - set(add_example_tiling_files | ||
| 18 | - ${CMAKE_CURRENT_SOURCE_DIR}/../../../op_host/add_example_tiling.cpp | ||
| 19 | - ) | ||
| 20 | - # 使用AddOpTestCase | ||
| 21 | - # param1:算子名称,以kernel方式命名 | ||
| 22 | - # param2:soc版本,多个以分号分隔,例如:"ascend910_9599;AscendB1" | ||
| 23 | - # param3:自定义编译选项,一般填写测试的一种典型数据类型组合,不需要则传入空字符串,例如:"-DDTYPE_X=float",多个使用空格分隔,例如:"-DDTYPE_X=float -DDTYPE_Y=float" | ||
| 24 | - # param4:该算子依赖的所有tiling源码文件 | ||
| 25 | - AddOpTestCase(add_example "ascend910b" "" "${add_example_tiling_files}") | ||
| 26 | -endif() | ||
| @@ -1,58 +0,0 @@ | |||
| 1 | -/** | ||
| 2 | - * Copyright (c) 2025 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 | -/*! | ||
| 12 | - * \file is_finite_tiling.h | ||
| 13 | - * \brief | ||
| 14 | - */ | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | -// using namespace AddExampleNs; | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | -inline[aicore] void InitTilingData(const __gm__ uint8_t *tiling, AddExampleTilingData *constData) | ||
| 29 | -{ | ||
| 30 | - const __gm__ uint32_t *src = (const __gm__ uint32_t *)tiling; | ||
| 31 | - uint32_t *dst = (uint32_t *)constData; | ||
| 32 | - for (size_t i = 0; i < sizeof(AddExampleTilingData) / 4; i++) { | ||
| 33 | - *(dst + i) = *(src + i); | ||
| 34 | - } | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | -inline void InitTilingData(uint8_t *tiling, AddExampleTilingData *constData) | ||
| 38 | -{ | ||
| 39 | - memcpy(constData, tiling, sizeof(AddExampleTilingData)); | ||
| 40 | -} | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - __ubuf__ tilingStruct *tilingDataPointer = \ | ||
| 45 | - reinterpret_cast<__ubuf__ tilingStruct *>((__ubuf__ uint8_t *)(tilingPointer)); | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - CONVERT_TILING_DATA(tilingStruct, tilingDataPointer, tilingPointer); | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - tilingStruct tilingData; \ | ||
| 52 | - InitTilingData(tilingArg, &tilingData) | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - AddExampleTilingData tilingData; \ | ||
| 56 | - InitTilingData(tilingArg, &tilingData) | ||
| 57 | - | ||
| 58 | - | ||
| @@ -1,82 +0,0 @@ | |||
| 1 | -/** | ||
| 2 | - * Copyright (c) 2025 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 | -/*! | ||
| 12 | - * \file test_add_example.cpp | ||
| 13 | - * \brief | ||
| 14 | - */ | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | -using namespace std; | ||
| 29 | - | ||
| 30 | -class add_example_test : public testing::Test { | ||
| 31 | -protected: | ||
| 32 | - static void SetUpTestCase() | ||
| 33 | - { | ||
| 34 | - cout << "add_example_test SetUp\n" << endl; | ||
| 35 | - } | ||
| 36 | - static void TearDownTestCase() | ||
| 37 | - { | ||
| 38 | - cout << "add_example_test TearDown\n" << endl; | ||
| 39 | - } | ||
| 40 | -}; | ||
| 41 | - | ||
| 42 | -TEST_F(add_example_test, test_case_0) | ||
| 43 | -{ | ||
| 44 | - size_t xByteSize = 32 * 4 * 4 * 4 * sizeof(float); | ||
| 45 | - size_t yByteSize = 32 * 4 * 4 * 4 * sizeof(float); | ||
| 46 | - size_t zByteSize = 32 * 4 * 4 * 4 * sizeof(float); | ||
| 47 | - size_t tiling_data_size = sizeof(AddExampleTilingData); | ||
| 48 | - uint32_t blockDim = 8; | ||
| 49 | - | ||
| 50 | - // 分配全局内存(AscendC::GmAlloc 是 Ascend 高层 API,正确) | ||
| 51 | - uint8_t* x = (uint8_t*)AscendC::GmAlloc(xByteSize); | ||
| 52 | - uint8_t* y = (uint8_t*)AscendC::GmAlloc(yByteSize); | ||
| 53 | - uint8_t* z = (uint8_t*)AscendC::GmAlloc(zByteSize); | ||
| 54 | - uint8_t* workspace = (uint8_t*)AscendC::GmAlloc(1024 * 1024 * 16); | ||
| 55 | - uint8_t* tiling = (uint8_t*)AscendC::GmAlloc(tiling_data_size); | ||
| 56 | - | ||
| 57 | - char* path_ = get_current_dir_name(); | ||
| 58 | - string path(path_); | ||
| 59 | - | ||
| 60 | - AddExampleTilingData* tilingDatafromBin = reinterpret_cast<AddExampleTilingData*>(tiling); | ||
| 61 | - tilingDatafromBin->totalLength = 32 * 4 * 4 * 4; | ||
| 62 | - tilingDatafromBin->tileNum = 8; | ||
| 63 | - | ||
| 64 | - ICPU_SET_TILING_KEY(0); | ||
| 65 | - AscendC::SetKernelMode(KernelMode::AIV_MODE); | ||
| 66 | - | ||
| 67 | - ICPU_RUN_KF(add_example<0>, | ||
| 68 | - blockDim, | ||
| 69 | - x, | ||
| 70 | - y, | ||
| 71 | - z, | ||
| 72 | - workspace, | ||
| 73 | - (uint8_t *)(tilingDatafromBin)); | ||
| 74 | - | ||
| 75 | - // 释放资源 | ||
| 76 | - AscendC::GmFree(x); | ||
| 77 | - AscendC::GmFree(y); | ||
| 78 | - AscendC::GmFree(z); | ||
| 79 | - AscendC::GmFree(workspace); | ||
| 80 | - AscendC::GmFree(tiling); | ||
| 81 | - free(path_); | ||
| 82 | -} | ||