MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / FreeTensor

Function FreeTensor

gpu.hpp:705–716  ·  view source on GitHub ↗

* @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); *

Source from the content-addressed store, hash-verified

703 * @endcode
704 */
705inline 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.

Callers 1

~TensorPoolMethod · 0.85

Calls 1

LOGFunction · 0.85

Tested by

no test coverage detected