| 150 | } // namespace |
| 151 | |
| 152 | std::shared_ptr<Tensor> Tensor::Wrap(ExternalBuffer &buffer, std::optional<nvcv::TensorLayout> layout) |
| 153 | { |
| 154 | const DLTensor &dlTensor = buffer.dlTensor(); |
| 155 | |
| 156 | nvcv::TensorDataStridedCuda data{FillNVCVTensorDataCUDA(dlTensor, std::move(layout))}; |
| 157 | |
| 158 | // This is the key of a tensor wrapper. |
| 159 | // All tensor wrappers have the same key. |
| 160 | Tensor::Key key; |
| 161 | // We take this opportunity to remove from cache all wrappers that aren't |
| 162 | // being used. They aren't reusable anyway. |
| 163 | Cache::Instance().removeAllNotInUseMatching(key); |
| 164 | |
| 165 | auto tensor = std::shared_ptr<Tensor>(new Tensor(data, py::cast(buffer.shared_from_this()))); |
| 166 | |
| 167 | // Need to add wrappers to cache so that they don't get destroyed by |
| 168 | // the cuda stream when they're last used, and python script isn't |
| 169 | // holding a reference to them. If we don't do it, things might break. |
| 170 | Cache::Instance().add(*tensor); |
| 171 | return tensor; |
| 172 | } |
| 173 | |
| 174 | std::shared_ptr<Tensor> Tensor::WrapImage(Image &img) |
| 175 | { |
nothing calls this directly
no test coverage detected