GetPointer
OpenLvVision_OpenCv.lvlib:Cuda.lvlib:GpuMat.lvclass:GpuMat GetPointer.vi
Returns the pointer to the Cuda memory.
This increments the OpenCV reference count. To prevent memory leaks, the generated handlePtr must be freed after use, either by the external library via the releaseCallback, or explicitly in LabVIEW using the "GpuMat ReleasePointer" VI.
struct GpuMat_PointerData
{
uintptr_t cudaPtr;
int64_t step;
uint64_t totalBytes;
int32_t cols;
int32_t rows;
int32_t elemSize;
int32_t cvType;
int32_t channels;
uintptr_t handlePtr;
uintptr_t releaseCallbackPtr;
};
typedef void (*ReleasePointerCallback)(void* handle);
// CUDA Kernel
__global__ void IncrementByOneKernel(uint8_t* data, int step, int cols, int rows)
{
// Derive the 2-D pixel coordinate from the launch grid.
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
// Discard threads that map outside the image boundaries.
if (x >= cols || y >= rows)
{
return;
}
// Compute the linear byte offset using the row stride to account for
// any alignment padding introduced by the CUDA memory allocator.
const int index = (y * step) + x;
// Increment the pixel value
data[index] += 1;
}
extern "C" __declspec(dllexport) void ProcessGpuDataWithKernel(GpuMat_PointerData* data)
{
// Validate the descriptor and device address before dereferencing either.
if (data == nullptr || data->cudaPtr == 0)
{
return;
}
uint8_t* deviceBuffer = reinterpret_cast<uint8_t*>(data->cudaPtr);
void* handle = reinterpret_cast<void*>(data->handlePtr);
ReleasePointerCallback releaseMem = reinterpret_cast<ReleasePointerCallback>(data->releaseCallbackPtr);
// Process only single-channel 8-bit images (CV_8UC1, OpenCV type value 0).
if (data->cvType == 0)
{
// Partition the image into 16×16 thread blocks and compute the minimum
// number of blocks required to cover every pixel in the image.
const dim3 threadsPerBlock(16, 16);
const dim3 numBlocks(
(data->cols + threadsPerBlock.x - 1) / threadsPerBlock.x,
(data->rows + threadsPerBlock.y - 1) / threadsPerBlock.y
);
// Dispatch the kernel asynchronously on the default CUDA stream.
IncrementByOneKernel<<<numBlocks, threadsPerBlock>>>(
deviceBuffer,
static_cast<int>(data->step),
data->cols,
data->rows
);
// Synchronise the host thread with the device to ensure the kernel has
// completed before control returns to LabVIEW or cleanup proceeds.
cudaDeviceSynchronize();
}
// Invoke the OpenCV DLL release callback to transfer buffer ownership back
// to the runtime, allowing it to decrement the reference count and free the handle.
if (handle != nullptr && releaseMem != nullptr)
{
releaseMem(handle);
}
}

| error in (no error) The error in cluster can accept error information wired from VIs previously called. Use this information to decide if any functionality should be bypassed in the event of errors from other VIs. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| status The status boolean is either TRUE (X) for an error, or FALSE (checkmark) for no error or a warning. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| code The code input identifies the error or warning. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| source The source string describes the origin of the error or warning. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| GpuMat in |
| error out The error out cluster passes error or warning information out of a VI to be used by other VIs. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| status The status boolean is either TRUE (X) for an error, or FALSE (checkmark) for no error or a warning. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| code The code input identifies the error or warning. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| source The source string describes the origin of the error or warning. The pop-up option Explain Error (or Explain Warning) gives more information about the error displayed. |
| GpuMat out |
| GpuMat Pointer Memory description of a CUDA memory for zero-copy interop. |
| CudaPtr The Gpu memory address of the first pixel in the image (top-left, coordinate 0,0) |
| Step Also known as the Stride or Line Pitch. This represents the number of bytes between the start of one row and the start of the next row |
| TotalBytes The total physical footprint of the image in RAM. It is calculated as step * rows |
| Cols The horizontal width of the image in pixels |
| Rows The vertical height of the image in pixels |
| ElemSize The number of bytes occupied by a single pixel |
| cvType The internal OpenCV integer constant representing the data format |
| Channels The number of components per pixel |
| handlePtr An opaque 64-bit pointer to allocated cv::cuda::HostMem instance that maintains a +1 reference count on the underlying memory payload. |
| releaseCallbackPtr C-convention function pointer that must be invoked with the handlePtr to safely decrement the OpenCV reference count and deallocate the handle. |













