-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Defer buffer release when no host memory to be updated #6837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0601210
aff3be6
1195b59
8d05802
b54b8e4
965a015
27ccbff
9540fe0
c00c7cb
661dace
6615db3
8174dc3
d55405e
bb2c4fb
5db9e85
53a1892
4b0a3fa
8daea20
c855f13
8dbcd1c
0f61c64
ddf215b
23bea82
aa41d76
e296d03
179c472
2076c7c
e911d0a
81c2b09
edcfcfc
b5e85de
a5980a0
ac06f1b
09b8359
1e75448
484b1cf
1061322
d4537a3
342ff91
fdab0e7
0872d7c
3a25f1e
28f008d
92b5e15
6247f8a
4133862
79b2125
868973c
1bc8e57
6e0943b
1c62d08
30dfaf2
60e3011
6964876
3d5315e
467a9ea
0b9032a
9d570ce
c6d5dc7
a0b37ef
619ee4e
3187f0a
dbe88e2
06e2608
71e9048
a89e577
ceea7f8
1f201a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,36 @@ | |
namespace sycl { | ||
__SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
namespace detail { | ||
|
||
// Utility class to track references on object. | ||
// Used for Scheduler now and created as thread_local object. | ||
// Origin idea is to track usage of Scheduler from main and other used threads - | ||
// they increment MCounter; and to use but not add extra reference by our | ||
// thread_pool threads. For this control MIncrementCounter class member is used. | ||
template <class ResourceHandler> class ObjectUsageCounter { | ||
public: | ||
ObjectUsageCounter(std::unique_ptr<ResourceHandler> &Obj, bool ModifyCounter) | ||
: MModifyCounter(ModifyCounter), MObj(Obj) { | ||
if (MModifyCounter) | ||
MCounter++; | ||
} | ||
~ObjectUsageCounter() { | ||
if (!MModifyCounter) | ||
return; | ||
|
||
MCounter--; | ||
if (!MCounter && MObj) | ||
MObj->releaseResources(); | ||
} | ||
|
||
private: | ||
static std::atomic_uint MCounter; | ||
bool MModifyCounter; | ||
std::unique_ptr<ResourceHandler> &MObj; | ||
}; | ||
template <class ResourceHandler> | ||
std::atomic_uint ObjectUsageCounter<ResourceHandler>::MCounter{0}; | ||
|
||
using LockGuard = std::lock_guard<SpinLock>; | ||
|
||
GlobalHandler::GlobalHandler() = default; | ||
|
@@ -47,7 +77,24 @@ T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types... Args) { | |
return *IWL.Inst; | ||
} | ||
|
||
Scheduler &GlobalHandler::getScheduler() { return getOrCreate(MScheduler); } | ||
void GlobalHandler::attachScheduler(Scheduler *Scheduler) { | ||
// The method is used in unit tests only. Do not protect with lock since | ||
// releaseResources will cause dead lock due to host queue release | ||
if (MScheduler.Inst) | ||
MScheduler.Inst->releaseResources(); | ||
MScheduler.Inst.reset(Scheduler); | ||
} | ||
|
||
Scheduler &GlobalHandler::getScheduler() { | ||
getOrCreate(MScheduler); | ||
registerSchedulerUsage(); | ||
return *MScheduler.Inst; | ||
} | ||
|
||
void GlobalHandler::registerSchedulerUsage(bool ModifyCounter) { | ||
thread_local ObjectUsageCounter SchedulerCounter(MScheduler.Inst, | ||
ModifyCounter); | ||
} | ||
|
||
ProgramManager &GlobalHandler::getProgramManager() { | ||
return getOrCreate(MProgramManager); | ||
|
@@ -141,9 +188,18 @@ void GlobalHandler::unloadPlugins() { | |
GlobalHandler::instance().getPlugins().clear(); | ||
} | ||
|
||
void GlobalHandler::drainThreadPool() { | ||
if (MHostTaskThreadPool.Inst) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we lock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please correct me if my understanding is wrong but I thought that lock in InstWithLock exists to protect during getOrCreate call to avoid data race for object creation. Drain call is done in releaseResources called on program exit and do not introduce any data races related to it. |
||
MHostTaskThreadPool.Inst->drain(); | ||
} | ||
|
||
void shutdown() { | ||
// Ensure neither host task is working so that no default context is accessed | ||
// upon its release | ||
|
||
if (GlobalHandler::instance().MScheduler.Inst) | ||
GlobalHandler::instance().MScheduler.Inst->releaseResources(); | ||
|
||
if (GlobalHandler::instance().MHostTaskThreadPool.Inst) | ||
GlobalHandler::instance().MHostTaskThreadPool.Inst->finishAndWait(); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this an appropriate default?
@dongkyunahn-intel, your help is needed to review this part. I believe the
Result
initialization should be a switch on State.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It think it would be better to set
Result
withswitch/case
statement as Konst suggested. CM_STATUS_* are defined in link below.https://github.com/intel/cm-cpu-emulation/blob/0c5fc287f34ae38d3184ab70ea5513d9fb1ff338/common/type_status.h#L13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @kbobrovs and @dongkyunahn-intel I did only two states intentionally, because other statuses (!= CM_STATUS_FINISHED) seems logical to map to running since it is all "work in progress" and RT does not need more details. I also used L0 plugin as reference which also has differentiation for two states - finished and not finished = running. I think it would be better to align plugins and not introduce extra value handling on level above. What do you think?
Although it may be needed to report CM_STATUS_RESET separately as error. Could you please educate me what does this status stands for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware that L0 has such implementation. Meanwhile, I looked into CM_EMU's
GetStatus()
implementation and found out that the function is dummy one returning onlyCM_STATUS_FINISHED
. Now it looks like okay to maintain current implementation - with comments about FINISHED/NOT_FINISHED.'CM_STATUS_RESET' is defined, but never used in CM_EMU. You can disregard it.