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

Array2D.copy is slow, you can use array.Clone #1

Closed
dsyme opened this issue Dec 5, 2015 · 2 comments
Closed

Array2D.copy is slow, you can use array.Clone #1

dsyme opened this issue Dec 5, 2015 · 2 comments

Comments

@dsyme
Copy link
Collaborator

dsyme commented Dec 5, 2015

The perf of the recurrent neural networks sample is dominated by Array2D.copy as part of DM addiiton as part of pushRec in DiffSharp.

  1. It might be possible to use in-place addition. I'm not entirely sure which addition operation in pushRec is dominating, but in cases like this it looks like in-place addition might be appropriate:

                    d.A <- d.A + (v :?> DM)
    
  2. Regardless, you're using Array2D.copy in DiffSharp and that seems to be slower than it should be since it does an initBased. That should be fixed in FSharp.Core. But in the meantime you can do this which seems 4x faster.

module Array2D =  
    let copyFast (array : 'T[,]) =  array.Clone() :?> 'T[,]

e.g.

#time "on"

let test1() = 
    let mutable res  = Array2D.zeroCreate<float32> 100 100 
    for i in 0 .. 1000 do   
        for j in 0 .. 100 do
            res <- Array2D.copy res

let test2() = 
    let mutable res  = Array2D.zeroCreate<float32> 100 100 
    for i in 0 .. 1000 do   
        for j in 0 .. 100 do
            res <- Array2D.copyFast res

test1()  // 4.4s
test2() // 0.98s
@gbaydin
Copy link
Collaborator

gbaydin commented Dec 5, 2015

In-place operations are definitely needed. It's already on our list for DiffSharp, here:

https://github.com/DiffSharp/DiffSharp/blob/master/Roadmap.txt

The reverse adjoint update rule d.A <- d.A + (v :?> DM) is a very good example of how much it will be useful.

For the Array2D.copy issue, I will definitely follow your suggestion and make the change in DiffSharp until FSharp.Core is fixed.

@gbaydin
Copy link
Collaborator

gbaydin commented Dec 8, 2015

This is fixed in DiffSharp 0.7.5.

@gbaydin gbaydin closed this as completed Dec 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants