Merged
refactor: 统一代码风格并修正Add算子文档及测试脚本 #7417
cai-chengchaoAdd on 3 days ago
refactor: 统一代码风格并修正Add算子文档及测试脚本 #7417
Merged
cai-chengchaoAdd on 3 days ago
Total: 20 files changed+271-299
@@ -18,11 +18,12 @@ __attribute__((weak)) bool RegistCpuKernelV2(const std::string& type, const KERN
18} // namespace aicpu18} // namespace aicpu
19 19 
20#if defined(OPS_MATH_AICPU_HOST_KERNEL)20#if defined(OPS_MATH_AICPU_HOST_KERNEL)
21-#define OPS_MATH_REGISTER_CPU_KERNELV2(type, clazz) \21+#define OPS_MATH_REGISTER_CPU_KERNELV2(type, clazz) \
22- static std::shared_ptr<aicpu::CpuKernel> Creator_##type##_Kernel() { return aicpu::MakeShared<clazz>(); } \22+ static std::shared_ptr<aicpu::CpuKernel> Creator_##type##_Kernel() { return aicpu::MakeShared<clazz>(); } \
23- static bool g_##type##_Kernel_Creator __attribute__((unused)) = \23+ static bool g_##type##_Kernel_Creator \
24- ((&::aicpu::RegistCpuKernelV2) != nullptr) ? ::aicpu::RegistCpuKernelV2((type), Creator_##type##_Kernel) : \24+ __attribute__((unused)) = ((&::aicpu::RegistCpuKernelV2) != nullptr) ? \
25- ::aicpu::RegistCpuKernel((type), Creator_##type##_Kernel)25+ ::aicpu::RegistCpuKernelV2((type), Creator_##type##_Kernel) : \
26+ ::aicpu::RegistCpuKernel((type), Creator_##type##_Kernel)
26#else27#else
27#define OPS_MATH_REGISTER_CPU_KERNELV2(type, clazz) REGISTER_CPU_KERNEL(type, clazz)28#define OPS_MATH_REGISTER_CPU_KERNELV2(type, clazz) REGISTER_CPU_KERNEL(type, clazz)
28#endif29#endif
@@ -31,9 +31,8 @@ bool IsNullptr(const T* param, const char* name)
31 int32_t status = -1;31 int32_t status = -1;
32 char* readableName = abi::__cxa_demangle(paramName, nullptr, nullptr, &status);32 char* readableName = abi::__cxa_demangle(paramName, nullptr, nullptr, &status);
33 if (status == 0 && readableName != nullptr) {33 if (status == 0 && readableName != nullptr) {
34- OP_LOGE(34+ OP_LOGE(ACLNN_ERR_PARAM_NULLPTR,
35- ACLNN_ERR_PARAM_NULLPTR, "Expected a value of type [%s] for argument [%s] but instead found nullptr.",35+ "Expected a value of type [%s] for argument [%s] but instead found nullptr.", readableName, name);
36- readableName, name);
37 free(readableName);36 free(readableName);
38 } else {37 } else {
39 OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a value for argument [%s] but instead found nullptr.", name);38 OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a value for argument [%s] but instead found nullptr.", name);
@@ -61,9 +60,8 @@ static inline bool CheckReduceOutShape(const aclTensor* inferOut, const aclTenso
61 auto const& yShape = out->GetViewShape();60 auto const& yShape = out->GetViewShape();
62 if (xShape != yShape) {61 if (xShape != yShape) {
63 if (!(xShape.GetShapeSize() == 1 && yShape.GetShapeSize() == 1)) {62 if (!(xShape.GetShapeSize() == 1 && yShape.GetShapeSize() == 1)) {
64- OP_LOGE(63+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The out tensor's shape[%s] is not equal with inferOut shape[%s].",
65- ACLNN_ERR_PARAM_INVALID, "The out tensor's shape[%s] is not equal with inferOut shape[%s].",64+ op::ToString(out->GetViewShape()).GetString(), op::ToString(inferOut->GetViewShape()).GetString());
66- op::ToString(out->GetViewShape()).GetString(), op::ToString(inferOut->GetViewShape()).GetString());
67 return false;65 return false;
68 }66 }
69 }67 }
@@ -92,9 +90,8 @@ static inline bool CheckNCDimValid(const aclTensor* self, const aclTensor* out)
92 return false;90 return false;
93 }91 }
94 if ((selfDimN != outDimN) || (selfDimC != outDimC)) {92 if ((selfDimN != outDimN) || (selfDimC != outDimC)) {
95- OP_LOGE(93+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The selfDimN[%ld]/outDimN[%ld] or selfDimC[%ld]/outDimC[%ld] not equal .",
96- ACLNN_ERR_PARAM_INVALID, "The selfDimN[%ld]/outDimN[%ld] or selfDimC[%ld]/outDimC[%ld] not equal .",94+ selfDimN, outDimN, selfDimC, outDimC);
97- selfDimN, outDimN, selfDimC, outDimC);
98 return false;95 return false;
99 }96 }
100 return true;97 return true;
@@ -105,145 +102,132 @@ static inline bool CheckNCDimValid(const aclTensor* self, const aclTensor* out)
105 retExpr; \102 retExpr; \
106 }103 }
107 104 
108-#define OP_CHECK_DTYPE_NOT_SUPPORT(tensor, supportList, retExpr) \105+#define OP_CHECK_DTYPE_NOT_SUPPORT(tensor, supportList, retExpr) \
109- do { \106+ do { \
110- if (!CheckType(tensor->GetDataType(), supportList)) { \107+ if (!CheckType(tensor->GetDataType(), supportList)) { \
111- OP_LOGE( \108+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Tensor %s not implemented for %s, should be in dtype support list %s.", \
112- ACLNN_ERR_PARAM_INVALID, "Tensor %s not implemented for %s, should be in dtype support list %s.", \109+ #tensor, op::ToString(tensor->GetDataType()).GetString(), op::ToString(supportList).GetString()); \
113- #tensor, op::ToString(tensor->GetDataType()).GetString(), op::ToString(supportList).GetString()); \110+ retExpr; \
114- retExpr; \111+ } \
115- } \
116 } while (0)112 } while (0)
117 113 
118-#define OP_CHECK_DTYPE_NOT_MATCH(tensor, expectedDtype, retExpr) \114+#define OP_CHECK_DTYPE_NOT_MATCH(tensor, expectedDtype, retExpr) \
119- do { \115+ do { \
120- if (tensor->GetDataType() != expectedDtype) { \116+ if (tensor->GetDataType() != expectedDtype) { \
121- OP_LOGE( \117+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Tensor %s expected dtype is %s but found %s.", #tensor, \
122- ACLNN_ERR_PARAM_INVALID, "Tensor %s expected dtype is %s but found %s.", #tensor, \118+ op::ToString(expectedDtype).GetString(), op::ToString(tensor->GetDataType()).GetString()); \
123- op::ToString(expectedDtype).GetString(), op::ToString(tensor->GetDataType()).GetString()); \119+ retExpr; \
124- retExpr; \120+ } \
125- } \
126 } while (0)121 } while (0)
127 122 
128-#define OP_CHECK_DTYPE_NOT_SAME(tensor1, tensor2, retExpr) \123+#define OP_CHECK_DTYPE_NOT_SAME(tensor1, tensor2, retExpr) \
129- do { \124+ do { \
130- if (tensor1->GetDataType() != tensor2->GetDataType()) { \125+ if (tensor1->GetDataType() != tensor2->GetDataType()) { \
131- OP_LOGE( \126+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected both tensors to have same dtype, but found %s %s and %s %s.", \
132- ACLNN_ERR_PARAM_INVALID, "Expected both tensors to have same dtype, but found %s %s and %s %s.", \127+ #tensor1, op::ToString(tensor1->GetDataType()).GetString(), #tensor2, \
133- #tensor1, op::ToString(tensor1->GetDataType()).GetString(), #tensor2, \128+ op::ToString(tensor2->GetDataType()).GetString()); \
134- op::ToString(tensor2->GetDataType()).GetString()); \129+ retExpr; \
135- retExpr; \130+ } \
136- } \
137 } while (0)131 } while (0)
138 132 
139-#define OP_CHECK_RESULT_DTYPE_CAST_FAILED(dtype, desiredDtype, retExpr) \133+#define OP_CHECK_RESULT_DTYPE_CAST_FAILED(dtype, desiredDtype, retExpr) \
140- do { \134+ do { \
141- if (!CanCast(dtype, desiredDtype)) { \135+ if (!CanCast(dtype, desiredDtype)) { \
142- OP_LOGE( \136+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Result type %s can't be cast to the desired output type %s.", \
143- ACLNN_ERR_PARAM_INVALID, "Result type %s can't be cast to the desired output type %s.", \137+ op::ToString(dtype).GetString(), op::ToString(desiredDtype).GetString()); \
144- op::ToString(dtype).GetString(), op::ToString(desiredDtype).GetString()); \138+ retExpr; \
145- retExpr; \139+ } \
146- } \
147 } while (0)140 } while (0)
148 141 
149-#define OP_CHECK_BROADCAST(tensor1, tensor2, retExpr) \142+#define OP_CHECK_BROADCAST(tensor1, tensor2, retExpr) \
150- do { \143+ do { \
151- if (!CheckBroadcastShape(tensor1->GetViewShape(), tensor2->GetViewShape())) { \144+ if (!CheckBroadcastShape(tensor1->GetViewShape(), tensor2->GetViewShape())) { \
152- OP_LOGE( \145+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size of tensor %s %s.", \
153- ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size of tensor %s %s.", #tensor1, \146+ #tensor1, op::ToString(tensor1->GetViewShape()).GetString(), #tensor2, \
154- op::ToString(tensor1->GetViewShape()).GetString(), #tensor2, \147+ op::ToString(tensor2->GetViewShape()).GetString()); \
155- op::ToString(tensor2->GetViewShape()).GetString()); \148+ retExpr; \
156- retExpr; \149+ } \
157- } \
158 } while (0)150 } while (0)
159 151 
160-#define OP_CHECK_BROADCAST_WITH_SHAPE(tensor, shape, retExpr) \152+#define OP_CHECK_BROADCAST_WITH_SHAPE(tensor, shape, retExpr) \
161- do { \153+ do { \
162- if (!CheckBroadcastShape(tensor->GetViewShape(), shape)) { \154+ if (!CheckBroadcastShape(tensor->GetViewShape(), shape)) { \
163- OP_LOGE( \155+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size %s.", #tensor, \
164- ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size %s.", #tensor, \156+ op::ToString(tensor->GetViewShape()).GetString(), op::ToString(shape).GetString()); \
165- op::ToString(tensor->GetViewShape()).GetString(), op::ToString(shape).GetString()); \157+ retExpr; \
166- retExpr; \158+ } \
167- } \
168 } while (0)159 } while (0)
169 160 
170-#define OP_CHECK_BROADCAST_AND_INFER_SHAPE(tensor1, tensor2, retShape, retExpr) \161+#define OP_CHECK_BROADCAST_AND_INFER_SHAPE(tensor1, tensor2, retShape, retExpr) \
171- do { \162+ do { \
172- if (!BroadcastInferShape(tensor1->GetViewShape(), tensor2->GetViewShape(), retShape)) { \163+ if (!BroadcastInferShape(tensor1->GetViewShape(), tensor2->GetViewShape(), retShape)) { \
173- OP_LOGE( \164+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size of tensor %s %s.", \
174- ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size of tensor %s %s.", #tensor1, \165+ #tensor1, op::ToString(tensor1->GetViewShape()).GetString(), #tensor2, \
175- op::ToString(tensor1->GetViewShape()).GetString(), #tensor2, \166+ op::ToString(tensor2->GetViewShape()).GetString()); \
176- op::ToString(tensor2->GetViewShape()).GetString()); \167+ retExpr; \
177- retExpr; \168+ } \
178- } \
179 } while (0)169 } while (0)
180 170 
181-#define OP_CHECK_SHAPE_NOT_EQUAL(tensor1, tensor2, retExpr) \171+#define OP_CHECK_SHAPE_NOT_EQUAL(tensor1, tensor2, retExpr) \
182- do { \172+ do { \
183- if (tensor1->GetViewShape() != tensor2->GetViewShape()) { \173+ if (tensor1->GetViewShape() != tensor2->GetViewShape()) { \
184- OP_LOGE( \174+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, \
185- ACLNN_ERR_PARAM_INVALID, \175+ "Expected tensor for %s to have same size as tensor for %s, but %s does not " \
186- "Expected tensor for %s to have same size as tensor for %s, but %s does not " \176+ "equal %s.", \
187- "equal %s.", \177+ #tensor1, #tensor2, op::ToString(tensor1->GetViewShape()).GetString(), \
188- #tensor1, #tensor2, op::ToString(tensor1->GetViewShape()).GetString(), \178+ op::ToString(tensor2->GetViewShape()).GetString()); \
189- op::ToString(tensor2->GetViewShape()).GetString()); \179+ retExpr; \
190- retExpr; \180+ } \
191- } \
192 } while (0)181 } while (0)
193 182 
194#define OP_CHECK_SHAPE_AND_SCALAR_EQUAL(tensor1, tensor2, retExpr) \183#define OP_CHECK_SHAPE_AND_SCALAR_EQUAL(tensor1, tensor2, retExpr) \
195 do { \184 do { \
196 if (tensor1->GetViewShape() != tensor2->GetViewShape()) { \185 if (tensor1->GetViewShape() != tensor2->GetViewShape()) { \
197 if (!(tensor1->GetViewShape().GetShapeSize() == 1 && tensor2->GetViewShape().GetShapeSize() == 1)) { \186 if (!(tensor1->GetViewShape().GetShapeSize() == 1 && tensor2->GetViewShape().GetShapeSize() == 1)) { \
198- OP_LOGE( \187+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, \
199- ACLNN_ERR_PARAM_INVALID, \188+ "Expected tensor for %s to have same size as tensor for %s, but %s does not " \
200- "Expected tensor for %s to have same size as tensor for %s, but %s does not " \189+ "equal %s.", \
201- "equal %s.", \190+ #tensor1, #tensor2, op::ToString(tensor1->GetViewShape()).GetString(), \
202- #tensor1, #tensor2, op::ToString(tensor1->GetViewShape()).GetString(), \191+ op::ToString(tensor2->GetViewShape()).GetString()); \
203- op::ToString(tensor2->GetViewShape()).GetString()); \
204 retExpr; \192 retExpr; \
205 } \193 } \
206 } \194 } \
207 } while (0)195 } while (0)
208 196 
209-#define OP_CHECK_SHAPE_NOT_EQUAL_WITH_EXPECTED_SIZE(tensor, shape, retExpr) \197+#define OP_CHECK_SHAPE_NOT_EQUAL_WITH_EXPECTED_SIZE(tensor, shape, retExpr) \
210- do { \198+ do { \
211- if (tensor->GetViewShape() != shape) { \199+ if (tensor->GetViewShape() != shape) { \
212- OP_LOGE( \200+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected tensor for %s to have same size as %s, but got %s.", #tensor, \
213- ACLNN_ERR_PARAM_INVALID, "Expected tensor for %s to have same size as %s, but got %s.", #tensor, \201+ op::ToString(shape).GetString(), op::ToString(tensor->GetViewShape()).GetString()); \
214- op::ToString(shape).GetString(), op::ToString(tensor->GetViewShape()).GetString()); \202+ retExpr; \
215- retExpr; \203+ } \
216- } \
217 } while (0)204 } while (0)
218 205 
219-#define OP_CHECK_WRONG_DIMENSION(tensor, expectedDimNum, retExpr) \206+#define OP_CHECK_WRONG_DIMENSION(tensor, expectedDimNum, retExpr) \
220- do { \207+ do { \
221- if (tensor->GetViewShape().GetDimNum() != expectedDimNum) { \208+ if (tensor->GetViewShape().GetDimNum() != expectedDimNum) { \
222- OP_LOGE( \209+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected %zu dimension input, but got %s with sizes %s.", \
223- ACLNN_ERR_PARAM_INVALID, "Expected %zu dimension input, but got %s with sizes %s.", \210+ static_cast<size_t>(expectedDimNum), #tensor, op::ToString(tensor->GetViewShape()).GetString()); \
224- static_cast<size_t>(expectedDimNum), #tensor, op::ToString(tensor->GetViewShape()).GetString()); \211+ retExpr; \
225- retExpr; \212+ } \
226- } \
227 } while (0)213 } while (0)
228 214 
229-#define OP_CHECK_MAX_DIM(tensor, maxDim, retExpr) \215+#define OP_CHECK_MAX_DIM(tensor, maxDim, retExpr) \
230- do { \216+ do { \
231- if (tensor->GetViewShape().GetDimNum() > static_cast<size_t>(maxDim)) { \217+ if (tensor->GetViewShape().GetDimNum() > static_cast<size_t>(maxDim)) { \
232- OP_LOGE( \218+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The %s tensor cannot be larger than %zu dimensions.", #tensor, \
233- ACLNN_ERR_PARAM_INVALID, "The %s tensor cannot be larger than %zu dimensions.", #tensor, \219+ static_cast<size_t>(maxDim)); \
234- static_cast<size_t>(maxDim)); \220+ retExpr; \
235- retExpr; \221+ } \
236- } \
237 } while (0)222 } while (0)
238 223 
239-#define OP_CHECK_MIN_DIM(tensor, minDim, retExpr) \224+#define OP_CHECK_MIN_DIM(tensor, minDim, retExpr) \
240- do { \225+ do { \
241- if (tensor->GetViewShape().GetDimNum() < static_cast<size_t>(minDim)) { \226+ if (tensor->GetViewShape().GetDimNum() < static_cast<size_t>(minDim)) { \
242- OP_LOGE( \227+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The %s tensor must have at least %zu dimensions.", #tensor, \
243- ACLNN_ERR_PARAM_INVALID, "The %s tensor must have at least %zu dimensions.", #tensor, \228+ static_cast<size_t>(minDim)); \
244- static_cast<size_t>(minDim)); \229+ retExpr; \
245- retExpr; \230+ } \
246- } \
247 } while (0)231 } while (0)
248 232 
249#define OP_CHECK_COMM_INPUT(workspaceSize, executor) \233#define OP_CHECK_COMM_INPUT(workspaceSize, executor) \
@@ -270,15 +254,14 @@ static inline bool CheckNCDimValid(const aclTensor* self, const aclTensor* out)
270 } \254 } \
271 } while (0)255 } while (0)
272 256 
273-#define OP_CHECK_TENSORLIST_SIZE_EQUAL(tensorlist1, tensorlist2, retExpr) \257+#define OP_CHECK_TENSORLIST_SIZE_EQUAL(tensorlist1, tensorlist2, retExpr) \
274- do { \258+ do { \
275- if ((tensorlist1)->Size() != (tensorlist2)->Size()) { \259+ if ((tensorlist1)->Size() != (tensorlist2)->Size()) { \
276- OP_LOGE( \260+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, \
277- ACLNN_ERR_PARAM_INVALID, \261+ "The %s tensorlist and %s tensorlist must have the same number of tensors, but got %ld and %ld.", \
278- "The %s tensorlist and %s tensorlist must have the same number of tensors, but got %ld and %ld.", \262+ #tensorlist1, #tensorlist2, (tensorlist1)->Size(), (tensorlist2)->Size()); \
279- #tensorlist1, #tensorlist2, (tensorlist1)->Size(), (tensorlist2)->Size()); \263+ retExpr; \
280- retExpr; \264+ } \
281- } \
282 } while (0)265 } while (0)
283 266 
284-#endif267+#endif
@@ -41,12 +41,11 @@ public:
41 template <typename T>41 template <typename T>
42 void AddTiling(int32_t priority)42 void AddTiling(int32_t priority)
43 {43 {
44- OP_CHECK_IF(44+ OP_CHECK_IF(cases_.find(priority) != cases_.end(), OP_LOGE(op_type_, "There are duplicate registrations."),
45- cases_.find(priority) != cases_.end(), OP_LOGE(op_type_, "There are duplicate registrations."), return);45+ return);
46 cases_[priority] = TILING_CLASS<T>;46 cases_[priority] = TILING_CLASS<T>;
47- OP_CHECK_IF(47+ OP_CHECK_IF(cases_[priority] == nullptr,
48- cases_[priority] == nullptr,48+ OP_LOGE(op_type_, "Register op tiling func failed, please check the class name."), return);
49- OP_LOGE(op_type_, "Register op tiling func failed, please check the class name."), return);
50 }49 }
51 50 
52 const std::map<int32_t, TilingClassCase>& GetTilingCases() { return cases_; }51 const std::map<int32_t, TilingClassCase>& GetTilingCases() { return cases_; }
@@ -84,9 +83,8 @@ public:
84 }83 }
85 }84 }
86 85 
87- OP_CHECK_IF(86+ OP_CHECK_IF(registry_map_[soc_version][op_type] == nullptr,
88- registry_map_[soc_version][op_type] == nullptr,87+ OP_LOGE(op_type, "Register tiling func failed, please check the class name."), return nullptr);
89- OP_LOGE(op_type, "Register tiling func failed, please check the class name."), return nullptr);
90 return registry_map_[soc_version][op_type];88 return registry_map_[soc_version][op_type];
91 }89 }
92 90 
@@ -97,8 +95,8 @@ public:
97 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();95 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
98 if (platformInfoPtr == nullptr) {96 if (platformInfoPtr == nullptr) {
99 auto compileInfoPtr = reinterpret_cast<const Ops::Base::CompileInfoCommon*>(context->GetCompileInfo());97 auto compileInfoPtr = reinterpret_cast<const Ops::Base::CompileInfoCommon*>(context->GetCompileInfo());
100- OP_CHECK_IF(98+ OP_CHECK_IF(compileInfoPtr == nullptr, OP_LOGE(op_type, "compileInfoPtr is null."),
101- compileInfoPtr == nullptr, OP_LOGE(op_type, "compileInfoPtr is null."), return ge::GRAPH_FAILED);99+ return ge::GRAPH_FAILED);
102 soc_version = compileInfoPtr->socVersion;100 soc_version = compileInfoPtr->socVersion;
103 OP_LOGD(context, "soc version in compileInfo is %d", soc_version);101 OP_LOGD(context, "soc version in compileInfo is %d", soc_version);
104 } else {102 } else {
@@ -133,8 +131,8 @@ public:
133 auto platformInfoPtr = context->GetPlatformInfo();131 auto platformInfoPtr = context->GetPlatformInfo();
134 if (platformInfoPtr == nullptr) {132 if (platformInfoPtr == nullptr) {
135 auto compileInfoPtr = reinterpret_cast<const Ops::Base::CompileInfoCommon*>(context->GetCompileInfo());133 auto compileInfoPtr = reinterpret_cast<const Ops::Base::CompileInfoCommon*>(context->GetCompileInfo());
136- OP_CHECK_IF(134+ OP_CHECK_IF(compileInfoPtr == nullptr, OP_LOGE(op_type, "compileInfoPtr is null."),
137- compileInfoPtr == nullptr, OP_LOGE(op_type, "compileInfoPtr is null."), return ge::GRAPH_FAILED);135+ return ge::GRAPH_FAILED);
138 soc_version = compileInfoPtr->socVersion;136 soc_version = compileInfoPtr->socVersion;
139 OP_LOGD(context, "soc version in compileInfo is %d", soc_version);137 OP_LOGD(context, "soc version in compileInfo is %d", soc_version);
140 } else {138 } else {
@@ -164,14 +162,13 @@ public:
164 const std::map<int32_t, TilingClassCase>& GetTilingTemplates(const std::string& op_type, int32_t soc_version)162 const std::map<int32_t, TilingClassCase>& GetTilingTemplates(const std::string& op_type, int32_t soc_version)
165 {163 {
166 auto soc_iter = registry_map_.find(soc_version);164 auto soc_iter = registry_map_.find(soc_version);
167- OP_CHECK_IF(165+ OP_CHECK_IF(soc_iter == registry_map_.end(),
168- soc_iter == registry_map_.end(),166+ OP_LOGE(op_type, "Get op tiling func failed, please check the soc version %d", soc_version),
169- OP_LOGE(op_type, "Get op tiling func failed, please check the soc version %d", soc_version),167+ return empty_tiling_case_);
170- return empty_tiling_case_);
171 auto op_iter = soc_iter->second.find(op_type);168 auto op_iter = soc_iter->second.find(op_type);
172- OP_CHECK_IF(169+ OP_CHECK_IF(op_iter == soc_iter->second.end(),
173- op_iter == soc_iter->second.end(), OP_LOGE(op_type, "Get op tiling func failed, please check the op name."),170+ OP_LOGE(op_type, "Get op tiling func failed, please check the op name."),
174- return empty_tiling_case_);171+ return empty_tiling_case_);
175 return op_iter->second->GetTilingCases();172 return op_iter->second->GetTilingCases();
176 }173 }
177 174 
@@ -188,8 +185,8 @@ public:
188 RegisterNew& tiling(int32_t priority, int32_t soc_version)185 RegisterNew& tiling(int32_t priority, int32_t soc_version)
189 {186 {
190 auto tilingCases = TilingRegistryNew::GetInstance().RegisterOp(op_type_, soc_version);187 auto tilingCases = TilingRegistryNew::GetInstance().RegisterOp(op_type_, soc_version);
191- OP_CHECK_IF(188+ OP_CHECK_IF(tilingCases == nullptr, OP_LOGE(op_type_, "Register op tiling failed, please the op name."),
192- tilingCases == nullptr, OP_LOGE(op_type_, "Register op tiling failed, please the op name."), return *this);189+ return *this);
193 tilingCases->AddTiling<T>(priority);190 tilingCases->AddTiling<T>(priority);
194 return *this;191 return *this;
195 }192 }
@@ -199,9 +196,8 @@ public:
199 {196 {
200 for (int32_t soc_version : soc_versions) {197 for (int32_t soc_version : soc_versions) {
201 auto tilingCases = TilingRegistryNew::GetInstance().RegisterOp(op_type_, soc_version);198 auto tilingCases = TilingRegistryNew::GetInstance().RegisterOp(op_type_, soc_version);
202- OP_CHECK_IF(199+ OP_CHECK_IF(tilingCases == nullptr, OP_LOGE(op_type_, "Register op tiling failed, please the op name."),
203- tilingCases == nullptr, OP_LOGE(op_type_, "Register op tiling failed, please the op name."),200+ return *this);
204- return *this);
205 tilingCases->AddTiling<T>(priority);201 tilingCases->AddTiling<T>(priority);
206 }202 }
207 return *this;203 return *this;
@@ -231,9 +227,8 @@ public:
231 if (registry_map_.find(op_type) == registry_map_.end()) {227 if (registry_map_.find(op_type) == registry_map_.end()) {
232 registry_map_[op_type] = std::shared_ptr<TilingCases>(new (std::nothrow) TilingCases(op_type));228 registry_map_[op_type] = std::shared_ptr<TilingCases>(new (std::nothrow) TilingCases(op_type));
233 }229 }
234- OP_CHECK_IF(230+ OP_CHECK_IF(registry_map_[op_type] == nullptr,
235- registry_map_[op_type] == nullptr,231+ OP_LOGE(op_type, "Register tiling func failed, please check the class name."), return nullptr);
236- OP_LOGE(op_type, "Register tiling func failed, please check the class name."), return nullptr);
237 return registry_map_[op_type];232 return registry_map_[op_type];
238 }233 }
239 234 
@@ -281,9 +276,9 @@ public:
281 276 
282 const std::map<int32_t, TilingClassCase>& GetTilingTemplates(const std::string& op_type)277 const std::map<int32_t, TilingClassCase>& GetTilingTemplates(const std::string& op_type)
283 {278 {
284- OP_CHECK_IF(279+ OP_CHECK_IF(registry_map_.find(op_type) == registry_map_.end(),
285- registry_map_.find(op_type) == registry_map_.end(),280+ OP_LOGE(op_type, "Get op tiling func failed, please check the op name."),
286- OP_LOGE(op_type, "Get op tiling func failed, please check the op name."), return empty_tiling_case_);281+ return empty_tiling_case_);
287 return registry_map_[op_type]->GetTilingCases();282 return registry_map_[op_type]->GetTilingCases();
288 }283 }
289 284 
@@ -300,8 +295,8 @@ public:
300 Register& tiling(int32_t priority)295 Register& tiling(int32_t priority)
301 {296 {
302 auto tilingCases = TilingRegistry::GetInstance().RegisterOp(op_type_);297 auto tilingCases = TilingRegistry::GetInstance().RegisterOp(op_type_);
303- OP_CHECK_IF(298+ OP_CHECK_IF(tilingCases == nullptr, OP_LOGE(op_type_, "Register op tiling failed, please the op name."),
304- tilingCases == nullptr, OP_LOGE(op_type_, "Register op tiling failed, please the op name."), return *this);299+ return *this);
305 tilingCases->AddTiling<T>(priority);300 tilingCases->AddTiling<T>(priority);
306 return *this;301 return *this;
307 }302 }
@@ -315,22 +310,24 @@ private:
315 310 
316// op_type: 算子名称, class_name: 注册的 tiling 类, soc_version:芯片版本号311// op_type: 算子名称, class_name: 注册的 tiling 类, soc_version:芯片版本号
317// priority: tiling 类的优先级, 越小表示优先级越高, 即会优先选择这个tiling类312// priority: tiling 类的优先级, 越小表示优先级越高, 即会优先选择这个tiling类
318-#define REGISTER_TILING_TEMPLATE_WITH_SOCVERSION(op_type, class_name, soc_versions, priority) \313+#define REGISTER_TILING_TEMPLATE_WITH_SOCVERSION(op_type, class_name, soc_versions, priority) \
319- static Ops::Math::OpTiling::RegisterNew VAR_UNUSED##op_type##class_name##priority_register = \314+ static Ops::Math::OpTiling::RegisterNew \
320- Ops::Math::OpTiling::RegisterNew(#op_type).tiling<class_name>(priority, soc_versions)315+ VAR_UNUSED##op_type##class_name##priority_register = Ops::Math::OpTiling::RegisterNew(#op_type) \
316+ .tiling<class_name>(priority, soc_versions)
321 317 
322// op_type: 算子名称, class_name: 注册的 tiling 类,318// op_type: 算子名称, class_name: 注册的 tiling 类,
323// soc_version: soc版本,用于区分不同的soc319// soc_version: soc版本,用于区分不同的soc
324// priority: tiling 类的优先级, 越小表示优先级越高, 即会优先选择这个tiling类320// priority: tiling 类的优先级, 越小表示优先级越高, 即会优先选择这个tiling类
325-#define REGISTER_TILING_TEMPLATE_NEW(op_type, class_name, soc_version, priority) \321+#define REGISTER_TILING_TEMPLATE_NEW(op_type, class_name, soc_version, priority) \
326- static Ops::Math::OpTiling::RegisterNew VAR_UNUSED##op_type##class_name##priority_register = \322+ static Ops::Math::OpTiling::RegisterNew \
327- Ops::Math::OpTiling::RegisterNew(#op_type).tiling<class_name>(priority, soc_version)323+ VAR_UNUSED##op_type##class_name##priority_register = Ops::Math::OpTiling::RegisterNew(#op_type) \
324+ .tiling<class_name>(priority, soc_version)
328 325 
329// op_type: 算子名称, class_name: 注册的 tiling 类,326// op_type: 算子名称, class_name: 注册的 tiling 类,
330// priority: tiling 类的优先级, 越小表示优先级越高, 即被选中的概率越大327// priority: tiling 类的优先级, 越小表示优先级越高, 即被选中的概率越大
331// 取代 REGISTER_TILING_TEMPLATE , 传入的op_type如果是字符串常量,需要去掉引号328// 取代 REGISTER_TILING_TEMPLATE , 传入的op_type如果是字符串常量,需要去掉引号
332-#define REGISTER_OPS_TILING_TEMPLATE(op_type, class_name, priority) \329+#define REGISTER_OPS_TILING_TEMPLATE(op_type, class_name, priority) \
333- [[maybe_unused]] uint32_t op_impl_register_template_##op_type##_##class_name##priority; \330+ [[maybe_unused]] uint32_t op_impl_register_template_##op_type##_##class_name##priority; \
334- static Ops::Math::OpTiling::Register \331+ static Ops::Math::OpTiling::Register __attribute__(( \
335- __attribute__((unused)) tiling_##op_type##_##class_name##_##priority##_register = \332+ unused)) tiling_##op_type##_##class_name##_##priority##_register = Ops::Math::OpTiling::Register(#op_type) \
336- Ops::Math::OpTiling::Register(#op_type).tiling<class_name>(priority)333+ .tiling<class_name>(priority)
@@ -42,21 +42,21 @@
42 <tr>42 <tr>
43 <td>x1</td>43 <td>x1</td>
44 <td>输入</td>44 <td>输入</td>
45- <td>公式中的输入张量x_1</td>45+ <td>公式中的输入张量x<sub>1</sub>。</td>
46 <td>BOOL, INT8, INT16, INT32, INT64, UINT8, FLOAT64, FLOAT16, BFLOAT16, FLOAT32, COMPLEX128, COMPLEX64</td>46 <td>BOOL, INT8, INT16, INT32, INT64, UINT8, FLOAT64, FLOAT16, BFLOAT16, FLOAT32, COMPLEX128, COMPLEX64</td>
47 <td>ND</td>47 <td>ND</td>
48 </tr>48 </tr>
49 <tr>49 <tr>
50 <td>x2</td>50 <td>x2</td>
51 <td>输入</td>51 <td>输入</td>
52- <td>公式中的输入张量x2</td>52+ <td>公式中的输入张量x<sub>2</sub>。</td>
53 <td>同x1</td>53 <td>同x1</td>
54 <td>ND</td>54 <td>ND</td>
55 </tr>55 </tr>
56 <tr>56 <tr>
57 <td>y</td>57 <td>y</td>
58 <td>输出</td>58 <td>输出</td>
59- <td>公式中的输出张量y</td>59+ <td>公式中的输出张量y。</td>
60 <td>同x1</td>60 <td>同x1</td>
61 <td>ND</td>61 <td>ND</td>
62 </tr>62 </tr>
@@ -72,5 +72,5 @@
72 72 
73| 调用方式 | 调用样例 | 说明 |73| 调用方式 | 调用样例 | 说明 |
74| ---------- | ---------------------------------------------- | ------------------------------------------------------------------------------------ |74| ---------- | ---------------------------------------------- | ------------------------------------------------------------------------------------ |
75-| aclnn调用 | [test\_aclnn\_add](./examples/test_aclnn_add.cpp) | 通过[aclnnAdd和aclnnInplaceAdd](./docs/aclnnAdd\&aclnnInplaceAdd.md)接口方式调用Add算子 |75+| aclnn API | [test\_aclnn\_add](./examples/test_aclnn_add.cpp) | 通过[aclnnAdd和aclnnInplaceAdd](./docs/aclnnAdd\&aclnnInplaceAdd.md)接口方式调用Add算子。 |
76-| 图模式调用 | [test\_geir\_add](./examples/test_geir_add.cpp) | 通过[算子IR](./op_graph/add_proto.h)构图方式调用Add算子 |76+| GE图模式 | [test\_geir\_add](./examples/test_geir_add.cpp) | 通过[算子IR](./op_graph/add_proto.h)构图方式调用Add算子,参见[算子调用](../../docs/zh/invocation/quick_op_invocation.md)完成编译和验证。 |
@@ -44,21 +44,21 @@ English | [简体中文](./README.md)
44 <tr>44 <tr>
45 <td>x1</td>45 <td>x1</td>
46 <td>Input</td>46 <td>Input</td>
47- <td>The input tensor x_1 in the formula</td>47+ <td>The input tensor x<sub>1</sub> in the formula.</td>
48 <td>BOOL, INT8, INT16, INT32, INT64, UINT8, FLOAT64, FLOAT16, BFLOAT16, FLOAT32, COMPLEX128, COMPLEX64</td>48 <td>BOOL, INT8, INT16, INT32, INT64, UINT8, FLOAT64, FLOAT16, BFLOAT16, FLOAT32, COMPLEX128, COMPLEX64</td>
49 <td>ND</td>49 <td>ND</td>
50 </tr>50 </tr>
51 <tr>51 <tr>
52 <td>x2</td>52 <td>x2</td>
53 <td>Input</td>53 <td>Input</td>
54- <td>The input tensor x2 in the formula</td>54+ <td>The input tensor x<sub>2</sub> in the formula.</td>
55 <td>Same as x1</td>55 <td>Same as x1</td>
56 <td>ND</td>56 <td>ND</td>
57 </tr>57 </tr>
58 <tr>58 <tr>
59 <td>y</td>59 <td>y</td>
60 <td>Output</td>60 <td>Output</td>
61- <td>The output tensor y in the formula</td>61+ <td>The output tensor y in the formula.</td>
62 <td>Same as x1</td>62 <td>Same as x1</td>
63 <td>ND</td>63 <td>ND</td>
64 </tr>64 </tr>
@@ -74,5 +74,5 @@ English | [简体中文](./README.md)
74 74 
75| Invocation Method | Invocation Sample | Description |75| Invocation Method | Invocation Sample | Description |
76| ---------- | ---------------------------------------------- | ------------------------------------------------------------------------------------ |76| ---------- | ---------------------------------------------- | ------------------------------------------------------------------------------------ |
77-| aclnn invocation | [test\_aclnn\_add](./examples/test_aclnn_add.cpp) | Invokes the Add operator through the [aclnnAdd and aclnnInplaceAdd](./docs/aclnnAdd&aclnnInplaceAdd_en.md) APIs |77+| aclnn API | [test\_aclnn\_add](./examples/test_aclnn_add.cpp) | Invokes the Add operator through the [aclnnAdd and aclnnInplaceAdd](./docs/aclnnAdd&aclnnInplaceAdd_en.md) APIs. |
78-| Graph-mode invocation | [test\_geir\_add](./examples/test_geir_add.cpp) | Invokes the Add operator by building a graph through the [operator IR](./op_graph/add_proto.h) |78+| GE graph mode | [test\_geir\_add](./examples/test_geir_add.cpp) | Invokes the Add operator by building a graph through the [operator IR](./op_graph/add_proto.h). For compilation and verification, see [Compile and Run Samples](../../docs/en/context/compile_and_run_sample.md). |
@@ -33,7 +33,7 @@ extern "C" {
33 * device侧的aclTensor,数据类型支持整型,浮点类型,且数据类型需要与self构成互相推导关系,shape需要与self满足broadcast关系。33 * device侧的aclTensor,数据类型支持整型,浮点类型,且数据类型需要与self构成互相推导关系,shape需要与self满足broadcast关系。
34 * 支持非连续的Tensor,数据格式支持ND,且数据格式需要与self一致。34 * 支持非连续的Tensor,数据格式支持ND,且数据格式需要与self一致。
35 * @param [in] alpha: host侧的aclScalar,数据类型需要可转换成self与other推导后的数据类型。35 * @param [in] alpha: host侧的aclScalar,数据类型需要可转换成self与other推导后的数据类型。
36- * @param [in] out: npu36+ * @param [out] out: npu
37 * device侧的aclTensor,数据类型支持整型,浮点类型,且数据类型需要是self与other推导之后可转换的数据类型,shape需要是self与other37 * device侧的aclTensor,数据类型支持整型,浮点类型,且数据类型需要是self与other推导之后可转换的数据类型,shape需要是self与other
38 * broadcast之后的shape,数据格式支持ND,且数据格式需要与self一致。38 * broadcast之后的shape,数据格式支持ND,且数据格式需要与self一致。
39 * @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。39 * @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。
@@ -74,7 +74,7 @@ ACLNN_API aclnnStatus aclnnAdds(void* workspace, uint64_t workspaceSize, aclOpEx
74 * 计算公式:74 * 计算公式:
75 * $$ output_i = self_i+alpha*other_i $$75 * $$ output_i = self_i+alpha*other_i $$
76 *76 *
77- * @param [in] self: npu77+ * @param [in/out] selfRef: npu
78 * device侧的aclTensor,数据类型支持整型,浮点类型,且数据类型需要与other构成互相推导关系,shape需要与other满足broadcast关系。78 * device侧的aclTensor,数据类型支持整型,浮点类型,且数据类型需要与other构成互相推导关系,shape需要与other满足broadcast关系。
79 * 支持非连续的Tensor,数据格式支持ND,且数据格式需要与other一致。79 * 支持非连续的Tensor,数据格式支持ND,且数据格式需要与other一致。
80 * @param [in] other: npu80 * @param [in] other: npu
@@ -115,17 +115,21 @@ class AddTestSpec:
115 out_dtype = str(out_dtypes[0]).lower() if out_dtypes else None115 out_dtype = str(out_dtypes[0]).lower() if out_dtypes else None
116 116 
117 if out_dtype == "complex32":117 if out_dtype == "complex32":
118- import numpy118+ x1_torch = numpy_to_torch_tensor(x1)
119- 119+ x2_torch = numpy_to_torch_tensor(x2)
120- a = x1[..., 0].astype(numpy.float32) + 1j * x1[..., 1].astype(numpy.float32)120+ a = torch.complex(
121- b = x2[..., 0].astype(numpy.float32) + 1j * x2[..., 1].astype(numpy.float32)121+ x1_torch[..., 0].to(torch.float32),
122- res = a + b122+ x1_torch[..., 1].to(torch.float32),
123- return [123+ )
124- numpy.stack(124+ b = torch.complex(
125- (res.real.astype(numpy.float16), res.imag.astype(numpy.float16)),125+ x2_torch[..., 0].to(torch.float32),
126- axis=-1,126+ x2_torch[..., 1].to(torch.float32),
127- )127+ )
128- ]128+ res = torch.add(a, b)
129+ res_torch = torch.stack(
130+ (res.real.to(torch.float16), res.imag.to(torch.float16)), dim=-1
131+ )
132+ return [torch_to_numpy_tensor(res_torch)]
129 133 
130 x1_torch = numpy_to_torch_tensor(x1)134 x1_torch = numpy_to_torch_tensor(x1)
131 x2_torch = numpy_to_torch_tensor(x2)135 x2_torch = numpy_to_torch_tensor(x2)
@@ -137,6 +141,7 @@ class AddTestSpec:
137class AclnnAddTestSpec:141class AclnnAddTestSpec:
138 """aclnnAdd / aclnnAdds 流程:out = self + alpha * other(other 张量或标量)。"""142 """aclnnAdd / aclnnAdds 流程:out = self + alpha * other(other 张量或标量)。"""
139 143 
144+ @staticmethod
140 def golden(self, other, alpha, out, **kwargs):145 def golden(self, other, alpha, out, **kwargs):
141 """参数跟随 aclnnAdd/aclnnAdds:self 张量、other 张量/标量、alpha 标量、out 张量。"""146 """参数跟随 aclnnAdd/aclnnAdds:self 张量、other 张量/标量、alpha 标量、out 张量。"""
142 return [_cast_to_out(_torch_add(self, other, alpha), out)]147 return [_cast_to_out(_torch_add(self, other, alpha), out)]
@@ -157,6 +162,7 @@ class AclnnInplaceAddTestSpec:
157class AclnnAddV3TestSpec:162class AclnnAddV3TestSpec:
158 """aclnnAddV3 流程:out = self + alpha * other(self 标量、other 张量)。"""163 """aclnnAddV3 流程:out = self + alpha * other(self 标量、other 张量)。"""
159 164 
165+ @staticmethod
160 def golden(self, other, alpha, out, **kwargs):166 def golden(self, other, alpha, out, **kwargs):
161 """参数跟随 aclnnAddV3:self 标量、other 张量、alpha 标量、out 张量。"""167 """参数跟随 aclnnAddV3:self 标量、other 张量、alpha 标量、out 张量。"""
162 return [_cast_to_out(_torch_add(self, other, alpha), out)]168 return [_cast_to_out(_torch_add(self, other, alpha), out)]
@@ -110,4 +110,4 @@ inline AnyValue AnyValue::CreateFrom<std::vector<std::vector<int64_t>>>(const st
110} // namespace Math110} // namespace Math
111} // namespace Ops111} // namespace Ops
112 112 
113-#endif // OPS_MATH_DEV_TESTS_UT_COMMON_ANY_VALUE_H113+#endif // OPS_MATH_DEV_TESTS_UT_COMMON_ANY_VALUE_H
@@ -13,8 +13,8 @@
13 13 
14#include "infershape_context_faker.h"14#include "infershape_context_faker.h"
15 15 
16-void ExecuteTestCase(16+void ExecuteTestCase(gert::InfershapeContextPara& infershapeContextPara,
17- gert::InfershapeContextPara& infershapeContextPara, ge::graphStatus expectResult = ge::GRAPH_FAILED,17+ ge::graphStatus expectResult = ge::GRAPH_FAILED,
18- const std::vector<std::vector<int64_t>>& expectOutputShape = {});18+ const std::vector<std::vector<int64_t>>& expectOutputShape = {});
19 19 
20-#endif // OPS_MATH_DEV_TESTS_UT_COMMON_INFERSHAPE_CASE_EXECUTOR_H20+#endif // OPS_MATH_DEV_TESTS_UT_COMMON_INFERSHAPE_CASE_EXECUTOR_H
@@ -25,20 +25,17 @@ struct TilingInfo {
25 size_t blockNum = 0;25 size_t blockNum = 0;
26};26};
27 27 
28-void ExecuteTestCase(28+void ExecuteTestCase(const gert::TilingContextPara& tilingContextPara, ge::graphStatus expectResult = ge::GRAPH_FAILED,
29- const gert::TilingContextPara& tilingContextPara, ge::graphStatus expectResult = ge::GRAPH_FAILED,29+ uint64_t expectTilingKey = 0, const string& expectTilingData = "",
30- uint64_t expectTilingKey = 0, const string& expectTilingData = "",30+ const std::vector<size_t>& expectWorkspaces = {});
31- const std::vector<size_t>& expectWorkspaces = {});
32 31 
33-void ExecuteTestCase(32+void ExecuteTestCase(const gert::TilingContextPara& tilingContextPara, ge::graphStatus expectResult,
34- const gert::TilingContextPara& tilingContextPara, ge::graphStatus expectResult, uint64_t expectTilingKey,33+ uint64_t expectTilingKey, const std::vector<size_t>& expectWorkspaces);
35- const std::vector<size_t>& expectWorkspaces);
36 34 
37-void ExecuteTestCaseForEle(35+void ExecuteTestCaseForEle(const gert::TilingContextPara& tilingContextPara, ge::graphStatus expectResult,
38- const gert::TilingContextPara& tilingContextPara, ge::graphStatus expectResult, bool needCheckTilingKey,36+ bool needCheckTilingKey, uint64_t expectTilingKey, bool needCheckTilingData,
39- uint64_t expectTilingKey, bool needCheckTilingData, const string& expectTilingData,37+ const string& expectTilingData, const std::vector<size_t>& expectWorkspaces);
40- const std::vector<size_t>& expectWorkspaces);
41 38 
42bool ExecuteTiling(const gert::TilingContextPara& tilingContextPara, TilingInfo& tilingInfo);39bool ExecuteTiling(const gert::TilingContextPara& tilingContextPara, TilingInfo& tilingInfo);
43 40 
44-#endif // OPS_MATH_DEV_TESTS_UT_COMMON_TILING_CASE_EXECUTOR_H41+#endif // OPS_MATH_DEV_TESTS_UT_COMMON_TILING_CASE_EXECUTOR_H
@@ -20,9 +20,8 @@ class TilingContextPara {
20public:20public:
21 class TensorDescription {21 class TensorDescription {
22 public:22 public:
23- TensorDescription(23+ TensorDescription(const gert::StorageShape& shape, ge::DataType dtype, ge::Format format, bool isConst = false,
24- const gert::StorageShape& shape, ge::DataType dtype, ge::Format format, bool isConst = false,24+ void* constValue = nullptr)
25- void* constValue = nullptr)
26 : shape_(shape), dtype_(dtype), format_(format), isConst_(isConst), constValue_(constValue)25 : shape_(shape), dtype_(dtype), format_(format), isConst_(isConst), constValue_(constValue)
27 {}26 {}
28 27 
@@ -44,10 +43,10 @@ public:
44 };43 };
45 44 
46public:45public:
47- TilingContextPara(46+ TilingContextPara(const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,
48- const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,47+ const std::vector<TensorDescription>& outputTensorDesc, const std::vector<OpAttr>& attrs,
49- const std::vector<TensorDescription>& outputTensorDesc, const std::vector<OpAttr>& attrs,48+ void* compileInfo = nullptr, uint64_t coreNum = 64, uint64_t ubSize = 262144,
50- void* compileInfo = nullptr, uint64_t coreNum = 64, uint64_t ubSize = 262144, uint64_t tilingDataSize = 4096)49+ uint64_t tilingDataSize = 4096)
51 : opName_(opName),50 : opName_(opName),
52 inputTensorDesc_(inputTensorDesc),51 inputTensorDesc_(inputTensorDesc),
53 outputTensorDesc_(outputTensorDesc),52 outputTensorDesc_(outputTensorDesc),
@@ -58,10 +57,9 @@ public:
58 tilingDataSize_(tilingDataSize)57 tilingDataSize_(tilingDataSize)
59 {}58 {}
60 59 
61- TilingContextPara(60+ TilingContextPara(const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,
62- const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,61+ const std::vector<TensorDescription>& outputTensorDesc, void* compileInfo = nullptr,
63- const std::vector<TensorDescription>& outputTensorDesc, void* compileInfo = nullptr, uint64_t coreNum = 64,62+ uint64_t coreNum = 64, uint64_t ubSize = 262144, uint64_t tilingDataSize = 4096)
64- uint64_t ubSize = 262144, uint64_t tilingDataSize = 4096)
65 : opName_(opName),63 : opName_(opName),
66 inputTensorDesc_(inputTensorDesc),64 inputTensorDesc_(inputTensorDesc),
67 outputTensorDesc_(outputTensorDesc),65 outputTensorDesc_(outputTensorDesc),
@@ -71,11 +69,11 @@ public:
71 tilingDataSize_(tilingDataSize)69 tilingDataSize_(tilingDataSize)
72 {}70 {}
73 71 
74- TilingContextPara(72+ TilingContextPara(const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,
75- const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,73+ const std::vector<TensorDescription>& outputTensorDesc, const std::vector<OpAttr>& attrs,
76- const std::vector<TensorDescription>& outputTensorDesc, const std::vector<OpAttr>& attrs,74+ const std::vector<uint32_t>& inputInstanceNum, const std::vector<uint32_t>& outputInstanceNum,
77- const std::vector<uint32_t>& inputInstanceNum, const std::vector<uint32_t>& outputInstanceNum,75+ void* compileInfo = nullptr, uint64_t coreNum = 64, uint64_t ubSize = 262144,
78- void* compileInfo = nullptr, uint64_t coreNum = 64, uint64_t ubSize = 262144, uint64_t tilingDataSize = 4096)76+ uint64_t tilingDataSize = 4096)
79 : opName_(opName),77 : opName_(opName),
80 inputTensorDesc_(inputTensorDesc),78 inputTensorDesc_(inputTensorDesc),
81 outputTensorDesc_(outputTensorDesc),79 outputTensorDesc_(outputTensorDesc),
@@ -88,11 +86,11 @@ public:
88 tilingDataSize_(tilingDataSize)86 tilingDataSize_(tilingDataSize)
89 {}87 {}
90 88 
91- TilingContextPara(89+ TilingContextPara(const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,
92- const std::string& opName, const std::vector<TensorDescription>& inputTensorDesc,90+ const std::vector<TensorDescription>& outputTensorDesc,
93- const std::vector<TensorDescription>& outputTensorDesc, const std::vector<uint32_t>& inputInstanceNum,91+ const std::vector<uint32_t>& inputInstanceNum, const std::vector<uint32_t>& outputInstanceNum,
94- const std::vector<uint32_t>& outputInstanceNum, void* compileInfo = nullptr, uint64_t coreNum = 64,92+ void* compileInfo = nullptr, uint64_t coreNum = 64, uint64_t ubSize = 262144,
95- uint64_t ubSize = 262144, uint64_t tilingDataSize = 4096)93+ uint64_t tilingDataSize = 4096)
96 : opName_(opName),94 : opName_(opName),
97 inputTensorDesc_(inputTensorDesc),95 inputTensorDesc_(inputTensorDesc),
98 outputTensorDesc_(outputTensorDesc),96 outputTensorDesc_(outputTensorDesc),
@@ -126,14 +124,14 @@ public:
126 124 
127 /* can be used for dynamic inputs/outputs125 /* can be used for dynamic inputs/outputs
128 * only one can be choosed from NodeIoNum */126 * only one can be choosed from NodeIoNum */
129- TilingContextFaker& IrInstanceNum(127+ TilingContextFaker& IrInstanceNum(const std::vector<uint32_t>& inputInstanceNum,
130- const std::vector<uint32_t>& inputInstanceNum, const std::vector<uint32_t>& outputInstanceNum);128+ const std::vector<uint32_t>& outputInstanceNum);
131 129 
132- TilingContextFaker& NodeInputTd(130+ TilingContextFaker& NodeInputTd(int32_t index, ge::DataType dtype, ge::Format originFormat,
133- int32_t index, ge::DataType dtype, ge::Format originFormat, ge::Format storageFormat);131+ ge::Format storageFormat);
134 132 
135- TilingContextFaker& NodeOutputTd(133+ TilingContextFaker& NodeOutputTd(int32_t index, ge::DataType dtype, ge::Format originFormat,
136- int32_t index, ge::DataType dtype, ge::Format originFormat, ge::Format storageFormat);134+ ge::Format storageFormat);
137 135 
138 TilingContextFaker& Attr(const std::string& attrName, bool attr)136 TilingContextFaker& Attr(const std::string& attrName, bool attr)
139 {137 {
@@ -87,4 +87,4 @@ ARRAY_DESC(Int, int64_t)
87ARRAY_DESC(Float, float)87ARRAY_DESC(Float, float)
88ARRAY_DESC(Bool, bool)88ARRAY_DESC(Bool, bool)
89 89 
90-#endif90+#endif
@@ -112,4 +112,4 @@ private:
112 PyObject* PyCompareFunc = nullptr;112 PyObject* PyCompareFunc = nullptr;
113};113};
114 114 
115-#endif115+#endif
@@ -22,4 +22,4 @@ const string& GetOpUtSrcPath();
22const string& GetExePath();22const string& GetExePath();
23int GetEnv(const string& name, string& value);23int GetEnv(const string& name, string& value);
24 24 
25-#endif25+#endif
@@ -21,4 +21,4 @@ int RtsInit();
21void RtsUnInit();21void RtsUnInit();
22int SynchronizeStream();22int SynchronizeStream();
23 23 
24-#endif24+#endif
@@ -31,9 +31,8 @@ using namespace nlohmann;
31//////////// reload tensor data ///////////////31//////////// reload tensor data ///////////////
32 32 
33template <typename T>33template <typename T>
34-int ReloadDataFromBinaryFile(34+int ReloadDataFromBinaryFile([[maybe_unused]] T arg, [[maybe_unused]] size_t index, [[maybe_unused]] size_t total_input,
35- [[maybe_unused]] T arg, [[maybe_unused]] size_t index, [[maybe_unused]] size_t total_input,35+ [[maybe_unused]] const string& file_prefix)
36- [[maybe_unused]] const string& file_prefix)
37{36{
38 return 0;37 return 0;
39}38}
@@ -68,8 +67,8 @@ int ReloadTensorData(tuple<Ts...>& t, size_t input_count, const string& file_pre
68 67 
69//////////// save result ///////////////68//////////// save result ///////////////
70 69 
71-[[maybe_unused]] static short int GetInplaceOutputIdx(70+[[maybe_unused]] static short int GetInplaceOutputIdx(size_t index, size_t input_count,
72- size_t index, size_t input_count, const map<short int, short int>& inplace_map_reserve)71+ const map<short int, short int>& inplace_map_reserve)
73{72{
74 if (index >= input_count) {73 if (index >= input_count) {
75 return -1;74 return -1;
@@ -79,25 +78,24 @@ int ReloadTensorData(tuple<Ts...>& t, size_t input_count, const string& file_pre
79}78}
80 79 
81template <typename T>80template <typename T>
82-int SaveResultToBinaryFile(81+int SaveResultToBinaryFile([[maybe_unused]] T arg, [[maybe_unused]] size_t index, [[maybe_unused]] size_t total_input,
83- [[maybe_unused]] T arg, [[maybe_unused]] size_t index, [[maybe_unused]] size_t total_input,82+ [[maybe_unused]] const string& file_prefix,
84- [[maybe_unused]] const string& file_prefix, [[maybe_unused]] const set<short int>& inplace_output)83+ [[maybe_unused]] const set<short int>& inplace_output)
85{84{
86 return 0;85 return 0;
87}86}
88 87 
89template <typename T>88template <typename T>
90-int SaveResultToBinaryFile(89+int SaveResultToBinaryFile([[maybe_unused]] T arg, [[maybe_unused]] size_t index,
91- [[maybe_unused]] T arg, [[maybe_unused]] size_t index, [[maybe_unused]] const string& file_prefix)90+ [[maybe_unused]] const string& file_prefix)
92{91{
93 return 0;92 return 0;
94}93}
95 94 
96template <size_t index, typename... Ts>95template <size_t index, typename... Ts>
97struct SaveIterator {96struct SaveIterator {
98- int operator()(97+ int operator()(tuple<Ts...>& t, size_t input_count, const string& file_prefix,
99- tuple<Ts...>& t, size_t input_count, const string& file_prefix,98+ const map<short int, short int>& inplace_map_reserve, const set<short int>& inplace_output)
100- const map<short int, short int>& inplace_map_reserve, const set<short int>& inplace_output)
101 {99 {
102 short int inplace_output_idx = GetInplaceOutputIdx(index, input_count, inplace_map_reserve);100 short int inplace_output_idx = GetInplaceOutputIdx(index, input_count, inplace_map_reserve);
103 int ret = 0;101 int ret = 0;
@@ -116,9 +114,8 @@ struct SaveIterator {
116 114 
117template <typename... Ts>115template <typename... Ts>
118struct SaveIterator<0, Ts...> {116struct SaveIterator<0, Ts...> {
119- int operator()(117+ int operator()(tuple<Ts...>& t, size_t input_count, const string& file_prefix,
120- tuple<Ts...>& t, size_t input_count, const string& file_prefix,118+ const map<short int, short int>& inplace_map_reserve, const set<short int>& inplace_output)
121- const map<short int, short int>& inplace_map_reserve, const set<short int>& inplace_output)
122 {119 {
123 short int inplace_output_idx = GetInplaceOutputIdx(0, input_count, inplace_map_reserve);120 short int inplace_output_idx = GetInplaceOutputIdx(0, input_count, inplace_map_reserve);
124 if (inplace_output_idx < 0) {121 if (inplace_output_idx < 0) {
@@ -130,9 +127,8 @@ struct SaveIterator<0, Ts...> {
130};127};
131 128 
132template <typename... Ts>129template <typename... Ts>
133-int SaveResult(130+int SaveResult(tuple<Ts...>& t, size_t input_count, const string& file_prefix,
134- tuple<Ts...>& t, size_t input_count, const string& file_prefix,131+ const map<short int, short int>& inplace_map_reserve, const set<short int>& inplace_output)
135- const map<short int, short int>& inplace_map_reserve, const set<short int>& inplace_output)
136{132{
137 const auto size = tuple_size<tuple<Ts...>>::value;133 const auto size = tuple_size<tuple<Ts...>>::value;
138 SaveIterator<size - 1, Ts...> it;134 SaveIterator<size - 1, Ts...> it;
@@ -167,10 +163,9 @@ private:
167template <typename GET_F, typename API_F, typename INPUT_T, typename OUTPUT_T, typename ACL_ARGS_T, typename EXTRA_T>163template <typename GET_F, typename API_F, typename INPUT_T, typename OUTPUT_T, typename ACL_ARGS_T, typename EXTRA_T>
168class OpApiUt {164class OpApiUt {
169public:165public:
170- OpApiUt(166+ OpApiUt(const string& test_suite_name, const string& test_case_name, const string& op_name,
171- const string& test_suite_name, const string& test_case_name, const string& op_name,167+ GET_F get_workspace_size_func, API_F api_func, const INPUT_T& inputs, const OUTPUT_T& outputs,
172- GET_F get_workspace_size_func, API_F api_func, const INPUT_T& inputs, const OUTPUT_T& outputs,168+ [[maybe_unused]] const ACL_ARGS_T& wrapper_args, const EXTRA_T& extra_args)
173- [[maybe_unused]] const ACL_ARGS_T& wrapper_args, const EXTRA_T& extra_args)
174 : op_name_(op_name),169 : op_name_(op_name),
175 case_name_(test_suite_name + "_" + test_case_name),170 case_name_(test_suite_name + "_" + test_case_name),
176 api_func_(api_func),171 api_func_(api_func),
@@ -235,8 +230,8 @@ public:
235 return;230 return;
236 }231 }
237 232 
238- unique_ptr<void, decltype(&FreeDeviceMemory)> workspace_ptr(233+ unique_ptr<void, decltype(&FreeDeviceMemory)> workspace_ptr(MallocDeviceMemory(workspace_size),
239- MallocDeviceMemory(workspace_size), FreeDeviceMemory);234+ FreeDeviceMemory);
240 235 
241 cout << "invoke aclnnX function ..." << endl;236 cout << "invoke aclnnX function ..." << endl;
242 aclRet = api_func_(workspace_ptr.get(), workspace_size, executor, nullptr);237 aclRet = api_func_(workspace_ptr.get(), workspace_size, executor, nullptr);
@@ -380,11 +375,10 @@ private:
380 size_t input_count_;375 size_t input_count_;
381};376};
382 377 
383-#define OP_API_UT(api, input, output, ...) \378+#define OP_API_UT(api, input, output, ...) \
384- OpApiUt( \379+ OpApiUt(testing::UnitTest::GetInstance()->current_test_info()->test_case_name(), \
385- testing::UnitTest::GetInstance()->current_test_info()->test_case_name(), \380+ testing::UnitTest::GetInstance()->current_test_info()->name(), #api, api##GetWorkspaceSize, api, input, \
386- testing::UnitTest::GetInstance()->current_test_info()->name(), #api, api##GetWorkspaceSize, api, input, \381+ output, InferAclTypes(tuple_cat(input, output)), make_tuple(__VA_ARGS__))
387- output, InferAclTypes(tuple_cat(input, output)), make_tuple(__VA_ARGS__))
388 382 
389#define INPUT(...) make_tuple(__VA_ARGS__)383#define INPUT(...) make_tuple(__VA_ARGS__)
390#define OUTPUT(...) make_tuple(__VA_ARGS__)384#define OUTPUT(...) make_tuple(__VA_ARGS__)
@@ -63,4 +63,4 @@ void Release(aclScalar* p);
63aclScalar* InferAclType(const ScalarDesc& scalar_desc);63aclScalar* InferAclType(const ScalarDesc& scalar_desc);
64void DescToJson(json& root, const ScalarDesc& scalar_desc, bool is_input = true);64void DescToJson(json& root, const ScalarDesc& scalar_desc, bool is_input = true);
65 65 
66-#endif66+#endif
@@ -22,10 +22,9 @@ using namespace nlohmann;
22 22 
23class TensorDesc {23class TensorDesc {
24public:24public:
25- TensorDesc(25+ TensorDesc(const vector<int64_t>& view_dims = {1, 1, 16, 16}, aclDataType data_type = ACL_FLOAT,
26- const vector<int64_t>& view_dims = {1, 1, 16, 16}, aclDataType data_type = ACL_FLOAT,26+ aclFormat format = ACL_FORMAT_NCHW, const vector<int64_t>& stride_ = {}, int64_t offset = 0,
27- aclFormat format = ACL_FORMAT_NCHW, const vector<int64_t>& stride_ = {}, int64_t offset = 0,27+ const vector<int64_t>& storage_dims = {});
28- const vector<int64_t>& storage_dims = {});
29 TensorDesc(const TensorDesc& desc);28 TensorDesc(const TensorDesc& desc);
30 ~TensorDesc();29 ~TensorDesc();
31 30 
@@ -127,13 +126,12 @@ void DescToJson(json& root, const TensorListDesc& tensor_list_desc, bool is_inpu
127int ReloadDataFromBinaryFile(aclTensor* p, size_t index, size_t total_input, const string& file_prefix);126int ReloadDataFromBinaryFile(aclTensor* p, size_t index, size_t total_input, const string& file_prefix);
128int ReloadDataFromBinaryFile(aclTensorList* p, size_t index, size_t total_input, const string& file_prefix);127int ReloadDataFromBinaryFile(aclTensorList* p, size_t index, size_t total_input, const string& file_prefix);
129 128 
130-int SaveResultToBinaryFile(129+int SaveResultToBinaryFile(aclTensor* p, size_t index, size_t total_input, const string& file_prefix,
131- aclTensor* p, size_t index, size_t total_input, const string& file_prefix, const set<short int>& inplace_output);130+ const set<short int>& inplace_output);
132-int SaveResultToBinaryFile(131+int SaveResultToBinaryFile(aclTensorList* p, size_t index, size_t total_input, const string& file_prefix,
133- aclTensorList* p, size_t index, size_t total_input, const string& file_prefix,132+ const set<short int>& inplace_output);
134- const set<short int>& inplace_output);
135 133 
136int SaveResultToBinaryFile(aclTensor* p, size_t index, const string& file_prefix);134int SaveResultToBinaryFile(aclTensor* p, size_t index, const string& file_prefix);
137int SaveResultToBinaryFile(aclTensorList* p, size_t index, const string& file_prefix);135int SaveResultToBinaryFile(aclTensorList* p, size_t index, const string& file_prefix);
138 136 
139-#endif137+#endif
@@ -69,9 +69,8 @@ void ReleaseAclTypes(const tuple<T...>& t)
69{69{
70 apply(70 apply(
71 [](const auto&... args) {71 [](const auto&... args) {
72- ((IsAny<72+ ((IsAny<remove_const_t<remove_pointer_t<remove_reference_t<decltype(args)>>>, aclTensor, aclScalar,
73- remove_const_t<remove_pointer_t<remove_reference_t<decltype(args)>>>, aclTensor, aclScalar,73+ aclTensorList, aclIntArray, aclFloatArray, aclBoolArray>::value ?
74- aclTensorList, aclIntArray, aclFloatArray, aclBoolArray>::value ?
75 Release(args) :74 Release(args) :
76 void()),75 void()),
77 ...);76 ...);
@@ -136,21 +135,20 @@ inline void ConvertDescToJson(json& root, const tuple<T...>& t, bool is_input =
136//////////// invoke acl***GetWorkspaceSize function ////////135//////////// invoke acl***GetWorkspaceSize function ////////
137 136 
138template <typename Function, typename Tuple, typename ExtraT, size_t... I, size_t... EI>137template <typename Function, typename Tuple, typename ExtraT, size_t... I, size_t... EI>
139-inline aclnnStatus InvokeGetWorkspaceSizeFunc(138+inline aclnnStatus InvokeGetWorkspaceSizeFunc(Function f, Tuple t, [[maybe_unused]] ExtraT et, index_sequence<I...>,
140- Function f, Tuple t, [[maybe_unused]] ExtraT et, index_sequence<I...>, index_sequence<EI...>,139+ index_sequence<EI...>, uint64_t* workspace_size, aclOpExecutor** executor)
141- uint64_t* workspace_size, aclOpExecutor** executor)
142{140{
143 return f(get<I>(t)..., get<EI>(et)..., workspace_size, executor);141 return f(get<I>(t)..., get<EI>(et)..., workspace_size, executor);
144}142}
145 143 
146template <typename Function, typename Tuple, typename ExtraT>144template <typename Function, typename Tuple, typename ExtraT>
147-inline aclnnStatus InvokeGetWorkspaceSizeFunc(145+inline aclnnStatus InvokeGetWorkspaceSizeFunc(Function f, Tuple t, ExtraT et, uint64_t* workspace_size,
148- Function f, Tuple t, ExtraT et, uint64_t* workspace_size, aclOpExecutor** executor)146+ aclOpExecutor** executor)
149{147{
150 constexpr auto s = tuple_size<Tuple>::value;148 constexpr auto s = tuple_size<Tuple>::value;
151 constexpr auto es = tuple_size<ExtraT>::value;149 constexpr auto es = tuple_size<ExtraT>::value;
152- return InvokeGetWorkspaceSizeFunc(150+ return InvokeGetWorkspaceSizeFunc(f, t, et, make_index_sequence<s>{}, make_index_sequence<es>{}, workspace_size,
153- f, t, et, make_index_sequence<s>{}, make_index_sequence<es>{}, workspace_size, executor);151+ executor);
154}152}
155 153 
156-#endif154+#endif
@@ -72,4 +72,4 @@ void SetRandomValue(T input[], uint64_t num, float min = 0.0, float max = 10.0)
72 uint32_t ret = CpuKernelRegister::Instance().RunCpuKernel(ctx); \72 uint32_t ret = CpuKernelRegister::Instance().RunCpuKernel(ctx); \
73 EXPECT_EQ(ret, expect)73 EXPECT_EQ(ret, expect)
74 74 
75-#endif75+#endif