Skip to content

Commit

Permalink
Convert yieldAccum to yield_accum
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasschmitz authored and apaszke committed May 10, 2022
1 parent c5e2401 commit 8e17301
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion benchmarks/parboil/mriq.dx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def mriq
: (cs=>Float & cs=>Float) =
unzip $ for i.
run_accum (AddMonoid Float) \qi.
yieldAccum (AddMonoid Float) \qr.
yield_accum (AddMonoid Float) \qr.
for j.
phiMag = phiR.j * phiR.j + phiI.j * phiI.j
expArg = kx.j * x.i + ky.j * y.i + kz.j * z.i
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/rodinia/kmeans.dx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ def dist (x : d=>Float) (y : d=>Float) : Float =
sum $ for i. d.i * d.i

def centroidsOf (points : n=>d=>Float) (membership : n=>k) : k=>d=>Float =
clusterSums = yieldAccum (AddMonoid Float) \clusterSums.
clusterSums = yield_accum (AddMonoid Float) \clusterSums.
for i. clusterSums!(membership.i) += points.i
clusterSizes = yieldAccum (AddMonoid Float) \clusterSizes.
clusterSizes = yield_accum (AddMonoid Float) \clusterSizes.
for i. clusterSizes!(membership.i) += 1.0
for i. clusterSums.i / (max clusterSizes.i 1.0)

Expand Down
4 changes: 2 additions & 2 deletions examples/raytrace.dx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def sampleLightRadiance {n}
(surfNor, surf) = osurf
(rayPos, _) = inRay
(MkScene objs) = scene
yieldAccum (AddMonoid Float) \radiance.
yield_accum (AddMonoid Float) \radiance.
for i. case objs.i of
PassiveObject _ _ -> ()
Light lightPos hw _ ->
Expand All @@ -229,7 +229,7 @@ def sampleLightRadiance {n}

def trace {n} (params:Params) (scene:Scene n) (initRay:Ray) (k:Key) : Color =
noFilter = [1.0, 1.0, 1.0]
yieldAccum (AddMonoid Float) \radiance.
yield_accum (AddMonoid Float) \radiance.
run_state noFilter \filter.
run_state initRay \ray.
bounded_iter (get_at #maxBounces params) () \i.
Expand Down
2 changes: 1 addition & 1 deletion examples/simplex.dx
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def constraints_satisfied (constraints: m=>Constraint n) (x: n=>Float) : Bool =

def extractSolution (tableau: AbsTableau cons vars extra) : vars=>Float =
(basics, _, table) = tableau
yieldAccum (AddMonoid Float) \varRef.
yield_accum (AddMonoid Float) \varRef.
for v:cons.
var = basics.v
case var of -- If this basic variable is an original variable, write it.
Expand Down
2 changes: 1 addition & 1 deletion examples/tiled-matmul.dx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def matmul
vectorTile = Fin VectorWidth
colTile = (colVectors & vectorTile)
(tile2d (\nt:(Tile n rowTile). \mt:(Tile m colTile).
ct = yieldAccum (AddMonoid Float) \acc.
ct = yield_accum (AddMonoid Float) \acc.
for l:k.
for i:rowTile.
ail = broadcastVector a.(nt +> i).l
Expand Down
2 changes: 1 addition & 1 deletion lib/fft.dx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def power_of_2_fft {log2_n}
ipow2 = get ipow2Ref

log2_half_n = log2_n - 1
xRef := yieldAccum (AddMonoid Complex) \bufRef.
xRef := yield_accum (AddMonoid Complex) \bufRef.
for j:((Fin log2_half_n)=>(Fin 2)). -- Executes in parallel.
(left_read_ix, right_read_ix,
left_write_ix, right_write_ix) = butterfly_ixs j ipow2
Expand Down
10 changes: 5 additions & 5 deletions lib/prelude.dx
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def run_accum
action' ref
%runWriter empty combine explicitAction

def yieldAccum
def yield_accum
{a b w eff}
[mlift:MonoidLifter b w]
(m:Monoid b)
Expand Down Expand Up @@ -692,7 +692,7 @@ instance Monoid Ordering

instance {a n} [Eq a] Eq (n=>a)
(==) = \xs ys.
yieldAccum AndMonoid \ref.
yield_accum AndMonoid \ref.
for i. ref += xs.i == ys.i

instance {a n} [Ord a] Ord (n=>a)
Expand Down Expand Up @@ -918,7 +918,7 @@ def reduce {a n} (identity:a) (combine:(a->a->a)) (xs:n=>a) : a =
-- TODO: call this `scan` and call the current `scan` something else
def scan' {a n} [Ix n] (init:a) (body:n->a->a) : n=>a = snd $ scan init \i x. dup (body i x)
-- TODO: allow tables-via-lambda and get rid of this
def fsum {n} (xs:n=>Float) : Float = yieldAccum (AddMonoid Float) \ref. for i. ref += xs.i
def fsum {n} (xs:n=>Float) : Float = yield_accum (AddMonoid Float) \ref. for i. ref += xs.i
def sum {n v} [Add v] (xs:n=>v) : v = reduce zero (+) xs
def prod {n v} [Mul v] (xs:n=>v) : v = reduce one (*) xs
def mean {n v} [VSpace v] (xs:n=>v) : v = sum xs / i_to_f (size n)
Expand Down Expand Up @@ -1139,14 +1139,14 @@ def append {a h} [AccumMonoid h (List a)]
list += AsList 1 [x]

def filter {a n} (condition:a->Bool) (xs:n=>a) : List a =
yieldAccum (ListMonoid a) \list.
yield_accum (ListMonoid a) \list.
for i.
if condition xs.i
then append list xs.i

def arg_filter {a n} (condition:a->Bool) (xs:n=>a) : List n =
-- Returns all indices where the condition is true.
yieldAccum (ListMonoid n) \list.
yield_accum (ListMonoid n) \list.
for i.
if condition xs.i
then append list i
Expand Down
2 changes: 1 addition & 1 deletion lib/sort.dx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Warning: Very slow for now!!
Because merging sorted lists is associative, we can expose the
parallelism of merge sort to the Dex compiler by making a monoid
and using reduce or yieldAccum.
and using reduce or yield_accum.
However, this approach puts a lot of pressure on the compiler.
As noted on [StackOverflow](https://stackoverflow.com/questions/21877572/can-you-formulate-the-bubble-sort-as-a-monoid-or-semigroup),
if the compiler does the reduction one element at a time,
Expand Down
8 changes: 4 additions & 4 deletions tests/ad-tests.dx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

-- TODO: use prelude sum instead once we can differentiate state effect
def sum' {n} (xs:n=>Float) : Float = yieldAccum (AddMonoid Float) \ref. for i. ref += xs.i
def sum' {n} (xs:n=>Float) : Float = yield_accum (AddMonoid Float) \ref. for i. ref += xs.i

:p
f : Float -> Float = \x. x
Expand Down Expand Up @@ -69,7 +69,7 @@ def sum' {n} (xs:n=>Float) : Float = yieldAccum (AddMonoid Float) \ref. for i. r
:p jvp sum' [1., 2.] [10.0, 20.0]
> 30.

f : Float -> Float = \x. yieldAccum (AddMonoid Float) \ref. ref += x
f : Float -> Float = \x. yield_accum (AddMonoid Float) \ref. ref += x
:p jvp f 1.0 1.0
> 1.

Expand Down Expand Up @@ -167,7 +167,7 @@ tripleit : Float --o Float = \x. x + x + x
> [2., 4.]

myOtherSquare : Float -> Float =
\x. yieldAccum (AddMonoid Float) \w. w += x * x
\x. yield_accum (AddMonoid Float) \w. w += x * x

:p check_deriv myOtherSquare 3.0
> True
Expand Down Expand Up @@ -225,7 +225,7 @@ vec = [1.]
:p
f : Float -> Float = \x.
y = x * 2.0
yieldAccum (AddMonoid Float) \a.
yield_accum (AddMonoid Float) \a.
a += x * 2.0
a += y
grad f 1.0
Expand Down
6 changes: 3 additions & 3 deletions tests/adt-tests.dx
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ myTab = [MyLeft 1, MyRight 3.5, MyLeft 123, MyLeft 456]
> Runtime error

:p
yieldAccum (AddMonoid Float) \ref.
yield_accum (AddMonoid Float) \ref.
for i. case myTab.i of
MyLeft tmp -> ()
MyRight val -> ref += 1.0 + val
> 4.5

:p
-- check that the order of the case alternatives doesn't matter
yieldAccum (AddMonoid Float) \ref.
yield_accum (AddMonoid Float) \ref.
for i. case myTab.i of
MyRight val -> ref += 1.0 + val
MyLeft tmp -> ()
Expand All @@ -128,7 +128,7 @@ threeCaseTab : (Fin 4)=>ThreeCases =
> [(TheIntCase 3), TheEmptyCase, (ThePairCase 2 0.1), TheEmptyCase]

:p
yieldAccum (AddMonoid Float) \ref.
yield_accum (AddMonoid Float) \ref.
for i. case threeCaseTab.i of
TheEmptyCase -> ref += 1000.0
ThePairCase x y -> ref += 100.0 + y + i_to_f x
Expand Down
2 changes: 1 addition & 1 deletion tests/eval-tests.dx
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def newtonSolve (tol:Float) (f : Float -> Float) (x0:Float) : Float =
-- x = for i:(Fin 3). for j:(Fin 200). 1.0
-- -- Last dimension split to allow for vector loads
-- y = for i:(Fin 200). for j:(Fin 4). for h:(Fin VectorWidth). IToF $ (iota _).(i,j,h)
-- z = yieldAccum \acc.
-- z = yield_accum \acc.
-- for l.
-- for i.
-- xil = (broadcastVector x.i.l)
Expand Down
8 changes: 4 additions & 4 deletions tests/monad-tests.dx
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ symmetrizeInPlace [[1.,2.],[3.,4.]]
:p with_reader 5 \r. ()
> ()

:p yieldAccum (AddMonoid Float) \w.
:p yield_accum (AddMonoid Float) \w.
for i:(Fin 2).
w += 1.0
w += 1.0
> 4.

:p yieldAccum (AddMonoid Float) \w.
:p yield_accum (AddMonoid Float) \w.
for i:(Fin 2).
w += 1.0
w += 1.0
> 3.

:p yieldAccum (AddMonoid Float) \ref.
:p yield_accum (AddMonoid Float) \ref.
ref += [1.,2.,3.]
ref += [2.,4.,5.]
> [3., 6., 8.]
Expand Down Expand Up @@ -196,7 +196,7 @@ def effectsAtZero {eff:Effects} (f: Int ->{|eff} Unit) : {|eff} Unit =

-- Test custom list monoid with accum
def adjacencyMatrixToEdgeList {n} (mat: n=>n=>Bool) : List (n & n) =
yieldAccum (ListMonoid (n & n)) \list.
yield_accum (ListMonoid (n & n)) \list.
for (i, j).
if mat.i.j then
append list (i, j)
Expand Down
2 changes: 1 addition & 1 deletion tests/parser-tests.dx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def myInt2 : {State Int} Int = 1
> Nullary def can't have effects

:p
yieldAccum (AddMonoid Float) \ref.
yield_accum (AddMonoid Float) \ref.
x = if True then 1. else 3.
if True then ref += x

Expand Down

0 comments on commit 8e17301

Please sign in to comment.