patch_paddle_inference.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import sys
  16. import shutil
  17. import subprocess
  18. import platform
  19. import sys
  20. def process_paddle_inference(paddle_inference_so_file, paddle_inference_version):
  21. if platform.system().lower() != "linux":
  22. return
  23. rpaths = [
  24. "$ORIGIN",
  25. "$ORIGIN/../../third_party/install/mklml/lib/",
  26. "$ORIGIN/../../third_party/install/xpu/lib/",
  27. "$ORIGIN/../../third_party/install/fdmodel/lib/",
  28. "$ORIGIN/../../../tensorrt/lib/",
  29. ]
  30. version_major = int(paddle_inference_version.split(".")[0])
  31. if paddle_inference_version != "0.0.0" and version_major < 2:
  32. raise ValueError("Invalid Paddle Inference version")
  33. if version_major == 2:
  34. rpaths.append("$ORIGIN/../../third_party/install/mkldnn/lib/")
  35. else:
  36. rpaths.append("$ORIGIN/../../third_party/install/onednn/lib/")
  37. patchelf_exe = os.getenv("PATCHELF_EXE", "patchelf")
  38. command = "{} --force-rpath --set-rpath '{}' {}".format(
  39. patchelf_exe, ":".join(rpaths), paddle_inference_so_file
  40. )
  41. if platform.machine() != "sw_64" and platform.machine() != "mips64":
  42. assert os.system(command) == 0, "patchelf {} failed, the command: {}".format(
  43. paddle_inference_so_file, command
  44. )
  45. if __name__ == "__main__":
  46. process_paddle_inference(sys.argv[1], sys.argv[2])