Giter Club home page Giter Club logo

blaze's Introduction

blaze

A reimplementation of STOKE in haskell.

STOKE is a superoptimizer that finds optimal instruction sequences to perform a particular task by using MCMC methods to explore the large search space.

High level algorithm

What we do is to "MCMC-sample the space of possible programs, with a scoring function based on program equivalence and performance". Broken down, the steps are:

  • Start with the original program p
  • Perturb it slightly to get a program q (add an instruction, remove some instructions, change an instruction)
  • Assign a score to q by sending p and q random inputs, and checking how often they answer the same.
  • If they answered the same for all random inputs, ask an SMT solver nicely if p and q are equivalent. If she's in a good mood and the universe is kind, the answer is yes.
  • Now, score q based on the factors of:
    1. Are p and q semantically equivalent?
    2. On how many inputs p and q had the same answer?
    3. is q faster than p?
  • Now, either pick q to be the new p or stay at p depending on q's score.
  • Repeat ~10,000 times.
  • Order best qs visited.

The results are quite impressive: Even with code as naive as what I've written, we are able to regain peephole optimisations that compilers perform essentially "for free".

Sample output
*** original: (nparams: 0 | [IPush 2,IPush 3,IAdd])***
[IPush 5] | score: 2.5 // constant folding
[IPush 2,IPush 3,IAdd] | score: 2.125
[IPush 2,IPush 3,ISwap,IAdd] | score: 2.0625

*** original: (nparams: 1 | [IPush 2,IMul])***
[IDup,IAdd] | score: 2.25 // strength reduction: 2 * x -> x + x
[IDup,ISwap,IAdd] | score: 2.125
[IDup,ISwap,ISwap,IAdd] | score: 2.0625
[IDup,ISwap,ISwap,ISwap,IAdd] | score: 2.03125

*** original: (nparams: 1 | progInsts = [IDup,IAnd])***
[] | score: 3.0 // constant folding: x & x == x
[IDup,IAnd] | score: 2.25
[IDup,ISwap,IAnd] | score: 2.125

blaze's People

Contributors

bollu 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  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

blaze's Issues

Indexing issue in perturbProgram

First off, thanks for making this! I found it extremely informative, and I thoroughly enjoyed reading the notebook and code.

One small issue: I think you might have an indexing problem in perturbProgram, specifically in the definition of ix'. As it stands, you have

ix' <- (ix +) <$> randint (0, length progInsts - 1)

This means that ix' could be larger than length progInsts - 1, since you're adding ix to it. While this doesn't result in an error due to how drop is defined (drop 10 [1..3] = []), it will mean that you're biased towards dropping the entire list after ix, rather than just a portion of it. I think ix' should be defined as

ix' <- randInt (ix, length progInsts - 1)

instead, which would ensure that it's never larger than the length of the list.

Cheers, and thanks again!

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.