mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
Initial support for oneAPI Level Zero
Change-Id: I221df8427b1844237a4d9d900c58512706b0be0f
This commit is contained in:
33
level_zero/tools/source/sysman/standby/CMakeLists.txt
Normal file
33
level_zero/tools/source/sysman/standby/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
#
|
||||
# Copyright (C) 2019-2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_STANDBY
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/standby.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/standby.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/standby_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/standby_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_standby.h
|
||||
)
|
||||
|
||||
target_include_directories(${TARGET_NAME_L0}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/
|
||||
)
|
||||
|
||||
target_sources(${TARGET_NAME_L0}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_STANDBY}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
add_subdirectory(linux)
|
||||
else()
|
||||
add_subdirectory(windows)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_STANDBY ${L0_SRCS_TOOLS_SYSMAN_STANDBY})
|
||||
20
level_zero/tools/source/sysman/standby/linux/CMakeLists.txt
Normal file
20
level_zero/tools/source/sysman/standby/linux/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Copyright (C) 2019-2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_STANDBY_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_standby_imp.cpp
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME_L0}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_STANDBY_LINUX}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_STANDBY_LINUX ${L0_SRCS_TOOLS_SYSMAN_STANDBY_LINUX})
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/source/device.h"
|
||||
|
||||
#include "drm_neo.h"
|
||||
#include "os_interface.h"
|
||||
#include "sysman/linux/os_sysman_imp.h"
|
||||
#include "sysman/linux/sysfs_access.h"
|
||||
#include "sysman/standby/os_standby.h"
|
||||
#include "sysman/standby/standby_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class LinuxStandbyImp : public OsStandby {
|
||||
public:
|
||||
ze_result_t getMode(zet_standby_promo_mode_t &mode) override;
|
||||
ze_result_t setMode(zet_standby_promo_mode_t mode) override;
|
||||
|
||||
LinuxStandbyImp(OsSysman *pOsSysman);
|
||||
~LinuxStandbyImp() override = default;
|
||||
|
||||
// Don't allow copies of the LinuxStandbyImp object
|
||||
LinuxStandbyImp(const LinuxStandbyImp &obj) = delete;
|
||||
LinuxStandbyImp &operator=(const LinuxStandbyImp &obj) = delete;
|
||||
|
||||
private:
|
||||
SysfsAccess *pSysfsAccess;
|
||||
|
||||
static const std::string standbyModeFile;
|
||||
static const int standbyModeDefault = 1;
|
||||
static const int standbyModeNever = 0;
|
||||
};
|
||||
|
||||
const std::string LinuxStandbyImp::standbyModeFile("power/rc6_enable");
|
||||
|
||||
ze_result_t LinuxStandbyImp::getMode(zet_standby_promo_mode_t &mode) {
|
||||
int currentMode;
|
||||
ze_result_t result = pSysfsAccess->read(standbyModeFile, currentMode);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return result;
|
||||
}
|
||||
if (standbyModeDefault == currentMode) {
|
||||
mode = ZET_STANDBY_PROMO_MODE_DEFAULT;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
if (standbyModeNever == currentMode) {
|
||||
mode = ZET_STANDBY_PROMO_MODE_NEVER;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
ze_result_t LinuxStandbyImp::setMode(zet_standby_promo_mode_t mode) {
|
||||
if (ZET_STANDBY_PROMO_MODE_DEFAULT == mode) {
|
||||
return pSysfsAccess->write(standbyModeFile, standbyModeDefault);
|
||||
}
|
||||
return pSysfsAccess->write(standbyModeFile, standbyModeNever);
|
||||
}
|
||||
|
||||
LinuxStandbyImp::LinuxStandbyImp(OsSysman *pOsSysman) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
|
||||
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
|
||||
}
|
||||
|
||||
OsStandby *OsStandby::create(OsSysman *pOsSysman) {
|
||||
LinuxStandbyImp *pLinuxStandbyImp = new LinuxStandbyImp(pOsSysman);
|
||||
return static_cast<OsStandby *>(pLinuxStandbyImp);
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
25
level_zero/tools/source/sysman/standby/os_standby.h
Normal file
25
level_zero/tools/source/sysman/standby/os_standby.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <level_zero/zet_api.h>
|
||||
|
||||
#include "sysman/os_sysman.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class OsStandby {
|
||||
public:
|
||||
virtual ze_result_t getMode(zet_standby_promo_mode_t &mode) = 0;
|
||||
virtual ze_result_t setMode(zet_standby_promo_mode_t mode) = 0;
|
||||
|
||||
static OsStandby *create(OsSysman *pOsSysman);
|
||||
virtual ~OsStandby() {}
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
41
level_zero/tools/source/sysman/standby/standby.cpp
Normal file
41
level_zero/tools/source/sysman/standby/standby.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "standby.h"
|
||||
|
||||
#include "standby_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
StandbyHandleContext::~StandbyHandleContext() {
|
||||
for (Standby *pStandby : handle_list) {
|
||||
delete pStandby;
|
||||
}
|
||||
}
|
||||
|
||||
ze_result_t StandbyHandleContext::init() {
|
||||
Standby *pStandby = new StandbyImp(pOsSysman);
|
||||
handle_list.push_back(pStandby);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t StandbyHandleContext::standbyGet(uint32_t *pCount, zet_sysman_standby_handle_t *phStandby) {
|
||||
if (nullptr == phStandby) {
|
||||
*pCount = static_cast<uint32_t>(handle_list.size());
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
uint32_t i = 0;
|
||||
for (Standby *standby : handle_list) {
|
||||
if (i >= *pCount)
|
||||
break;
|
||||
phStandby[i++] = standby->toHandle();
|
||||
}
|
||||
*pCount = i;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
44
level_zero/tools/source/sysman/standby/standby.h
Normal file
44
level_zero/tools/source/sysman/standby/standby.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <level_zero/zet_api.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct _zet_sysman_standby_handle_t {};
|
||||
|
||||
namespace L0 {
|
||||
|
||||
struct OsSysman;
|
||||
|
||||
class Standby : _zet_sysman_standby_handle_t {
|
||||
public:
|
||||
virtual ~Standby() {}
|
||||
virtual ze_result_t standbyGetProperties(zet_standby_properties_t *pProperties) = 0;
|
||||
virtual ze_result_t standbyGetMode(zet_standby_promo_mode_t *pMode) = 0;
|
||||
virtual ze_result_t standbySetMode(const zet_standby_promo_mode_t mode) = 0;
|
||||
|
||||
static Standby *fromHandle(zet_sysman_standby_handle_t handle) {
|
||||
return static_cast<Standby *>(handle);
|
||||
}
|
||||
inline zet_sysman_standby_handle_t toHandle() { return this; }
|
||||
};
|
||||
|
||||
struct StandbyHandleContext {
|
||||
StandbyHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
|
||||
~StandbyHandleContext();
|
||||
|
||||
ze_result_t init();
|
||||
|
||||
ze_result_t standbyGet(uint32_t *pCount, zet_sysman_standby_handle_t *phStandby);
|
||||
|
||||
OsSysman *pOsSysman;
|
||||
std::vector<Standby *> handle_list;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
46
level_zero/tools/source/sysman/standby/standby_imp.cpp
Normal file
46
level_zero/tools/source/sysman/standby/standby_imp.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "standby_imp.h"
|
||||
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t StandbyImp::standbyGetProperties(zet_standby_properties_t *pProperties) {
|
||||
*pProperties = standbyProperties;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t StandbyImp::standbyGetMode(zet_standby_promo_mode_t *pMode) {
|
||||
return pOsStandby->getMode(*pMode);
|
||||
}
|
||||
|
||||
ze_result_t StandbyImp::standbySetMode(const zet_standby_promo_mode_t mode) {
|
||||
return pOsStandby->setMode(mode);
|
||||
}
|
||||
|
||||
void StandbyImp::init() {
|
||||
standbyProperties.type = ZET_STANDBY_TYPE_GLOBAL; // Currently the only defined type
|
||||
standbyProperties.onSubdevice = false;
|
||||
standbyProperties.subdeviceId = 0;
|
||||
}
|
||||
|
||||
StandbyImp::StandbyImp(OsSysman *pOsSysman) {
|
||||
pOsStandby = OsStandby::create(pOsSysman);
|
||||
UNRECOVERABLE_IF(nullptr == pOsStandby);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
StandbyImp::~StandbyImp() {
|
||||
delete pOsStandby;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
38
level_zero/tools/source/sysman/standby/standby_imp.h
Normal file
38
level_zero/tools/source/sysman/standby/standby_imp.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <level_zero/zet_api.h>
|
||||
|
||||
#include "os_standby.h"
|
||||
#include "standby.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class StandbyImp : public Standby {
|
||||
public:
|
||||
ze_result_t standbyGetProperties(zet_standby_properties_t *pProperties) override;
|
||||
ze_result_t standbyGetMode(zet_standby_promo_mode_t *pMode) override;
|
||||
ze_result_t standbySetMode(const zet_standby_promo_mode_t mode) override;
|
||||
|
||||
StandbyImp(OsSysman *pOsSysman);
|
||||
~StandbyImp() override;
|
||||
|
||||
StandbyImp(OsStandby *pOsStandby) : pOsStandby(pOsStandby) { init(); };
|
||||
|
||||
// Don't allow copies of the StandbyImp object
|
||||
StandbyImp(const StandbyImp &obj) = delete;
|
||||
StandbyImp &operator=(const StandbyImp &obj) = delete;
|
||||
|
||||
private:
|
||||
OsStandby *pOsStandby;
|
||||
zet_standby_properties_t standbyProperties;
|
||||
void init();
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright (C) 2019-2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_STANDBY_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_standby_imp.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(${TARGET_NAME_L0}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_STANDBY_WINDOWS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_STANDBY_WINDOWS ${L0_SRCS_TOOLS_SYSMAN_STANDBY_WINDOWS})
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../os_standby.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class WddmStandbyImp : public OsStandby {
|
||||
public:
|
||||
ze_result_t getMode(zet_standby_promo_mode_t &mode) override;
|
||||
ze_result_t setMode(zet_standby_promo_mode_t mode) override;
|
||||
};
|
||||
|
||||
ze_result_t WddmStandbyImp::getMode(zet_standby_promo_mode_t &mode) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t WddmStandbyImp::setMode(zet_standby_promo_mode_t mode) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
OsStandby *OsStandby::create(OsSysman *pOsSysman) {
|
||||
WddmStandbyImp *pWddmStandbyImp = new WddmStandbyImp();
|
||||
return static_cast<OsStandby *>(pWddmStandbyImp);
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user