Skip to content

Transfer of arrays with different strides #145

Description

@mabau

Hi,

First, thanks for writing this library! It's a very convenient way to do GPU programming.

I found the following unexpected behaviour when debugging one of my programs that uses numpy arrays in different orders:

import pycuda.autoinit
from pycuda.gpuarray import to_gpu
import numpy as np


# Creating a GPU array in fortran layou
cpu_arr_f = np.zeros([3,4], order='F')
gpu_arr = to_gpu(cpu_arr_f)

# Copying an array in C layout to and from GPU changes it
# pycuda apparently assumes that CPU array has same strides as GPU array without checking it
cpu_arr_c = np.zeros([3,4], order='C')
cpu_arr_c[0,:] = 1

gpu_arr.set(cpu_arr_c)
assert(np.allclose(gpu_arr.get(), cpu_arr_c))

The last assert fails since pycuda apparently assumes that the strides of the source and destination arrays match. Is this the intended behaviour? If yes, I think a warning or a documentation note might be helpful in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions