Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fastest way to write a row to a mutable array? [Question] #237

Answered by 9prady9
BA8F0D39 asked this question in Q&A
Discussion options

Using set_row, I can write array B to a row of array A.
However, set_row copies the whole array A and this is very slow.
Is there a faster way to write row by row to a mutable array?

let mut A = randu::<f32>(Dim4::new(&[100000, 3, 1, 1]));
let mut C = randu::<f32>(Dim4::new(&[1, 3, 1, 1]));
for n in 0..100000 {
 let B = randu::<f32>(Dim4::new(&[1, 3, 1, 1]));
 let B = my_computation_function(&B,&C);
 A = set_row(&A,&B,n);
 C = my_computation_function2(&B,&C);
}

batch_func exists but it only can take 2 arrays.

You must be logged in to vote

@9prady9
Will assignments be faster for mutable arrays because you are not copying the entire array?

The missing mut qualifier is an issue at rust wrapper not reflecting how the lhs parameter to set_row is handled internally to ArrayFire. Therefore, it is fix at rust wrapper level to an already existing behavior I explained here

Hence, whatever slowness you are observing is not related to this missing mut issue. Have you looked into what I have mentioned here ?

Replies: 5 comments

Comment options

@BA8F0D39 Copy of whole Array A would only happen in a special case where if there are two Array's using same memory region. From you code sample, it doesn't seem like A has more than one copy at any time. The only time it is used, it is borrowed by reference which doesn't increase the internal reference count for associated memory region. May I know how you have come to the conclusion that whole Array is getting copied ?

Note that the program could also be slow because you are making about 100K round trips to the GPU just for three elements of data transfer which is very inefficient and costly in terms of performance.

You must be logged in to vote
0 replies
Comment options

@9prady9

http://arrayfire.org/arrayfire-rust/arrayfire/fn.set_row.html
From the documentation, set_row takes in an input immutable array. Therefore, the set_row must make a copy of the input in order to modify it.

You must be logged in to vote
0 replies
Comment options

@BA8F0D39 We have corrected that mutability in master already to reflect the same. This change will be available from next release. I hope to do this release by end of this week. So, kindly bare with us for the temporary inconvenience.

You must be logged in to vote
0 replies
Comment options

@9prady9
Will assignments be faster for mutable arrays because you are not copying the entire array?

You must be logged in to vote
0 replies
Comment options

@9prady9
Will assignments be faster for mutable arrays because you are not copying the entire array?

The missing mut qualifier is an issue at rust wrapper not reflecting how the lhs parameter to set_row is handled internally to ArrayFire. Therefore, it is fix at rust wrapper level to an already existing behavior I explained here

Hence, whatever slowness you are observing is not related to this missing mut issue. Have you looked into what I have mentioned here ?

You must be logged in to vote
0 replies
Answer selected by 9prady9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #237 on December 09, 2020 05:16.

AltStyle によって変換されたページ (->オリジナル) /