gpu.cpp 0.1.0
 
Loading...
Searching...
No Matches
gpu::TensorPool Struct Reference

Represents a pool of tensors to manage GPU resources. The pool is responsible for managing the lifetime of the tensors and freeing them when the pool is destroyed. More...

#include <gpu.h>

Public Member Functions

 TensorPool (Context *ctx)
 
 ~TensorPool ()
 Destructor for TensorPool which frees all tensors in the pool.
 

Public Attributes

Contextctx
 
std::unordered_map< WGPUBuffer, Tensordata
 

Detailed Description

Represents a pool of tensors to manage GPU resources. The pool is responsible for managing the lifetime of the tensors and freeing them when the pool is destroyed.

Most users do not need to interact with the TensorPool type, as there is a member instance in the Context struct to simplify lifetime management of GPU resources.

Definition at line 176 of file gpu.h.

Constructor & Destructor Documentation

◆ TensorPool()

gpu::TensorPool::TensorPool ( Context * ctx)
inline

Definition at line 177 of file gpu.h.

177: ctx(ctx), data() {};
Context * ctx
Definition gpu.h:178
std::unordered_map< WGPUBuffer, Tensor > data
Definition gpu.h:179

◆ ~TensorPool()

gpu::TensorPool::~TensorPool ( )
inline

Destructor for TensorPool which frees all tensors in the pool.

Definition at line 624 of file gpu.h.

624 {
625 // Need to get keys in a separate iteration, otherwise iterator is getting
626 // invalidated during erase.
627 std::vector<WGPUBuffer> keys;
628 for (auto &pair : data) {
629 keys.push_back(pair.first);
630 }
631 for (auto &key : keys) {
632 FreeTensor(*this, data[key]);
633 LOG(kDefLog, kTrace, "Freed tensor");
634 }
635}
static Logger kDefLog
Default logger for logging messages to stdout at the info level. Output stream and logging level for ...
Definition logging.h:64
void FreeTensor(TensorPool &pool, Tensor tensor)
Frees a tensor resource and updates the tensor pool.
Definition gpu.h:608
void LOG(Logger &logger, int level, const char *message,...)
Log a message to the logger. If NDEBUG is defined in a source or as a compiler flag,...
Definition logging.h:34
@ kTrace
Definition logging.h:9

Member Data Documentation

◆ ctx

Context* gpu::TensorPool::ctx

Definition at line 178 of file gpu.h.

◆ data

std::unordered_map<WGPUBuffer, Tensor> gpu::TensorPool::data

Definition at line 179 of file gpu.h.


The documentation for this struct was generated from the following file: