From 9f2ec30b9122289100046903daa6143ab24c11c9 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Tue, 20 Sep 2022 10:28:10 -0700 Subject: [PATCH 1/4] Widen compat bounds, bump version --- Project.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 02e79a5..8c8033c 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "GFlops" uuid = "2ea8233c-34d4-5acc-88b4-02f326385bcc" license = "MIT" authors = ["François Févotte "] -version = "0.1.7" +version = "0.1.8" [deps] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" @@ -14,8 +14,8 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] BenchmarkTools = "^0.4.2, 0.5, 0.6, 0.7, 1" -Cassette = "^0.2.3, 0.3.2" -PrettyTables = "^0.12, 1" +Cassette = "^0.2.3, 0.3" +PrettyTables = "^0.12, 1, 2" julia = "^1" [extras] From c6ecc448e27d7c5e41d110b89191895784473990 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Tue, 20 Sep 2022 10:57:32 -0700 Subject: [PATCH 2/4] Fix conflicts with PrettyTables --- src/Counter.jl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Counter.jl b/src/Counter.jl index 44e2787..99f4a99 100644 --- a/src/Counter.jl +++ b/src/Counter.jl @@ -21,24 +21,31 @@ import Base: ==, *, show function Base.show(io::IO, c::Counter) type_names = [typ for (typ, _) in typs] type_suffix = [suffix for (_, suffix) in typs] - op_names = [name for (name, _) in ops] + row_labels = [name for (name, _) in ops] mat = [getfield(c, Symbol(name, suffix)) for - name in op_names, + name in row_labels, suffix in type_suffix] + fc(data, i) = any(data[:,i] .> 0) + fr(data, i) = any(data[i,:] .> 0) + + # PrettyTables now data to be filtered ahead of time: + cols_to_filter = filter(i-> fc(mat, i), 1:size(mat, 2)) + rows_to_filter = filter(i-> fr(mat, i), 1:size(mat, 1)) + mat = hcat(map(i-> mat[:, i], cols_to_filter)...) + mat = vcat(map(i-> mat[i, :], rows_to_filter)...) + fl = flop(c) print(io, "Flop Counter: $fl flop") fl == 0 && return + type_names = vcat(map(i-> type_names[i], cols_to_filter)...) + row_labels = vcat(map(i-> row_labels[i], rows_to_filter)...) print(io, "\n") - fc(data, i) = any(data[:,i] .> 0) - fr(data, i) = any(data[i,:] .> 0) pretty_table(io, mat, header = type_names, - row_names = op_names, - filters_col = (fc,), - filters_row = (fr,), + row_labels = row_labels, newline_at_end = false) end From ec42e47a10ec893bff4d695c41174cd08d312b90 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Tue, 20 Sep 2022 11:14:39 -0700 Subject: [PATCH 3/4] Make backwards compatible --- Project.toml | 1 + src/Counter.jl | 9 +++++++-- src/GFlops.jl | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 8c8033c..61977b4 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ version = "0.1.8" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" Cassette = "7057c7e9-c182-5462-911a-8362d720325c" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/src/Counter.jl b/src/Counter.jl index 99f4a99..fd4e6d5 100644 --- a/src/Counter.jl +++ b/src/Counter.jl @@ -42,10 +42,15 @@ function Base.show(io::IO, c::Counter) type_names = vcat(map(i-> type_names[i], cols_to_filter)...) row_labels = vcat(map(i-> row_labels[i], rows_to_filter)...) + row_label_kwargs = if pkgversion(PrettyTables) < v"2.0.0" + (; row_names = row_labels) + else + (; row_labels) + end print(io, "\n") - pretty_table(io, mat, + pretty_table(io, mat; header = type_names, - row_labels = row_labels, + row_label_kwargs..., newline_at_end = false) end diff --git a/src/GFlops.jl b/src/GFlops.jl index c7eaa87..ec481df 100644 --- a/src/GFlops.jl +++ b/src/GFlops.jl @@ -1,9 +1,16 @@ module GFlops import Statistics import BenchmarkTools +using Pkg +# https://discourse.julialang.org/t/how-to-find-out-the-version-of-a-package-from-its-module/37755 + +pkgversion(m::Module) = + VersionNumber(Pkg.TOML.parsefile(joinpath(dirname(string(first(methods(m.eval)).file)), "..", "Project.toml"))["version"]) + using BenchmarkTools: @benchmark using InteractiveUtils: peakflops using Printf: @printf +import PrettyTables using PrettyTables: pretty_table export @gflops, @count_ops From 17e1203bbebd828bf2fbde71c8b789ae417a7d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= Date: Sat, 26 Aug 2023 23:58:14 +0200 Subject: [PATCH 4/4] Remove support for PrettyTables v1 + fix issues with counter display in mixed precision --- Project.toml | 7 +++---- src/Counter.jl | 35 ++++++++++++----------------------- src/GFlops.jl | 7 ------- test/runtests.jl | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Project.toml b/Project.toml index 61977b4..bf68e9a 100644 --- a/Project.toml +++ b/Project.toml @@ -8,16 +8,15 @@ version = "0.1.8" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" Cassette = "7057c7e9-c182-5462-911a-8362d720325c" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] BenchmarkTools = "^0.4.2, 0.5, 0.6, 0.7, 1" -Cassette = "^0.2.3, 0.3" -PrettyTables = "^0.12, 1, 2" -julia = "^1" +Cassette = "^0.2.3, 0.3.2" +PrettyTables = "^2" +julia = "^1.6" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/Counter.jl b/src/Counter.jl index fd4e6d5..7bdc9f3 100644 --- a/src/Counter.jl +++ b/src/Counter.jl @@ -19,38 +19,27 @@ end import Base: ==, *, show function Base.show(io::IO, c::Counter) + fl = flop(c) + print(io, "Flop Counter: $fl flop") + fl == 0 && return + type_names = [typ for (typ, _) in typs] type_suffix = [suffix for (_, suffix) in typs] - row_labels = [name for (name, _) in ops] + op_names = [name for (name, _) in ops] mat = [getfield(c, Symbol(name, suffix)) for - name in row_labels, + name in op_names, suffix in type_suffix] - fc(data, i) = any(data[:,i] .> 0) - fr(data, i) = any(data[i,:] .> 0) - - # PrettyTables now data to be filtered ahead of time: - cols_to_filter = filter(i-> fc(mat, i), 1:size(mat, 2)) - rows_to_filter = filter(i-> fr(mat, i), 1:size(mat, 1)) - mat = hcat(map(i-> mat[:, i], cols_to_filter)...) - mat = vcat(map(i-> mat[i, :], rows_to_filter)...) + # PrettyTables now needs data to be filtered ahead of time: + rows = filter(i -> any(mat[i,:] .> 0), 1:size(mat, 1)) + cols = filter(i -> any(mat[:,i] .> 0), 1:size(mat, 2)) + mat = mat[rows, cols] - fl = flop(c) - print(io, "Flop Counter: $fl flop") - fl == 0 && return - - type_names = vcat(map(i-> type_names[i], cols_to_filter)...) - row_labels = vcat(map(i-> row_labels[i], rows_to_filter)...) - row_label_kwargs = if pkgversion(PrettyTables) < v"2.0.0" - (; row_names = row_labels) - else - (; row_labels) - end print(io, "\n") pretty_table(io, mat; - header = type_names, - row_label_kwargs..., + header = type_names[cols], + row_labels = op_names[rows], newline_at_end = false) end diff --git a/src/GFlops.jl b/src/GFlops.jl index ec481df..c7eaa87 100644 --- a/src/GFlops.jl +++ b/src/GFlops.jl @@ -1,16 +1,9 @@ module GFlops import Statistics import BenchmarkTools -using Pkg -# https://discourse.julialang.org/t/how-to-find-out-the-version-of-a-package-from-its-module/37755 - -pkgversion(m::Module) = - VersionNumber(Pkg.TOML.parsefile(joinpath(dirname(string(first(methods(m.eval)).file)), "..", "Project.toml"))["version"]) - using BenchmarkTools: @benchmark using InteractiveUtils: peakflops using Printf: @printf -import PrettyTables using PrettyTables: pretty_table export @gflops, @count_ops diff --git a/test/runtests.jl b/test/runtests.jl index bbd3611..319827d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -46,6 +46,22 @@ GFlops.times(::BenchmarkTools.Trial) = [2.0, 3.0] @test occursin(" 1 ", str) end end + + @testset "display mixed" begin + let + cnt = GFlops.Counter() + cnt.add32 = 1 + cnt.mul64 = 2 + str = string(cnt) + @test occursin("Float32", str) + @test occursin("Float64", str) + @test occursin("add", str) + @test occursin("mul", str) + @test !occursin("div", str) + @test occursin(" 1 ", str) + @test occursin(" 2 ", str) + end + end end @testset "@count_ops" begin