summaryrefslogtreecommitdiff
path: root/bitsandbytes/cuda_setup
diff options
context:
space:
mode:
authorDmitry Baranchuk <dmitrybaranchuk@gmail.com>2022-09-10 19:33:21 -0700
committerGitHub <noreply@github.com>2022-09-10 19:33:21 -0700
commit843ad0631c65eabc7f64e80906ecf5482cc1a036 (patch)
tree07ab541ec59ab3474a711c155daa118fc0ae6864 /bitsandbytes/cuda_setup
parent8d34d36f150b0fd4914cdb56d4e3bda34c029ccc (diff)
parent2e630b55f51d454f3bd723dffda68a07ef93190c (diff)
Merge pull request #1 from TimDettmers/main
Update main branch
Diffstat (limited to 'bitsandbytes/cuda_setup')
-rw-r--r--bitsandbytes/cuda_setup/compute_capability.py79
-rw-r--r--bitsandbytes/cuda_setup/main.py11
-rw-r--r--bitsandbytes/cuda_setup/paths.py16
3 files changed, 7 insertions, 99 deletions
diff --git a/bitsandbytes/cuda_setup/compute_capability.py b/bitsandbytes/cuda_setup/compute_capability.py
deleted file mode 100644
index 7a3f463..0000000
--- a/bitsandbytes/cuda_setup/compute_capability.py
+++ /dev/null
@@ -1,79 +0,0 @@
-import ctypes
-from dataclasses import dataclass, field
-
-
-@dataclass
-class CudaLibVals:
- # code bits taken from
- # https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
-
- nGpus: ctypes.c_int = field(default=ctypes.c_int())
- cc_major: ctypes.c_int = field(default=ctypes.c_int())
- cc_minor: ctypes.c_int = field(default=ctypes.c_int())
- device: ctypes.c_int = field(default=ctypes.c_int())
- error_str: ctypes.c_char_p = field(default=ctypes.c_char_p())
- cuda: ctypes.CDLL = field(init=False, repr=False)
- ccs: List[str, ...] = field(init=False)
-
- def _initialize_driver_API(self):
- self.check_cuda_result(self.cuda.cuInit(0))
-
- def _load_cuda_lib(self):
- """
- 1. find libcuda.so library (GPU driver) (/usr/lib)
- init_device -> init variables -> call function by reference
- """
- libnames = "libcuda.so"
- for libname in libnames:
- try:
- self.cuda = ctypes.CDLL(libname)
- except OSError:
- continue
- else:
- break
- else:
- raise OSError("could not load any of: " + " ".join(libnames))
-
- def call_cuda_func(self, function_obj, **kwargs):
- CUDA_SUCCESS = 0 # constant taken from cuda.h
- pass
- # if (CUDA_SUCCESS := function_obj(
-
- def _error_handle(cuda_lib_call_return_value):
- """
- 2. call extern C function to determine CC
- (see https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__DEVICE__DEPRECATED.html)
- """
- CUDA_SUCCESS = 0 # constant taken from cuda.h
-
- if cuda_lib_call_return_value != CUDA_SUCCESS:
- self.cuda.cuGetErrorString(
- cuda_lib_call_return_value,
- ctypes.byref(self.error_str),
- )
- print("Count not initialize CUDA - failure!")
- raise Exception("CUDA exception!")
- return cuda_lib_call_return_value
-
- def __post_init__(self):
- self._load_cuda_lib()
- self._initialize_driver_API()
- self.check_cuda_result(
- self.cuda, self.cuda.cuDeviceGetCount(ctypes.byref(self.nGpus))
- )
- tmp_ccs = []
- for gpu_index in range(self.nGpus.value):
- check_cuda_result(
- self.cuda,
- self.cuda.cuDeviceGet(ctypes.byref(self.device), gpu_index),
- )
- check_cuda_result(
- self.cuda,
- self.cuda.cuDeviceComputeCapability(
- ctypes.byref(self.cc_major),
- ctypes.byref(self.cc_minor),
- self.device,
- ),
- )
- tmp_ccs.append(f"{self.cc_major.value}.{self.cc_minor.value}")
- self.ccs = sorted(tmp_ccs, reverse=True)
diff --git a/bitsandbytes/cuda_setup/main.py b/bitsandbytes/cuda_setup/main.py
index 975b772..78a2844 100644
--- a/bitsandbytes/cuda_setup/main.py
+++ b/bitsandbytes/cuda_setup/main.py
@@ -17,9 +17,7 @@ evaluation:
"""
import ctypes
-from pathlib import Path
-from ..utils import execute_and_return
from .paths import determine_cuda_runtime_lib_path
@@ -28,7 +26,7 @@ def check_cuda_result(cuda, result_val):
if result_val != 0:
error_str = ctypes.c_char_p()
cuda.cuGetErrorString(result_val, ctypes.byref(error_str))
- raise Exception(f"CUDA exception! Error code: {error_str.value.decode()}")
+ print(f"CUDA exception! Error code: {error_str.value.decode()}")
def get_cuda_version(cuda, cudart_path):
# https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART____VERSION.html#group__CUDART____VERSION
@@ -57,7 +55,7 @@ def get_cuda_lib_handle():
cuda = ctypes.CDLL("libcuda.so")
except OSError:
# TODO: shouldn't we error or at least warn here?
- raise Exception('CUDA SETUP: ERROR! libcuda.so not found! Do you have a CUDA driver installed? If you are on a cluster, make sure you are on a CUDA machine!')
+ print('CUDA SETUP: WARNING! libcuda.so not found! Do you have a CUDA driver installed? If you are on a cluster, make sure you are on a CUDA machine!')
return None
check_cuda_result(cuda, cuda.cuInit(0))
@@ -80,7 +78,6 @@ def get_compute_capabilities(cuda):
cc_major = ctypes.c_int()
cc_minor = ctypes.c_int()
- result = ctypes.c_int()
device = ctypes.c_int()
check_cuda_result(cuda, cuda.cuDeviceGetCount(ctypes.byref(nGpus)))
@@ -119,6 +116,10 @@ def evaluate_cuda_setup():
print('For effortless bug reporting copy-paste your error into this form: https://docs.google.com/forms/d/e/1FAIpQLScPB8emS3Thkp66nvqwmjTEgxp8Y9ufuWTzFyr9kJ5AoI47dQ/viewform?usp=sf_link')
print('='*80)
binary_name = "libbitsandbytes_cpu.so"
+ #if not torch.cuda.is_available():
+ #print('No GPU detected. Loading CPU library...')
+ #return binary_name
+
cudart_path = determine_cuda_runtime_lib_path()
if cudart_path is None:
print(
diff --git a/bitsandbytes/cuda_setup/paths.py b/bitsandbytes/cuda_setup/paths.py
index 9c565c7..6f6425f 100644
--- a/bitsandbytes/cuda_setup/paths.py
+++ b/bitsandbytes/cuda_setup/paths.py
@@ -2,23 +2,11 @@ from pathlib import Path
from typing import Set, Union
from warnings import warn
-from ..utils import print_stderr
from .env_vars import get_potentially_lib_path_containing_env_vars
-
CUDA_RUNTIME_LIB: str = "libcudart.so"
-def purge_unwanted_semicolon(tentative_path: Path) -> Path:
- """
- Special function to handle the following exception:
- __LMOD_REF_COUNT_PATH=/sw/cuda/11.6.2/bin:2;/mmfs1/home/dettmers/git/sched/bin:1;/mmfs1/home/dettmers/data/anaconda3/bin:1;/mmfs1/home/dettmers/data/anaconda3/condabin:1;/mmfs1/home/dettmers/.local/bin:1;/mmfs1/home/dettmers/bin:1;/usr/local/bin:1;/usr/bin:1;/usr/local/sbin:1;/usr/sbin:1;/mmfs1/home/dettmers/.fzf/bin:1;/mmfs1/home/dettmers/data/local/cuda-11.4/bin:1
- """
- # if ';' in str(tentative_path):
- # path_as_str, _ = str(tentative_path).split(';')
- pass
-
-
def extract_candidate_paths(paths_list_candidate: str) -> Set[Path]:
return {Path(ld_path) for ld_path in paths_list_candidate.split(":") if ld_path}
@@ -29,7 +17,7 @@ def remove_non_existent_dirs(candidate_paths: Set[Path]) -> Set[Path]:
}
if non_existent_directories:
- print_stderr(
+ warn(
"WARNING: The following directories listed in your path were found to "
f"be non-existent: {non_existent_directories}"
)
@@ -117,8 +105,6 @@ def determine_cuda_runtime_lib_path() -> Union[Path, None]:
if env_var not in {"CONDA_PREFIX", "LD_LIBRARY_PATH"}
}
-
-
cuda_runtime_libs = set()
for env_var, value in remaining_candidate_env_vars.items():
cuda_runtime_libs.update(find_cuda_lib_in(value))