question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot determine the device from pointer using `cudaPointerGetAttributes` if device mismatch

See original GitHub issue

It seems cudaPointerGetAttributes (and cuPointerGetAttributes) is no longer working in CUDA 10.1+ if the device the pointer resides and the current device do not match. It was working in CUDA 10.0.

import cupy
a = cupy.arange(10)  # array on GPU 0
cupy.cuda.Device(0).use()
cupy.cuda.runtime.pointerGetAttributes(a.data.ptr)
cupy.cuda.Device(1).use()
cupy.cuda.runtime.pointerGetAttributes(a.data.ptr) # raises CUDARuntimeError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cupy_backends/cuda/api/runtime.pyx", line 601, in cupy_backends.cuda.api.runtime.pointerGetAttributes
    cpdef PointerAttributes pointerGetAttributes(intptr_t ptr):
  File "cupy_backends/cuda/api/runtime.pyx", line 604, in cupy_backends.cuda.api.runtime.pointerGetAttributes
    check_status(status)
  File "cupy_backends/cuda/api/runtime.pyx", line 246, in cupy_backends.cuda.api.runtime.check_status
    raise CUDARuntimeError(status)
cupy_backends.cuda.api.runtime.CUDARuntimeError: cudaErrorInvalidValue: invalid argument

We rely on cudaPointerGetAttributes to determine the device for foreign pointers, e.g., __cuda_array_interface__ which does not contain the device number. https://github.com/cupy/cupy/blob/v8.0.0rc1/cupy/cuda/memory.pyx#L123

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
anarusecommented, Oct 6, 2020

This issue is related to timing of CUDA context creation. If you allocate memory on “current” GPU before calling cudaPointGetAttributes(), this issue can be avoided.

import cupy
a = cupy.arange(10)  # array on GPU 0
cupy.cuda.Device(0).use()
cupy.cuda.runtime.pointerGetAttributes(a.data.ptr)
cupy.cuda.Device(1).use()
b = cupy.arange(1)  # work-around
cupy.cuda.runtime.pointerGetAttributes(a.data.ptr)
2reactions
anarusecommented, Sep 15, 2020

We’re checking with the CUDA team, so please wait for a while.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detection if a pointer is pointing in the device or host in CUDA
This is a small example showing how Unified Virtual Addressing can be used to detect if a pointer is pointing to host or...
Read more >
host & device pointer mismatch detection
Hi, I'm still learning and took me 20 minutes to figure out why I get execution error under debugger: Cuda error: vecSum Kernel...
Read more >
cudart - CUDA Python 12.0.0 documentation - GitHub Pages
Opens an interprocess memory handle exported from another process and returns a device pointer usable in the local process.
Read more >
CUDA C Programming Guide
Clarified that values of const-qualified variables with builtin floating-point types cannot be used directly in device code when the Microsoft compiler is ...
Read more >
CUDA Runtime API - 5.11. Unified Addressing
CUDA devices can share a unified address space with the host. ... one may want to know if a pointer points to host...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found