Skip to content

Commit

Permalink
distribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashi Gowda committed Jul 23, 2017
1 parent c3e4c38 commit 8f7f2b1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
9 changes: 0 additions & 9 deletions src/array/alloc.jl
Expand Up @@ -9,13 +9,6 @@ type AllocateArray{T,N} <: ArrayOp{T,N}
end
size(a::AllocateArray) = size(a.domain)

export BlockPartition, Blocks

immutable Blocks{N}
blocksize::NTuple{N, Int}
end
Blocks(xs::Int...) = Blocks(xs)

function _cumlength(len, step)
nice_pieces = div(len, step)
extra = rem(len, step)
Expand All @@ -28,8 +21,6 @@ function partition(p::Blocks, dom::ArrayDomain)
map(_cumlength, map(length, indexes(dom)), p.blocksize))
end

Base.@deprecate BlockPartition Blocks

function stage(ctx, a::AllocateArray)
alloc(idx, sz) = a.f(idx, a.eltype, sz)
thunks = [delayed(alloc)(i, size(x)) for (i, x) in enumerate(a.domainchunks)]
Expand Down
52 changes: 52 additions & 0 deletions src/array/darray.jl
Expand Up @@ -292,3 +292,55 @@ end

Base.@deprecate_binding Cat DArray
Base.@deprecate_binding ComputedArray DArray

export Distribute, distribute

immutable Distribute{N, T} <: ArrayOp{N, T}
domainchunks
data::Union{Chunk, Thunk}
end

Distribute(dmn, data) =
Distribute(dmn, persist!(tochunk(data)))

Distribute(d, p::Union{Chunk, Thunk}) =
Distribute{eltype(chunktype(p)), ndims(d)}(d, p)

size(x::Distribute) = size(domain(x.data))

export BlockPartition, Blocks

immutable Blocks{N}
blocksize::NTuple{N, Int}
end
Blocks(xs::Int...) = Blocks(xs)

Base.@deprecate BlockPartition Blocks


Distribute(p::Blocks, data) =
Distribute(partition(p, domain(data)), data)

function stage(ctx, d::Distribute)
DArray{eltype(chunktype(d.data)), ndims(domain(d.data))}(
domain(d.data),
d.domainchunks,
map(c -> delayed(getindex)(d.data, c), d.domainchunks))
end

function distribute(x::AbstractArray, dist)
compute(Distribute(dist, x))
end

function distribute{T,N}(x::AbstractArray{T,N}, n::NTuple{N})
p = map((d, dn)->ceil(Int, d / dn), size(x), n)
distribute(x, Blocks(p))
end

function distribute(x::AbstractVector, n::Int)
distribute(x, (n,))
end

function distribute(x::AbstractVector, n::Vector)
distribute(x, DomainBlocks((1,), n))
end
27 changes: 0 additions & 27 deletions src/array/matrix.jl
Expand Up @@ -44,33 +44,6 @@ function stage(ctx, node::Transpose)
DArray{eltype(inp),ndims(inp)}(domain(inp)', domainchunks(inp)', thunks)
end

export Distribute

immutable Distribute{N, T} <: ArrayOp{N, T}
domainchunks
data::Union{Chunk, Thunk}
end

Distribute(dmn, data) =
Distribute(dmn, persist!(tochunk(data)))

Distribute(d, p::Union{Chunk, Thunk}) =
Distribute{eltype(chunktype(p)), ndims(d)}(d, p)

size(x::Distribute) = size(domain(x.data))


Distribute(p::Blocks, data) =
Distribute(partition(p, domain(data)), data)

function stage(ctx, d::Distribute)
DArray{eltype(chunktype(d.data)), ndims(domain(d.data))}(
domain(d.data),
d.domainchunks,
map(c -> delayed(getindex)(d.data, c), d.domainchunks))
end


import Base: *, +

immutable MatMul{T, N} <: ArrayOp{T, N}
Expand Down

0 comments on commit 8f7f2b1

Please sign in to comment.