Skip to content

Async API for GAPI#14346

Merged
alalek merged 2 commits intoopencv:masterfrom
anton-potapov:gapi_async
Apr 30, 2019
Merged

Async API for GAPI#14346
alalek merged 2 commits intoopencv:masterfrom
anton-potapov:gapi_async

Conversation

@anton-potapov
Copy link
Copy Markdown
Contributor

  • naive implementation as a starting point

This pullrequest changes

  • Adds a naive implementation of Asynchronous API for GAPI module

@dmatveev
Copy link
Copy Markdown
Contributor

Seems ok, fix minor stuff and add missing pieces (and make build green of course).

Thanks

@anton-potapov
Copy link
Copy Markdown
Contributor Author

@dmatveev @rgarnov @dbudniko please take a look

mtx.lock();
mtx.unlock();
cv.notify_one();
thrd.join();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful with waiting for notifications from worker threads during "cleanup".
Win32 ExitProcess() terminates all non-main threads unconditionally - probably with broken synchronization state - holding mutexes (user space at least) and other synchronization primitives.
And after that, it calls atexit() handlers from shared libraries, like this destructor.

Hopefully thrd.joinable() can handle that properly.

}
};

async_service the_ctx;
Copy link
Copy Markdown
Member

@alalek alalek Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably static (or anonymous namespace)

What is about initialization "on-demand"?

static
async_service& getAsyncService()
{
    static async_service g_asyncService;
    return g_asyncService;
}
...
the_ctx. => getAsyncService().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for on-demand

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread It is already on created on - demand - during first call of add_task() async.cpp line 49


auto f = cv::gapi::wip::async_apply(self_mul,cv::gin(in_mat), cv::gout(out));
f.wait();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is DISABLED BTW?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabled back

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comments at all. What is the general idea behind these tests?

};

async_service the_ctx;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block of code still lacks comments. "What author has wanted to say?"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below at line 128

Is it enough - or more comments are required ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the code and added comments

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand what is happening here. Queue, second queue (local instance). What is the purpose of this async_service? Why it's so complicated?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reply on @alalek's concerns regarding #14346 (comment) ?

 - naive implementation as a starting point
@anton-potapov
Copy link
Copy Markdown
Contributor Author

@dbudniko please review , it seems that @dmatveev is not reachable ...
@alalek could you please change the reviewer to @dbudniko or review it yourself ? (All design issues were resolved, only fixes for technical issues are left for review )

#ifndef OPENCV_GAPI_GCOMPILED_ASYNC_HPP
#define OPENCV_GAPI_GCOMPILED_ASYNC_HPP

#include <future>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//for std::future
to align with next std headers comments.

class GCompiled;

namespace gapi{
namespace wip {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be it worth to choose better name for namespace? Something containing "volatile".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, wip was my proposal (communicated to Anton "verbally")


namespace gapi{
namespace wip {
GAPI_EXPORTS void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these overloads? Please provide comments for usage scenario for both.

class GComputation;
namespace gapi {
namespace wip {
GAPI_EXPORTS void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, please, provide comments regarding these overloads.


#include <future>
#include <condition_variable>
//#include <chrono>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove

};

async_service the_ctx;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand what is happening here. Queue, second queue (local instance). What is the purpose of this async_service? Why it's so complicated?

}//namespace

//For now these async functions are simply wrapping serial version of apply/operator() into a functor.
//These functors are then serialized into single queue, which is when processed by a devoted background thread.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"when" - "then" missprint?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, removed


auto f = cv::gapi::wip::async_apply(self_mul,cv::gin(in_mat), cv::gout(out));
f.wait();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comments at all. What is the general idea behind these tests?

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can go ahead with these changes, since critical issues were addressed and API is more or less stabilized for external team use.

I believe Anton will handle the rest with time.

q.swap(second_q);
lck.unlock();

while (!second_q.empty())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this while condition be extended with exiting check as well?

What is the policy on exiting? Should be wait for all issues request or just "forget" it?

};

async_service the_ctx;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reply on @alalek's concerns regarding #14346 (comment) ?

@dmatveev
Copy link
Copy Markdown
Contributor

👍 @alalek can you please proceed with merge?

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Approved with ARs"

@alalek alalek merged commit f5801ee into opencv:master Apr 30, 2019
@anton-potapov anton-potapov deleted the gapi_async branch May 8, 2019 11:20
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* Async API for GAPI

 - naive implementation as a starting point

* Fix namespace comment in header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants