You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was going over an example of yours where you and the scikit-image team showed that it was hard to get good performance from scikit-image algorithms and dask.
I decided to jump down the rabbit hole and found that there were probably 2 places that could probably be optimized:
Serialization/serialization of numpy arrays. You seem to have identified this one, and might come in later versions of numpy.
The final blocking of the result.
I think it many cases, making the final result a C_continguous numpy array is probably not necessary.
Passing the arrays 4 arrays 50MB each, of around a threaded scheduler takes a few ms. while blocking the final result (200 MB) in a contiguous array takes 100ms+.
Have you considered returned a result as a blocked matrix that is not c-contiguous? Is this possible at the moment? I don't think I saw the option in the docs, but maybe I'm blind.
I don't know if getting rid of blocking might help map_overlaped as well.
Have you considered returned a result as a blocked matrix that is not c-contiguous? Is this possible at the moment? I don't think I saw the option in the docs, but maybe I'm blind.
Did you have a target data structure in mind? The way I would represent such a blocked matrix in Python is probably with a dask array. You might consider looking at timings that use dask.persist, which returns a dask array rather than dask.compute, which returns a numpy array
Thanks you for the info. Persist does mostly what is needed for the question I had. I guess I wrote off persist when I first read through the docs a few months back.
I was talking with @jni about parallelizing the computation of a Gaussian filter using Dask and the question of blocked operations came up. It made use of map_overlap which seems to a convenience function that calls overlap, map_blocks and trim.
Going a step further, it seems that trim returns blocks that are C-contiguous.
Any chance of returning memory views of the original arrays? (See benchmark below)
Any chance of having dask arrays with more transparent overlaps, ie. they would hold extra memory for the overlapping regions, but a call to np.asarray would omit copies of the overlapped parts?
fromdaskimportarrayasdaimportnumpyasnpfromskimage.filtersimportgaussianasgaussian_filtershape=(150, 1024, 1024)
chunks=(-1, 512, 512)
dtype='float32'z=da.zeros(shape=shape, chunks=chunks, dtype=dtype)
# This takes time 407 ms%time_=z.compute()
# This is fast. (24 ms) Thank you for hint!%time_=z.persist()
z_overlaped=da.overlap.overlap(z, 10, boundary='none')
# This is slow (450 ms)%time_=z_overlaped.compute()
# This is kinda slow (160 ms) but I understand why a memory copy is necessary.%timez_overalaped_persisted=z_overlaped.persist()
# convenience function, inverse of da.overlap.overlap# logic taken from map_overlapdeftrim(x, depth, boundary=None):
fromdask.array.overlapimportcoerce_boundary, coerce_depth, trim_internal, add_dummy_paddingboundary2=coerce_boundary(x.ndim, boundary)
depth2=coerce_depth(x.ndim, depth)
x2=add_dummy_padding(x, depth2, boundary2)
returntrim_internal(x2, depth2)
# This takes 775 ms%timetrim(z_overalaped_persisted, 10, boundary='none').compute()
# This takes 488 ms, I wish it returned a memory view so as to return in 1ms.%timetrim(z_overalaped_persisted, 10, boundary='none').persist(scheduler='threads')
On Tue, Sep 4, 2018 at 3:59 PM, Mark Harfouche ***@***.***> wrote:
Thanks you for the info. Persist does mostly what is needed for the
question I had. I guess I wrote off persist when I first read through the
docs a few months back.
I was talking with @jni <https://github.com/jni> about parallelizing the
computation of a Gaussian filter using Dask and the question of blocked
operations came up. It made use of map_overlap which seems to a
convenience function that calls overlap, map_blocks and trim.
Going a step further, it seems that trim returns blocks that are
C-contiguous.
- Any chance of returning memory views of the original arrays? (See
benchmark below)
- Any chance of having dask arrays with more *transparent* overlaps,
ie. they would hold extra memory for the overlapping regions, but a call to
np.asarray would omit copies of the overlapped parts?
from dask import array as daimport numpy as np
from skimage.filters import gaussian as gaussian_filter
shape=(150, 1024, 1024)
chunks=(-1, 512, 512)
dtype='float32'
z = da.zeros(shape=shape, chunks=chunks, dtype=dtype)# This takes time 407 ms%time _ = z.compute()# This is fast. (24 ms) Thank you for hint!%time _ = z.persist()
z_overlaped = da.overlap.overlap(z, 10, boundary='none')# This is slow (450 ms)%time _ = z_overlaped.compute()# This is kinda slow (160 ms) but I understand why a memory copy is necessary.%time z_overalaped_persisted = z_overlaped.persist()
# convenience function, inverse of da.overlap.overlap# logic taken from map_overlapdef trim(x, depth, boundary=None):
from dask.array.overlap import coerce_boundary, coerce_depth, trim_internal, add_dummy_padding
boundary2 = coerce_boundary(x.ndim, boundary)
depth2 = coerce_depth(x.ndim, depth)
x2 = add_dummy_padding(x, depth2, boundary2)
return trim_internal(x2, depth2)
# This takes 775 ms%time trim(z_overalaped_persisted, 10, boundary='none').compute()# This takes 488 ms, I wish it returned a memory view so as to return in 1ms.%time trim(z_overalaped_persisted, 10, boundary='none').persist(scheduler='threads')
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3938 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszB1Wn8qZhG6n-vlvfCH3d4yho7p8ks5uXtuUgaJpZM4WYItL>
.
2.25 ms ± 47.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
3.83 ms ± 46.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
1.72 ms ± 24.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
meaning that the cost of trim_internal approximately the same as just calling persist on a dask array, but the call to add_dummy_padding should be removed, instead the slicing logic should probably be moved to trim_internal.
Activity
mrocklin commentedon Sep 4, 2018
Did you have a target data structure in mind? The way I would represent such a blocked matrix in Python is probably with a dask array. You might consider looking at timings that use
dask.persist, which returns a dask array rather thandask.compute, which returns a numpy arraymrocklin commentedon Sep 4, 2018
Serialization shouldn't be a problem if you use a threaded scheduler
hmaarrfk commentedon Sep 4, 2018
Thanks you for the info. Persist does mostly what is needed for the question I had. I guess I wrote off persist when I first read through the docs a few months back.
I was talking with @jni about parallelizing the computation of a Gaussian filter using Dask and the question of blocked operations came up. It made use of
map_overlapwhich seems to a convenience function that callsoverlap,map_blocksandtrim.Going a step further, it seems that
trimreturns blocks that are C-contiguous.np.asarraywould omit copies of the overlapped parts?mrocklin commentedon Sep 4, 2018
hmaarrfk commentedon Sep 4, 2018
@mrocklin thank you for replying so quickly. Benchmarking on the plane kept me busy.
I think I need to rerun benchmarks with a hacked up version of dask that doesn't hash every call to
from_array. See Issue #3946hmaarrfk commentedon Sep 5, 2018
@mrocklin I'm mostly convinced that it is the issue outlined #3947
returns
meaning that the cost of
trim_internalapproximately the same as just calling persist on a dask array, but the call toadd_dummy_paddingshould be removed, instead the slicing logic should probably be moved totrim_internal.