mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 12:22:51 +08:00
Fix Halide buffer behavior in case of OpenCL device memory allocation
This commit is contained in:
parent
1d4a29f149
commit
4e28c00e7b
@ -76,6 +76,7 @@ HalideBackendNode::HalideBackendNode(const Ptr<HalideBackendNode>& base,
|
|||||||
HalideBackendWrapper::HalideBackendWrapper(int targetId, const cv::Mat& m)
|
HalideBackendWrapper::HalideBackendWrapper(int targetId, const cv::Mat& m)
|
||||||
: BackendWrapper(DNN_BACKEND_HALIDE, targetId)
|
: BackendWrapper(DNN_BACKEND_HALIDE, targetId)
|
||||||
{
|
{
|
||||||
|
managesDevMemory = true;
|
||||||
buffer = wrapToHalideBuffer(m);
|
buffer = wrapToHalideBuffer(m);
|
||||||
if (targetId == DNN_TARGET_CPU)
|
if (targetId == DNN_TARGET_CPU)
|
||||||
{
|
{
|
||||||
@ -95,6 +96,7 @@ HalideBackendWrapper::HalideBackendWrapper(const Ptr<BackendWrapper>& base,
|
|||||||
const MatShape& shape)
|
const MatShape& shape)
|
||||||
: BackendWrapper(DNN_BACKEND_HALIDE, base->targetId)
|
: BackendWrapper(DNN_BACKEND_HALIDE, base->targetId)
|
||||||
{
|
{
|
||||||
|
managesDevMemory = false;
|
||||||
int w, h, c, n;
|
int w, h, c, n;
|
||||||
getCanonicalSize(shape, &w, &h, &c, &n);
|
getCanonicalSize(shape, &w, &h, &c, &n);
|
||||||
Halide::Buffer<float> baseBuffer = halideBuffer(base);
|
Halide::Buffer<float> baseBuffer = halideBuffer(base);
|
||||||
@ -113,6 +115,16 @@ HalideBackendWrapper::HalideBackendWrapper(const Ptr<BackendWrapper>& base,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HalideBackendWrapper::~HalideBackendWrapper()
|
||||||
|
{
|
||||||
|
if (buffer.has_device_allocation() && !managesDevMemory)
|
||||||
|
{
|
||||||
|
buffer.raw_buffer()->device = 0;
|
||||||
|
buffer.raw_buffer()->device_interface = 0;
|
||||||
|
buffer.set_device_dirty(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HalideBackendWrapper::copyToHost()
|
void HalideBackendWrapper::copyToHost()
|
||||||
{
|
{
|
||||||
CV_Assert(targetId == DNN_TARGET_CPU || buffer.device_dirty());
|
CV_Assert(targetId == DNN_TARGET_CPU || buffer.device_dirty());
|
||||||
|
@ -57,9 +57,14 @@ namespace dnn
|
|||||||
|
|
||||||
HalideBackendWrapper(const Ptr<BackendWrapper>& base, const MatShape& shape);
|
HalideBackendWrapper(const Ptr<BackendWrapper>& base, const MatShape& shape);
|
||||||
|
|
||||||
|
~HalideBackendWrapper();
|
||||||
|
|
||||||
virtual void copyToHost();
|
virtual void copyToHost();
|
||||||
|
|
||||||
Halide::Buffer<float> buffer;
|
Halide::Buffer<float> buffer;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool managesDevMemory;
|
||||||
};
|
};
|
||||||
#endif // HAVE_HALIDE
|
#endif // HAVE_HALIDE
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user