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

deprecate keyword color_space for ErrorDiffusion #72

Closed
wants to merge 1 commit into from

Conversation

johnnychen94
Copy link
Member

@johnnychen94 johnnychen94 commented Apr 28, 2022

This is not type inferrable and would thus hurt the performance.

Changing the order of parameters is technically breaking, but I doubt people outside are depending on it. Thus an appropriate deprecation of color_space keyword should make this a transparent improvement.

This is not type inferrable and would thus hurt the performance.
@johnnychen94 johnnychen94 added the run benchmark Run benchmark CI action label Apr 28, 2022
@codecov
Copy link

codecov bot commented Apr 28, 2022

Codecov Report

Merging #72 (fb22593) into master (7969627) will decrease coverage by 0.08%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #72      +/-   ##
==========================================
- Coverage   98.44%   98.36%   -0.09%     
==========================================
  Files          14       14              
  Lines         257      244      -13     
==========================================
- Hits          253      240      -13     
  Misses          4        4              
Impacted Files Coverage Δ
src/DitherPunk.jl 100.00% <ø> (ø)
src/error_diffusion.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7969627...fb22593. Read the comment docs.

@github-actions
Copy link
Contributor

Benchmark result

Judge result

Benchmark Report for /home/runner/work/DitherPunk.jl/DitherPunk.jl

Job Properties

  • Time of benchmarks:
    • Target: 28 Apr 2022 - 07:57
    • Baseline: 28 Apr 2022 - 07:59
  • Package commits:
    • Target: 9f681d
    • Baseline: 796962
  • Julia commits:
    • Target: bf5349
    • Baseline: bf5349
  • Julia command flags:
    • Target: None
    • Baseline: None
  • Environment variables:
    • Target: None
    • Baseline: None

Results

A ratio greater than 1.0 denotes a possible regression (marked with ❌), while a ratio less
than 1.0 denotes a possible improvement (marked with ✅). Only significant results - results
that indicate possible regressions or improvements - are shown below (thus, an empty table means that all
benchmark results remained invariant between builds).

ID time ratio memory ratio
["closest color", "binary inplace"] 1.36 (5%) ❌ 1.00 (1%)
["closest color", "binary new"] 1.49 (5%) ❌ 1.00 (1%)
["closest color", "per-channel inplace"] 1.09 (5%) ❌ 1.00 (1%)
["error diffusion", "binary inplace"] 0.88 (5%) ✅ 1.00 (1%)
["error diffusion", "binary new"] 0.90 (5%) ✅ 1.00 (1%)
["error diffusion", "color inplace"] 1.17 (5%) ❌ 2.30 (1%) ❌
["ordered dithering", "color inplace"] 1.18 (5%) ❌ 1.00 (1%)
["ordered dithering", "color new"] 1.12 (5%) ❌ 1.00 (1%)
["ordered dithering", "per-channel inplace"] 1.16 (5%) ❌ 1.00 (1%)
["ordered dithering", "per-channel new"] 0.92 (5%) ✅ 1.00 (1%)
["threshold dithering", "binary inplace"] 1.27 (5%) ❌ 1.00 (1%)
["threshold dithering", "binary new"] 1.34 (5%) ❌ 1.00 (1%)

Benchmark Group List

Here's a list of all the benchmark groups executed by this job:

  • ["closest color"]
  • ["error diffusion"]
  • ["ordered dithering"]
  • ["threshold dithering"]

Julia versioninfo

Target

Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
      Ubuntu 20.04.4 LTS
  uname: Linux 5.13.0-1022-azure #26~20.04.1-Ubuntu SMP Thu Apr 7 19:42:45 UTC 2022 x86_64 x86_64
  CPU: Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz: 
              speed         user         nice          sys         idle          irq
       #1  2095 MHz       2361 s          2 s        172 s       1365 s          0 s
       #2  2095 MHz       1572 s          1 s        178 s       2160 s          0 s
       
  Memory: 6.783603668212891 GB (3584.24609375 MB free)
  Uptime: 395.59 sec
  Load Avg:  1.04  0.84  0.41
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)

Baseline

Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
      Ubuntu 20.04.4 LTS
  uname: Linux 5.13.0-1022-azure #26~20.04.1-Ubuntu SMP Thu Apr 7 19:42:45 UTC 2022 x86_64 x86_64
  CPU: Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz: 
              speed         user         nice          sys         idle          irq
       #1  2095 MHz       2441 s          2 s        178 s       2530 s          0 s
       #2  2095 MHz       2738 s          1 s        192 s       2235 s          0 s
       
  Memory: 6.783603668212891 GB (3775.87890625 MB free)
  Uptime: 521.17 sec
  Load Avg:  1.0  0.9  0.5
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)

Target result

Benchmark Report for /home/runner/work/DitherPunk.jl/DitherPunk.jl

Job Properties

  • Time of benchmark: 28 Apr 2022 - 7:57
  • Package commit: 9f681d
  • Julia commit: bf5349
  • Julia command flags: None
  • Environment variables: None

Results

Below is a table of this job's results, obtained by running the benchmarks.
The values listed in the ID column have the structure [parent_group, child_group, ..., key], and can be used to
index into the BaseBenchmarks suite to retrieve the corresponding benchmarks.
The percentages accompanying time and memory values in the below table are noise tolerances. The "true"
time/memory value for a given benchmark is expected to fall within this percentage of the reported value.
An empty cell means that the value was zero.

ID time GC time memory allocations
["closest color", "binary inplace"] 7.767 μs (5%) 64.11 KiB (1%) 2
["closest color", "binary new"] 5.967 μs (5%) 64.11 KiB (1%) 2
["closest color", "color inplace"] 168.474 ms (5%) 36.50 MiB (1%) 2359336
["closest color", "color new"] 171.882 ms (5%) 36.48 MiB (1%) 2357848
["closest color", "per-channel inplace"] 1.015 ms (5%) 192.05 KiB (1%) 2
["closest color", "per-channel new"] 916.006 μs (5%) 192.05 KiB (1%) 2
["error diffusion", "binary inplace"] 945.413 μs (5%) 320.23 KiB (1%) 5
["error diffusion", "binary new"] 911.112 μs (5%) 320.23 KiB (1%) 5
["error diffusion", "color inplace"] 168.193 ms (5%) 36.81 MiB (1%) 2359340
["error diffusion", "color new"] 130.022 ms (5%) 16.01 MiB (1%) 995660
["error diffusion", "per-channel inplace"] 3.798 ms (5%) 960.42 KiB (1%) 11
["error diffusion", "per-channel new"] 4.128 ms (5%) 960.42 KiB (1%) 11
["ordered dithering", "binary inplace"] 97.501 μs (5%) 69.42 KiB (1%) 5
["ordered dithering", "binary new"] 92.001 μs (5%) 69.42 KiB (1%) 5
["ordered dithering", "color inplace"] 831.650 ms (5%) 33.919 ms 247.07 MiB (1%) 14417965
["ordered dithering", "color new"] 955.776 ms (5%) 47.591 ms 281.11 MiB (1%) 16473466
["ordered dithering", "per-channel inplace"] 1.200 ms (5%) 207.98 KiB (1%) 11
["ordered dithering", "per-channel new"] 1.014 ms (5%) 207.98 KiB (1%) 11
["threshold dithering", "binary inplace"] 15.001 μs (5%) 128.27 KiB (1%) 7
["threshold dithering", "binary new"] 13.500 μs (5%) 128.27 KiB (1%) 7
["threshold dithering", "per-channel inplace"] 960.306 μs (5%) 384.38 KiB (1%) 8
["threshold dithering", "per-channel new"] 1.032 ms (5%) 384.38 KiB (1%) 8

Benchmark Group List

Here's a list of all the benchmark groups executed by this job:

  • ["closest color"]
  • ["error diffusion"]
  • ["ordered dithering"]
  • ["threshold dithering"]

Julia versioninfo

Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
      Ubuntu 20.04.4 LTS
  uname: Linux 5.13.0-1022-azure #26~20.04.1-Ubuntu SMP Thu Apr 7 19:42:45 UTC 2022 x86_64 x86_64
  CPU: Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz: 
              speed         user         nice          sys         idle          irq
       #1  2095 MHz       2361 s          2 s        172 s       1365 s          0 s
       #2  2095 MHz       1572 s          1 s        178 s       2160 s          0 s
       
  Memory: 6.783603668212891 GB (3584.24609375 MB free)
  Uptime: 395.59 sec
  Load Avg:  1.04  0.84  0.41
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)

Baseline result

Benchmark Report for /home/runner/work/DitherPunk.jl/DitherPunk.jl

Job Properties

  • Time of benchmark: 28 Apr 2022 - 7:59
  • Package commit: 796962
  • Julia commit: bf5349
  • Julia command flags: None
  • Environment variables: None

Results

Below is a table of this job's results, obtained by running the benchmarks.
The values listed in the ID column have the structure [parent_group, child_group, ..., key], and can be used to
index into the BaseBenchmarks suite to retrieve the corresponding benchmarks.
The percentages accompanying time and memory values in the below table are noise tolerances. The "true"
time/memory value for a given benchmark is expected to fall within this percentage of the reported value.
An empty cell means that the value was zero.

ID time GC time memory allocations
["closest color", "binary inplace"] 5.700 μs (5%) 64.11 KiB (1%) 2
["closest color", "binary new"] 4.000 μs (5%) 64.11 KiB (1%) 2
["closest color", "color inplace"] 167.478 ms (5%) 36.48 MiB (1%) 2357848
["closest color", "color new"] 165.058 ms (5%) 36.48 MiB (1%) 2357848
["closest color", "per-channel inplace"] 932.211 μs (5%) 192.05 KiB (1%) 2
["closest color", "per-channel new"] 914.411 μs (5%) 192.05 KiB (1%) 2
["error diffusion", "binary inplace"] 1.074 ms (5%) 320.23 KiB (1%) 5
["error diffusion", "binary new"] 1.016 ms (5%) 320.23 KiB (1%) 5
["error diffusion", "color inplace"] 143.166 ms (5%) 16.01 MiB (1%) 995660
["error diffusion", "color new"] 133.922 ms (5%) 16.01 MiB (1%) 995660
["error diffusion", "per-channel inplace"] 3.876 ms (5%) 960.42 KiB (1%) 11
["error diffusion", "per-channel new"] 4.202 ms (5%) 960.42 KiB (1%) 11
["ordered dithering", "binary inplace"] 96.802 μs (5%) 69.42 KiB (1%) 5
["ordered dithering", "binary new"] 91.902 μs (5%) 69.42 KiB (1%) 5
["ordered dithering", "color inplace"] 704.037 ms (5%) 11.638 ms 247.07 MiB (1%) 14417965
["ordered dithering", "color new"] 852.045 ms (5%) 15.808 ms 281.11 MiB (1%) 16473466
["ordered dithering", "per-channel inplace"] 1.035 ms (5%) 207.98 KiB (1%) 11
["ordered dithering", "per-channel new"] 1.097 ms (5%) 207.98 KiB (1%) 11
["threshold dithering", "binary inplace"] 11.800 μs (5%) 128.27 KiB (1%) 7
["threshold dithering", "binary new"] 10.100 μs (5%) 128.27 KiB (1%) 7
["threshold dithering", "per-channel inplace"] 1.004 ms (5%) 384.38 KiB (1%) 8
["threshold dithering", "per-channel new"] 1.057 ms (5%) 384.38 KiB (1%) 8

Benchmark Group List

Here's a list of all the benchmark groups executed by this job:

  • ["closest color"]
  • ["error diffusion"]
  • ["ordered dithering"]
  • ["threshold dithering"]

Julia versioninfo

Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
      Ubuntu 20.04.4 LTS
  uname: Linux 5.13.0-1022-azure #26~20.04.1-Ubuntu SMP Thu Apr 7 19:42:45 UTC 2022 x86_64 x86_64
  CPU: Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz: 
              speed         user         nice          sys         idle          irq
       #1  2095 MHz       2441 s          2 s        178 s       2530 s          0 s
       #2  2095 MHz       2738 s          1 s        192 s       2235 s          0 s
       
  Memory: 6.783603668212891 GB (3775.87890625 MB free)
  Uptime: 521.17 sec
  Load Avg:  1.0  0.9  0.5
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)

Runtime information

Runtime Info
BLAS #threads 2
BLAS.vendor() openblas64
Sys.CPU_THREADS 2

lscpu output:

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          2
On-line CPU(s) list:             0,1
Thread(s) per core:              1
Core(s) per socket:              2
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz
Stepping:                        4
CPU MHz:                         2095.077
BogoMIPS:                        4190.15
Hypervisor vendor:               Microsoft
Virtualization type:             full
L1d cache:                       64 KiB
L1i cache:                       64 KiB
L2 cache:                        2 MiB
L3 cache:                        35.8 MiB
NUMA node0 CPU(s):               0,1
Vulnerability Itlb multihit:     KVM: Mitigation: VMX unsupported
Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, STIBP disabled, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT Host state unknown
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt avx512cd avx512bw avx512vl xsaveopt xsavec xsaves md_clear
Cpu Property Value
Brand Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz
Vendor :Intel
Architecture :Skylake
Model Family: 0x06, Model: 0x55, Stepping: 0x04, Type: 0x00
Cores 2 physical cores, 2 logical cores (on executing CPU)
No Hyperthreading hardware capability detected
Clock Frequencies Not supported by CPU
Data Cache Level 1:3 : (32, 1024, 36608) kbytes
64 byte cache line size
Address Size 48 bits virtual, 46 bits physical
SIMD 512 bit = 64 byte max. SIMD vector size
Time Stamp Counter TSC is accessible via rdtsc
TSC increased at every clock cycle (non-invariant TSC)
Perf. Monitoring Performance Monitoring Counters (PMC) are not supported
Hypervisor Yes, Microsoft

@johnnychen94
Copy link
Member Author

johnnychen94 commented Apr 28, 2022

I'm surprised that this actually makes things slower...

Edit:

This might be implementation-specific; if the filter weights are StaticMatrix then the performance regression here can be eliminated. I'll try to rework the error diffusion dither implementation on top of this PR and see if we get better results.

@@ -71,11 +73,11 @@ function binarydither!(alg::ErrorDiffusion, out::GenericGrayImage, img::GenericG
end

function colordither(
alg::ErrorDiffusion{F,C},
alg::ErrorDiffusion{C},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be ErrorDiffusion{C,F}?

@@ -116,7 +118,7 @@ function colordither(
end

"""
SimpleErrorDiffusion()
SimpleErrorDiffusion(color_space=XYZ)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can just interpolate a second const docstring similar to _error_diffusion_kwargs into all methods?

@@ -131,10 +133,11 @@ $(_error_diffusion_kwargs)
Scale." SID 1975, International Symposium Digest of Technical Papers,
vol 1975m, pp. 36-37.
"""
SimpleErrorDiffusion() = ErrorDiffusion(OffsetMatrix([0 1; 1 0]//2, 0:1, 0:1))
SimpleErrorDiffusion(CT=XYZ) = ErrorDiffusion{CT}(_simple_filter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a bug in master, SimpleErrorDiffusion should also pass kwargs... such as clamp_error forward.

function FloydSteinberg(; kwargs...)
return ErrorDiffusion(OffsetMatrix([0 0 7; 3 5 1]//16, 0:1, -1:1); kwargs...)
end
FloydSteinberg(CT=XYZ; kwargs...) = ErrorDiffusion{CT}(_floydsteinberg_filter; kwargs...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using the pattern

Method(CT=XYZ; kwargs...) = ErrorDiffusion{CT}(filter; kwargs...)

wouldn't it be possible to do

Method(args...; kwargs...) = ErrorDiffusion(filter, args...; kwargs...)

using a second ErrorDiffusion constructor

ErrorDiffusion(filter, CT=XYZ; kwargs...) = ErrorDiffusion{CT}(filter; kwargs...)

This way, future changes to ErrorDiffusion don't require changes to all other methods.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Master currently defines

function ErrorDiffusion(filter; color_space=XYZ, clamp_error=true)

on L32. Would changing this to

function ErrorDiffusion(filter, color_space=XYZ; clamp_error=true)

be enough for type inference?

return ErrorDiffusion(OffsetMatrix([0 0 7; 3 5 1]//16, 0:1, -1:1); kwargs...)
end
FloydSteinberg(CT=XYZ; kwargs...) = ErrorDiffusion{CT}(_floydsteinberg_filter; kwargs...)
const _floydsteinberg_filter = OffsetMatrix([0 0 7; 3 5 1]//16,0:1,-1:1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very nitpicky feedback, but maybe we could call this const FLOYDSTEINBERG_FILTER to be consistent with the constant matrices in ordered.jl.

@adrhill
Copy link
Collaborator

adrhill commented Apr 28, 2022

This might be implementation-specific; if the filter weights are StaticMatrix then the performance regression here can be eliminated. I'll try to rework the error diffusion dither implementation on top of this PR and see if we get better results.

I've had some shower-thoughts about this. I think we should fully drop the dependency on OffsetArrays and use CartesianIndices to iterate over the neighborhoods defined in the filters. This might also simplify a future implementation of #20.

adrhill added a commit that referenced this pull request May 3, 2022
@adrhill
Copy link
Collaborator

adrhill commented Jun 26, 2022

Closing this as it is outdated by #73 , which contains parts of this PR.

@adrhill adrhill closed this Jun 26, 2022
@adrhill adrhill deleted the jc/ct branch June 26, 2022 20:24
@adrhill adrhill restored the jc/ct branch June 26, 2022 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run benchmark Run benchmark CI action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants