Skip to content

add move-semantics to main OpenCL classes in cv::ocl #19573

@diablodale

Description

@diablodale

I propose adding move-semantics to the main cv::ocl classes like Device, Context, Program, etc. Move semantics allow for more flexible and clear code regarding constructors, ownership, etc. Most of these classes contain an Impl and therefore it is easy to implement the move-semantics using the canonical programming method. Test cases are included in the PR.

This is a C++11 and newer feature. Therefore this is only for OpenCV 4.x and newer.
The PR for this is best merged after the PR for #19571. I will submit them sequentially.

System information (version)

  • OpenCV => 4.5.0
  • Operating System / Platform => all
  • Compiler => all

Detailed description

Adding move semantics allows for more efficient code (e.g. move the Impl; don't copy, increment, and decrement). Allows for clearer transfer of ownership (e.g. move a Program from one owning variable to another). And allows for more features of the C++ STL for those features that require move-semantics.

For example, pseudocode

class myclass {
ocl::Program prog;

ocl::Program getTheProgram() {  
  return ocl::Program(...);
}

void doit() {
  prog = getTheProgram(); // this is a move since getTheProgram() returns an r-value
}
}

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

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