| 1 |
/* |
| 2 |
* Copyright (C) 2020-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "level_zero/tools/source/sysman/os_sysman.h" |
| 9 |
#include "level_zero/tools/source/sysman/scheduler/scheduler_imp.h" |
| 10 |
|
| 11 |
#include <algorithm> |
| 12 |
|
| 13 |
class OsScheduler; |
| 14 |
namespace L0 { |
| 15 |
|
| 16 |
SchedulerHandleContext::SchedulerHandleContext(OsSysman *pOsSysman) { |
| 17 |
this->pOsSysman = pOsSysman; |
| 18 |
} |
| 19 |
|
| 20 |
SchedulerHandleContext::~SchedulerHandleContext() { |
| 21 |
handleList.clear(); |
| 22 |
} |
| 23 |
void SchedulerHandleContext::createHandle(zes_engine_type_flag_t engineType, std::vector<std::string> &listOfEngines, ze_device_handle_t deviceHandle) { |
| 24 |
std::unique_ptr<Scheduler> pScheduler = std::make_unique<SchedulerImp>(pOsSysman, engineType, listOfEngines, deviceHandle); |
| 25 |
handleList.push_back(std::move(pScheduler)); |
| 26 |
} |
| 27 |
|
| 28 |
void SchedulerHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles) { |
| 29 |
for (const auto &deviceHandle : deviceHandles) { |
| 30 |
std::map<zes_engine_type_flag_t, std::vector<std::string>> engineTypeInstance = {}; |
| 31 |
OsScheduler::getNumEngineTypeAndInstances(engineTypeInstance, pOsSysman, deviceHandle); |
| 32 |
for (auto itr = engineTypeInstance.begin(); itr != engineTypeInstance.end(); ++itr) { |
| 33 |
createHandle(itr->first, itr->second, deviceHandle); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
ze_result_t SchedulerHandleContext::schedulerGet(uint32_t *pCount, zes_sched_handle_t *phScheduler) { |
| 39 |
std::call_once(initSchedulerOnce, [this]() { |
| 40 |
this->init(pOsSysman->getDeviceHandles()); |
| 41 |
}); |
| 42 |
uint32_t handleListSize = static_cast<uint32_t>(handleList.size()); |
| 43 |
uint32_t numToCopy = std::min(*pCount, handleListSize); |
| 44 |
if (0 == *pCount || *pCount > handleListSize) { |
| 45 |
*pCount = handleListSize; |
| 46 |
} |
| 47 |
if (nullptr != phScheduler) { |
| 48 |
for (uint32_t i = 0; i < numToCopy; i++) { |
| 49 |
phScheduler[i] = handleList[i]->toHandle(); |
| 50 |
} |
| 51 |
} |
| 52 |
return ZE_RESULT_SUCCESS; |
| 53 |
} |
| 54 |
|
| 55 |
} // namespace L0 |