Skip to content
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

[Hexagon] Add power manager #13162

Merged
merged 5 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/runtime/hexagon/hexagon_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
int result = api_call; \
if (result != 0) { \
HEXAGON_PRINT(ERROR, "ERROR: " #api_call " failed with error %d.", result); \
abort(); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe LogFatal instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address this in a future PR

} \
} while (0)

Expand Down
10 changes: 10 additions & 0 deletions src/runtime/hexagon/hexagon_device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "hexagon_buffer.h"
#include "hexagon_buffer_manager.h"
#include "hexagon_power_manager.h"
#include "hexagon_thread_manager.h"
#include "hexagon_user_dma.h"
#include "hexagon_vtcm_pool.h"
Expand All @@ -55,6 +56,9 @@ class HexagonDeviceAPI final : public DeviceAPI {

//! \brief Ensures resource managers are in a good state for the runtime
void AcquireResources() {
CHECK_EQ(runtime_power_manager, nullptr);
runtime_power_manager = std::make_unique<HexagonPowerManager>();

CHECK_EQ(runtime_vtcm, nullptr);
runtime_vtcm = std::make_unique<HexagonVtcmPool>();

Expand All @@ -81,6 +85,9 @@ class HexagonDeviceAPI final : public DeviceAPI {

CHECK(runtime_vtcm) << "runtime_vtcm was not created in AcquireResources";
runtime_vtcm.reset();

CHECK(runtime_power_manager) << "runtime_power_manager was not created in AcquireResources";
runtime_power_manager.reset();
}

/*! \brief Currently unimplemented interface to specify the active
Expand Down Expand Up @@ -202,6 +209,9 @@ class HexagonDeviceAPI final : public DeviceAPI {

//! \brief VTCM memory manager
std::unique_ptr<HexagonVtcmPool> runtime_vtcm;

//! \brief Hexagon power manager
std::unique_ptr<HexagonPowerManager> runtime_power_manager;
};
} // namespace hexagon
} // namespace runtime
Expand Down
34 changes: 2 additions & 32 deletions src/runtime/hexagon/hexagon_htp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,9 @@ namespace tvm {
namespace runtime {
namespace hexagon {

HexagonHtp::HexagonHtp() {
PowerOn();
Acquire();
}

HexagonHtp::~HexagonHtp() {
Release();
PowerOff();
}

void HexagonHtp::PowerOn() {
HAP_power_request_t pwr_req;
int nErr;

hap_pwr_ctx_ = HAP_utils_create_context();
pwr_req.type = HAP_power_set_HMX;
pwr_req.hmx.power_up = true;
if ((nErr = HAP_power_set(hap_pwr_ctx_, &pwr_req))) {
LOG(FATAL) << "InternalError: HAP_power_set failed\n";
}
}

void HexagonHtp::PowerOff() {
HAP_power_request_t pwr_req;
int nErr;
HexagonHtp::HexagonHtp() { Acquire(); }
supersat marked this conversation as resolved.
Show resolved Hide resolved

pwr_req.type = HAP_power_set_HMX;
pwr_req.hmx.power_up = false;
if ((nErr = HAP_power_set(hap_pwr_ctx_, &pwr_req))) {
LOG(FATAL) << "InternalError: HAP_power_set failed\n";
}
HAP_utils_destroy_context(hap_pwr_ctx_);
}
HexagonHtp::~HexagonHtp() { Release(); }

void HexagonHtp::Acquire() {
compute_res_attr_t compute_res_attr;
Expand Down
5 changes: 0 additions & 5 deletions src/runtime/hexagon/hexagon_htp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,9 @@ class HexagonHtp {
HexagonHtp& operator=(HexagonHtp&&) = delete;

private:
//! \brief Power context
void* hap_pwr_ctx_;

//! \brief Acquisition context ID
unsigned int context_id_;

void PowerOn();
void PowerOff();
void Acquire();
void Release();
};
Expand Down
108 changes: 108 additions & 0 deletions src/runtime/hexagon/hexagon_power_manager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "hexagon_power_manager.h"

#include <AEEStdDef.h>
#include <AEEStdErr.h>

#include "HAP_power.h"
#include "hexagon_common.h"

namespace tvm {
namespace runtime {
namespace hexagon {

HexagonPowerManager::HexagonPowerManager() {
hap_pwr_ctx_ = HAP_utils_create_context();
PowerOnHVX();
PowerOnHTP();
SetAppType();
SetDCVS();
}

HexagonPowerManager::~HexagonPowerManager() {
PowerOffHTP();
PowerOffHVX();
HAP_utils_destroy_context(hap_pwr_ctx_);
}

void HexagonPowerManager::PowerOnHVX() {
supersat marked this conversation as resolved.
Show resolved Hide resolved
HAP_power_request_t pwr_req;

pwr_req.type = HAP_power_set_HVX;
pwr_req.hvx.power_up = true;
HEXAGON_SAFE_CALL(HAP_power_set(hap_pwr_ctx_, &pwr_req));
}

void HexagonPowerManager::PowerOffHVX() {
HAP_power_request_t pwr_req;

pwr_req.type = HAP_power_set_HVX;
pwr_req.hvx.power_up = false;
HEXAGON_SAFE_CALL(HAP_power_set(hap_pwr_ctx_, &pwr_req));
}

void HexagonPowerManager::PowerOnHTP() {
HAP_power_request_t pwr_req;

pwr_req.type = HAP_power_set_HMX;
pwr_req.hmx.power_up = true;
HEXAGON_SAFE_CALL(HAP_power_set(hap_pwr_ctx_, &pwr_req));
}

void HexagonPowerManager::PowerOffHTP() {
HAP_power_request_t pwr_req;

pwr_req.type = HAP_power_set_HMX;
pwr_req.hmx.power_up = false;
HEXAGON_SAFE_CALL(HAP_power_set(hap_pwr_ctx_, &pwr_req));
}

void HexagonPowerManager::SetAppType() {
HAP_power_request_t pwr_req;

pwr_req.type = HAP_power_set_apptype;
pwr_req.apptype = HAP_POWER_COMPUTE_CLIENT_CLASS;
HEXAGON_SAFE_CALL(HAP_power_set(hap_pwr_ctx_, &pwr_req));
}

void HexagonPowerManager::SetDCVS() {
HAP_power_request_t pwr_req;

memset(&pwr_req, 0, sizeof(HAP_power_request_t));
pwr_req.type = HAP_power_set_DCVS_v3;
pwr_req.dcvs_v3.set_dcvs_enable = TRUE;
pwr_req.dcvs_v3.dcvs_enable = FALSE;
pwr_req.dcvs_v3.set_core_params = TRUE;
pwr_req.dcvs_v3.core_params.min_corner = HAP_DCVS_VCORNER_TURBO_PLUS;
pwr_req.dcvs_v3.core_params.max_corner = HAP_DCVS_VCORNER_TURBO_PLUS;
pwr_req.dcvs_v3.core_params.target_corner = HAP_DCVS_VCORNER_TURBO_PLUS;
pwr_req.dcvs_v3.set_bus_params = TRUE;
pwr_req.dcvs_v3.bus_params.min_corner = HAP_DCVS_VCORNER_TURBO_PLUS;
pwr_req.dcvs_v3.bus_params.max_corner = HAP_DCVS_VCORNER_TURBO_PLUS;
pwr_req.dcvs_v3.bus_params.target_corner = HAP_DCVS_VCORNER_TURBO_PLUS;
pwr_req.dcvs_v3.set_sleep_disable = TRUE;
pwr_req.dcvs_v3.sleep_disable = TRUE;
HEXAGON_SAFE_CALL(HAP_power_set(hap_pwr_ctx_, &pwr_req));
}

} // namespace hexagon
} // namespace runtime
} // namespace tvm
63 changes: 63 additions & 0 deletions src/runtime/hexagon/hexagon_power_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_HEXAGON_POWER_MANAGER_H_
#define TVM_RUNTIME_HEXAGON_HEXAGON_POWER_MANAGER_H_

namespace tvm {
namespace runtime {
namespace hexagon {

class HexagonPowerManager {
public:
//! \brief Constructor.
HexagonPowerManager();

//! \brief Destructor.
~HexagonPowerManager();

//! \brief Prevent copy construction of HexagonPowerManager.
HexagonPowerManager(const HexagonPowerManager&) = delete;

//! \brief Prevent copy assignment with HexagonPowerManager.
HexagonPowerManager& operator=(const HexagonPowerManager&) = delete;

//! \brief Prevent move construction.
HexagonPowerManager(HexagonPowerManager&&) = delete;

//! \brief Prevent move assignment.
HexagonPowerManager& operator=(HexagonPowerManager&&) = delete;

private:
//! \brief Power context
void* hap_pwr_ctx_;

void PowerOnHVX();
void PowerOffHVX();
void PowerOnHTP();
void PowerOffHTP();
void SetAppType();
void SetDCVS();
};

} // namespace hexagon
} // namespace runtime
} // namespace tvm

#endif // TVM_RUNTIME_HEXAGON_HEXAGON_POWER_MANAGER_H_