| 339 | } |
| 340 | |
| 341 | at::Tensor offloadTensor(at::Tensor tensor, long id) |
| 342 | { |
| 343 | if (!hasKey(offload_events_, id)) { |
| 344 | offload_events_[id] = std::make_shared<at::cuda::CUDAEvent>(cudaEventDisableTiming); |
| 345 | offload_comp_done_events_[id] = |
| 346 | std::make_shared<at::cuda::CUDAEvent>(cudaEventDisableTiming); |
| 347 | |
| 348 | // Pin by default so async D2H/H2D can use full PCIe bandwidth; controlled by |
| 349 | // compile.offload_activation_pin_memory. |
| 350 | const auto options = at::TensorOptions() |
| 351 | .pinned_memory(offload_activation_pin_memory) |
| 352 | .device(torch::kCPU); |
| 353 | offload_buffers_[id] = at::empty_like(tensor, options); |
| 354 | } |
| 355 | |
| 356 | offload_comp_done_events_[id]->record(); |
| 357 | offload_comp_done_events_[id]->block(offload_stream_); |
| 358 | { |
| 359 | at::cuda::CUDAStreamGuard guard(offload_stream_); |
| 360 | offload_buffers_.at(id).copy_(tensor, true); |
| 361 | } |
| 362 | |
| 363 | tensor.record_stream(offload_stream_); |
| 364 | |
| 365 | offload_events_[id]->record(offload_stream_); |
| 366 | assert(hasKey(offload_buffers_, id)); |
| 367 | return offload_buffers_.at(id); |
| 368 | } |
| 369 | |
| 370 | at::Tensor reloadTensor(at::Tensor tensor, long id) |
| 371 | { |
no test coverage detected