You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL2环境运行cuML代码遭遇CUDA_ERROR_NO_DEVICE错误求助

WSL2环境运行cuML代码遭遇CUDA_ERROR_NO_DEVICE错误求助

我正在Windows的WSL2环境里尝试运行cuML,我的环境配置如下:

  • Ubuntu 22.04
  • amd64架构
  • NVIDIA RTX A2000 8GB 笔记本GPU
  • CUDA 12.6

main.py

import logging

import cudf
from cuml.ensemble import RandomForestClassifier
from cuml.preprocessing import StandardScaler
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score, classification_report
from sklearn.model_selection import train_test_split

logger = logging.getLogger(__name__)


def main() -> None:
    # Load the iris dataset
    iris = load_iris()
    x = iris.data
    y = iris.target

    # Split the data
    x_train, x_test, y_train, y_test = train_test_split(
        x, y, test_size=0.2, random_state=42
    )

    # Convert to cuDF DataFrames
    X_train_cudf = cudf.DataFrame(x_train)
    X_test_cudf = cudf.DataFrame(x_test)
    y_train_cudf = cudf.Series(y_train)
    y_test_cudf = cudf.Series(y_test)

    # Scale the features
    scaler = StandardScaler()
    x_train_scaled = scaler.fit_transform(X_train_cudf)
    x_test_scaled = scaler.transform(X_test_cudf)

    # Create and train the model
    rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42)
    rf_classifier.fit(x_train_scaled, y_train_cudf)

    # Make predictions
    y_pred_cudf = rf_classifier.predict(x_test_scaled)

    # Convert predictions back to CPU for evaluation
    y_pred = y_pred_cudf.values_host
    y_test = y_test_cudf.values_host

    # Print results
    logger.info("cuML Results:")
    logger.info(f"Accuracy: {accuracy_score(y_test, y_pred):.4f}")
    logger.info("\nClassification Report:")
    logger.info(classification_report(y_test, y_pred, target_names=iris.target_names))


if __name__ == "__main__":
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s - %(levelname)s - %(message)s",
    )
    main()

pyproject.toml

[project]
name = "hm-cuml"
version = "1.0.0"
requires-python = "~=3.12.0"
dependencies = [
  "cudf-cu12==24.12.0",
  "cuml-cu12==24.12.0",
  "scikit-learn==1.6.1",
]

现在我执行uv run main.py命令时出现了如下错误:

hm-cuml/.venv/lib/python3.12/site-packages/cudf/utils/_ptxcompiler.py:64: UserWarning: Error getting driver and runtime versions:

stdout:

stderr:

Traceback (most recent call last):
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 254, in ensure_initialized
    self.cuInit(0)
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 304, in safe_cuda_api_call
    self._check_ctypes_error(fname, retcode)
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 372, in _check_ctypes_error
    raise CudaAPIError(retcode, msg)
numba.cuda.cudadrv.driver.CudaAPIError: [100] Call to cuInit results in CUDA_ERROR_NO_DEVICE

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 269, in __getattr__
    self.ensure_initialized()
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 258, in ensure_initialized
    raise CudaSupportError(f"Error at driver init: {description}")
numba.cuda.cudadrv.error.CudaSupportError: Error at driver init: Call to cuInit results in CUDA_ERROR_NO_DEVICE (100)


Not patching Numba
  warnings.warn(msg, UserWarning)
Traceback (most recent call last):
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 254, in ensure_initialized
    self.cuInit(0)
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 304, in safe_cuda_api_call
    self._check_ctypes_error(fname, retcode)
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 372, in _check_ctypes_error
    raise CudaAPIError(retcode, msg)
numba.cuda.cudadrv.driver.CudaAPIError: [100] Call to cuInit results in CUDA_ERROR_NO_DEVICE

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "hm-cuml/src/main.py", line 58, in <module>
    main()
  File "hm-cuml/src/main.py", line 32, in main
    x_train_scaled = scaler.fit_transform(X_train_cudf)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/_thirdparty/sklearn/utils/skl_dependencies.py", line 162, in fit_transform
    return self.fit(X, **fit_params).transform(X)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/internals/api_decorators.py", line 188, in wrapper
    ret = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/_thirdparty/sklearn/preprocessing/_data.py", line 678, in fit
    return self.partial_fit(X, y)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/internals/api_decorators.py", line 188, in wrapper
    ret = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/_thirdparty/sklearn/preprocessing/_data.py", line 707, in partial_fit
    X = self._validate_data(X, accept_sparse=('csr', 'csc'),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/_thirdparty/sklearn/utils/skl_dependencies.py", line 111, in _validate_data
    X = check_array(X, **check_params)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/thirdparty_adapters/adapters.py", line 322, in check_array
    X, n_rows, n_cols, dtype = input_to_cupy_array(
                               ^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/nvtx/nvtx.py", line 116, in inner
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cuml/internals/input_utils.py", line 465, in input_to_cupy_array
    X = X.values
        ^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/utils/performance_tracking.py", line 51, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/frame.py", line 420, in values
    return self.to_cupy()
           ^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/utils/performance_tracking.py", line 51, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/frame.py", line 542, in to_cupy
    return self._to_array(
           ^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/utils/performance_tracking.py", line 51, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/frame.py", line 507, in _to_array
    matrix[:, i] = to_array(col, dtype)
                   ^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/frame.py", line 471, in to_array
    array = get_array(col)
            ^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/frame.py", line 543, in <lambda>
    lambda col: col.values,
                ^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/column/column.py", line 233, in values
    return cupy.asarray(self.data_array_view(mode="write"))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/cudf/core/column/column.py", line 135, in data_array_view
    return cuda.as_cuda_array(obj).view(self.dtype)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/api.py", line 76, in as_cuda_array
    return from_cuda_array_interface(obj.__cuda_array_interface__,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/devices.py", line 231, in _require_cuda_context
    with _runtime.ensure_context():
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hongbo-miao/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/devices.py", line 121, in ensure_context
    with driver.get_active_context():
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 472, in __enter__
    driver.cuCtxGetCurrent(byref(hctx))
    ^^^^^^^^^^^^^^^^^^^^^^
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 269, in __getattr__
    self.ensure_initialized()
  File "hm-cuml/.venv/lib/python3.12/site-packages/numba_cuda/numba/cuda/cudadrv/driver.py", line 258, in ensure_initialized
    raise CudaSupportError(f"Error at driver init: {description}")
numba.cuda.cudadrv.error.CudaSupportError: Error at driver init: Call to cuInit results in CUDA_ERROR_NO_DEVICE (100)

备注:内容来源于stack exchange,提问作者Hongbo Miao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 14:13:04