Skip to content

Commit

Permalink
[HVX] Fix state_var issue (halide#6894)
Browse files Browse the repository at this point in the history
* fix HVX state_var issue

* abort if host is nullptr
  • Loading branch information
rootjalex authored and ardier committed Mar 3, 2024
1 parent b99b41a commit b764dfb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/CodeGen_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ bool function_takes_user_context(const std::string &name) {
"halide_hexagon_initialize_kernels",
"halide_hexagon_run",
"halide_hexagon_device_release",
"halide_hexagon_get_module_state",
"halide_hexagon_power_hvx_on",
"halide_hexagon_power_hvx_on_mode",
"halide_hexagon_power_hvx_on_perf",
Expand Down
8 changes: 1 addition & 7 deletions src/HexagonOffload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,6 @@ class InjectHexagonRpc : public IRMutator {

Module &device_code;

Expr state_var(const std::string &name, Type type) {
return Let::make(name, state_var_ptr(name, type),
Load::make(type_of<void *>(), name, 0,
Buffer<>(), Parameter(), const_true(), ModulusRemainder()));
}

Expr state_var_ptr(const std::string &name, Type type) {
Expr &buf = state_bufs[name];
if (!buf.defined()) {
Expand All @@ -712,7 +706,7 @@ class InjectHexagonRpc : public IRMutator {
}

Expr module_state() {
return state_var("hexagon_module_state", type_of<void *>());
return Call::make(type_of<void *>(), "halide_hexagon_get_module_state", {state_var_ptr("hexagon_module_state", type_of<void *>())}, Call::Extern);
}

Expr module_state_ptr() {
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/HalideRuntimeHexagonHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ extern int halide_hexagon_detach_device_handle(void *user_context, struct halide
extern void *halide_hexagon_get_device_handle(void *user_context, struct halide_buffer_t *buf);
extern uint64_t halide_hexagon_get_device_size(void *user_context, struct halide_buffer_t *buf);

/** Return a pointer to the module_state. */
extern void *halide_hexagon_get_module_state(void *user_context, void **host);

/** Power HVX on and off. Calling a Halide pipeline will do this
* automatically on each pipeline invocation; however, it costs a
* small but possibly significant amount of time for short running
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/hexagon_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ WEAK uint64_t halide_hexagon_get_device_size(void *user_context, struct halide_b
return handle->size;
}

WEAK void *halide_hexagon_get_module_state(void *user_context, void **host) {
halide_abort_if_false(user_context, host != nullptr);
return host[0];
}

WEAK int halide_hexagon_device_and_host_malloc(void *user_context, struct halide_buffer_t *buf) {
debug(user_context) << "halide_hexagon_device_and_host_malloc called.\n";
int result = halide_hexagon_device_malloc(user_context, buf);
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern "C" __attribute__((used)) void *halide_runtime_api_functions[] = {
(void *)&halide_hexagon_device_release,
(void *)&halide_hexagon_get_device_handle,
(void *)&halide_hexagon_get_device_size,
(void *)&halide_hexagon_get_module_state,
(void *)&halide_hexagon_initialize_kernels,
(void *)&halide_hexagon_finalize_kernels,
(void *)&halide_hexagon_power_hvx_off,
Expand Down

0 comments on commit b764dfb

Please sign in to comment.