66//!
77//! 1. RustaCUDA doesn't expose a higher level function to launch a kernel on the default stream
88//! 2. There was a bug, when the default stream was used implicitly via RustaCUDA's synchronuous
9- //! copy methods. To prevent such kind of bugs, be explicit which stream is used.
9+ //! copy methods. To prevent such kind of bugs, be explicit which stream is used.
1010
1111pub ( crate ) mod utils;
1212
@@ -133,13 +133,11 @@ impl Program {
133133 pub fn from_binary ( device : & Device , filename : & CStr ) -> GPUResult < Program > {
134134 debug ! ( "Creating CUDA program from binary file." ) ;
135135 rustacuda:: context:: CurrentContext :: set_current ( & device. context ) ?;
136- let module = rustacuda:: module:: Module :: load_from_file ( filename) . map_err ( |err | {
136+ let module = rustacuda:: module:: Module :: load_from_file ( filename) . inspect_err ( |_err | {
137137 Self :: pop_context ( ) ;
138- err
139138 } ) ?;
140- let stream = Stream :: new ( StreamFlags :: NON_BLOCKING , None ) . map_err ( |err | {
139+ let stream = Stream :: new ( StreamFlags :: NON_BLOCKING , None ) . inspect_err ( |_err | {
141140 Self :: pop_context ( ) ;
142- err
143141 } ) ?;
144142 let prog = Program {
145143 module,
@@ -155,13 +153,11 @@ impl Program {
155153 pub fn from_bytes ( device : & Device , bytes : & [ u8 ] ) -> GPUResult < Program > {
156154 debug ! ( "Creating CUDA program from bytes." ) ;
157155 rustacuda:: context:: CurrentContext :: set_current ( & device. context ) ?;
158- let module = rustacuda:: module:: Module :: load_from_bytes ( bytes) . map_err ( |err | {
156+ let module = rustacuda:: module:: Module :: load_from_bytes ( bytes) . inspect_err ( |_err | {
159157 Self :: pop_context ( ) ;
160- err
161158 } ) ?;
162- let stream = Stream :: new ( StreamFlags :: NON_BLOCKING , None ) . map_err ( |err | {
159+ let stream = Stream :: new ( StreamFlags :: NON_BLOCKING , None ) . inspect_err ( |_err | {
163160 Self :: pop_context ( ) ;
164- err
165161 } ) ?;
166162 let prog = Program {
167163 module,
@@ -203,9 +199,7 @@ impl Program {
203199 let bytes_len = mem:: size_of_val ( slice) ;
204200
205201 // Transmuting types is safe as long a sizes match.
206- let bytes = unsafe {
207- std:: slice:: from_raw_parts ( slice. as_ptr ( ) as * const T as * const u8 , bytes_len)
208- } ;
202+ let bytes = unsafe { std:: slice:: from_raw_parts ( slice. as_ptr ( ) as * const u8 , bytes_len) } ;
209203
210204 // It is only unsafe as long as the buffer isn't initialized, but that's what we do next.
211205 let mut buffer = unsafe { DeviceBuffer :: < u8 > :: uninitialized ( bytes_len) ? } ;
@@ -245,10 +239,7 @@ impl Program {
245239
246240 // Transmuting types is safe as long a sizes match.
247241 let bytes = unsafe {
248- std:: slice:: from_raw_parts (
249- data. as_ptr ( ) as * const T as * const u8 ,
250- mem:: size_of_val ( data) ,
251- )
242+ std:: slice:: from_raw_parts ( data. as_ptr ( ) as * const u8 , mem:: size_of_val ( data) )
252243 } ;
253244
254245 // It is safe as we synchronize the stream after the call.
@@ -264,10 +255,7 @@ impl Program {
264255
265256 // Transmuting types is safe as long a sizes match.
266257 let bytes = unsafe {
267- std:: slice:: from_raw_parts_mut (
268- data. as_mut_ptr ( ) as * mut T as * mut u8 ,
269- mem:: size_of_val ( data) ,
270- )
258+ std:: slice:: from_raw_parts_mut ( data. as_mut_ptr ( ) as * mut u8 , mem:: size_of_val ( data) )
271259 } ;
272260
273261 // It is safe as we synchronize the stream after the call.
0 commit comments