已合并
refactor(inplace_add_layer_norm_fusion_pass): replace D4 dlsym with weak symbol #11082
refactor(inplace_add_layer_norm_fusion_pass): replace D4 dlsym with weak symbol #11082
已合并
rk创建于 9月22日
共 1 个文件变更+9-35
@@ -16,8 +16,6 @@
16 */16 */
17#include "inplace_add_layer_norm_fusion_pass.h"17#include "inplace_add_layer_norm_fusion_pass.h"
18 18 
19-#include <dlfcn.h>
20- 
21#include <cstdlib>19#include <cstdlib>
22#include <set>20#include <set>
23#include <string>21#include <string>
@@ -28,33 +26,11 @@
28#include "common/inc/error_util.h"26#include "common/inc/error_util.h"
29#include "graph/operator_factory.h"27#include "graph/operator_factory.h"
30#include "platform/platform_info.h"28#include "platform/platform_info.h"
31-#include "securec.h"
32#include "version/ge-compiler_version.h"29#include "version/ge-compiler_version.h"
33#include "ge/fusion/pass/pattern_fusion_pass.h"30#include "ge/fusion/pass/pattern_fusion_pass.h"
34 31 
35namespace ops {32namespace ops {
36namespace {33namespace {
37-// GetOptionValue @since 9.0.0,按 D4 走 dlsym。
38-const char* const kGetOptionValueSymbol = "_ZNK2ge17CustomPassContext14GetOptionValueERKNS_12AscendStringERS1_";
39-using GetOptionValueFn = graphStatus (*)(const void*, const AscendString&, AscendString&);
40- 
41-// GE 库以 RTLD_GLOBAL 加载,故查全局符号表;
42-GetOptionValueFn ResolveGetOptionValue()
43-{
44- static GetOptionValueFn fn = []() -> GetOptionValueFn {
45- void* symbol = dlsym(RTLD_DEFAULT, kGetOptionValueSymbol);
46- GetOptionValueFn resolved = nullptr;
47- if (symbol != nullptr) {
48- auto memRet = memcpy_s(&resolved, sizeof(GetOptionValueFn), &symbol, sizeof(GetOptionValueFn));
49- if (memRet != EOK) {
50- return nullptr;
51- }
52- }
53- return resolved;
54- }();
55- return fn;
56-}
57- 
58const std::string kPassName = "ZInplaceAddLayerNormFusionPass";34const std::string kPassName = "ZInplaceAddLayerNormFusionPass";
59 35 
60const char* const kAddLayerNormType = "AddLayerNorm";36const char* const kAddLayerNormType = "AddLayerNorm";
@@ -109,25 +85,19 @@ enum class SceneCheckResult {
109 API_UNAVAILABLE // 运行时 < 9.0.085 API_UNAVAILABLE // 运行时 < 9.0.0
110};86};
111 87 
112-// 守卫 G1:训练场景不做原地改写;读不到 option 则返回 API_UNAVAILABLE 保持静默。88+// 守卫 G1:训练场景不做原地改写;接口不可用时保持静默。
113SceneCheckResult CheckScene(CustomPassContext& passContext)89SceneCheckResult CheckScene(CustomPassContext& passContext)
114{90{
115- // 运行期check91+#if defined(GE_COMPILER_VERSION_NUM) && (GE_COMPILER_VERSION_NUM >= 90000000)
92+ // 高编低跑依赖构建后的公共符号弱化,调用前仍须确认运行时支持。
116 int32_t runtimeVersion = 0;93 int32_t runtimeVersion = 0;
117 char geCompilerName[] = "ge_compiler";94 char geCompilerName[] = "ge_compiler";
118- (void)aclsysGetVersionNum(geCompilerName, &runtimeVersion);95+ if (aclsysGetVersionNum(geCompilerName, &runtimeVersion) != ACL_SUCCESS || runtimeVersion < kMinGeCompilerVersion) {
119- if (runtimeVersion > 0 && runtimeVersion < kMinGeCompilerVersion) {
120- return SceneCheckResult::API_UNAVAILABLE;
121- }
122- 
123- // 符号可达性
124- const GetOptionValueFn getOptionValue = ResolveGetOptionValue();
125- if (getOptionValue == nullptr) {
126 return SceneCheckResult::API_UNAVAILABLE;96 return SceneCheckResult::API_UNAVAILABLE;
127 }97 }
128 98 
129 AscendString value;99 AscendString value;
130- if (getOptionValue(&passContext, AscendString(kOptionGraphRunMode), value) != GRAPH_SUCCESS) {100+ if (passContext.GetOptionValue(AscendString(kOptionGraphRunMode), value) != GRAPH_SUCCESS) {
131 OPS_LOG_D(kPassName.c_str(), "Option %s is not set, treat as inference scene.", kOptionGraphRunMode);101 OPS_LOG_D(kPassName.c_str(), "Option %s is not set, treat as inference scene.", kOptionGraphRunMode);
132 return SceneCheckResult::INFERENCE;102 return SceneCheckResult::INFERENCE;
133 }103 }
@@ -139,6 +109,10 @@ SceneCheckResult CheckScene(CustomPassContext& passContext)
139 return SceneCheckResult::TRAIN;109 return SceneCheckResult::TRAIN;
140 }110 }
141 return SceneCheckResult::INFERENCE;111 return SceneCheckResult::INFERENCE;
112+#else
113+ (void)passContext;
114+ return SceneCheckResult::API_UNAVAILABLE;
115+#endif
142}116}
143 117 
144// 守卫 G2:平台check。118// 守卫 G2:平台check。