Git Product home page Git Product logo

sherlogs.jl's Introduction

Sherlogs.jl

CI DOI

If Sherlock Holmes was a number format.

Sherlogs.jl provides a number format Sherlog64 that behaves like Float64, but inspects your code by logging all arithmetic results into a 16bit bitpattern histogram. On the fly.

What's the largest number occuring in your algorithm/model/function/package? What's the smallest? And is your code ready for 16bit? Sherlog will let you know.

A 32bit version is provided as Sherlog32, which behaves like Float32. A 16bit version is provided as Sherlog16{T}, which uses T for computations as well as for logging. If T not provided it falls back to Float16.

Example

What are the numbers that occur when solving a linear equation system?

julia> using Sherlogs
julia> A = Sherlog64.(rand(1000,1000));
julia> b = Sherlog64.(rand(1000));
julia> x = A\b;
julia> lb = get_logbook()
65536-element LogBook(1091, 192, 234, 181, 206,  , 0, 0, 0, 0, 0, 0)

lb is now a Float16 (by default) bitpattern histogram LogBook. This tells us for example that 0 - the zero bitpattern 0x00...00 (i.e. the first entry of lb) occured 1091 times in the LU decomposition (which is used in the \-operation). Use get_logbook() to retrieve the LogBook, use reset_logbook() to set the counters back to 0. Other 16bit number formats that are used as bins for the histogram can be used by specifying the parametric type Sherlog64{T,i}. The second parameter i (in 1:32) is an integer that specifies which logbook to use.

Example bitpattern histogram

bitpattern

This is the bitpattern histogram for the uniformly distributed U(0,1) input data, once represented with Float16 (blue). Using Sherlog64 inside the solver A\b, creates a bitpattern histogram for that algorithm (LU-decomposition) (orange). The x-axis is ranging from bitpattern 0x0000 to 0xffff but for readability relabelled with the respective decimal numbers. The entropy is denoted with H. A uniform distribution has maximum entropy of 16bit. The script for this example can be found here)

Performance

Logging the arithmetic results comes with overhead (the allocations are just preallocations).

julia> using BenchmarkTools, Lorenz96, BFloat16s
julia> @btime L96(Float32,N=100000);
  26.321 ms (200023 allocations: 97.66 MiB)
julia> @btime L96(Sherlog32{BFloat16,1},N=100000);
  346.052 ms (200023 allocations: 97.66 MiB)
julia> @btime L96(Sherlog32{Float16,1},N=100000);
  1.098 s (200023 allocations: 97.66 MiB)

which depends on the number system used for binning.

Installation

Sherlogs is a registered package, so simply do

julia> ] add Sherlogs

where ] opens the package manager.

sherlogs.jl's People

Contributors

bjarthur avatar milankl avatar onbuttonup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bjarthur

sherlogs.jl's Issues

`rand` does not work with Sherlog64

julia> using Sherlogs

julia> x=rand(Float64, 3)
3-element Vector{Float64}:
 0.40189430899764034
 0.7603918178002613
 0.5363160895268921

julia> x=rand(Sherlog64, 3)
ERROR: ArgumentError: Sampler for this object is not defined
Stacktrace:
 [1] Random.Sampler(#unused#::Type{Random.MersenneTwister}, sp::Random.SamplerTrivial{Random.CloseOpen01{Sherlog64}, Sherlog64}, #unused#::Val{1})
   @ Random ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:145
 [2] Random.Sampler(rng::Random.MersenneTwister, x::Random.SamplerTrivial{Random.CloseOpen01{Sherlog64}, Sherlog64}, r::Val{1})
   @ Random ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:139
 [3] rand(rng::Random.MersenneTwister, X::Random.SamplerTrivial{Random.CloseOpen01{Sherlog64}, Sherlog64})
   @ Random ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:253
 [4] rand!
   @ ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:271 [inlined]
 [5] rand!
   @ ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:267 [inlined]
 [6] rand
   @ ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:288 [inlined]
 [7] rand
   @ ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:289 [inlined]
 [8] rand(::Type{Sherlog64}, ::Int64)
   @ Random ~/bin/julia-1.6.1/share/julia/stdlib/v1.6/Random/src/Random.jl:292
 [9] top-level scope
   @ REPL[3]:1

DrWatson documentation

you mentioned it at juliacon2021, but there is no mention in the README.

also, how did you generate the purple, green, and orange lines in that plot at juliacon? sherlogs.jl's logbook seems to just return everything as represented in 16-bit floats, but how do i get the 32- and 64-bit distribution?

thanks!

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Ambiguous type definition

WARNING: Method definition (::Type{Sherlogs.Sherlog16{T} where T<:AbstractFloat})(T<:AbstractFloat) where {T<:AbstractFloat} in module Sherlogs at /Users/milan/.julia/packages/Sherlogs/QDndd/src/Sherlog16.jl:2 overwritten at /Users/milan/.julia/packages/Sherlogs/QDndd/src/Sherlog16.jl:11.
  ** incremental compilation may be fatally broken for this module **

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.