patch_paddle_inference.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  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 platform
  16. import sys
  17. def process_paddle_inference(paddle_inference_so_file, paddle_inference_version):
  18. if platform.system().lower() != "linux":
  19. return
  20. rpaths = [
  21. "$ORIGIN",
  22. "$ORIGIN/../../third_party/install/mklml/lib/",
  23. "$ORIGIN/../../third_party/install/xpu/lib/",
  24. "$ORIGIN/../../third_party/install/fdmodel/lib/",
  25. "$ORIGIN/../../../tensorrt/lib/",
  26. ]
  27. version_major = int(paddle_inference_version.split(".")[0])
  28. if paddle_inference_version != "0.0.0" and version_major < 2:
  29. raise ValueError("Invalid Paddle Inference version")
  30. if version_major == 2:
  31. rpaths.append("$ORIGIN/../../third_party/install/mkldnn/lib/")
  32. else:
  33. rpaths.append("$ORIGIN/../../third_party/install/onednn/lib/")
  34. patchelf_exe = os.getenv("PATCHELF_EXE", "patchelf")
  35. command = "{} --force-rpath --set-rpath '{}' {}".format(
  36. patchelf_exe, ":".join(rpaths), paddle_inference_so_file
  37. )
  38. if platform.machine() != "sw_64" and platform.machine() != "mips64":
  39. assert os.system(command) == 0, "patchelf {} failed, the command: {}".format(
  40. paddle_inference_so_file, command
  41. )
  42. if __name__ == "__main__":
  43. process_paddle_inference(sys.argv[1], sys.argv[2])