You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ma...@apache.org on 2022/11/30 01:54:47 UTC
[tvm] branch main updated: Add methods to get the size of VTCM on device as well as the allocated size of the HexagonVtcmPool (#13511)
This is an automated email from the ASF dual-hosted git repository.
masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new e47eed13d9 Add methods to get the size of VTCM on device as well as the allocated size of the HexagonVtcmPool (#13511)
e47eed13d9 is described below
commit e47eed13d9a0af3bab5fc6fafbc8228797419249
Author: Janet Schneider <21...@users.noreply.github.com>
AuthorDate: Tue Nov 29 19:54:41 2022 -0600
Add methods to get the size of VTCM on device as well as the allocated size of the HexagonVtcmPool (#13511)
* Get device size and allocated size of VTCM
* Add python API
---
src/runtime/hexagon/hexagon_device_api.cc | 6 ++++++
src/runtime/hexagon/hexagon_vtcm_pool.cc | 15 ++++++++-------
src/runtime/hexagon/hexagon_vtcm_pool.h | 14 ++++++++++----
tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc | 9 +++++++--
4 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/src/runtime/hexagon/hexagon_device_api.cc b/src/runtime/hexagon/hexagon_device_api.cc
index 51cc976e46..a1d55db42f 100644
--- a/src/runtime/hexagon/hexagon_device_api.cc
+++ b/src/runtime/hexagon/hexagon_device_api.cc
@@ -299,6 +299,12 @@ TVM_REGISTER_GLOBAL("device_api.hexagon.release_resources")
api->ReleaseResources();
});
+TVM_REGISTER_GLOBAL("device_api.hexagon.vtcm_device_bytes")
+ .set_body([](TVMArgs args, TVMRetValue* rv) {
+ HexagonDeviceAPI* api = HexagonDeviceAPI::Global();
+ *rv = static_cast<int32_t>(api->VtcmPool()->VtcmDeviceBytes());
+ });
+
TVM_REGISTER_GLOBAL("device_api.hexagon").set_body([](TVMArgs args, TVMRetValue* rv) {
DeviceAPI* ptr = HexagonDeviceAPI::Global();
*rv = static_cast<void*>(ptr);
diff --git a/src/runtime/hexagon/hexagon_vtcm_pool.cc b/src/runtime/hexagon/hexagon_vtcm_pool.cc
index 17089852a9..8373ef61c9 100644
--- a/src/runtime/hexagon/hexagon_vtcm_pool.cc
+++ b/src/runtime/hexagon/hexagon_vtcm_pool.cc
@@ -29,20 +29,19 @@ HexagonVtcmPool::HexagonVtcmPool() {
compute_res_attr_t res_info;
HEXAGON_SAFE_CALL(HAP_compute_res_attr_init(&res_info));
- unsigned int total_block_size;
unsigned int avail_block_size;
compute_res_vtcm_page_t total_block_layout;
compute_res_vtcm_page_t avail_block_layout;
- HEXAGON_SAFE_CALL(compute_resource_query_VTCM(/* application_id = */ 0, &total_block_size,
+ HEXAGON_SAFE_CALL(compute_resource_query_VTCM(/* application_id = */ 0, &vtcm_device_size_,
&total_block_layout, &avail_block_size,
&avail_block_layout));
- DLOG(INFO) << "HexagonVtcmPool total " << total_block_size << " avail " << avail_block_size;
+ DLOG(INFO) << "HexagonVtcmPool total " << vtcm_device_size_ << " avail " << avail_block_size;
CHECK(avail_block_size >= (1024 * 1024)) << "Less than 1MB VTCM available";
// allocate nbytes of vtcm on a single page
HEXAGON_SAFE_CALL(HAP_compute_res_attr_set_vtcm_param_v2(&res_info,
- /*vtcm_size = */ total_block_size,
+ /*vtcm_size = */ vtcm_device_size_,
/*min_page_size = */ 1,
/*min_vtcm_size = */ avail_block_size));
@@ -50,11 +49,13 @@ HexagonVtcmPool::HexagonVtcmPool() {
// hanging, both in the simulator and on hardware.
context_id_ = HAP_compute_res_acquire(&res_info, /*timeout = */ 0);
CHECK(context_id_) << "HAP_compute_res_acquire failed to acquire requested VTCM resource.";
- HEXAGON_SAFE_CALL(HAP_compute_res_attr_get_vtcm_ptr_v2(&res_info, &vtcm_data_, &vtcm_size_));
+ HEXAGON_SAFE_CALL(
+ HAP_compute_res_attr_get_vtcm_ptr_v2(&res_info, &vtcm_data_, &vtcm_allocated_size_));
CHECK(vtcm_data_ != nullptr) << "HAP_compute_res_acquire returned nullptr when allocating VTCM.";
- CHECK(vtcm_size_ >= avail_block_size)
+ CHECK(vtcm_allocated_size_ >= avail_block_size)
<< "HAP_compute_res_acquire failed to allocate minimum amount of VTCM";
- free_.emplace_back(std::pair<char*, size_t>(static_cast<char*>(vtcm_data_), vtcm_size_));
+ free_.emplace_back(
+ std::pair<char*, size_t>(static_cast<char*>(vtcm_data_), vtcm_allocated_size_));
// DebugDump();
}
diff --git a/src/runtime/hexagon/hexagon_vtcm_pool.h b/src/runtime/hexagon/hexagon_vtcm_pool.h
index 2e0918e997..88b8f1470c 100644
--- a/src/runtime/hexagon/hexagon_vtcm_pool.h
+++ b/src/runtime/hexagon/hexagon_vtcm_pool.h
@@ -68,7 +68,10 @@ class HexagonVtcmPool {
void Free(void* ptr, size_t nbytes);
//! \brief Returns the total number of bytes in this pool
- size_t TotalBytes() { return reinterpret_cast<size_t>(vtcm_size_); }
+ size_t VtcmDeviceBytes() { return reinterpret_cast<size_t>(vtcm_device_size_); }
+
+ //! \brief Returns the total number of bytes in this pool
+ size_t VtcmAllocatedBytes() { return reinterpret_cast<size_t>(vtcm_allocated_size_); }
bool IsVtcm(void* ptr, unsigned size) {
auto char_ptr = static_cast<char*>(ptr);
@@ -76,15 +79,18 @@ class HexagonVtcmPool {
auto char_vtcm = static_cast<char*>(vtcm_data_);
CHECK(vtcm_data_ != nullptr);
- if (char_ptr >= char_vtcm && (char_ptr + size) <= (char_vtcm + vtcm_size_)) {
+ if (char_ptr >= char_vtcm && (char_ptr + size) <= (char_vtcm + vtcm_allocated_size_)) {
return true;
}
return false;
}
private:
- //! \brief Total size of VTCM pool
- unsigned int vtcm_size_;
+ //! \brief Total size of VTCM memory on device
+ unsigned int vtcm_device_size_;
+
+ //! \brief Total size of VTCM pool allocated on device
+ unsigned int vtcm_allocated_size_;
//! \brief Pointer to the beginning of the pool
void* vtcm_data_;
diff --git a/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc b/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc
index 81bd31cc84..8240241eee 100644
--- a/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc
+++ b/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc
@@ -27,13 +27,15 @@ using namespace tvm::runtime::hexagon;
class HexagonVtcmPoolTest : public ::testing::Test {
void SetUp() override {
vtcm_pool = HexagonDeviceAPI::Global()->VtcmPool();
- max_bytes = vtcm_pool->TotalBytes();
+ max_bytes = vtcm_pool->VtcmAllocatedBytes();
+ device_bytes = vtcm_pool->VtcmDeviceBytes();
}
void TearDown() override {}
public:
HexagonVtcmPool* vtcm_pool;
size_t max_bytes;
+ size_t device_bytes;
size_t four_k_block = 4096;
size_t two_k_block = 2048;
size_t one_k_block = 1024;
@@ -44,6 +46,9 @@ TEST_F(HexagonVtcmPoolTest, basic) {
void* ptr;
void* ptr2;
+ CHECK(device_bytes >= max_bytes) << "VTCM device size " << device_bytes
+ << " not greater than or equal to allocated size " << max_bytes;
+
ptr = vtcm_pool->Allocate(max_bytes);
CHECK((reinterpret_cast<uintptr_t>(ptr) & 0x7FF) == 0)
<< "Must be multiple of 2k " << ptr << " " << max_bytes;
@@ -123,7 +128,7 @@ TEST_F(HexagonVtcmPoolTest, free_alloc_combinations) {
void* ptr3;
void* ptr4;
void* new_ptr;
- size_t max_less_3_blocks = vtcm_pool->TotalBytes() - (3 * two_k_block);
+ size_t max_less_3_blocks = max_bytes - (3 * two_k_block);
ptr1 = vtcm_pool->Allocate(two_k_block);
ptr2 = vtcm_pool->Allocate(two_k_block);
ptr3 = vtcm_pool->Allocate(two_k_block);