-
Couldn't load subscription status.
- Fork 58
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
@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
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@9prady9
Will assignments be faster for mutable arrays because you are not copying the entire array?
Beta Was this translation helpful? Give feedback.
All reactions
-
@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 ?
Beta Was this translation helpful? Give feedback.