Files
compute-runtime/level_zero/tools/source/sysman/frequency/frequency.cpp
Bill Jordan c64eab402e Update all L0 Sysman getHandle routines to match spec.
Updated all the getHandle routines to use the following
algorithm:
    n = min(*pCount, available)
    if (*pCount == 0 || *pCount > available) {
        *pCount = available;
    }
    if (pArrayn != nullptr) {
        for(i = 0; i < n; i++) {
            pArray[i] = handle[i];
        }
    }

Change-Id: I3b2a2170c2b52d1651bddae4f85f361fd86167a0
Signed-off-by: Bill Jordan <bill.jordan@intel.com>
2020-07-30 07:27:21 +02:00

57 lines
1.6 KiB
C++

/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/frequency/frequency.h"
#include "shared/source/helpers/basic_math.h"
#include "level_zero/tools/source/sysman/frequency/frequency_imp.h"
namespace L0 {
FrequencyHandleContext::~FrequencyHandleContext() {
for (Frequency *pFrequency : handleList) {
delete pFrequency;
}
}
ze_result_t FrequencyHandleContext::init() {
Frequency *pFrequency = new FrequencyImp(pOsSysman);
handleList.push_back(pFrequency);
return ZE_RESULT_SUCCESS;
}
ze_result_t FrequencyHandleContext::frequencyGet(uint32_t *pCount, zet_sysman_freq_handle_t *phFrequency) {
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {
*pCount = handleListSize;
}
if (nullptr != phFrequency) {
for (uint32_t i = 0; i < numToCopy; i++) {
phFrequency[i] = handleList[i]->toHandle();
}
}
return ZE_RESULT_SUCCESS;
}
ze_result_t FrequencyHandleContext::frequencyGet(uint32_t *pCount, zes_freq_handle_t *phFrequency) {
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {
*pCount = handleListSize;
}
if (nullptr != phFrequency) {
for (uint32_t i = 0; i < numToCopy; i++) {
phFrequency[i] = handleList[i]->toZesFreqHandle();
}
}
return ZE_RESULT_SUCCESS;
}
} // namespace L0