* @brief Frees a tensor resource and updates the tensor pool. * * Only needed if the use case requires manually managing resource lifetimes of * GPU tensors. For simple use cases, the TensorPool destructor will * automatically free all tensors. * * @param[in] pool TensorPool instance to manage the tensor * @param[in] tensor Tensor instance to free * * @code * FreeTensor(pool, tensor); *
| 703 | * @endcode |
| 704 | */ |
| 705 | inline void FreeTensor(TensorPool &pool, Tensor tensor) { |
| 706 | if (tensor.data.buffer) { |
| 707 | wgpuBufferRelease(tensor.data.buffer); |
| 708 | } else { |
| 709 | LOG(kDefLog, kWarn, "Tried to free tensor with null buffer"); |
| 710 | } |
| 711 | if (pool.data.find(tensor.data.buffer) != pool.data.end()) { |
| 712 | pool.data.erase(tensor.data.buffer); |
| 713 | } else { |
| 714 | LOG(kDefLog, kWarn, "Tried to free tensor that was not in pool"); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * @brief Destructor for TensorPool which frees all tensors in the pool. |