Skip to content
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/shardcache-runtime/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub struct ConnectorTransferReport {
}

#[derive(Debug)]
// Preserve the public handle shape and keep submission free of a new allocation.
#[allow(clippy::large_enum_variant)]
pub enum ConnectorTransferHandle {
Completed(ConnectorTransferReport),
#[cfg(all(feature = "cuda", target_os = "linux"))]
Expand Down Expand Up @@ -690,7 +692,7 @@ mod tests {
device_ordinal: 0,
stream_ordinal: 0,
allocation_id: 9001,
dst_device_ptr: device_buffer.as_device_ptr().as_raw() as u64,
dst_device_ptr: device_buffer.as_device_ptr().as_raw(),
dst_base_offset_bytes: 0,
}),
&mut engine,
Expand Down Expand Up @@ -748,7 +750,7 @@ mod tests {
device_ordinal: 0,
stream_ordinal: 0,
allocation_id: 9002,
dst_device_ptr: device_buffer.as_device_ptr().as_raw() as u64,
dst_device_ptr: device_buffer.as_device_ptr().as_raw(),
dst_base_offset_bytes: 0,
},
);
Expand Down Expand Up @@ -820,7 +822,7 @@ mod tests {
device_ordinal: 0,
stream_ordinal: 0,
allocation_id: 9003,
dst_device_ptr: device_buffer.as_device_ptr().as_raw() as u64,
dst_device_ptr: device_buffer.as_device_ptr().as_raw(),
dst_base_offset_bytes: 0,
},
);
Expand Down Expand Up @@ -890,7 +892,7 @@ mod tests {
let mut sorted = values.to_vec();
sorted.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
let mid = sorted.len() / 2;
if sorted.len() % 2 == 0 {
if sorted.len().is_multiple_of(2) {
(sorted[mid - 1] + sorted[mid]) / 2.0
} else {
sorted[mid]
Expand All @@ -907,6 +909,8 @@ mod tests {
}

#[cfg(all(feature = "cuda", target_os = "linux"))]
// Keep the independent CUDA benchmark dimensions visible at each call site.
#[allow(clippy::too_many_arguments)]
fn run_real_cuda_benchmark_case(
case_name: &str,
cuda: shardmap::cuda::CudaConfig,
Expand Down Expand Up @@ -959,7 +963,7 @@ mod tests {
device_ordinal: 0,
stream_ordinal: 0,
allocation_id: 9100,
dst_device_ptr: device_buffer.as_device_ptr().as_raw() as u64,
dst_device_ptr: device_buffer.as_device_ptr().as_raw(),
dst_base_offset_bytes: 0,
},
);
Expand Down
73 changes: 39 additions & 34 deletions crates/shardcache-runtime/src/cuda_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,10 @@ impl CudaTransferEngine {
let aligned = aligned_host_range(ptr, len, HOST_PAGE_BYTES)?;
let existing = self.registered_host_ranges();
for uncovered in uncovered_host_ranges(aligned, &existing) {
crate::cuda_ffi::register_host_region(uncovered.start as *mut u8, uncovered.len())?;
crate::cuda_ffi::register_host_region(
uncovered.start as *mut u8,
uncovered.end - uncovered.start,
)?;
self.temporary_registered_regions
.push(RegisteredHostRegion { range: uncovered });
}
Expand All @@ -499,7 +502,10 @@ impl CudaTransferEngine {
let mut existing = Vec::with_capacity(self.cached_session_views.len());
for cached in &self.cached_session_views {
for uncovered in uncovered_host_ranges(cached.range, &existing) {
crate::cuda_ffi::register_host_region(uncovered.start as *mut u8, uncovered.len())?;
crate::cuda_ffi::register_host_region(
uncovered.start as *mut u8,
uncovered.end - uncovered.start,
)?;
self.persistent_registered_regions
.push(RegisteredHostRegion { range: uncovered });
existing.push(uncovered);
Expand Down Expand Up @@ -576,26 +582,26 @@ impl CudaTransferEngine {
continue;
}

if matches!(transfer.target(), RuntimeTransferTarget::Gpu(_)) {
if let Some(plan) = detect_strided_host_copy_plan(
if matches!(transfer.target(), RuntimeTransferTarget::Gpu(_))
&& let Some(plan) = detect_strided_host_copy_plan(
&packed.offsets,
&packed.lengths,
&dst_offsets,
index,
) {
let src = unsafe { src_base.add(plan.src_offset) };
self.submit_host_copy_2d(
transfer.target(),
&descriptors[index],
src,
plan.row_bytes,
plan.row_count,
plan.dst_pitch,
)?;
index += plan.row_count;
self.advance_stream();
continue;
}
)
{
let src = unsafe { src_base.add(plan.src_offset) };
self.submit_host_copy_2d(
transfer.target(),
&descriptors[index],
src,
plan.row_bytes,
plan.row_count,
plan.dst_pitch,
)?;
index += plan.row_count;
self.advance_stream();
continue;
}

let start_index = index;
Expand Down Expand Up @@ -669,23 +675,22 @@ impl CudaTransferEngine {
continue;
}

if matches!(transfer.target(), RuntimeTransferTarget::Gpu(_)) {
if let Some(plan) =
if matches!(transfer.target(), RuntimeTransferTarget::Gpu(_))
&& let Some(plan) =
detect_strided_host_copy_plan(offsets, lengths, &dst_offsets, index)
{
let src = unsafe { src_base.add(plan.src_offset) };
self.submit_host_copy_2d(
transfer.target(),
&descriptors[index],
src,
plan.row_bytes,
plan.row_count,
plan.dst_pitch,
)?;
index += plan.row_count;
self.advance_stream();
continue;
}
{
let src = unsafe { src_base.add(plan.src_offset) };
self.submit_host_copy_2d(
transfer.target(),
&descriptors[index],
src,
plan.row_bytes,
plan.row_count,
plan.dst_pitch,
)?;
index += plan.row_count;
self.advance_stream();
continue;
}

let start_index = index;
Expand Down
Loading