Skip to content

cupy backend crashes when the GPU UUID has a zero byte (bytes is not a 16-char string) #430

Backlog

Description

@kjwierenga

On an A100-SXM4-40GB in MIG mode, CupyFunctions raises an error before it compiles anything:

File ".../kernel_tuner/backends/cupy.py", line 81, in __init__
    env["uuid"] = str(uuid.UUID(bytes=props["uuid"]))
ValueError: bytes is not a 16-char string

The error message is the same as in #426, but the cause is different. This GPU has a valid UUID. In MIG mode, CUDA reports the UUID of the physical GPU. nvidia-smi -L shows GPU-1eed7047-720e-7d2e-4561-4205587600d0. CuPy returns only the first 14 bytes: b'\x1e\xedpGr\x0e}.EaB\x05Xv'.

CuPy copies the char[16] field like a C string. A C string ends at the first zero byte. About 6% of random UUIDs have a zero byte, so many GPUs are affected.

I reported this to CuPy in cupy/cupy#10522. I also sent a fix in cupy/cupy#10523. Until a CuPy release has the fix, Kernel Tuner crashes on these GPUs.

Fix: Set the UUID to None when it is shorter than 16 bytes, as #427 does for HIP. The code that reads env["uuid"] already accepts None. Do not pad the UUID with zeros: the padded UUID is wrong.

props = cp.cuda.runtime.getDeviceProperties(device)
# CuPy stops at the first zero byte of the UUID, so a valid UUID can be too short.
# Do not pad it: the result would be a wrong UUID.
env["uuid"] = None
if len(props["uuid"]) == 16:
    env["uuid"] = str(uuid.UUID(bytes=props["uuid"]))

I have this fix with a test that uses a fake cupy module, so the test needs no GPU. I will open a PR for it.

I did not test nvcuda.py (device_properties.uuid.bytes). It uses the same code pattern.

Versions: Kernel Tuner at commit 6c8e367 (includes #427), cupy-cuda12x 14.2.0, CUDA 12.9, Python 3.12.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions