Skip to content

Commit

Permalink
dtop tests working waduup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashi Gowda committed Feb 22, 2017
1 parent 1648c61 commit 6ef9437
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/array/tensorop-parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ include("tensorop.jl")
function equivalent_chunks(X::Iter)
# An iterator on the chunks of iterators
# TODO: handle IterConsts
Iter(map(c -> Thunk(x -> Iter(x, X.idx), c), chunks(X.A)), X.idx)
let idx = X.idx
Iter(map(c -> Thunk(x -> Iter(x, idx), c), chunks(X.A)), X.idx)
end
end

function equivalent_chunks(X::Map)
Expand All @@ -24,14 +26,14 @@ function equivalent_chunks(X::Map)
end
end


function equivalent_chunks{dim}(X::Reduce{dim})
@show dim
let f = X.f
# Reduce each chunk first
reduced_chunks = map(c -> Thunk(x -> Reduce(dim(), f, x), c), equivalent_chunks(X.X))
reduced_chunks = Map(c -> Thunk(x -> Reduce(dim(), f, x), c), (equivalent_chunks(X.X),))

# reduce the chunks array
Reduce(dim(), (x,y) -> Thunk((p, q) -> Reduce(dim(), f, DimCat(dim(), p, q)), x, y),
Reduce(dim(), (x,y) -> Thunk((a,b)->Map(f, (a, b)), x, y),
reduced_chunks, Thunk(()->nothing)) # must be made tree reduce
end
end
Expand All @@ -41,9 +43,10 @@ function equivalent_chunks(itr::TensorOp)
end

function dtop!(t::TensorOp)
chunks = top!(equivalent_chunks(t))
chunksA = chunks(t.lhs.A)
chunksA = map(c -> Thunk(c -> top!(c)), chunksA)
cs = top!(equivalent_chunks(t))
L(x) = Iter(x, t.lhs.idx)
chunksA = map(c -> Thunk(x -> top!(TensorOp(L(Array(Float64, 2,2)), x)), c), cs)
t.lhs.A.result.chunks = chunksA
t.lhs.A
end

Expand All @@ -66,6 +69,5 @@ let

@dtop A[i,j] = B[i,k]*C[k,j]
map(gather, chunks(A))
@test gather(D) == gather(A)
@test gather(A) == gather(B)*gather(C)
@test gather(A) gather(B)*gather(C)
end

0 comments on commit 6ef9437

Please sign in to comment.