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

arrayfire::info and arrayfire::set_device both increase performance #226

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

While doing some basic performance testing I noticed that initialising an Array on the GPU is much faster if you either used arrayfire::info or arrayfire::set_device before.

For me using either one decreased the time from about 1.5s to about 350ms.

Is this intended, especially for arrayfire::info ?

use arrayfire::{Array, Dim4, pow, set_device, info};
use std::time::{Instant};

use arrayfire::{Array, Dim4, pow, set_device, info};
use std::time::{Instant};
fn main() {
 //set_device(0);
 //info();
 let values: [f64; 100000] = [3.5; 100000];
 
 let start_loop = Instant::now();
 let mut res_loop: [f64; 100000] = [0.0; 100000];
 for i in 0..values.len() {
 res_loop[i] = values[i].powi(2) + 3.14159 / 6.7;
 }
 println!("Loop:{:?}", start_loop.elapsed());
 let start_gpu_setup = Instant::now();
 let indices = Array::<f64>::new(&values, Dim4::new(&[100000, 1, 1, 1]));
 println!("GPU Setup:{:?}", start_gpu_setup.elapsed());
 let start_gpu = Instant::now();
 let res_gpu = pow(&indices, &2, false) + 3.14159 / 6.7;
 println!("GPU:{:?}", start_gpu.elapsed());
 
}
You must be logged in to vote

The device warmup does take time depending the backend. How much time should be considered okay really depends on what other processes are running on the system and how long the the corresponding device initialisation takes place.

By calling, info or set_device ahead of timing section of code you are taking care of the warmup separately so it doesn't show up later. Basically, init is run by whichever function you call later if it isn't done already.

This is not bug.

Replies: 2 comments

Comment options

The device warmup does take time depending the backend. How much time should be considered okay really depends on what other processes are running on the system and how long the the corresponding device initialisation takes place.

By calling, info or set_device ahead of timing section of code you are taking care of the warmup separately so it doesn't show up later. Basically, init is run by whichever function you call later if it isn't done already.

This is not bug.

You must be logged in to vote
0 replies
Answer selected by 9prady9
Comment options

Alright thanks for the clarification.

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

This discussion was converted from issue #226 on December 09, 2020 05:15.

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