MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / build_plugin

Function build_plugin

custom_ops/xpu_ops/setup_ops.py:69–123  ·  view source on GitHub ↗

build xpu plugin

(CLANG_PATH, XRE_INC_DIR, XRE_LIB_DIR, XDNN_INC_DIR, XDNN_LIB_DIR)

Source from the content-addressed store, hash-verified

67
68
69def build_plugin(CLANG_PATH, XRE_INC_DIR, XRE_LIB_DIR, XDNN_INC_DIR, XDNN_LIB_DIR):
70 """
71 build xpu plugin
72 """
73 current_working_directory = base_dir
74 print(f"Current working directory: {current_working_directory}")
75
76 # 设置环境变量
77 os.environ["XRE_INC_DIR"] = XRE_INC_DIR
78 os.environ["XRE_LIB_DIR"] = XRE_LIB_DIR
79 os.environ["XDNN_INC_DIR"] = XDNN_INC_DIR
80 os.environ["XDNN_LIB_DIR"] = XDNN_LIB_DIR
81
82 # 设置 Clang 路径
83 os.environ["CLANG_PATH"] = CLANG_PATH
84
85 # 删除指定目录
86 dirs_to_remove = [
87 "dist",
88 "fastdeploy_ops.egg-info",
89 "build",
90 "plugin/build",
91 ]
92 for dir_name in dirs_to_remove:
93 if os.path.exists(dir_name):
94 shutil.rmtree(dir_name)
95 print(f"Removed directory: {dir_name}")
96
97 # 在 plugin 目录中执行构建脚本
98 plugin_dir = "plugin"
99 build_script = os.path.join(current_working_directory, plugin_dir, "build.sh")
100
101 print("build_script: ", build_script)
102
103 if not os.path.isfile(build_script):
104 print(f"Error: Build script not found at {build_script}")
105 return
106
107 # 赋予执行权限 (如果尚未设置)
108 if not os.access(build_script, os.X_OK):
109 os.chmod(build_script, 0o755)
110
111 # 执行构建脚本
112 try:
113 print("Running build script...")
114 subprocess.run(
115 [build_script],
116 check=True,
117 cwd=os.path.join(current_working_directory, plugin_dir),
118 )
119 print("Build completed successfully.")
120 except subprocess.CalledProcessError as e:
121 print(f"Build failed with error: {e}")
122 except Exception as e:
123 print(f"Unexpected error: {e!s}")
124
125
126def xpu_setup_ops():

Callers 1

xpu_setup_opsFunction · 0.85

Calls 4

printFunction · 0.85
joinMethod · 0.80
existsMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected