Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion kernel_tuner/backends/cupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
# and run tests without cupy installed
try:
import cupy as cp
import cupyx
except ImportError:
cp = None
cupyx = None


class CupyFunctions(GPUBackend):
Expand Down Expand Up @@ -68,7 +70,7 @@ def __init__(self, device=0, iterations=7, compiler_options=None, observers=None

# collect environment information
env = dict()
cupy_info = str(cp._cupyx.get_runtime_info()).split("\n")[:-1]
cupy_info = str(cupyx.get_runtime_info()).split("\n")[:-1]
info_dict = {
s.split(":")[0].strip(): s.split(":")[1].strip() for s in cupy_info
}
Expand Down
29 changes: 29 additions & 0 deletions test/test_cupy_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

import numpy as np

try:
from unittest.mock import patch, Mock, MagicMock
except ImportError:
from mock import patch, Mock, MagicMock

import kernel_tuner

from .context import skip_if_no_cupy
Expand All @@ -10,3 +17,25 @@ def test_tune_kernel(env):
result, _ = kernel_tuner.tune_kernel(*env, lang="cupy", verbose=True)
assert len(result) > 0


@patch('kernel_tuner.backends.cupy.cupyx')
@patch('kernel_tuner.backends.cupy.cp')
def test_cupy_init_uses_cupyx_not_private_attr(cp_mock, cupyx_mock):
"""Regression test: CupyFunctions should use cupyx.get_runtime_info(), not cp._cupyx."""
# Setup cp mock
dev_mock = MagicMock()
dev_mock.attributes = {"MaxThreadsPerBlock": 1024}
dev_mock.compute_capability = "75"
cp_mock.cuda.Device.return_value = dev_mock
cp_mock.cuda.runtime.driverGetVersion.return_value = 11000

# Setup cupyx mock to return runtime info string
runtime_info = "CuPy Version : 14.0.1\nCUDA Root : /usr/local/cuda\nDevice 0 Name : Tesla T4\n"
cupyx_mock.get_runtime_info.return_value = runtime_info

from kernel_tuner.backends.cupy import CupyFunctions
dev = CupyFunctions(device=0)

# Verify cupyx.get_runtime_info() was called, not cp._cupyx.get_runtime_info()
cupyx_mock.get_runtime_info.assert_called_once()
assert dev.name == "Tesla T4"