MCPcopy Create free account
hub / github.com/RightNow-AI/rightnow-cli / CUDACompiler

Class CUDACompiler

rightnow_cli/compiler.py:14–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class CUDACompiler:
15 def __init__(self):
16 self.nvcc_path = self._find_nvcc()
17 if not self.nvcc_path:
18 raise RuntimeError("NVIDIA CUDA Toolkit not found. Please install CUDA toolkit.")
19
20 self.cuda_version = self._get_cuda_version()
21 self.arch_flags = self._detect_gpu_architecture()
22
23 console.print(f"[green]Found CUDA {self.cuda_version} at {self.nvcc_path}[/green]")
24
25 def _find_nvcc(self) -> Optional[str]:
26 """Find nvcc compiler in system PATH or common locations."""
27 nvcc_name = "nvcc.exe" if platform.system() == "Windows" else "nvcc"
28
29 nvcc_path = shutil.which(nvcc_name)
30 if nvcc_path:
31 return nvcc_path
32
33 common_paths = []
34 if platform.system() == "Windows":
35 common_paths = [
36 r"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v*\bin",
37 r"C:\Program Files\NVIDIA Corporation\CUDA\v*\bin",
38 r"C:\CUDA\v*\bin"
39 ]
40 else:
41 common_paths = [
42 "/usr/local/cuda/bin",
43 "/usr/local/cuda-*/bin",
44 "/opt/cuda/bin",
45 "/opt/cuda-*/bin"
46 ]
47
48 import glob
49 for pattern in common_paths:
50 for path in glob.glob(pattern):
51 nvcc_candidate = os.path.join(path, nvcc_name)
52 if os.path.exists(nvcc_candidate):
53 return nvcc_candidate
54
55 return None
56
57 def _get_cuda_version(self) -> str:
58 """Get CUDA toolkit version."""
59 try:
60 result = subprocess.run(
61 [self.nvcc_path, "--version"],
62 capture_output=True,
63 text=True,
64 check=True
65 )
66
67 version_match = re.search(r"release (\d+\.\d+)", result.stdout)
68 if version_match:
69 return version_match.group(1)
70 return "Unknown"
71 except Exception:

Callers 3

_run_optimizationMethod · 0.85
_create_test_programMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected