-
Notifications
You must be signed in to change notification settings - Fork 57
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
Remove unwrap
from examples
#1
Comments
Is this still open? |
Hey, thanks for your interest! Yes, this is still open. I meant that we should remove |
I'm happy to give it a go! hopefully, the 'beginner' tag isn't too far out of my reach! |
Can I take a stab at this? |
Please do! |
I finally got this compiling this evening!!! first contribution to open source here we come. |
If possible, could you post all of the problems you ran into while trying to get it to compile? It might help us make it easier for others. |
I think they were all CUDA install related:
-I'm on windows 10 developer preview. [ Ryzen 7 1800x, 32GB RAM, GTX1080ti ] |
Hmm. My understanding is that the CUDA driver and graphics driver are not the same thing, so you might need the CUDA driver as well. I could be wrong though. Anyway, yeah, it sounds like more of a problem with NVIDIA's documentation than ours. The one thing we can do is automatically detect common installation paths so that the user doesn't have to set CUDA_LIBRARY_PATH, and I think some folks are already working on that for |
@bheisler this kinda thing yeah? fn main() -> Result<(), Box<dyn Error>> {
rustacuda::init(rustacuda::CudaFlags::empty())?;
let device = Device::get_device(0)?;
let context =
Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device)?;
// call RustaCUDA functions which use the context
// The context will be destroyed when dropped or it falls out of scope.
Ok(drop(context))
} So, for the docs using # to hide the main(s) //! # use std::error::Error;
//! # use rustacuda;
//! # use rustacuda::context::{Context, ContextFlags};
//! # use rustacuda::device::Device;
//! # fn main() -> Result<(), Box<dyn Error>> {
//! rustacuda::init(rustacuda::CudaFlags::empty())?;
//! let device = Device::get_device(0)?;
//! let context =
//! Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device)?;
//! // call RustaCUDA functions which use the context
//! // The context will be destroyed when dropped or it falls out of scope.
//!
//! # Ok(drop(context))
//! #} It looks like some of the content may be more difficult than propogating dyn errors, // Create and pop contexts for each device
let contexts = Device::devices()?
.map(|device| {
let ctx = Context::create_and_push(
ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO,
device.unwrap(), // One
).unwrap(); // Two
ContextStack::pop().unwrap(); // For One, Two & Three, are .expects best here or with (mroe) research will I find specific cuda erros from the errors.rs
ctx
})
.collect::<Vec<Context>>();
CurrentContext::set_current(&contexts[0])?;
Ok(()) Hope I'm on the right track & that this isn't causing more work than just removing them yourself :P |
That looks about right, yeah. I would like to remove all of the For the one you posted, I would change it to something like this: // Create and pop contexts for each device
let mut contexts = vec![];
for device in Device::devices()? {
let device = device?;
let ctx = Context::create_and_push(
ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO,
device)?;
ContextStack::pop()?;
contexts.push(ctx);
}
CurrentContext::set_current(&contexts[0])?; EDIT: For most of these examples, the drop(context);
# Ok(()) |
Should I remove the unwraps from the #[test]
fn test_copy_from_module() {
let _context = quick_init();
let ptx = CString::new(include_str!("../resources/add.ptx")).unwrap();
let module = Module::load_from_string(&ptx).unwrap();
let constant_name = CString::new("my_constant").unwrap();
let symbol = module.get_global::<u32>(&constant_name).unwrap();
let mut constant_copy = 0u32;
symbol.copy_to(&mut constant_copy).unwrap();
assert_eq!(314, constant_copy);
}``` |
Huh. I had no idea that returning In that case, sure. Might as well update the tests too. |
We shouldn't be encouraging users to unwrap errors, but to use
?
instead. Go through all of the examples in the Rustdoc comments and change them to use?
instead ofunwrap()
, like so:The text was updated successfully, but these errors were encountered: