diff --git a/crates/cust/src/memory/malloc.rs b/crates/cust/src/memory/malloc.rs index 890a1ce3..b46a87a9 100644 --- a/crates/cust/src/memory/malloc.rs +++ b/crates/cust/src/memory/malloc.rs @@ -149,9 +149,9 @@ pub unsafe fn cuda_malloc_unified<T: DeviceCopy>(count: usize) -> CudaResult<Uni } /// Unsafe wrapper around the `cuMemAllocPitch` function, which allocates device memory in two dimensions -/// where rows are memory aligned to the containing datatype. -/// -/// Returns a [`DevicePointer`](struct.DevicePointer.html), pointing to the allocated memory and +/// where rows are memory aligned to the containing datatype. +/// +/// Returns a [`DevicePointer`](struct.DevicePointer.html), pointing to the allocated memory and /// an `usize` containing the row pitch in *bytes*. The memory is not cleared. /// /// 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 /// # } /// # foo().unwrap(); /// ``` -pub unsafe fn cuda_malloc_pitched<T: DeviceCopy>(width: usize, height: usize) -> CudaResult<(DevicePointer<T>, usize)> { +pub unsafe fn cuda_malloc_pitched<T: DeviceCopy>( + width: usize, + height: usize, +) -> CudaResult<(DevicePointer<T>, usize)> { let element_size: std::os::raw::c_uint = std::mem::size_of::<T>() .try_into() .map_err(|_| CudaError::InvalidMemoryAllocation)?; @@ -198,7 +201,8 @@ pub unsafe fn cuda_malloc_pitched<T: DeviceCopy>(width: usize, height: usize) -> let mut ptr = 0; let mut pitch = 0; - cuda::cuMemAllocPitch_v2(&mut ptr, &mut pitch, width_bytes, height, element_size).to_result()?; + cuda::cuMemAllocPitch_v2(&mut ptr, &mut pitch, width_bytes, height, element_size) + .to_result()?; Ok((DevicePointer::from_raw(ptr), pitch)) } diff --git a/crates/cust/src/memory/mod.rs b/crates/cust/src/memory/mod.rs index d8caa736..152f1cfe 100644 --- a/crates/cust/src/memory/mod.rs +++ b/crates/cust/src/memory/mod.rs @@ -226,11 +226,11 @@ pub unsafe fn memcpy_dtoh( } /// Similar to `cudaMemcpy2D` with `HostToDevice` copy type. -/// +/// /// `dpitch`/`spitch` is bytes between the start of two rows. /// `width` is the number of *elements* (not bytes) in a row. /// `height` is the total number of rows (not bytes). -/// +/// /// # Examples /// /// ``` @@ -240,32 +240,32 @@ pub unsafe fn memcpy_dtoh( /// unsafe { /// // Allocate space for a 3x3 matrix of f32s /// let (device_buffer, pitch) = cuda_malloc_pitched::<f32>(3, 3)?; -/// +/// /// let src_array: [f32; 9] = [ -/// 1.0, 2.0, 3.0, -/// 4.0, 5.0, 6.0, +/// 1.0, 2.0, 3.0, +/// 4.0, 5.0, 6.0, /// 7.0, 8.0, 9.0]; -/// +/// /// memcpy_2d_htod( -/// device_buffer, -/// pitch, +/// device_buffer, +/// pitch, /// src_array.as_slice().as_ptr(), /// 3*std::mem::size_of::<f32>(), /// 3, /// 3 /// )?; -/// +/// /// let mut dst_array = [0.0f32; 9]; /// /// memcpy_2d_dtoh( /// dst_array.as_mut_slice().as_mut_ptr(), /// 3*std::mem::size_of::<f32>(), -/// device_buffer, -/// pitch, +/// device_buffer, +/// pitch, /// 3, /// 3 -/// )?; -/// +/// )?; +/// /// assert_eq!(dst_array, src_array); /// cuda_free(device_buffer)?; /// } @@ -284,7 +284,8 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>( ) -> CudaResult<()> { use cust_raw::CUmemorytype; - let width_in_bytes = width.checked_mul(std::mem::size_of::<T>()) + let width_in_bytes = width + .checked_mul(std::mem::size_of::<T>()) .ok_or(CudaError::InvalidMemoryAllocation)?; let pcopy = cust_raw::CUDA_MEMCPY2D_st { @@ -292,7 +293,7 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>( srcY: 0, srcMemoryType: CUmemorytype::CU_MEMORYTYPE_HOST, srcHost: src as *const c_void, - srcDevice: 0, // Ignored + srcDevice: 0, // Ignored srcArray: std::ptr::null_mut::<cust_raw::CUarray_st>(), // Ignored srcPitch: spitch, dstXInBytes: 0, @@ -311,11 +312,11 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>( } /// Similar to `cudaMemcpy2D` with `DeviceToHost` copy type. -/// +/// /// `dpitch`/`spitch` is bytes between the start of two rows. /// `width` is the number of *elements* (not bytes) in a row. /// `height` is the total number of rows (not bytes). -/// +/// /// # Examples /// /// ``` @@ -325,32 +326,32 @@ pub unsafe fn memcpy_2d_htod<T: DeviceCopy>( /// unsafe { /// // Allocate space for a 3x3 matrix of f32s /// let (device_buffer, pitch) = cuda_malloc_pitched::<f32>(3, 3)?; -/// +/// /// let src_array: [f32; 9] = [ -/// 1.0, 2.0, 3.0, -/// 4.0, 5.0, 6.0, +/// 1.0, 2.0, 3.0, +/// 4.0, 5.0, 6.0, /// 7.0, 8.0, 9.0]; -/// +/// /// memcpy_2d_htod( -/// device_buffer, -/// pitch, +/// device_buffer, +/// pitch, /// src_array.as_slice().as_ptr(), /// 3*std::mem::size_of::<f32>(), /// 3, /// 3 /// )?; -/// +/// /// let mut dst_array = [0.0f32; 9]; /// /// memcpy_2d_dtoh( /// dst_array.as_mut_slice().as_mut_ptr(), /// 3*std::mem::size_of::<f32>(), -/// device_buffer, -/// pitch, +/// device_buffer, +/// pitch, /// 3, /// 3 -/// )?; -/// +/// )?; +/// /// assert_eq!(dst_array, src_array); /// cuda_free(device_buffer)?; /// } @@ -369,7 +370,8 @@ pub unsafe fn memcpy_2d_dtoh<T: DeviceCopy>( ) -> CudaResult<()> { use cust_raw::CUmemorytype; - let width_in_bytes = width.checked_mul(std::mem::size_of::<T>()) + let width_in_bytes = width + .checked_mul(std::mem::size_of::<T>()) .ok_or(CudaError::InvalidMemoryAllocation)?; let pcopy = cust_raw::CUDA_MEMCPY2D_st { @@ -383,8 +385,8 @@ pub unsafe fn memcpy_2d_dtoh<T: DeviceCopy>( dstXInBytes: 0, dstY: 0, dstMemoryType: CUmemorytype::CU_MEMORYTYPE_HOST, - dstHost: dst as *mut c_void, - dstDevice: 0, // Ignored + dstHost: dst as *mut c_void, + dstDevice: 0, // Ignored dstArray: std::ptr::null_mut::<cust_raw::CUarray_st>(), // Ignored dstPitch: dpitch, WidthInBytes: width_in_bytes, diff --git a/crates/rustc_codegen_nvvm/build.rs b/crates/rustc_codegen_nvvm/build.rs index dfb85985..2b663329 100644 --- a/crates/rustc_codegen_nvvm/build.rs +++ b/crates/rustc_codegen_nvvm/build.rs @@ -75,7 +75,10 @@ fn find_llvm_config(target: &str) -> PathBuf { if version.starts_with(&REQUIRED_MAJOR_LLVM_VERSION.to_string()) { return PathBuf::from(path_to_try); } - println!("cargo:warning=Prebuilt llvm-config version does not start with {}", REQUIRED_MAJOR_LLVM_VERSION); + println!( + "cargo:warning=Prebuilt llvm-config version does not start with {}", + REQUIRED_MAJOR_LLVM_VERSION + ); } else { println!("cargo:warning=Failed to run prebuilt llvm-config"); }