Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Linux: clash between OpenCV::CUDA and mxDAQ

I have a C++ application that communicates with NI drivers and needs to link with OpenCV::CUDA modules.  When I link with opencv::cuda, and run the application, DAQmxCreateTask throws ni::dsc::osdep::PosixError "Operation not permitted".  The test code doesn't make any calls to opencv AT ALL, but does link to it.  If I comment out the line with the "cv::cuda::max" call, CV::CUDA doesn't link in and there is no exception.

I'm at a loss as to how to fix this.  Has anyone seen anything like this?

Note that DAQmxCreateTask isn't even supposed to throw C++ exceptions, it returns errors via an error code like the good old C function that it is.

~~~~~~~~~~
I'm using OpenCV 4.7, CUDA 12.1, and DAQmx that comes in the "stream" driver package (so, most recent as of the date of this post)


Test project, running on Ubuntu 22.04, requires OpenCV to be built with CUDA support (the version that comes w/ Ubuntu doesn't include CUDA).  The project consists of 2 little files, with DAQmx all in a separate file so that OpenCV headers and DAQmx headers are not included in the same file (otherwise there is a typedef conflict).

File test1.cc:

 

#include <opencv2/cudaarithm.hpp>
void test1();

 

void test2() {

  // This function doesn't get called, but the lines below cause OpenCV::CUDA to link into the binary

  cv::cuda::GpuMat x(100, 100, CV_8UC1);
  cv::cuda::max(x, x, x);  // Comment this line out to fix the exception!

}

 

int main(int argc, char **argv) {
test1();
return 0;
}

 

File test2.cc:

#include <NIDAQmx.h>
void test1() {
  TaskHandle x{};
  DAQmxCreateTask("", &x);
}

 

Project file (meson.build):

project('test_mx', ['cpp'])

cpp = meson.get_compiler('cpp')
opencv_dep = dependency('OpenCV')
ni_dep = cpp.find_library('nidaqmx', has_headers: 'NIDAQmx.h')

executable('test_mx', ['test_mx.cc', 'test1.cc'], dependencies: [ni_dep, opencv_dep])

0 Kudos
Message 1 of 2
(1,025 Views)

Adding build instructions for OpenCV+CUDA minimum build that takes 1 minute to build, yet exhibits the bug.  Install CUDA-12.1 first, then clone opencv and opencv_contrib as usual.  Check out version e.g. 4.7, then run the following in the build subdir of opencv.  This configures OpenCV to include cudaarithm, but no other modules:

#!/bin/sh
export MODULES="cudaarithm cudev"
export MODULE_LIST=$(echo "$MODULES" | sed -e 's/ /,/g')
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local \
-DWITH_PTHREADS_PF=OFF -DWITH_PTHREADS=OFF -DWITH_PTHREAD=OFF \
-DWITH_OPENCL=OFF -DWITH_CUDA=ON -DWITH_CUDNN=OFF -DWITH_CUBLAS=OFF \
-DWITH_TBB=OFF -DOPENCV_DNN_CUDA=OFF -DOPENCV_ENABLE_NONFREE=OFF \
-DCUDA_ARCH_BIN=8.6 -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DBUILD_EXAMPLES=OFF -DHAVE_opencv_python3=OFF -DBUILD_LIST="$MODULE_LIST" -DOPENCV_GENERATE_PKGCONFIG=YES -GNinja ..

 

0 Kudos
Message 2 of 2
(982 Views)