test_cuda_setup_evaluator.py 1.4 KB
Newer Older
1
import os
2
from typing import List, NamedTuple
3

Tom Aarsen's avatar
Tom Aarsen committed
4
5
6
import pytest

import bitsandbytes as bnb
7
from bitsandbytes.cuda_setup.main import (
8
    determine_cuda_runtime_lib_path,
Tom Aarsen's avatar
Tom Aarsen committed
9
    evaluate_cuda_setup,
10
    extract_candidate_paths,
11
)
12

13

14
def test_cuda_full_system():
15
    ## this only tests the cuda version and not compute capability
16
17
18

    # if CONDA_PREFIX exists, it has priority before all other env variables
    # but it does not contain the library directly, so we need to look at the a sub-folder
19
20
    version = ""
    if "CONDA_PREFIX" in os.environ:
21
        ls_output, err = bnb.utils.execute_and_return(f'ls -l {os.environ["CONDA_PREFIX"]}/lib/libcudart.so.11.0')
22
        major, minor, revision = (ls_output.split(" ")[-1].replace("libcudart.so.", "").split("."))
23
24
        version = float(f"{major}.{minor}")

25
    if version == "" and "LD_LIBRARY_PATH" in os.environ:
26
27
28
29
30
31
32
33
34
35
        ld_path = os.environ["LD_LIBRARY_PATH"]
        paths = ld_path.split(":")
        version = ""
        for p in paths:
            if "cuda" in p:
                idx = p.rfind("cuda-")
                version = p[idx + 5 : idx + 5 + 4].replace("/", "")
                version = float(version)
                break

36

37
    assert version > 0
38
    binary_name, cudart_path, cuda, cc, cuda_version_string = evaluate_cuda_setup()
39
40
    binary_name = binary_name.replace("libbitsandbytes_cuda", "")
    assert binary_name.startswith(str(version).replace(".", ""))