patch_paddle_lite.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_lite(paddle_lite_so_path):
  18. if platform.system().lower() != "linux":
  19. return
  20. rpaths = ["$ORIGIN", "$ORIGIN/mklml/lib/"]
  21. patchelf_exe = os.getenv("PATCHELF_EXE", "patchelf")
  22. for root, dirs, files in os.walk(paddle_lite_so_path):
  23. for lib in files:
  24. if ".so" in lib:
  25. paddle_lite_so_file = os.path.join(root, lib)
  26. command = "{} --set-rpath '{}' {}".format(
  27. patchelf_exe, ":".join(rpaths), paddle_lite_so_file
  28. )
  29. if platform.machine() != "sw_64" and platform.machine() != "mips64":
  30. assert (
  31. os.system(command) == 0
  32. ), "patchelf {} failed, the command: {}".format(
  33. paddle_lite_so_file, command
  34. )
  35. if __name__ == "__main__":
  36. process_paddle_lite(sys.argv[1])