gcompiled_async.hpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2019 Intel Corporation
  6. #ifndef OPENCV_GAPI_GCOMPILED_ASYNC_HPP
  7. #define OPENCV_GAPI_GCOMPILED_ASYNC_HPP
  8. #include <future> //for std::future
  9. #include <exception> //for std::exception_ptr
  10. #include <functional> //for std::function
  11. #include <opencv2/gapi/garg.hpp>
  12. #include <opencv2/gapi/own/exports.hpp>
  13. namespace cv {
  14. //fwd declaration
  15. class GCompiled;
  16. namespace gapi{
  17. namespace wip {
  18. class GAsyncContext;
  19. /**
  20. These functions asynchronously (i.e. probably on a separate thread of execution) call GCompiled::operator() member function of their first argument with copies of rest of arguments (except callback) passed in.
  21. The difference between the function is the way to get the completion notification (via callback or a waiting on std::future object)
  22. If exception is occurred during execution of apply it is transferred to the callback (via function parameter) or passed to future (and will be thrown on call to std::future::get)
  23. N.B. :
  24. Input arguments are copied on call to async function (actually on call to cv::gin) and thus do not have to outlive the actual completion of asynchronous activity.
  25. While output arguments are "captured" by reference(pointer) and therefore _must_ outlive the asynchronous activity
  26. (i.e. live at least until callback is called or future is unblocked)
  27. @param gcmpld Compiled computation (graph) to start asynchronously
  28. @param callback Callback to be called when execution of gcmpld is done
  29. @param ins Input parameters for gcmpld
  30. @param outs Output parameters for gcmpld
  31. */
  32. GAPI_EXPORTS void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs);
  33. /** @overload
  34. @param gcmpld Compiled computation (graph) to run asynchronously
  35. @param callback Callback to be called when execution of gcmpld is done
  36. @param ins Input parameters for gcmpld
  37. @param outs Output parameters for gcmpld
  38. @param ctx Context this request belongs to
  39. @see async GAsyncContext
  40. */
  41. GAPI_EXPORTS void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx);
  42. /** @overload
  43. @param gcmpld Compiled computation (graph) to run asynchronously
  44. @param ins Input parameters for gcmpld
  45. @param outs Output parameters for gcmpld
  46. @return std::future<void> object to wait for completion of async operation
  47. @see async
  48. */
  49. GAPI_EXPORTS std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs);
  50. /**
  51. @param gcmpld Compiled computation (graph) to run asynchronously
  52. @param ins Input parameters for gcmpld
  53. @param outs Output parameters for gcmpld
  54. @param ctx Context this request belongs to
  55. @return std::future<void> object to wait for completion of async operation
  56. @see async GAsyncContext
  57. */
  58. GAPI_EXPORTS std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx);
  59. } // namespace wip
  60. } // namespace gapi
  61. } // namespace cv
  62. #endif // OPENCV_GAPI_GCOMPILED_ASYNC_HPP