Commit 324d165
authored
* Parallelize convolve_2d numpy kernel (#3615)
_convolve_2d_numpy iterated with numba.prange but was decorated
@jit(nopython=True, nogil=True) with no parallel=True, so prange
degraded to a serial range. On a 20-core host a 2000x2000 float64
raster with a 15x15 kernel dropped from ~356 ms to ~53 ms end-to-end
once parallel=True was enabled, with identical results.
Add parallel=True and serialize the kernel launch behind a
module-level threading.Lock, since dask calls it per chunk under a
threaded scheduler and numba's workqueue layer is not threadsafe
across host threads (SIGABRT on macOS, same hazard as #3141 fixed in
terrain.py). A single numpy call takes the lock uncontended and still
runs across all cores.
Add benchmarks/benchmarks/convolution.py (Convolve2d, CircleKernel)
so the regression cannot silently return.
* bench(convolution): force dask compute in convolve_2d benchmark
The dask case of time_convolve_2d returned a lazy array, so asv timed
graph construction instead of the kernel this PR parallelizes. Force the
compute for backends that produce a lazy array, matching the convention
in the twi/interpolate/flood benchmarks. numpy and cupy results have no
.compute and are unaffected. (#3615)
1 parent 5325aa5 commit 324d165
3 files changed
Lines changed: 56 additions & 5 deletions
File tree
- .claude
- benchmarks/benchmarks
- xrspatial
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
346 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
347 | 357 | | |
348 | 358 | | |
349 | 359 | | |
| |||
373 | 383 | | |
374 | 384 | | |
375 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
376 | 395 | | |
377 | 396 | | |
378 | 397 | | |
379 | | - | |
| 398 | + | |
380 | 399 | | |
381 | 400 | | |
382 | 401 | | |
383 | | - | |
| 402 | + | |
384 | 403 | | |
385 | 404 | | |
386 | 405 | | |
| |||
392 | 411 | | |
393 | 412 | | |
394 | 413 | | |
395 | | - | |
| 414 | + | |
396 | 415 | | |
397 | 416 | | |
398 | 417 | | |
| |||
0 commit comments