Skip to content

OpenCV 3.1 cannot explicitly set OpenCL device #6926

@atinfinity

Description

@atinfinity
System information (version)

I checked the following environment.

  • OpenCV => 3.1
  • Operating System / Platform => Windows 10 64bit
  • Compiler => Visual Studio 2013
  • CUDA Toolkit => 7.5(64bit)

addtional information

  • WITH_OPENCL
  • WITH_OPENCLAMDBLAS
  • WITH_OPENCLAMDFFT
  • WITH_OPENCL_SVM

But, I think that there is same issue in other platforms.

Detailed description

OpenCV 2.4.x can explicitly set OpenCL device by cv::ocl::setDevice.
Because, context is defined as a global variable. And, this variable is changed by cv::ocl::setDevice.

On the other hands, OpenCV 3.x cannot explicitly set OpenCL device.
Because, cv::ocl::setDevice was removed from OpenCV 3.0.

And, cv::ocl::Device's constructor sets context. But, this change does not affect the global.
And, device id is not set CoreTLSData.

Steps to reproduce
#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>

int main(int argc, char** argv)
{
    cv::ocl::Context context;
    cv::ocl::Device(context.device(1)); // NG

    cv::UMat img, gray;
    cv::imread("lena.jpg", cv::IMREAD_UNCHANGED).copyTo(img);
    cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY);
    cv::imwrite("gray.jpg", gray);

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions