mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Merge pull request #16835 from YashasSamaga:cuda4dnn-hotfix-memory-lock
This commit is contained in:
commit
dbb30134bc
@ -276,14 +276,22 @@ namespace cv { namespace dnn { namespace cuda4dnn { namespace csl {
|
|||||||
|
|
||||||
MemoryLockGuard& operator=(const MemoryLockGuard&) = delete;
|
MemoryLockGuard& operator=(const MemoryLockGuard&) = delete;
|
||||||
MemoryLockGuard& operator=(MemoryLockGuard&& other) noexcept {
|
MemoryLockGuard& operator=(MemoryLockGuard&& other) noexcept {
|
||||||
ptr = other.ptr;
|
if (&other != this) {
|
||||||
other.ptr = nullptr;
|
if(ptr != nullptr) {
|
||||||
|
/* cudaHostUnregister does not throw for a valid ptr */
|
||||||
|
CUDA4DNN_CHECK_CUDA(cudaHostUnregister(ptr));
|
||||||
|
}
|
||||||
|
ptr = other.ptr;
|
||||||
|
other.ptr = nullptr;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~MemoryLockGuard() {
|
~MemoryLockGuard() {
|
||||||
if(ptr != nullptr)
|
if(ptr != nullptr) {
|
||||||
|
/* cudaHostUnregister does not throw for a valid ptr */
|
||||||
CUDA4DNN_CHECK_CUDA(cudaHostUnregister(ptr));
|
CUDA4DNN_CHECK_CUDA(cudaHostUnregister(ptr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -308,7 +308,18 @@ namespace cv { namespace dnn {
|
|||||||
|
|
||||||
auto numel = total(shape_);
|
auto numel = total(shape_);
|
||||||
if (numel > shared_block->device.size())
|
if (numel > shared_block->device.size())
|
||||||
|
{
|
||||||
|
/* if the host memory was already page-locked, release it and register again with the new size */
|
||||||
|
shared_block->memGuard = cuda4dnn::csl::MemoryLockGuard();
|
||||||
|
try {
|
||||||
|
CV_Assert(shared_block->host.type() == CV_32F);
|
||||||
|
shared_block->memGuard = cuda4dnn::csl::MemoryLockGuard(shared_block->host.data, numel * sizeof(float));
|
||||||
|
} catch (...) {
|
||||||
|
/* a common reason for failure is that the host system (for example, a Jetson device) does not support it */
|
||||||
|
/* we ignore the failure as this is just an optimization and not a requirement */
|
||||||
|
}
|
||||||
shared_block->device.reset(numel);
|
shared_block->device.reset(numel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Ptr<BackendWrapper> create(Mat& m) {
|
static Ptr<BackendWrapper> create(Mat& m) {
|
||||||
|
Loading…
Reference in New Issue
Block a user