From 8e0e71078c142f46855cdbfad9f6833501a369d3 Mon Sep 17 00:00:00 2001 From: Box Date: Thu, 10 Oct 2024 16:45:40 +0800 Subject: [PATCH] Refactor get_cuda() function to check for CUDA version using nvcc command in PATH --- jtop/core/jetson_libraries.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jtop/core/jetson_libraries.py b/jtop/core/jetson_libraries.py index f79ade35..bd886f65 100644 --- a/jtop/core/jetson_libraries.py +++ b/jtop/core/jetson_libraries.py @@ -17,6 +17,7 @@ import os import re +import subprocess from .common import cat from .command import Command # Fix connection refused for python 2.7 @@ -49,6 +50,17 @@ def get_cuda(): break except (OSError, Command.CommandException): pass + elif subprocess.call(["which", "nvcc"]) == 0: + cmd = Command(['nvcc', '--version']) + try: + lines = cmd() + for line in lines: + match = re.search(CUDA_NVCC_RE, line) + if match: + cuda_version = match.group(1) + break + except (OSError, Command.CommandException): + pass return cuda_version