| 40 | } |
| 41 | |
| 42 | std::shared_ptr<TensorBatch> TensorBatch::Create(int capacity) |
| 43 | { |
| 44 | std::vector<std::shared_ptr<CacheItem>> vcont = Cache::Instance().fetch(Key{capacity}); |
| 45 | |
| 46 | // None found? |
| 47 | if (vcont.empty()) |
| 48 | { |
| 49 | std::shared_ptr<TensorBatch> batch(new TensorBatch(capacity)); |
| 50 | Cache::Instance().add(*batch); |
| 51 | return batch; |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | // Get the first one |
| 56 | auto batch = std::static_pointer_cast<TensorBatch>(vcont[0]); |
| 57 | batch->clear(); // make sure it's in pristine state |
| 58 | return batch; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | std::shared_ptr<TensorBatch> TensorBatch::WrapExternalBufferVector(std::vector<py::object> buffers, |
| 63 | std::optional<nvcv::TensorLayout> layout) |