Skip to content

Commit

Permalink
cudaFree
Browse files Browse the repository at this point in the history
  • Loading branch information
benfred committed Feb 12, 2024
1 parent 346f6cf commit 291c140
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rust/cuvs/src/dlpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ impl ManagedTensor {

let mut ret = self.0.clone();
ret.dl_tensor.data = device_data;
// call cudaFree automatically to clean up data
ret.deleter = Some(cuda_free_tensor);
ret.dl_tensor.device.device_type = ffi::DLDeviceType::kDLCUDA;
// TODO: do we need to set the device id here too?
// TODO: set deleter here to call cudaFree

Ok(ManagedTensor(ret))
}
}
}

unsafe extern "C" fn cuda_free_tensor(self_: *mut ffi::DLManagedTensor) {
let _ = ffi::cudaFree((*self_).dl_tensor.data);
}

impl Drop for ManagedTensor {
fn drop(&mut self) {
unsafe {
Expand Down

0 comments on commit 291c140

Please sign in to comment.