Skip to content
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

Fix formatting #134

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions crates/cust/src/memory/malloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
Expand All @@ -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))
}

Expand Down
64 changes: 33 additions & 31 deletions crates/cust/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
/// ```
Expand All @@ -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)?;
/// }
Expand All @@ -284,15 +284,16 @@ 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 {
srcXInBytes: 0,
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,
Expand All @@ -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
///
/// ```
Expand All @@ -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)?;
/// }
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion crates/rustc_codegen_nvvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Loading