Skip to content

Commit 1b56eb0

Browse files
authored
Fix formatting (#134)
1 parent a3dc410 commit 1b56eb0

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

crates/cust/src/memory/malloc.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ pub unsafe fn cuda_malloc_unified<T: DeviceCopy>(count: usize) -> CudaResult<Uni
149149
}
150150

151151
/// Unsafe wrapper around the `cuMemAllocPitch` function, which allocates device memory in two dimensions
152-
/// where rows are memory aligned to the containing datatype.
153-
///
154-
/// Returns a [`DevicePointer`](struct.DevicePointer.html), pointing to the allocated memory and
152+
/// where rows are memory aligned to the containing datatype.
153+
///
154+
/// Returns a [`DevicePointer`](struct.DevicePointer.html), pointing to the allocated memory and
155155
/// an `usize` containing the row pitch in *bytes*. The memory is not cleared.
156156
///
157157
/// Note that `count` is in units of T; thus a `count` of 3 will allocate `3 * size_of::<T>()` bytes
@@ -186,7 +186,10 @@ pub unsafe fn cuda_malloc_unified<T: DeviceCopy>(count: usize) -> CudaResult<Uni
186186
/// # }
187187
/// # foo().unwrap();
188188
/// ```
189-
pub unsafe fn cuda_malloc_pitched<T: DeviceCopy>(width: usize, height: usize) -> CudaResult<(DevicePointer<T>, usize)> {
189+
pub unsafe fn cuda_malloc_pitched<T: DeviceCopy>(
190+
width: usize,
191+
height: usize,
192+
) -> CudaResult<(DevicePointer<T>, usize)> {
190193
let element_size: std::os::raw::c_uint = std::mem::size_of::<T>()
191194
.try_into()
192195
.map_err(|_| CudaError::InvalidMemoryAllocation)?;
@@ -198,7 +201,8 @@ pub unsafe fn cuda_malloc_pitched<T: DeviceCopy>(width: usize, height: usize) ->
198201

199202
let mut ptr = 0;
200203
let mut pitch = 0;
201-
cuda::cuMemAllocPitch_v2(&mut ptr, &mut pitch, width_bytes, height, element_size).to_result()?;
204+
cuda::cuMemAllocPitch_v2(&mut ptr, &mut pitch, width_bytes, height, element_size)
205+
.to_result()?;
202206
Ok((DevicePointer::from_raw(ptr), pitch))
203207
}
204208

crates/cust/src/memory/mod.rs

+33-31
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ pub unsafe fn memcpy_dtoh(
226226
}
227227

228228
/// Similar to `cudaMemcpy2D` with `HostToDevice` copy type.
229-
///
229+
///
230230
/// `dpitch`/`spitch` is bytes between the start of two rows.
231231
/// `width` is the number of *elements* (not bytes) in a row.
232232
/// `height` is the total number of rows (not bytes).
233-
///
233+
///
234234
/// # Examples
235235
///
236236
/// ```
@@ -240,32 +240,32 @@ pub unsafe fn memcpy_dtoh(
240240
/// unsafe {
241241
/// // Allocate space for a 3x3 matrix of f32s
242242
/// let (device_buffer, pitch) = cuda_malloc_pitched::<f32>(3, 3)?;
243-
///
243+
///
244244
/// 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,
247247
/// 7.0, 8.0, 9.0];
248-
///
248+
///
249249
/// memcpy_2d_htod(
250-
/// device_buffer,
251-
/// pitch,
250+
/// device_buffer,
251+
/// pitch,
252252
/// src_array.as_slice().as_ptr(),
253253
/// 3*std::mem::size_of::<f32>(),
254254
/// 3,
255255
/// 3
256256
/// )?;
257-
///
257+
///
258258
/// let mut dst_array = [0.0f32; 9];
259259
///
260260
/// memcpy_2d_dtoh(
261261
/// dst_array.as_mut_slice().as_mut_ptr(),
262262
/// 3*std::mem::size_of::<f32>(),
263-
/// device_buffer,
264-
/// pitch,
263+
/// device_buffer,
264+
/// pitch,
265265
/// 3,
266266
/// 3
267-
/// )?;
268-
///
267+
/// )?;
268+
///
269269
/// assert_eq!(dst_array, src_array);
270270
/// cuda_free(device_buffer)?;
271271
/// }
@@ -284,15 +284,16 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>(
284284
) -> CudaResult<()> {
285285
use cust_raw::CUmemorytype;
286286

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>())
288289
.ok_or(CudaError::InvalidMemoryAllocation)?;
289290

290291
let pcopy = cust_raw::CUDA_MEMCPY2D_st {
291292
srcXInBytes: 0,
292293
srcY: 0,
293294
srcMemoryType: CUmemorytype::CU_MEMORYTYPE_HOST,
294295
srcHost: src as *const c_void,
295-
srcDevice: 0, // Ignored
296+
srcDevice: 0, // Ignored
296297
srcArray: std::ptr::null_mut::<cust_raw::CUarray_st>(), // Ignored
297298
srcPitch: spitch,
298299
dstXInBytes: 0,
@@ -311,11 +312,11 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>(
311312
}
312313

313314
/// Similar to `cudaMemcpy2D` with `DeviceToHost` copy type.
314-
///
315+
///
315316
/// `dpitch`/`spitch` is bytes between the start of two rows.
316317
/// `width` is the number of *elements* (not bytes) in a row.
317318
/// `height` is the total number of rows (not bytes).
318-
///
319+
///
319320
/// # Examples
320321
///
321322
/// ```
@@ -325,32 +326,32 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>(
325326
/// unsafe {
326327
/// // Allocate space for a 3x3 matrix of f32s
327328
/// let (device_buffer, pitch) = cuda_malloc_pitched::<f32>(3, 3)?;
328-
///
329+
///
329330
/// 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,
332333
/// 7.0, 8.0, 9.0];
333-
///
334+
///
334335
/// memcpy_2d_htod(
335-
/// device_buffer,
336-
/// pitch,
336+
/// device_buffer,
337+
/// pitch,
337338
/// src_array.as_slice().as_ptr(),
338339
/// 3*std::mem::size_of::<f32>(),
339340
/// 3,
340341
/// 3
341342
/// )?;
342-
///
343+
///
343344
/// let mut dst_array = [0.0f32; 9];
344345
///
345346
/// memcpy_2d_dtoh(
346347
/// dst_array.as_mut_slice().as_mut_ptr(),
347348
/// 3*std::mem::size_of::<f32>(),
348-
/// device_buffer,
349-
/// pitch,
349+
/// device_buffer,
350+
/// pitch,
350351
/// 3,
351352
/// 3
352-
/// )?;
353-
///
353+
/// )?;
354+
///
354355
/// assert_eq!(dst_array, src_array);
355356
/// cuda_free(device_buffer)?;
356357
/// }
@@ -369,7 +370,8 @@ pub unsafe fn memcpy_2d_dtoh<T: DeviceCopy>(
369370
) -> CudaResult<()> {
370371
use cust_raw::CUmemorytype;
371372

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>())
373375
.ok_or(CudaError::InvalidMemoryAllocation)?;
374376

375377
let pcopy = cust_raw::CUDA_MEMCPY2D_st {
@@ -383,8 +385,8 @@ pub unsafe fn memcpy_2d_dtoh<T: DeviceCopy>(
383385
dstXInBytes: 0,
384386
dstY: 0,
385387
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
388390
dstArray: std::ptr::null_mut::<cust_raw::CUarray_st>(), // Ignored
389391
dstPitch: dpitch,
390392
WidthInBytes: width_in_bytes,

crates/rustc_codegen_nvvm/build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ fn find_llvm_config(target: &str) -> PathBuf {
7575
if version.starts_with(&REQUIRED_MAJOR_LLVM_VERSION.to_string()) {
7676
return PathBuf::from(path_to_try);
7777
}
78-
println!("cargo:warning=Prebuilt llvm-config version does not start with {}", REQUIRED_MAJOR_LLVM_VERSION);
78+
println!(
79+
"cargo:warning=Prebuilt llvm-config version does not start with {}",
80+
REQUIRED_MAJOR_LLVM_VERSION
81+
);
7982
} else {
8083
println!("cargo:warning=Failed to run prebuilt llvm-config");
8184
}

0 commit comments

Comments
 (0)