Skip to content

Conversation

@wizenink
Copy link
Contributor

@wizenink wizenink commented Nov 1, 2025

[DRAFT] Adds low-level support for 2D/3D pitched memory allocation and transfers. Safe API wrappers
to follow.

Changes

  • Result layer: Added wrappers for pitched memory operations:
    • malloc_pitched() - Allocate 2D memory with GPU-optimized row alignment
    • memcpy_2d_async() / memcpy_2d_sync() - 2D memory transfers
    • memcpy_3d_async() / memcpy_3d_sync() - 3D memory transfers
  • Example: Added 11-pitched-memory.rs demonstrating:
    • Pitched allocation (512-byte aligned rows for 32-byte data)
    • Host <-> Device 2D transfers
    • Sub-region (strided) copying
    • Data verification

Usage (unsafe for now)

let (device_ptr, pitch) = unsafe {
    result::malloc_pitched(width_bytes, height, elem_size)?
};

let copy_params = sys::CUDA_MEMCPY2D { /* ... */ };
unsafe { result::memcpy_2d_async(&copy_params, stream)? };

TODO (before marking ready for review)

  • Design safe API (CudaPitched2D, CudaPitched3D types)
  • Implement builder pattern for copy operations
  • Add safe wrapper methods to CudaStream

@wizenink
Copy link
Contributor Author

wizenink commented Nov 1, 2025

@coreylowman Any tips or preferences on how to design the safe API? Might have some time to implement this later tonight.
BTW, thank you for your work, really loving this bindings, very idiomatic :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant