mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* hold async data and wait only at the end of the pipeline * fix use-after-free bugs * fix wording * bypass trivial cases for Pad to avoid ppl.cv's bug * fix pad * fix lint * cleanup * fix DefaultFormatBundle * fix all cpu preprocess impl * suppress log * fix dynamic library build & add comments for SyncOnScopeExit
43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#include "device_utils.h"
|
|
|
|
#include "core/logger.h"
|
|
|
|
namespace mmdeploy {
|
|
|
|
Result<Mat> MakeAvailableOnDevice(const Mat& src, const Device& device, Stream& stream) {
|
|
if (src.device() == device) {
|
|
return src;
|
|
}
|
|
|
|
Mat dst{src.height(), src.width(), src.pixel_format(), src.type(), device};
|
|
OUTCOME_TRY(stream.Copy(src.buffer(), dst.buffer(), dst.byte_size()));
|
|
return dst;
|
|
}
|
|
|
|
Result<Tensor> MakeAvailableOnDevice(const Tensor& src, const Device& device, Stream& stream) {
|
|
if (src.device() == device) {
|
|
return src;
|
|
}
|
|
|
|
TensorDesc desc{device, src.data_type(), src.shape(), src.name()};
|
|
Tensor dst(desc);
|
|
|
|
OUTCOME_TRY(stream.Copy(src.buffer(), dst.buffer(), src.byte_size()));
|
|
|
|
return dst;
|
|
}
|
|
|
|
SyncOnScopeExit::~SyncOnScopeExit() {
|
|
if (active_ && stream_) {
|
|
if (!stream_.Wait()) {
|
|
MMDEPLOY_ERROR("Implicit stream synchronization failed.");
|
|
} else {
|
|
MMDEPLOY_DEBUG("Implicit stream synchronization succeeded.");
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace mmdeploy
|