                  chk = os.popen("ls {} | grep -P -o \"libcudart.so.\\d+.\\d+\" | "
                                 "head -n 1".format(path)).read()
                  if chk:
                      break
          if not chk:
              self.output.error("CUDA not found. Install and try again.\n"
                                "Recommended version:      CUDA 10.1     cuDNN 7.6\n"
                                "CUDA: https://developer.nvidia.com/cuda-downloads\n"
                                "cuDNN: https://developer.nvidia.com/rdp/cudnn-download")
              return
          cudavers = chk.strip().replace("libcudart.so.", "")
          self.env.cuda_version = cudavers[:cudavers.find(" ")]
          if self.env.cuda_version:
              self.output.info("CUDA version: " + self.env.cuda_version)
 
</s> remove         if self.env.ld_library_path and not chk:
            paths = self.env.ld_library_path.split(":")
            for path in paths:
                chk = os.popen("ls {} | grep -P -o \"libcudart.so.\\d+.\\d+\" | "
                               "head -n 1".format(path)).read()
 </s> add         if not chk and os.environ.get("LD_LIBRARY_PATH"):
            for path in os.environ["LD_LIBRARY_PATH"].split(":"):
                chk = os.popen(f"ls {path} | grep -P -o \"libcudart.so.\\d+.\\d+\" | "
                               "head -n 1").read() </s> remove         self.env.cuda_version = cudavers[:cudavers.find(" ")]
        if self.env.cuda_version:
            self.output.info("CUDA version: " + self.env.cuda_version)
            self.env.cuda_path = chk[chk.find("=>") + 3:chk.find("targets") - 1]

    def cuda_check_windows(self):
        """ Check Windows CUDA Version """
        cuda_keys = self.cuda_keys_windows
        if not cuda_keys:
            self.output.error("CUDA not found. See "
                              "https://github.com/deepfakes/faceswap/blob/master/INSTALL.md#cuda "
                              "for instructions")
 </s> add         self.cuda_version = cudavers[:cudavers.find(" ")]
        self.cuda_path = chk[chk.find("=>") + 3:chk.find("targets") - 1]

    def _cuda_check_windows(self):
        """ Check Windows CUDA Version and path from Environment Variables"""
        if not self._cuda_keys:  # Cuda environment variable not found </s> remove             self.cuda_check()
            self.cudnn_check()
 </s> add             check = CudaCheck()
            if check.cuda_version:
                self.env.cuda_version = check.cuda_version
                self.output.info("CUDA version: " + self.env.cuda_version)
            else:
                self.output.error("CUDA not found. Install and try again.\n"
                                  "Recommended version:      CUDA 10.1     cuDNN 7.6\n"
                                  "CUDA: https://developer.nvidia.com/cuda-downloads\n"
                                  "cuDNN: https://developer.nvidia.com/rdp/cudnn-download")
                return

            if check.cudnn_version:
                self.env.cudnn_version = ".".join(check.cudnn_version.split(".")[:2])
                self.output.info(f"cuDNN version: {self.env.cudnn_version}")
            else:
                self.output.error("cuDNN not found. See "
                                  "https://github.com/deepfakes/faceswap/blob/master/INSTALL.md#"
                                  "cudnn for instructions")
                return </s> remove             return retval
        return "{}.{}.{}".format(major, minor, patchlevel)

    @staticmethod
    def _cudnn_checkfiles_linux():
        """ Obtain the location of the files to check for cuDNN location in Linux.

        Returns
        str:
            The location of the header files for cuDNN
        """
        chk = os.popen("ldconfig -p | grep -P \"libcudnn.so.\\d+\" | head -n 1").read()
        if "libcudnn.so." not in chk:
            return list()
        chk = chk.strip().replace("libcudnn.so.", "")
        cudnn_vers = chk[0]
        cudnn_path = chk[chk.find("=>") + 3:chk.find("libcudnn") - 1]
        cudnn_path = cudnn_path.replace("lib", "include")
        cudnn_checkfiles = [os.path.join(cudnn_path, "cudnn_v{}.h".format(cudnn_vers)),
                            os.path.join(cudnn_path, "cudnn.h")]
        return cudnn_checkfiles

    def _cudnn_checkfiles_windows(self):
        """ Obtain the location of the files to check for cuDNN location in Windows.

        Returns
        str:
            The location of the header files for cuDNN
        """
        # TODO A more reliable way of getting the windows location
        if not self._cuda_path and not self._cuda_keys_windows:
            return list()
        if not self._cuda_path:
            self._cuda_path = os.environ[self._cuda_keys_windows[0]]

        cudnn_checkfile = os.path.join(self._cuda_path, "include", "cudnn.h")
        return [cudnn_checkfile]

    def _get_cuda_path(self):
        """ Obtain the path to Cuda install location.

        Returns
        -------
        str
            The path to the install location of Cuda on the system
        """
        if self._is_linux:
            path = self._cuda_path_linux()
        elif self._is_windows:
            path = self._cuda_path_windows()
        else:
            path = None
        return path

    @staticmethod
    def _cuda_path_linux():
        """ Obtain the path to Cuda install location on Linux.

        Returns
        -------
        str
            The path to the install location of Cuda on a Linux system
        """
        ld_library_path = os.environ.get("LD_LIBRARY_PATH", None)
        chk = os.popen("ldconfig -p | grep -P \"libcudart.so.\\d+.\\d+\" | head -n 1").read()
        if ld_library_path and not chk:
            paths = ld_library_path.split(":")
            for path in paths:
                chk = os.popen("ls {} | grep -P -o \"libcudart.so.\\d+.\\d+\" | "
                               "head -n 1".format(path)).read()
                if chk:
                    break
        if not chk:
            return None
        return chk[chk.find("=>") + 3:chk.find("targets") - 1]

    @staticmethod
    def _cuda_path_windows():
        """ Obtain the path to Cuda install location on Windows.

        Returns
        -------
        str
            The path to the install location of Cuda on a Windows system
        """
        cuda_path = os.environ.get("CUDA_PATH", None)
        return cuda_path

    def _cuda_version_linux(self):
        """ Obtain the installed version of Cuda on a Linux system.

        Returns
        -------
        The installed CUDA version on a Linux system
        """
        ld_library_path = os.environ.get("LD_LIBRARY_PATH", None)
        chk = os.popen("ldconfig -p | grep -P \"libcudart.so.\\d+.\\d+\" | head -n 1").read()
        if ld_library_path and not chk:
            paths = ld_library_path.split(":")
            for path in paths:
                chk = os.popen("ls {} | grep -P -o \"libcudart.so.\\d+.\\d+\" | "
                               "head -n 1".format(path)).read()
                if chk:
                    break
        if not chk:
            retval = "No global version found"
            if self._is_conda:
                retval += ". Check Conda packages for Conda Cuda"
            return retval
        cudavers = chk.strip().replace("libcudart.so.", "")
        return cudavers[:cudavers.find(" ")]

    def _cuda_version_windows(self):
        """ Obtain the installed version of Cuda on a Windows system.

        Returns
        -------
        The installed CUDA version on a Windows system
        """
        cuda_keys = self._cuda_keys_windows
        if not cuda_keys:
            retval = "No global version found"
            if self._is_conda:
                retval += ". Check Conda packages for Conda Cuda"
            return retval
        cudavers = [key.lower().replace("cuda_path_v", "").replace("_", ".") for key in cuda_keys]
        return " ".join(cudavers)
 </s> add         return retval </s> remove             version = re.search(r".*release (?P<cuda>\d+\.\d+)", stdout.decode(self.env.encoding))
            self.env.cuda_version = version.groupdict().get("cuda", None)
            if self.env.cuda_version:
                self.output.info("CUDA version: " + self.env.cuda_version)
                return
        # Failed to load nvcc
        if self.env.os_version[0] == "Linux":
            self.cuda_check_linux()
        elif self.env.os_version[0] == "Windows":
            self.cuda_check_windows()

    def cuda_check_linux(self):
        """ Check Linux CUDA Version """
 </s> add             version = re.search(r".*release (?P<cuda>\d+\.\d+)",
                                stdout.decode(locale.getpreferredencoding()))
            self.cuda_version = version.groupdict().get("cuda", None)
            locate = "where" if self._os == "windows" else "which"
            path = os.popen(f"{locate} nvcc").read()
            if path:
                path = path.split("\n")[0]  # Split multiple entries and take first found
                while True:  # Get Cuda root folder
                    path, split = os.path.split(path)
                    if split == "bin":
                        break
                self.cuda_path = path
            return

        # Failed to load nvcc, manual check
        getattr(self, f"_cuda_check_{self._os}")()

    def _cuda_check_linux(self):
        """ For Linux check the dynamic link loader for libcudart. If not found with ldconfig then
        attempt to find it in LD_LIBRARY_PATH. """
        if not chk:  # Cuda not found
                  chk = os.popen("ls {} | grep -P -o \"libcudart.so.\\d+.\\d+\" | "
                                 "head -n 1".format(path)).read()
                  if chk:
                      break
        if not chk:  # Cuda not found
        if not chk:  # Cuda not found
        if not chk:  # Cuda not found
        if not chk:  # Cuda not found
        if not chk:  # Cuda not found
              return
          cudavers = chk.strip().replace("libcudart.so.", "")
          self.env.cuda_version = cudavers[:cudavers.find(" ")]
          if self.env.cuda_version:
              self.output.info("CUDA version: " + self.env.cuda_version)
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
 sysinfo/setup - Standardize cuda/cudnn checks 
setup.py