@@ -226,11 +226,11 @@ pub unsafe fn memcpy_dtoh(
226
226
}
227
227
228
228
/// Similar to `cudaMemcpy2D` with `HostToDevice` copy type.
229
- ///
229
+ ///
230
230
/// `dpitch`/`spitch` is bytes between the start of two rows.
231
231
/// `width` is the number of *elements* (not bytes) in a row.
232
232
/// `height` is the total number of rows (not bytes).
233
- ///
233
+ ///
234
234
/// # Examples
235
235
///
236
236
/// ```
@@ -240,32 +240,32 @@ pub unsafe fn memcpy_dtoh(
240
240
/// unsafe {
241
241
/// // Allocate space for a 3x3 matrix of f32s
242
242
/// let (device_buffer, pitch) = cuda_malloc_pitched::<f32>(3, 3)?;
243
- ///
243
+ ///
244
244
/// let src_array: [f32; 9] = [
245
- /// 1.0, 2.0, 3.0,
246
- /// 4.0, 5.0, 6.0,
245
+ /// 1.0, 2.0, 3.0,
246
+ /// 4.0, 5.0, 6.0,
247
247
/// 7.0, 8.0, 9.0];
248
- ///
248
+ ///
249
249
/// memcpy_2d_htod(
250
- /// device_buffer,
251
- /// pitch,
250
+ /// device_buffer,
251
+ /// pitch,
252
252
/// src_array.as_slice().as_ptr(),
253
253
/// 3*std::mem::size_of::<f32>(),
254
254
/// 3,
255
255
/// 3
256
256
/// )?;
257
- ///
257
+ ///
258
258
/// let mut dst_array = [0.0f32; 9];
259
259
///
260
260
/// memcpy_2d_dtoh(
261
261
/// dst_array.as_mut_slice().as_mut_ptr(),
262
262
/// 3*std::mem::size_of::<f32>(),
263
- /// device_buffer,
264
- /// pitch,
263
+ /// device_buffer,
264
+ /// pitch,
265
265
/// 3,
266
266
/// 3
267
- /// )?;
268
- ///
267
+ /// )?;
268
+ ///
269
269
/// assert_eq!(dst_array, src_array);
270
270
/// cuda_free(device_buffer)?;
271
271
/// }
@@ -284,15 +284,16 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>(
284
284
) -> CudaResult < ( ) > {
285
285
use cust_raw:: CUmemorytype ;
286
286
287
- let width_in_bytes = width. checked_mul ( std:: mem:: size_of :: < T > ( ) )
287
+ let width_in_bytes = width
288
+ . checked_mul ( std:: mem:: size_of :: < T > ( ) )
288
289
. ok_or ( CudaError :: InvalidMemoryAllocation ) ?;
289
290
290
291
let pcopy = cust_raw:: CUDA_MEMCPY2D_st {
291
292
srcXInBytes : 0 ,
292
293
srcY : 0 ,
293
294
srcMemoryType : CUmemorytype :: CU_MEMORYTYPE_HOST ,
294
295
srcHost : src as * const c_void ,
295
- srcDevice : 0 , // Ignored
296
+ srcDevice : 0 , // Ignored
296
297
srcArray : std:: ptr:: null_mut :: < cust_raw:: CUarray_st > ( ) , // Ignored
297
298
srcPitch : spitch,
298
299
dstXInBytes : 0 ,
@@ -311,11 +312,11 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>(
311
312
}
312
313
313
314
/// Similar to `cudaMemcpy2D` with `DeviceToHost` copy type.
314
- ///
315
+ ///
315
316
/// `dpitch`/`spitch` is bytes between the start of two rows.
316
317
/// `width` is the number of *elements* (not bytes) in a row.
317
318
/// `height` is the total number of rows (not bytes).
318
- ///
319
+ ///
319
320
/// # Examples
320
321
///
321
322
/// ```
@@ -325,32 +326,32 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>(
325
326
/// unsafe {
326
327
/// // Allocate space for a 3x3 matrix of f32s
327
328
/// let (device_buffer, pitch) = cuda_malloc_pitched::<f32>(3, 3)?;
328
- ///
329
+ ///
329
330
/// let src_array: [f32; 9] = [
330
- /// 1.0, 2.0, 3.0,
331
- /// 4.0, 5.0, 6.0,
331
+ /// 1.0, 2.0, 3.0,
332
+ /// 4.0, 5.0, 6.0,
332
333
/// 7.0, 8.0, 9.0];
333
- ///
334
+ ///
334
335
/// memcpy_2d_htod(
335
- /// device_buffer,
336
- /// pitch,
336
+ /// device_buffer,
337
+ /// pitch,
337
338
/// src_array.as_slice().as_ptr(),
338
339
/// 3*std::mem::size_of::<f32>(),
339
340
/// 3,
340
341
/// 3
341
342
/// )?;
342
- ///
343
+ ///
343
344
/// let mut dst_array = [0.0f32; 9];
344
345
///
345
346
/// memcpy_2d_dtoh(
346
347
/// dst_array.as_mut_slice().as_mut_ptr(),
347
348
/// 3*std::mem::size_of::<f32>(),
348
- /// device_buffer,
349
- /// pitch,
349
+ /// device_buffer,
350
+ /// pitch,
350
351
/// 3,
351
352
/// 3
352
- /// )?;
353
- ///
353
+ /// )?;
354
+ ///
354
355
/// assert_eq!(dst_array, src_array);
355
356
/// cuda_free(device_buffer)?;
356
357
/// }
@@ -369,7 +370,8 @@ pub unsafe fn memcpy_2d_dtoh<T: DeviceCopy>(
369
370
) -> CudaResult < ( ) > {
370
371
use cust_raw:: CUmemorytype ;
371
372
372
- let width_in_bytes = width. checked_mul ( std:: mem:: size_of :: < T > ( ) )
373
+ let width_in_bytes = width
374
+ . checked_mul ( std:: mem:: size_of :: < T > ( ) )
373
375
. ok_or ( CudaError :: InvalidMemoryAllocation ) ?;
374
376
375
377
let pcopy = cust_raw:: CUDA_MEMCPY2D_st {
@@ -383,8 +385,8 @@ pub unsafe fn memcpy_2d_dtoh<T: DeviceCopy>(
383
385
dstXInBytes : 0 ,
384
386
dstY : 0 ,
385
387
dstMemoryType : CUmemorytype :: CU_MEMORYTYPE_HOST ,
386
- dstHost : dst as * mut c_void ,
387
- dstDevice : 0 , // Ignored
388
+ dstHost : dst as * mut c_void ,
389
+ dstDevice : 0 , // Ignored
388
390
dstArray : std:: ptr:: null_mut :: < cust_raw:: CUarray_st > ( ) , // Ignored
389
391
dstPitch : dpitch,
390
392
WidthInBytes : width_in_bytes,
0 commit comments