env.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. def get_device_type():
  15. import paddle
  16. device_str = paddle.get_device()
  17. return device_str.split(":")[0]
  18. def get_paddle_version():
  19. import paddle
  20. version = paddle.__version__
  21. if "-" in version:
  22. version, tag = version.split("-")
  23. else:
  24. tag = None
  25. version = version.split(".")
  26. assert len(version) == 3
  27. major_v, minor_v, patch_v = map(int, version)
  28. if tag:
  29. return major_v, minor_v, patch_v, tag
  30. else:
  31. return major_v, minor_v, patch_v, None
  32. def get_paddle_cuda_version():
  33. import paddle.version
  34. cuda_version = paddle.version.cuda()
  35. if cuda_version == "False":
  36. return None
  37. return tuple(map(int, cuda_version.split(".")))
  38. def get_paddle_cudnn_version():
  39. import paddle.version
  40. cudnn_version = paddle.version.cudnn()
  41. if cudnn_version == "False":
  42. return None
  43. return tuple(map(int, cudnn_version.split(".")))
  44. # Should we also support getting the runtime versions of CUDA and cuDNN?