Closed vincefn closed 1 year ago
GPUArray.copy() does not copy the strides parameters
GPUArray.copy()
For example:
import numpy as np from scipy.misc import ascent import matplotlib.pyplot as plt import pycuda.autoinit import pycuda.gpuarray as cua d0 = np.asarray(ascent(), order='F') d1 = cua.to_gpu(d0) d2 = d1.copy() print(d0.strides, d1.strides, d2.strides, cua.empty_like(d1).strides) plt.figure(figsize=(15, 5)) plt.subplot(121) plt.imshow(abs(d1.get())) plt.colorbar() plt.subplot(122) plt.imshow(abs(d2.get())) plt.colorbar()
yields:
(8, 4096) (8, 4096) (4096, 8) (8, 4096)
and the copied array appears indeed flipped due to the missing strides information:
I guess a simple addition of strides=self.strides in https://github.com/inducer/pycuda/blob/main/pycuda/gpuarray.py#L392 would fix this ?
strides=self.strides
By comparison, CPUArray.empty_like() copies the strides parameters, and pyOpenCL's array.copy() too.
CPUArray.empty_like()
array.copy()
Thanks for the report! https://gitlab.tiker.net/inducer/pycuda/-/merge_requests/89
Thanks ! This should also close #154
GPUArray.copy()
does not copy the strides parametersFor example:
yields:
and the copied array appears indeed flipped due to the missing strides information:
I guess a simple addition of
strides=self.strides
in https://github.com/inducer/pycuda/blob/main/pycuda/gpuarray.py#L392 would fix this ?By comparison,
CPUArray.empty_like()
copies the strides parameters, and pyOpenCL'sarray.copy()
too.