| 117 | } // namespace |
| 118 | |
| 119 | std::shared_ptr<Array> Array::Wrap(ExternalBuffer &buffer) |
| 120 | { |
| 121 | const DLTensor &dlTensor = buffer.dlTensor(); |
| 122 | |
| 123 | nvcv::ArrayDataCuda data{FillNVCVArrayDataCUDA(dlTensor)}; |
| 124 | |
| 125 | // This is the key of a tensor wrapper. |
| 126 | // All tensor wrappers have the same key. |
| 127 | Array::Key key; |
| 128 | // We take this opportunity to remove from cache all wrappers that aren't |
| 129 | // being used. They aren't reusable anyway. |
| 130 | Cache::Instance().removeAllNotInUseMatching(key); |
| 131 | |
| 132 | auto array = std::shared_ptr<Array>(new Array(data, py::cast(buffer.shared_from_this()))); |
| 133 | |
| 134 | // Need to add wrappers to cache so that they don't get destroyed by |
| 135 | // the cuda stream when they're last used, and python script isn't |
| 136 | // holding a reference to them. If we don't do it, things might break. |
| 137 | Cache::Instance().add(*array); |
| 138 | return array; |
| 139 | } |
| 140 | |
| 141 | std::shared_ptr<Array> Array::ResizeArray(Array &array, int64_t length) |
| 142 | { |
nothing calls this directly
no test coverage detected