MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / Wrap

Method Wrap

python/mod_cvcuda/nvcv/Tensor.cpp:152–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150} // namespace
151
152std::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
174std::shared_ptr<Tensor> Tensor::WrapImage(Image &img)
175{

Callers

nothing calls this directly

Calls 5

FillNVCVTensorDataCUDAFunction · 0.85
castFunction · 0.85
shared_from_thisMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected