Skip to content
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

Binary morphology: omit weights array when possible #517

Merged

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Feb 21, 2023

This is a follow-up to #485 allowing the overhead of creating a weights array of uniform values to be omitted when possible for all binary morphology operators. This gives a large performance benefit for small footprints (and small images) with the benefit becoming minimal for large footprint size.

As currently implemented, a shape tuple can be passed to structure to indicate the equivalent of an array of ones of that shape. This is a deviation from SciPy's API which does not currently allow this. I am not positive if this is the best API choice or if it might be better to instead add a size keyword-only argument like the grayscale morphology functions currently have.

The footprint generation methods square, rectangle, cube etc. use this new tuple format when possible to reduce overhead.

I will post benchmarks below.

@grlee77 grlee77 added non-breaking Introduces a non-breaking change performance Performance improvement labels Feb 21, 2023
@grlee77 grlee77 added this to the v23.04.00 milestone Feb 21, 2023
@grlee77 grlee77 requested a review from a team as a code owner February 21, 2023 15:56
@grlee77 grlee77 added the improvement Improves an existing functionality label Feb 21, 2023
@grlee77 grlee77 force-pushed the binary_morphology_omit_weights_array branch from 98f7c16 to abfc4d8 Compare February 21, 2023 15:59
@grlee77
Copy link
Contributor Author

grlee77 commented Feb 22, 2023

Benchmark results

Acceleration here is the ratio of the runtime when passing a boolean array of footprint_shape size vs. just passing the size tuple.

These are worse case accelerations as they assume the footprint had already been created and don't include the initial overhead of allocating the footprint on the GPU.

Acceleration factors run from ~3x for small images approaching 1x as the image size becomes larger.

shape footprint_shape acceleration
(256, 256) (3, 3) 3.04
(256, 256) (5, 5) 3.06
(256, 256) (7, 7) 2.90
(256, 256) (15, 15) 2.91
(256, 256) (31, 31) 2.88
(512, 512) (3, 3) 3.03
(512, 512) (5, 5) 2.77
(512, 512) (7, 7) 2.88
(512, 512) (15, 15) 2.89
(512, 512) (31, 31) 2.82
(1024, 1024) (3, 3) 2.57
(1024, 1024) (5, 5) 2.22
(1024, 1024) (7, 7) 2.73
(1024, 1024) (15, 15) 2.58
(1024, 1024) (31, 31) 2.08
(2048, 2048) (3, 3) 1.83
(2048, 2048) (5, 5) 1.55
(2048, 2048) (7, 7) 1.66
(2048, 2048) (15, 15) 1.47
(2048, 2048) (31, 31) 1.31
(4096, 4096) (3, 3) 1.25
(4096, 4096) (5, 5) 1.14
(4096, 4096) (7, 7) 1.18
(4096, 4096) (15, 15) 1.12
(4096, 4096) (31, 31) 1.08
(32, 32, 32) (3, 3, 3) 2.99
(32, 32, 32) (5, 5, 5) 2.87
(32, 32, 32) (9, 9, 9) 2.88
(32, 32, 32) (13, 13, 13) 2.86
(64, 64, 64) (3, 3, 3) 2.63
(64, 64, 64) (5, 5, 5) 2.85
(64, 64, 64) (9, 9, 9) 2.89
(64, 64, 64) (13, 13, 13) 2.87
(128, 128, 128) (3, 3, 3) 1.63
(128, 128, 128) (5, 5, 5) 2.17
(128, 128, 128) (9, 9, 9) 1.94
(128, 128, 128) (13, 13, 13) 1.83
(256, 256, 256) (3, 3, 3) 1.09
(256, 256, 256) (5, 5, 5) 1.12
(256, 256, 256) (9, 9, 9) 1.10
(256, 256, 256) (13, 13, 13) 1.09

Copy link
Contributor

@gigony gigony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @grlee77 ! Looks good to me!

@@ -144,19 +167,30 @@ def square(width, dtype=cp.uint8, *, decomposition=None):
The 'sequence' decomposition mode only supports odd valued `width`. If
`width` is even, the sequence used will be identical to the 'separable'
mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary blank line?

@grlee77
Copy link
Contributor Author

grlee77 commented Apr 4, 2023

rerun tests

@grlee77
Copy link
Contributor Author

grlee77 commented Apr 5, 2023

@gigony, test failures in unrelated isotropic morphology functions have been fixed. I added checks to enforce properties of the provided output.

@grlee77
Copy link
Contributor Author

grlee77 commented Apr 5, 2023

/merge

@rapids-bot rapids-bot bot merged commit 82ee855 into rapidsai:branch-23.04 Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change performance Performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants