Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcastable Register #139

Closed
GiggleLiu opened this issue Oct 3, 2018 · 9 comments
Closed

Broadcastable Register #139

GiggleLiu opened this issue Oct 3, 2018 · 9 comments
Labels
discussion Need discussion
Milestone

Comments

@GiggleLiu
Copy link
Member

Going to support broadcast for batched register, something like this

function broadcastable(reg::DefaultRegister{B}) where B
    st = reg |> rank3
    Tuple(register(view(st, :, :, i)) for i = 1:B)
end
broadcastable(reg::DefaultRegister{1}) = Ref{reg}

@testset "broadcast register" begin
    reg = rand_state(5,3)
    c = put(5, 2=>X)
    ra = copy(reg)
    rb = copy(reg)
    @test all(ra .|> Ref(c) .≈ rb .|> Ref(c))
    @test typeof.(reg)[1] <: DefaultRegister{<:Any, <:Any, <:SubArray}
end

This realization requrires modifications of intrinsic functions (not shown here).

Any comments?

@GiggleLiu GiggleLiu added the discussion Need discussion label Oct 3, 2018
@Roger-luo
Copy link
Member

why not just let register support broadcast?

@GiggleLiu
Copy link
Member Author

broadcastable is the broadcast interface. Do you mean implement broadcast directly? what's the advantage of doing this?

@Roger-luo
Copy link
Member

Roger-luo commented Oct 3, 2018

directly inherit broadcast will not cause an extra API.

We don't want to create so much API, or this will be too noisy and not Julian. Julia types are duck typed, if you implement broadcast then it is broadcast-able, you don't need to create an API for this.

@GiggleLiu
Copy link
Member Author

broadcastable is the offically recommended interface. JuliaLang/julia#26435

@Roger-luo
Copy link
Member

I see. But shouldn't we should provide the batch as multi-process/multi-threaded? rather than a Tuple. Or what's the meaning of a batch.

@GiggleLiu
Copy link
Member Author

GiggleLiu commented Oct 4, 2018

Can broadcast support parallelism?
We probably need to implement pmap for parallism.

Generator seems better than Tuple for a single threading task.

@GiggleLiu GiggleLiu added this to the v0.3 milestone Oct 4, 2018
@Roger-luo Roger-luo removed this from the v0.3 milestone Oct 4, 2018
@Roger-luo
Copy link
Member

Roger-luo commented Oct 4, 2018

Generator seems better than Tuple for a single threading task.

To return a generator:

function broadcastable(reg::DefaultRegister{B}) where B
    st = reg |> rank3
    (register(view(st, :, :, i)) for i = 1:B)
end

But what do you mean for single threaded? better performance?

I would prefer process rather than threading for batch on CPUs, because usually each single task in a batch can take a long time, use process is easier to dispatch on multiple CPUs.

BTW, what is rank3?

@GiggleLiu
Copy link
Member Author

Cool, thanks for your suggestion.
Batch wise operations should not use multiple processing, we don’t want data communication. This is the same as matrix operations.

rank3 is the (active, remaining, batch) tensor representation for reg. I can not find a better name.

@Roger-luo
Copy link
Member

Roger-luo commented Oct 4, 2018

They call it cube in Eigen and some other libs.

I see, then threaded would be better, or you won't want to use batch if this does not have any significant besides sugars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Need discussion
Projects
None yet
Development

No branches or pull requests

2 participants