-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Separate benchmarks by enabled features #1538
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f04a79
Use cfg to seperate benchmark results based on features
ivarflakstad ad075a5
Remove allow pragma
ivarflakstad fb05af4
Avoid some unnecessary returns.
LaurentMazare 88945f2
Improve benchmarks layout
ivarflakstad dc3725b
Derive bench_name from actual device
ivarflakstad e9e31f1
Run CPU benchmarks even when GPU feature is enabled
ivarflakstad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use candle_core::{Device, Result}; | ||
|
||
pub(crate) trait BenchDevice { | ||
fn sync(&self) -> Result<()>; | ||
} | ||
|
||
impl BenchDevice for Device { | ||
fn sync(&self) -> Result<()> { | ||
match self { | ||
Device::Cpu => Ok(()), | ||
Device::Cuda(device) => { | ||
#[cfg(feature = "cuda")] | ||
return Ok(device.synchronize()?); | ||
#[cfg(not(feature = "cuda"))] | ||
panic!("Cuda device without cuda feature enabled: {:?}", device) | ||
} | ||
Device::Metal(device) => { | ||
#[cfg(feature = "metal")] | ||
return Ok(device.wait_until_completed()?); | ||
#[cfg(not(feature = "metal"))] | ||
panic!("Metal device without metal feature enabled: {:?}", device) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) fn device() -> Result<Device> { | ||
return if cfg!(feature = "metal") { | ||
Device::new_metal(0) | ||
} else if cfg!(feature = "cuda") { | ||
Device::new_cuda(0) | ||
} else { | ||
Ok(Device::Cpu) | ||
}; | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) fn bench_name<S: Into<String>>(name: S) -> String { | ||
format!("{}_{}", device_variant(), name.into()) | ||
} | ||
|
||
#[allow(dead_code)] | ||
const fn device_variant() -> &'static str { | ||
return if cfg!(feature = "metal") { | ||
"metal" | ||
} else if cfg!(feature = "cuda") { | ||
"cuda" | ||
} else if cfg!(feature = "accelerate") { | ||
"accelerate" | ||
} else if cfg!(feature = "mkl") { | ||
"mkl" | ||
} else { | ||
"cpu" | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this allow pragma? Maybe there is a way to avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I don't know a way to get around it. Criterion doesn't run the code in the same way as the standard rust testing framework, so it doesn't register as being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I guess you googled a bit on the criterion side and haven't found anything (I haven't checked), could you add a comment to explain why these are needed? (and link to any criterion resource that would document this if any)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cargo isn't complaining about unused code anymore 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? I just tried running the benchmarks with no feature enabled and got the warnings?

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I tried after cargo clean and still get no warnings 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is related to the
/benches
folder file structure https://users.rust-lang.org/t/how-to-properly-add-test-cases-for-benches/102859/4There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the warnings still present? If they are still there for any of you I'll try a different approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Just remove the utils file. Bench will walk all files including the utils which is why it will complain. Just but them in the core file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "core" file, do you mean
matmul.rs
?I was thinking we could have several benchmarks
matmul.rs
,random.rs
, etc.If I place these in their own module and load them from a
bench_main.rs
file we won't be able to specify which benchmark to run.