Skip to content

How to set cuda device in dnn module? #17852

@zccyman

Description

@zccyman
System information (version)
  • OpenCV => 4.3.0
  • Operating System / Platform => CentOS7
  • Compiler => GCC6.2
Detailed description
int gpu_id = 2;
int device_count;

device_count = cv::cuda::getCudaEnabledDeviceCount();
//cudaGetDeviceCount(&device_count);

cv::cuda::setDevice(gpu_id);
//cudaSetDevice(gpu_id);

net = cv::dnn::readNetFromONNX("colorE.onnx");

net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);

when I set gpu_id is 2, but Memory appear in GPU:0 and GPU:2. I don't know what's wrong with the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: gpu/cuda (contrib)OpenCV 4.0+: moved to opencv_contribquestion (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.org

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions