-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.to_numpy(), .to_cupy(), etc. #55
Comments
Did some tests with the |
@dpgrote @RemiLehe and I did some performance tests of: import cupy as cp
x = cp.random.rand(10000, 20000)
f = cp.copy(x, order='F')
x.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
f.flags
C_CONTIGUOUS : False
F_CONTIGUOUS : True
OWNDATA : True
r=x**2; cp.cuda.runtime.deviceSynchronize()
%timeit -n 10 r=x**2; cp.cuda.runtime.deviceSynchronize()
283 ms ± 3.2 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
r=f**2; cp.cuda.runtime.deviceSynchronize()
%timeit -n 10 r=f**2; cp.cuda.runtime.deviceSynchronize()
409 ms ± 15.4 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) Here (and we also remember from numpy), the kernels always loop contiguously by what is assumed the fastest running index in C. Thus, we would not do the user a favor returning our data with:
|
Idea: we add an |
It turns out this is pretty easy to achieve via In [1]: import numpy as np
In [2]: x = np.array([[1,2,3], [4,5,6]])
In [3]: x.flags
Out[3]:
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
In [4]: x.T.flags
Out[4]:
C_CONTIGUOUS : False
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False Seen in an implementation by @dpgrote |
Updated #88. |
Opened a performance request in cupy in cupy/cupy#7783 |
For all objects that expose the
__array_interface__
, we should add a helper member function called.to_numpy()
that does nothing but create a view:Similar to:
Equivalently, we want to add
.to_copy()
et al. functions for #30 and later DLPack interfaces.The text was updated successfully, but these errors were encountered: