Skip to content

Commit 4b1b2c3

Browse files
alexreinkingsoldair
authored andcommitted
run pre-commit
1 parent 3631f0d commit 4b1b2c3

3 files changed

Lines changed: 63 additions & 11 deletions

File tree

src/WasmExecutor.cpp

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,19 @@ const HostCallbackMap &get_host_callback_map() {
22572257
#if WITH_WAMR
22582258
void halide_print_native(wasm_exec_env_t exec_env, int32_t ucon, const char *str);
22592259
void halide_error_native(wasm_exec_env_t exec_env, int32_t ucon, const char *str);
2260+
int32_t halide_trace_helper_native(wasm_exec_env_t exec_env,
2261+
int32_t ucon,
2262+
int32_t func_name,
2263+
int32_t value,
2264+
int32_t coordinates,
2265+
int32_t type_code,
2266+
int32_t type_bits,
2267+
int32_t type_lanes,
2268+
int32_t trace_code,
2269+
int32_t parent_id,
2270+
int32_t value_index,
2271+
int32_t dimensions,
2272+
int32_t trace_tag);
22602273

22612274
int32_t malloc_native(wasm_exec_env_t exec_env, int32_t size) {
22622275
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
@@ -2564,9 +2577,8 @@ void wamr_extern_wrapper_n(wasm_exec_env_t exec_env, uint64_t *args) {
25642577

25652578
template<size_t... Is>
25662579
constexpr auto make_wrapper_table(std::index_sequence<Is...>) {
2567-
return std::array<void(*)(wasm_exec_env_t, uint64_t *), sizeof...(Is)>{
2568-
&wamr_extern_wrapper_n<Is>...
2569-
};
2580+
return std::array<void (*)(wasm_exec_env_t, uint64_t *), sizeof...(Is)>{
2581+
&wamr_extern_wrapper_n<Is>...};
25702582
}
25712583

25722584
constexpr size_t kMaxExternWrappers = 128;
@@ -2596,6 +2608,45 @@ void halide_error_native(wasm_exec_env_t exec_env, int32_t ucon, const char *str
25962608
}
25972609
}
25982610

2611+
int32_t halide_trace_helper_native(wasm_exec_env_t exec_env,
2612+
int32_t ucon,
2613+
int32_t func_name_ptr,
2614+
int32_t value_ptr,
2615+
int32_t coordinates_ptr,
2616+
int32_t type_code,
2617+
int32_t type_bits,
2618+
int32_t type_lanes,
2619+
int32_t trace_code,
2620+
int32_t parent_id,
2621+
int32_t value_index,
2622+
int32_t dimensions,
2623+
int32_t trace_tag_ptr) {
2624+
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
2625+
WasmModuleContents *contents = (WasmModuleContents *)wasm_runtime_get_custom_data(instance);
2626+
JITUserContext *jit_user_context = contents ? contents->jit_user_context : nullptr;
2627+
2628+
uint8_t *base = (uint8_t *)wasm_runtime_addr_app_to_native(instance, 0);
2629+
2630+
halide_trace_event_t event;
2631+
event.func = (const char *)(base + func_name_ptr);
2632+
event.value = value_ptr ? ((void *)(base + value_ptr)) : nullptr;
2633+
event.coordinates = coordinates_ptr ? ((int32_t *)(base + coordinates_ptr)) : nullptr;
2634+
event.trace_tag = (const char *)(base + trace_tag_ptr);
2635+
event.type.code = (halide_type_code_t)type_code;
2636+
event.type.bits = (uint8_t)type_bits;
2637+
event.type.lanes = (uint16_t)type_lanes;
2638+
event.event = (halide_trace_event_code_t)trace_code;
2639+
event.parent_id = parent_id;
2640+
event.value_index = value_index;
2641+
event.dimensions = dimensions;
2642+
2643+
int32_t result = 0;
2644+
if (jit_user_context && jit_user_context->handlers.custom_trace != nullptr) {
2645+
result = (*jit_user_context->handlers.custom_trace)(jit_user_context, &event);
2646+
}
2647+
return result;
2648+
}
2649+
25992650
bool should_skip_extern_symbol(const std::string &name) {
26002651
static std::set<std::string> symbols = {
26012652
"halide_print",
@@ -2641,6 +2692,7 @@ WasmModuleContents::WasmModuleContents(
26412692
static NativeSymbol native_symbols[] = {
26422693
{"halide_print", (void *)halide_print_native, "(i$)", NULL},
26432694
{"halide_error", (void *)halide_error_native, "(i$)", NULL},
2695+
{"halide_trace_helper", (void *)halide_trace_helper_native, "(iiiiiiiiiiii)i", NULL},
26442696
{"malloc", (void *)malloc_native, "(i)i", NULL},
26452697
{"free", (void *)free_native, "(i)", NULL},
26462698
{"memcpy", (void *)memcpy_native, "(iii)i", NULL},
@@ -2715,7 +2767,7 @@ WasmModuleContents::WasmModuleContents(
27152767
internal_assert(success) << "Failed to build extern signature for " << fn_name << "\n";
27162768

27172769
internal_assert(current_extern_idx < kMaxExternWrappers) << "Exceeded dynamic extern callback registration limit for WAMR";
2718-
2770+
27192771
wamr_extern_names.push_back(fn_name);
27202772
wamr_extern_arg_types.push_back(arg_types);
27212773
wamr_extern_trampoline_fns.push_back(trampoline_fn);
@@ -2999,7 +3051,7 @@ WasmModuleContents::WasmModuleContents(
29993051
#if WITH_WAMR
30003052
void WasmModuleContents::run_extern_callback(size_t index, wasm_exec_env_t exec_env, uint64_t *args) {
30013053
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
3002-
3054+
30033055
internal_assert(index < wamr_extern_names.size());
30043056
const auto &arg_types = wamr_extern_arg_types[index];
30053057
TrampolineFn trampoline_fn = wamr_extern_trampoline_fns[index];
@@ -3028,7 +3080,7 @@ void WasmModuleContents::run_extern_callback(size_t index, wasm_exec_env_t exec_
30283080
buf_ptrs[i] = buf_ptr;
30293081
void *native_buf_ptr = wasm_runtime_addr_app_to_native(instance, buf_ptr);
30303082
internal_assert(native_buf_ptr);
3031-
3083+
30323084
// Fill buffer instance from interpreted wasm_halide_buffer_t
30333085
wasm_halide_buffer_t *src = (wasm_halide_buffer_t *)native_buf_ptr;
30343086
halide_buffer_t dst_tmp;
@@ -3047,7 +3099,7 @@ void WasmModuleContents::run_extern_callback(size_t index, wasm_exec_env_t exec_
30473099
void *src_host_native = wasm_runtime_addr_app_to_native(instance, src->host);
30483100
memcpy(buffers[i].raw_buffer()->host, src_host_native, buffers[i].raw_buffer()->size_in_bytes());
30493101
}
3050-
3102+
30513103
trampoline_args[i] = buffers[i].raw_buffer();
30523104
} else {
30533105
if (a.type.code == halide_type_int || a.type.code == halide_type_uint) {

test/correctness/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ tests(GROUPS correctness
358358
vectorized_initialization.cpp
359359
vectorized_load_from_vectorized_allocation.cpp
360360
vectorized_reduction_bug.cpp
361-
widening_reduction.cpp
362361
wasm_jit_externs.cpp
362+
widening_reduction.cpp
363363
# keep-sorted end
364364
)
365365

test/correctness/wasm_jit_externs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool test_issue_1_extern_funcs() {
2222
Var x("x");
2323

2424
f(x) = x;
25-
25+
2626
std::vector<ExternFuncArgument> args;
2727
args.push_back(f);
2828

@@ -33,7 +33,7 @@ bool test_issue_1_extern_funcs() {
3333
Target t("wasm-32-wasmrt");
3434

3535
Pipeline p(g);
36-
36+
3737
JITExtern extern_fn(my_extern_func);
3838
p.set_jit_externs({{"my_extern_func", extern_fn}});
3939

@@ -59,7 +59,7 @@ bool test_issue_2_allocation_sizes() {
5959
Pipeline p(f);
6060

6161
// Moderate allocation size: 48KB image output buffer
62-
constexpr int kSize = 49152 / sizeof(int); // 48KB
62+
constexpr int kSize = 49152 / sizeof(int); // 48KB
6363
Buffer<int> output = p.realize({kSize}, t);
6464

6565
printf("Issue 2 success!\n");

0 commit comments

Comments
 (0)