Skip to content

Commit

Permalink
Merge pull request #174 from willow-ahrens/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
willow-ahrens authored Apr 25, 2023
2 parents b0305ba + 9f8bbf9 commit af40dc9
Show file tree
Hide file tree
Showing 16 changed files with 377 additions and 104 deletions.
37 changes: 29 additions & 8 deletions README.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# # Finch.jl
#
# [docs_ico]:https://img.shields.io/badge/docs-stable-blue.svg
# [docs]:https://willow-ahrens.github.io/Finch.jl/stable
#
# [ci_ico]:https://github.com/willow-ahrens/Finch.jl/actions/workflows/CI.yml/badge.svg?branch=main
# [ci]:https://github.com/willow-ahrens/Finch.jl/actions/workflows/CI.yml?query=branch%3Amain
#
# [cov_ico]:https://codecov.io/gh/willow-ahrens/Finch.jl/branch/main/graph/badge.svg
# [cov]:https://codecov.io/gh/willow-ahrens/Finch.jl
# [tool]:https://mybinder.org/v2/gh/willow-ahrens/Finch.jl/gh-pages?labpath=dev%2Finteractive.ipynb
#
# [docs_ico]:https://img.shields.io/badge/docs-stable-blue.svg
# [ci_ico]:https://github.com/willow-ahrens/Finch.jl/actions/workflows/CI.yml/badge.svg?branch=main
# [cov_ico]:https://codecov.io/gh/willow-ahrens/Finch.jl/branch/main/graph/badge.svg
# [tool_ico]:https://mybinder.org/badge_logo.svg
# [tool]:https://mybinder.org/v2/gh/willow-ahrens/Finch.jl/gh-pages?labpath=dev%2Finteractive.ipynb
#
# | **Documentation** | **Build Status** | **Try It Online!** |
# |:---------------------:|:-------------------------------------:|:---------------------:|
Expand All @@ -37,6 +35,8 @@
# variance of a sparse vector, reading the vector only once, and only reading
# nonzero values:

using Finch

X = @fiber(sl(e(0.0)), fsprand((10,), 0.5))
x = Scalar(0.0)
x_min = Scalar(Inf)
Expand All @@ -52,6 +52,19 @@ x_var = Scalar(0.0)
x_sum[] += x[]
x_var[] += x[] * x[]
end
end;

# You can see what kind of code Finch generates using `@finch_code`

@finch_code begin
for i = _
x .= 0
x[] = X[i]
x_min[] <<min>>= x[]
x_max[] <<max>>= x[]
x_sum[] += x[]
x_var[] += x[] * x[]
end
end

# Array formats in Finch are described recursively mode by mode. Semantically, an
Expand All @@ -69,11 +82,19 @@ y = @fiber(d(e(0.0)));
for j=_, i=_
y[i] += A[i, j] * x[j]
end
end
end;

# At it's heart, Finch is powered by a new domain specific language for
# coiteration, breaking structured iterators into control flow units we call
# **Looplets**. Looplets are lowered progressively with
# several stages for rewriting and simplification.
#
# The technologies enabling Finch are described in our [manuscript](doi.org/10.1145/3579990.3580020).
# The technologies enabling Finch are described in our [manuscript](doi.org/10.1145/3579990.3580020).
#
# # Installation
#
# At the [Julia](https://julialang.org/downloads/) REPL, install the latest stable version by running:
#
# ```julia-repl
# julia> using Pkg; Pkg.add("Finch")
# ```
97 changes: 90 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Finch.jl

[docs_ico]:https://img.shields.io/badge/docs-stable-blue.svg
[docs]:https://willow-ahrens.github.io/Finch.jl/stable

[ci_ico]:https://github.com/willow-ahrens/Finch.jl/actions/workflows/CI.yml/badge.svg?branch=main
[ci]:https://github.com/willow-ahrens/Finch.jl/actions/workflows/CI.yml?query=branch%3Amain

[cov_ico]:https://codecov.io/gh/willow-ahrens/Finch.jl/branch/main/graph/badge.svg
[cov]:https://codecov.io/gh/willow-ahrens/Finch.jl
[tool]:https://mybinder.org/v2/gh/willow-ahrens/Finch.jl/gh-pages?labpath=dev%2Finteractive.ipynb

[docs_ico]:https://img.shields.io/badge/docs-stable-blue.svg
[ci_ico]:https://github.com/willow-ahrens/Finch.jl/actions/workflows/CI.yml/badge.svg?branch=main
[cov_ico]:https://codecov.io/gh/willow-ahrens/Finch.jl/branch/main/graph/badge.svg
[tool_ico]:https://mybinder.org/badge_logo.svg
[tool]:https://mybinder.org/v2/gh/willow-ahrens/Finch.jl/gh-pages?labpath=dev%2Finteractive.ipynb

| **Documentation** | **Build Status** | **Try It Online!** |
|:---------------------:|:-------------------------------------:|:---------------------:|
Expand Down Expand Up @@ -38,6 +36,8 @@ variance of a sparse vector, reading the vector only once, and only reading
nonzero values:

````julia
using Finch

X = @fiber(sl(e(0.0)), fsprand((10,), 0.5))
x = Scalar(0.0)
x_min = Scalar(Inf)
Expand All @@ -53,6 +53,81 @@ x_var = Scalar(0.0)
x_sum[] += x[]
x_var[] += x[] * x[]
end
end;
````

You can see what kind of code Finch generates using `@finch_code`

````julia
@finch_code begin
for i = _
x .= 0
x[] = X[i]
x_min[] <<min>>= x[]
x_max[] <<max>>= x[]
x_sum[] += x[]
x_var[] += x[] * x[]
end
end
````

````
quote
X_lvl = (ex.body.bodies[2]).rhs.tns.tns.lvl
X_lvl_2 = X_lvl.lvl
x_min = (ex.body.bodies[3]).lhs.tns.tns
x_min_val = x_min.val
x_max = (ex.body.bodies[4]).lhs.tns.tns
x_max_val = x_max.val
x_sum = (ex.body.bodies[5]).lhs.tns.tns
x_sum_val = x_sum.val
x_var = (ex.body.bodies[6]).lhs.tns.tns
x_var_val = x_var.val
X_lvl_q = X_lvl.ptr[1]
X_lvl_q_stop = X_lvl.ptr[1 + 1]
if X_lvl_q < X_lvl_q_stop
X_lvl_i1 = X_lvl.idx[X_lvl_q_stop - 1]
else
X_lvl_i1 = 0
end
i = 1
phase_stop = min(X_lvl_i1, X_lvl.shape)
if phase_stop >= 1
i = 1
if X_lvl.idx[X_lvl_q] < 1
X_lvl_q = scansearch(X_lvl.idx, 1, X_lvl_q, X_lvl_q_stop - 1)
end
while i <= phase_stop
X_lvl_i = X_lvl.idx[X_lvl_q]
phase_stop_2 = min(phase_stop, X_lvl_i)
if X_lvl_i == phase_stop_2
cond = 0 < -i + phase_stop_2
if cond
x_max_val = max(0.0, x_max_val)
x_min_val = min(0.0, x_min_val)
end
X_lvl_2_val_2 = X_lvl_2.val[X_lvl_q]
x_min_val = min(x_min_val, X_lvl_2_val_2)
x_max_val = max(x_max_val, X_lvl_2_val_2)
x_sum_val = X_lvl_2_val_2 + x_sum_val
x_var_val = X_lvl_2_val_2 * X_lvl_2_val_2 + x_var_val
X_lvl_q += 1
else
x_max_val = max(0.0, x_max_val)
x_min_val = min(0.0, x_min_val)
end
i = phase_stop_2 + 1
end
i = phase_stop + 1
end
if X_lvl.shape >= i
cond_2 = 0 < X_lvl.shape + 1 + -i
if cond_2
x_max_val = max(0.0, x_max_val)
x_min_val = min(0.0, x_min_val)
end
end
(x_var = (Scalar){0.0, Float64}(x_var_val), x_sum = (Scalar){0.0, Float64}(x_sum_val), x_max = (Scalar){-Inf, Float64}(x_max_val), x_min = (Scalar){Inf, Float64}(x_min_val))
end
````

Expand All @@ -72,7 +147,7 @@ y = @fiber(d(e(0.0)));
for j=_, i=_
y[i] += A[i, j] * x[j]
end
end
end;
````

At it's heart, Finch is powered by a new domain specific language for
Expand All @@ -82,3 +157,11 @@ several stages for rewriting and simplification.

The technologies enabling Finch are described in our [manuscript](doi.org/10.1145/3579990.3580020).

# Installation

At the [Julia](https://julialang.org/downloads/) REPL, install the latest stable version by running:

```julia-repl
julia> using Pkg; Pkg.add("Finch")
```

6 changes: 5 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ coverage:
project:
default:
target: auto
threshold: 5%
threshold: 5%
patch:
default:
target: auto
threshold: 100%
1 change: 1 addition & 0 deletions docs/fix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DocMeta.setdocmeta!(Finch, :DocTestSetup, :(using Finch; using SparseArrays); re

mdkwargs = (flavor = Literate.CommonMarkFlavor(),
postprocess = update_FINCHVERSION,
execute = true,
credit = false)

Literate.markdown(joinpath(root, "README.jl"), root; mdkwargs...)
Expand Down
3 changes: 2 additions & 1 deletion docs/src/figures/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TEXFLAGS= -shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -pdf

all:levels-A-matrix.png levels-A-d-d-e.png levels-A-d-sl-e.png levels-A-sl-sl-e.png levels-A-sc2-e.png figure-csc-format.png logo.png favicon.ico
all:levels-A-matrix.png levels-A-d-d-e.png levels-A-d-sl-e.png levels-A-sl-sl-e.png levels-A-sc2-e.png logo.png favicon.ico figure-birb-matrix.png figure-birb-rle-protocol.png figure-cluster-matrix.png figure-cluster-vbl-protocol.png figure-sym-matrix.png figure-sym-sym-protocol.png figure-uniform-list-walk-protocol.png figure-uniform-matrix.png figure-banded-matrix.png figure-banded-banded-protocol.png


%.png: %.pdf # requires ImageMagick
convert -density 600x600 $^ -quality 90 -resize 600x600 -background white -alpha remove -alpha off $@
Expand Down
22 changes: 22 additions & 0 deletions docs/src/figures/figure-banded-banded-protocol.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
\documentclass{standalone}
\input{common.tex}
\begin{document}

\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,
nodes = {whclsty},
left delimiter = (,
right delimiter = ),
ampersand replacement=\&] at (0,0)
{
\zecl \& \zecl \& \zecl \& |[nzsty]|3.7 \& |[nzsty]|4.7 \& |[nzsty]|9.2 \& |[nzsty]|1.5 \& |[nzsty]|8.7 \& \zecl \& \zecl \& \zecl \\
};

\draw[lpltsty] ([yshift=-0*\myunit]A-1-1.south west) -- ([yshift=-0*\myunit]A-1-3.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-4.south west) -- ([yshift=-0*\myunit]A-1-8.south east) node[namesty]{Lookup};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-9.south west) -- ([yshift=-0*\myunit]A-1-11.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-1*\myunit]A-1-1.south west) -- ([yshift=-1*\myunit]A-1-11.south east) node[namesty]{Pipeline};
\end{tikzpicture}%
}
\end{document}
28 changes: 28 additions & 0 deletions docs/src/figures/figure-banded-matrix.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
\documentclass{standalone}
\input{common.tex}
\begin{document}

\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,
nodes = {whclsty},
left delimiter = (,
right delimiter = ),
ampersand replacement=\&] at (0,0)
{
|[nzsty]|0.4 \& |[nzsty]|3.8 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
|[nzsty]|4.1 \& |[nzsty]|1.1 \& |[nzsty]|1.7 \& |[nzsty]|3.2 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
\zecl \& |[nzsty]|1.9 \& |[nzsty]|7.8 \& |[nzsty]|6.9 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
\zecl \& |[nzsty]|9.0 \& |[nzsty]|2.4 \& |[nzsty]|9.4 \& |[nzsty]|9.9 \& |[nzsty]|4.6 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& |[nzsty]|2.6 \& |[nzsty]|8.2 \& |[nzsty]|5.7 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& |[nzsty]|3.7 \& |[nzsty]|4.7 \& |[nzsty]|9.2 \& |[nzsty]|1.5 \& |[nzsty]|8.7 \& \zecl \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|7.0 \& |[nzsty]|1.4 \& |[nzsty]|6.9 \& \zecl \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|8.1 \& |[nzsty]|3.9 \& |[nzsty]|5.2 \& |[nzsty]|8.5 \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|2.3 \& |[nzsty]|6.3 \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|2.8 \& |[nzsty]|5.7 \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|8.1 \& |[nzsty]|8.0 \\
};

\draw[hlsty] (A-6-1.south west) rectangle (A-6-11.north east);
\end{tikzpicture}}
\end{document}
25 changes: 25 additions & 0 deletions docs/src/figures/figure-birb-rle-protocol.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
\documentclass{standalone}
\input{common.tex}
\begin{document}

\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,
nodes = {whclsty},
left delimiter = (,
right delimiter = ),
ampersand replacement=\&] at (0,0)
{
\becl \& \becl \& \becl \& \blcl \& \blcl \& \blcl \& \brcl \& \brcl \& \bkcl \& \brcl \& \orcl\\
};

\draw[lpltsty] ([yshift=-0*\myunit]A-1-1.south west) -- ([yshift=-0*\myunit]A-1-3.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-4.south west) -- ([yshift=-0*\myunit]A-1-6.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-7.south west) -- ([yshift=-0*\myunit]A-1-8.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-9.south west) -- ([yshift=-0*\myunit]A-1-9.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-10.south west) -- ([yshift=-0*\myunit]A-1-10.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-11.south west) -- ([yshift=-0*\myunit]A-1-11.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-1*\myunit]A-1-1.south west) -- ([yshift=-1*\myunit]A-1-11.south east) node[namesty]{Stepper};
\end{tikzpicture}%
}
\end{document}
30 changes: 30 additions & 0 deletions docs/src/figures/figure-cluster-matrix.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
\documentclass{standalone}
\input{common.tex}
\begin{document}

\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,
nodes = {whclsty},
left delimiter = (,
right delimiter = ),
ampersand replacement=\&,
anchor=north west] at (0,0)
{
\zecl \& \zecl \& |[nzsty]|5.9 \& |[nzsty]|4.7 \& |[nzsty]|0.3 \& \zecl \& \zecl \& |[nzsty]|2.9 \& |[nzsty]|2.3 \& \zecl \& \zecl \\
|[nzsty]|6.0 \& \zecl \& \zecl \& \zecl \& |[nzsty]|4.2 \& |[nzsty]|7.5 \& |[nzsty]|5.6 \& \zecl \& \zecl \& \zecl \& \zecl \\
|[nzsty]|3.0 \& \zecl \& \zecl \& |[nzsty]|3.2 \& \zecl \& \zecl \& \zecl \& |[nzsty]|5.9 \& |[nzsty]|5.1 \& |[nzsty]|1.4 \& |[nzsty]|2.1 \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|6.5 \& |[nzsty]|5.9 \& |[nzsty]|6.3 \& \zecl \& \zecl \\
\zecl \& \zecl \& |[nzsty]|2.7 \& |[nzsty]|5.0 \& |[nzsty]|0.9 \& \zecl \& \zecl \& |[nzsty]|1.4 \& |[nzsty]|2.3 \& \zecl \& \zecl \\
\zecl \& \zecl \& \zecl \& |[nzsty]|5.3 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
\zecl \& \zecl \& |[nzsty]|0.9 \& |[nzsty]|3.9 \& |[nzsty]|8.2 \& \zecl \& \zecl \& |[nzsty]|0.1 \& |[nzsty]|4.4 \& |[nzsty]|4.1 \& \zecl \\
|[nzsty]|8.7 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|3.1 \\
|[nzsty]|7.9 \& \zecl \& |[nzsty]|2.3 \& \zecl \& \zecl \& |[nzsty]|9.0 \& |[nzsty]|9.1 \& |[nzsty]|2.5 \& |[nzsty]|1.1 \& |[nzsty]|0.8 \& |[nzsty]|8.6 \\
\zecl \& \zecl \& |[nzsty]|0.7 \& |[nzsty]|6.7 \& |[nzsty]|5.2 \& |[nzsty]|3.2 \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \\
|[nzsty]|1.8 \& \zecl \& \zecl \& |[nzsty]|3.6 \& \zecl \& |[nzsty]|4.1 \& |[nzsty]|0.7 \& |[nzsty]|7.7 \& |[nzsty]|3.1 \& \zecl \& |[nzsty]|3.7 \\
\zecl \& \zecl \& \zecl \& \zecl \& \zecl \& \zecl \& |[nzsty]|6.2 \& |[nzsty]|6.4 \& |[nzsty]|6.5 \& \zecl \& \zecl \\
};

\draw[hlsty] (A-5-1.south west) rectangle (A-5-11.north east);
\end{tikzpicture}}
\end{document}
27 changes: 27 additions & 0 deletions docs/src/figures/figure-cluster-vbl-protocol.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\documentclass{standalone}
\input{common.tex}
\begin{document}

\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,
nodes = {whclsty},
left delimiter = (,
right delimiter = ),
ampersand replacement=\&] at (0,0)
{
\zecl \& \zecl \& |[nzsty]|2.7 \& |[nzsty]|5.0 \& |[nzsty]|0.9 \& \zecl \& \zecl \& |[nzsty]|1.4 \& |[nzsty]|2.3 \& \zecl \& \zecl \\
};

\draw[lpltsty] ([yshift=-0*\myunit]A-1-1.south west) -- ([yshift=-0*\myunit]A-1-2.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-3.south west) -- ([yshift=-0*\myunit]A-1-5.south east) node[namesty]{Lookup};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-6.south west) -- ([yshift=-0*\myunit]A-1-7.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-8.south west) -- ([yshift=-0*\myunit]A-1-9.south east) node[namesty]{Lookup};
\draw[lpltsty] ([yshift=-0*\myunit]A-1-10.south west) -- ([yshift=-0*\myunit]A-1-11.south east) node[namesty]{Run};
\draw[lpltsty] ([yshift=-1*\myunit]A-1-1.south west) -- ([yshift=-1*\myunit]A-1-5.south east) node[namesty]{Pipeline};
\draw[lpltsty] ([yshift=-1*\myunit]A-1-6.south west) -- ([yshift=-1*\myunit]A-1-9.south east) node[namesty]{Pipeline};
\draw[lpltsty] ([yshift=-2*\myunit]A-1-1.south west) -- ([yshift=-2*\myunit]A-1-9.south east) node[namesty]{Stepper};
\draw[lpltsty] ([yshift=-3*\myunit]A-1-1.south west) -- ([yshift=-3*\myunit]A-1-11.south east) node[namesty]{Pipeline};
\end{tikzpicture}%
}
\end{document}
Loading

0 comments on commit af40dc9

Please sign in to comment.