Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/fastcv/include/opencv2/fastcv/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ class QcResourceManager {
/**
* @brief Qualcomm's custom allocator.
* This allocator uses Qualcomm's memory management functions.
*
* Note: The userdata field of cv::UMatData is used to store the file descriptor (fd) of the allocated memory.
*
*/
class QcAllocator : public cv::MatAllocator {
public:
QcAllocator();
~QcAllocator();

cv::UMatData* allocate(int dims, const int* sizes, int type, void* data0, size_t* step, cv::AccessFlag flags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE;
bool allocate(cv::UMatData* u, cv::AccessFlag accessFlags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE;
void deallocate(cv::UMatData* u) const CV_OVERRIDE;
Expand Down
8 changes: 7 additions & 1 deletion modules/fastcv/src/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ cv::UMatData* QcAllocator::allocate(int dims, const int* sizes, int type,
}
total *= sizes[i];
}
uchar* data = data0 ? (uchar*)data0 : (uchar*)fcvHwMemAlloc(total, 16);

int fd = -1;
uchar* data = data0 ? (uchar*)data0 : (uchar*)fcvHwMemAlloc(total, 16, &fd);
cv::UMatData* u = new cv::UMatData(this);
u->data = u->origdata = data;
u->size = total;
if(data0)
u->flags |= cv::UMatData::USER_ALLOCATED;

// Store FD in userdata (cast to void*)
if (fd >= 0)
u->userdata = reinterpret_cast<void*>(static_cast<intptr_t>(fd));

// Add to active allocations
cv::fastcv::QcResourceManager::getInstance().addAllocation(data);

Expand Down
Loading