cudaPointerAttributes failing for CUDA device memory pointer + offset

cudaPointerAttributes is a very useful function to decide if a given pointer refers to memory allocated
in device or host memory space.
However, It seems to fail if the pointer is given with an offset that clearly still is in the same memory space:

double* device_ptr;
cudaMalloc(&device_ptr, 10);
cudaPointerAttributes attributes;
cudaPointerGetAttributes(&attributes, device_ptr);

results in the reported memory space to be device memory. On the other hand,

double* device_ptr;
cudaMalloc(&device_ptr, 10);
cudaPointerAttributes attributes;
cudaPointerGetAttributes(&attributes, device_ptr+1);

results in a “cudaErrorInvalidValue” error. It seems that cudaPointerAttributes simply cannot handle this. Is there any workaround that can be used to find out what kind of memory space a given pointer refers to even if it has an offset with respect to the one used in cudaMalloc?

When I run your test case, I get no error:

$ cat t320.cu
#include <stdio.h>

int main(){

double* device_ptr;
cudaMalloc(&device_ptr, 10);
cudaPointerAttributes attributes;
cudaError_t err = cudaPointerGetAttributes(&attributes, device_ptr+1);
printf(" result = %s\n", cudaGetErrorString(err));
}
$ nvcc -o t320 t320.cu
$ ./t320
 result = no error
$

CUDA 10.0, CentOS7

Nevermind, error on my side, sorry for the noise.
I was implementing a check for a span-like object and was looking at an object of length zero where the memory is indeed invalid.