99
1010#include " shared/source/command_container/implicit_scaling.h"
1111#include " shared/source/command_stream/aub_subcapture_status.h"
12+ #include " shared/source/command_stream/host_function_worker_interface.h"
1213#include " shared/source/command_stream/scratch_space_controller.h"
1314#include " shared/source/command_stream/submission_status.h"
1415#include " shared/source/command_stream/submissions_aggregator.h"
@@ -97,6 +98,7 @@ CommandStreamReceiver::CommandStreamReceiver(ExecutionEnvironment &executionEnvi
9798 auto &compilerProductHelper = rootDeviceEnvironment.getHelper <CompilerProductHelper>();
9899 this ->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled (hwInfo);
99100 this ->heaplessStateInitEnabled = compilerProductHelper.isHeaplessStateInitEnabled (heaplessModeEnabled);
101+ this ->hostFunctionWorkerMode = debugManager.flags .HostFunctionWorkMode .get ();
100102}
101103
102104CommandStreamReceiver::~CommandStreamReceiver () {
@@ -235,6 +237,25 @@ WaitStatus CommandStreamReceiver::waitForTaskCountAndCleanTemporaryAllocationLis
235237 return waitForTaskCountAndCleanAllocationList (requiredTaskCount, TEMPORARY_ALLOCATION);
236238}
237239
240+ void CommandStreamReceiver::createHostFunctionWorker () {
241+
242+ if (this ->hostFunctionWorker != nullptr ) {
243+ return ;
244+ }
245+
246+ this ->hostFunctionWorker = HostFunctionFactory::createHostFunctionWorker (this ->hostFunctionWorkerMode ,
247+ this ->isAubMode (),
248+ this ->downloadAllocationImpl ,
249+ this ->getHostFunctionDataAllocation (),
250+ &this ->getHostFunctionData ());
251+
252+ this ->hostFunctionWorker ->start ();
253+ }
254+
255+ IHostFunctionWorker *CommandStreamReceiver::getHostFunctionWorker () {
256+ return this ->hostFunctionWorker ;
257+ }
258+
238259void CommandStreamReceiver::ensureCommandBufferAllocation (LinearStream &commandStream, size_t minimumRequiredSize, size_t additionalAllocationSize) {
239260 if (commandStream.getAvailableSpace () >= minimumRequiredSize) {
240261 return ;
@@ -419,6 +440,10 @@ void CommandStreamReceiver::cleanupResources() {
419440 tagsMultiAllocation = nullptr ;
420441 }
421442
443+ if (hostFunctionWorker) {
444+ cleanupHostFunctionWorker ();
445+ }
446+
422447 if (hostFunctionDataMultiAllocation) {
423448 hostFunctionDataAllocation = nullptr ;
424449
@@ -464,6 +489,12 @@ void CommandStreamReceiver::cleanupResources() {
464489 ownedPrivateAllocations.clear ();
465490}
466491
492+ void CommandStreamReceiver ::cleanupHostFunctionWorker () {
493+ hostFunctionWorker->finish ();
494+ delete hostFunctionWorker;
495+ hostFunctionWorker = nullptr ;
496+ }
497+
467498WaitStatus CommandStreamReceiver::waitForCompletionWithTimeout (const WaitParams ¶ms, TaskCountType taskCountToWait) {
468499 bool printWaitForCompletion = debugManager.flags .LogWaitingForCompletion .get ();
469500 if (printWaitForCompletion) {
@@ -697,6 +728,10 @@ void *CommandStreamReceiver::getIndirectHeapCurrentPtr(IndirectHeapType heapType
697728 return nullptr ;
698729}
699730
731+ void CommandStreamReceiver::signalHostFunctionWorker () {
732+ hostFunctionWorker->submit ();
733+ }
734+
700735void CommandStreamReceiver::ensureHostFunctionDataInitialization () {
701736 if (!this ->hostFunctionInitialized .load (std::memory_order_acquire)) {
702737 initializeHostFunctionData ();
@@ -717,6 +752,9 @@ void CommandStreamReceiver::initializeHostFunctionData() {
717752 this ->hostFunctionData .entry = reinterpret_cast <decltype (HostFunctionData::entry)>(ptrOffset (hostFunctionBuffer, HostFunctionHelper::entryOffset));
718753 this ->hostFunctionData .userData = reinterpret_cast <decltype (HostFunctionData::userData)>(ptrOffset (hostFunctionBuffer, HostFunctionHelper::userDataOffset));
719754 this ->hostFunctionData .internalTag = reinterpret_cast <decltype (HostFunctionData::internalTag)>(ptrOffset (hostFunctionBuffer, HostFunctionHelper::internalTagOffset));
755+
756+ createHostFunctionWorker ();
757+
720758 this ->hostFunctionInitialized .store (true , std::memory_order_release);
721759}
722760
@@ -968,12 +1006,14 @@ bool CommandStreamReceiver::createPreemptionAllocation() {
9681006std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::obtainUniqueOwnership () {
9691007 return std::unique_lock<CommandStreamReceiver::MutexType>(this ->ownershipMutex );
9701008}
1009+
9711010std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::tryObtainUniqueOwnership () {
9721011 return std::unique_lock<CommandStreamReceiver::MutexType>(this ->ownershipMutex , std::try_to_lock);
9731012}
9741013std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::obtainHostPtrSurfaceCreationLock () {
9751014 return std::unique_lock<CommandStreamReceiver::MutexType>(this ->hostPtrSurfaceCreationMutex );
9761015}
1016+
9771017AllocationsList &CommandStreamReceiver::getTemporaryAllocations () { return internalAllocationStorage->getTemporaryAllocations (); }
9781018AllocationsList &CommandStreamReceiver::getAllocationsForReuse () { return internalAllocationStorage->getAllocationsForReuse (); }
9791019AllocationsList &CommandStreamReceiver::getDeferredAllocations () { return internalAllocationStorage->getDeferredAllocations (); }
0 commit comments