import pyarrow.cuda as cuda


def pyarrow_cuda_buffer(cp_arr):
    """Return pyarrow.cuda.CudaBuffer view of cupy.ndarray.
    """
    ctx = cuda.Context(cp_arr.data.device.id)
    return ctx.foreign_buffer(cp_arr.data.ptr, cp_arr.nbytes)