Skip to content

BUG: Fix typo in advise and prefetch affecting cuda 13#9493

Merged
kmaehashi merged 8 commits into
cupy:mainfrom
seberg:advise-cu13
Nov 27, 2025
Merged

BUG: Fix typo in advise and prefetch affecting cuda 13#9493
kmaehashi merged 8 commits into
cupy:mainfrom
seberg:advise-cu13

Conversation

@seberg
Copy link
Copy Markdown
Member

@seberg seberg commented Nov 20, 2025

The struct is already the location, so this added one level. Strangely, Cython chooses to not fail compilation but rather raise a runtime error (pretending that this is a dict).

Added a very simple test, but happy to iterate on it if it doesn't seem ideal.

Just as a note: this API is documented as experimental.

The struct is already the location, so this added one level.
Strangely, Cython chooses to not fail compilation but rather raise
a runtime error (pretending that this is a dict).

Added a very simple test, but happy to iterate on it if it doesn't
seem ideal.

Just as a note: this API is documented as experimental.
@seberg seberg requested a review from a team as a code owner November 20, 2025 13:12
@seberg seberg changed the title BUG: Fix typo in advise and prefetch BUG: Fix typo in advise and prefetch affecting cuda 13 Nov 20, 2025
@leofang
Copy link
Copy Markdown
Member

leofang commented Nov 24, 2025

/test mini

@leofang leofang added this to the v14.0.0rc1 milestone Nov 24, 2025
@leofang leofang self-assigned this Nov 24, 2025
@seberg
Copy link
Copy Markdown
Member Author

seberg commented Nov 24, 2025

Oops, the way these enum levels are defined means that they need an explicit cast (as in some other places here).

/test mini

@seberg
Copy link
Copy Markdown
Member Author

seberg commented Nov 25, 2025

Hmmm, is this something obvious? The call should be using mem.device_id as the default isn't passed but on windows that leads to an invalid device?

================================== FAILURES ===================================
_____________________ test_managed_memory_prefetch_basic ______________________

    def test_managed_memory_prefetch_basic():
        # Check that the prefetch API (and runtime API) seem to work.
        mem = memory.malloc_managed(1024)
>       mem.mem.prefetch(stream_module.get_current_stream())

cupy_tests\cuda_tests\test_memory.py:1337: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cupy/cuda/memory.pyx:254: in cupy.cuda.memory.ManagedMemory.prefetch
    ???
cupy_backends/cuda/api/runtime.pyx:744: in cupy_backends.cuda.api.runtime.memPrefetchAsync
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   cupy_backends.cuda.api.runtime.CUDARuntimeError: cudaErrorInvalidDevice: invalid device ordinal

cupy_backends/cuda/api/runtime.pyx:147: CUDARuntimeError

@kmaehashi
Copy link
Copy Markdown
Member

@kmaehashi
Copy link
Copy Markdown
Member

This reproduced on my local Windows machine, so it's not CI specific.

>>> import cupy
>>> from cupy.cuda import memory, stream as stream_module
>>> mem = memory.malloc_managed(1024)
>>> mem.mem.prefetch(stream_module.get_current_stream())
devPtr=8637120512 count=1024 dstDevice=0 stream=0
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    mem.mem.prefetch(stream_module.get_current_stream())
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cupy/cuda/memory.pyx", line 256, in cupy.cuda.memory.ManagedMemory.prefetch
    runtime.memPrefetchAsync(self.ptr, self.size, device_id, stream.ptr)
  File "cupy_backends/cuda/api/runtime.pyx", line 745, in cupy_backends.cuda.api.runtime.memPrefetchAsync
    check_status(status)
  File "cupy_backends/cuda/api/runtime.pyx", line 147, in cupy_backends.cuda.api.runtime.check_status
    raise CUDARuntimeError(status)
cupy_backends.cuda.api.runtime.CUDARuntimeError: cudaErrorInvalidDevice: invalid device ordinal

@seberg
Copy link
Copy Markdown
Member Author

seberg commented Nov 26, 2025

ahhh, thanks, that makes sense! Added a skipif(sys.platform != 'linux').

@leofang
Copy link
Copy Markdown
Member

leofang commented Nov 26, 2025

/test mini

@kmaehashi
Copy link
Copy Markdown
Member

kmaehashi commented Nov 27, 2025

On Windows it seems test_managed_memory_prefetch_basic is failing but madvise is working.

@seberg
Copy link
Copy Markdown
Member Author

seberg commented Nov 27, 2025

/test mini

🤦 sorry I put the skip on the wrong test...

Comment thread tests/cupy_tests/cuda_tests/test_memory.py Outdated
Co-authored-by: Sebastian Berg <[email protected]>
@kmaehashi
Copy link
Copy Markdown
Member

Confirmed all tests passed for 5845cff

/test skip

@kmaehashi kmaehashi enabled auto-merge November 27, 2025 16:03
@kmaehashi kmaehashi merged commit 863294b into cupy:main Nov 27, 2025
47 checks passed
@seberg seberg deleted the advise-cu13 branch November 27, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants