已合并
fix(softmax): release resources on init failure #8603
zhang-song-rui创建于 25 天前
fix(softmax): release resources on init failure #8603
已合并
zhang-song-rui创建于 25 天前
已删除 :master合入到cann/ops-nnmaster
2 个文件变更+9-5
@@ -260,9 +260,12 @@ int Init(int32_t deviceId, aclrtStream* stream) {
260 auto ret = aclInit(nullptr);260 auto ret = aclInit(nullptr);
261 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);261 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
262 ret = aclrtSetDevice(deviceId);262 ret = aclrtSetDevice(deviceId);
263- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);263+ CHECK_RET(ret == ACL_SUCCESS,
264+ LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); aclFinalize(); return ret);
264 ret = aclrtCreateStream(stream);265 ret = aclrtCreateStream(stream);
265- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);266+ CHECK_RET(ret == ACL_SUCCESS,
267+ LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret);
268+ aclrtResetDevice(deviceId); aclFinalize(); return ret);
F

其他有问题的算子也一并修改

likedislike
266 return 0;269 return 0;
267}270}
268 271 
@@ -39,9 +39,10 @@ int Init(int32_t deviceId, aclrtStream* stream)
39 auto ret = aclInit(nullptr);39 auto ret = aclInit(nullptr);
40 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);40 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
41 ret = aclrtSetDevice(deviceId);41 ret = aclrtSetDevice(deviceId);
42- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);42+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); aclFinalize(); return ret);
43 ret = aclrtCreateStream(stream);43 ret = aclrtCreateStream(stream);
44- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);44+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); aclrtResetDevice(deviceId);
45+ aclFinalize(); return ret);
45 return 0;46 return 0;
46}47}
47 48 
@@ -139,4 +140,4 @@ int main()
139 aclrtResetDevice(deviceId);140 aclrtResetDevice(deviceId);
140 aclFinalize();141 aclFinalize();
141 return 0;142 return 0;
142-}143+}