Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
[Hexagon] Create tests to showcase vtcm loading capabilities on Hexag…
Browse files Browse the repository at this point in the history
…on. (apache#12667)

* [Hexagon] Increase max buffer size for tvm_rpc_android to 1GB.

* [Hexagon] Make errors more clear when unable to allocate VTCM buffers and throw an error to fail early.

* [Hexagon] Add mem_copy_DLTensor to enable directly calling DMA for mem copies.

* [Hexagon] Add new tests as examples of the performance to expect when copying data to VTCM.

* [Hexagon] Reduce rpc max size.

* [Hexagon] Fix test_parallel_hvx_load_vtcm.py test output to be human readable.

* Comment out tests that only work on 8Gen1 HDKs to get CI to pass
  • Loading branch information
nverke authored and xinetzone committed Nov 25, 2022
1 parent e2361d8 commit 816e69a
Show file tree
Hide file tree
Showing 5 changed files with 723 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/tvm/contrib/hexagon/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
remote_kw: dict,
session_name: str = "hexagon-rpc",
remote_stack_size_bytes: int = 256 * 1024, # Min size for main thread in QuRT/sim
rpc_receive_buffer_size_bytes: int = 5 * 1024 * 1024, # Size for passing hexagon tests
rpc_receive_buffer_size_bytes: int = 256 * 1024 * 1024, # Size for passing hexagon tests
):
self._launcher = launcher
self._session_name: str = session_name
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/hexagon/hexagon_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct VTCMAllocation : public Allocation {

// allocate nbytes of vtcm on a single page
HEXAGON_SAFE_CALL(HAP_compute_res_attr_set_vtcm_param(&res_info, /*vtcm_size = */ nbytes,
/*b_single_page = */ 1));
/*b_single_page = */ 0));

// TODO(HWE): Investigate why a non-zero timeout results in
// hanging, both in the simulator and on hardware.
Expand All @@ -71,13 +71,14 @@ struct VTCMAllocation : public Allocation {
if (context_id_) {
data_ = HAP_compute_res_attr_get_vtcm_ptr(&res_info);
if (!data_) {
LOG(ERROR) << "ERROR: Allocated VTCM ptr is null.";
LOG(ERROR) << "ERROR: HAP_compute_res_acquire returned nullptr when allocating VTCM.";
HEXAGON_SAFE_CALL(HAP_compute_res_release(context_id_));
return;
}
} else {
LOG(ERROR) << "ERROR: Unable to acquire requeisted resource.";
return;
LOG(FATAL) << "FATAL: HAP_compute_res_acquire failed to acquire requested VTCM resource.";
throw std::runtime_error(
"HAP_compute_res_acquire failed to acquire requested VTCM resource.");
}
}
~VTCMAllocation() {
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/hexagon/hexagon_device_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ void HexagonDeviceAPI::CopyDataFromTo(const void* from, size_t from_offset, void
memcpy(static_cast<char*>(to) + to_offset, static_cast<const char*>(from) + from_offset, size);
}

TVM_REGISTER_GLOBAL("device_api.hexagon.mem_copy_DLTensor")
.set_body([](TVMArgs args, TVMRetValue* rv) {
DLTensor* dst = args[0];
DLTensor* src = args[1];
int size = args[2];

hexagon_user_dma_1d_sync(dst->data, src->data, size);

*rv = static_cast<int32_t>(0);
});

TVM_REGISTER_GLOBAL("device_api.hexagon.mem_copy").set_body([](TVMArgs args, TVMRetValue* rv) {
void* dst = args[0];
void* src = args[1];
Expand Down
Loading

0 comments on commit 816e69a

Please sign in to comment.