Cache a dispatch output buffer by the returned Tensor's TensorId. If the next dispatch consumes this tensor, `get_or_upload` will find the buffer here and skip the re-upload.
(&self, tensor_id: TensorId, buf: MappedBuffer)
| 550 | /// If the next dispatch consumes this tensor, `get_or_upload` will find |
| 551 | /// the buffer here and skip the re-upload. |
| 552 | fn cache_activation(&self, tensor_id: TensorId, buf: MappedBuffer) { |
| 553 | let buf = Arc::new(buf); |
| 554 | let mut act_cache = self.activation_cache.lock().unwrap(); |
| 555 | if act_cache.len() >= 16 { |
| 556 | // Evict oldest entry, release its buffer back to pool |
| 557 | let (_, old_buf) = act_cache.remove(0); |
| 558 | if let Ok(old) = Arc::try_unwrap(old_buf) { |
| 559 | self.release_output(old); |
| 560 | } |
| 561 | } |
| 562 | act_cache.push((tensor_id, buf)); |
| 563 | } |
| 564 | |
| 565 | /// Compute a stable cache key from tensor's storage pointer + layout. |
| 566 | /// Survives `.t()` calls which create new TensorIds but share storage. |
no test coverage detected