Skip to content

Commit

Permalink
Merge pull request #286 from gwsystems/spec-alignment
Browse files Browse the repository at this point in the history
Spec alignment
  • Loading branch information
bushidocodes authored Dec 5, 2021
2 parents b841889 + 5efee76 commit 6b037e3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./runtime/bin/gocr_wasm.so
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/Makefile', './runtime/tests/gocr/**', './runtime/compiletime/**', './runtime/compiletime/memory/**') }}
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/Makefile', './runtime/tests/gocr/**', './runtime/compiletime/**') }}
if: success() || failure()
- name: Hyde
run: |
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./runtime/bin/ekf_wasm.so
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/Makefile', './runtime/tests/TinyEKF/**', './runtime/compiletime/**', './runtime/compiletime/memory/**') }}
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/Makefile', './runtime/tests/TinyEKF/**', './runtime/compiletime/**') }}
if: success() || failure()
- name: EKF one iteration
run: |
Expand Down
5 changes: 5 additions & 0 deletions runtime/compiletime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A WebAssembly module instance is statically linked with the backing functions implementing the wasm32 ABI, yielding a *.so file that SLEdge can execute. This ensures that the instance is able to aggressively inline and optimize this code.

They are broken into instruction types as on https://webassembly.github.io/spec/core/exec/instructions.html. They depend on common headers for the WebAssembly types located in the WebAssembly instance struct. These are located in runtime/include/common.

The stubs correspond to awsm/src/codegen/runtime_stubs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>

#include "types.h"

uint32_t
Expand Down Expand Up @@ -164,19 +165,3 @@ set_global_i64(uint32_t offset, int64_t v)
{
set_i64(offset, v);
}

// Table handling functionality
// INLINE char *
// get_function_from_table(uint32_t idx, uint32_t type_id)
// {
// assert(idx < INDIRECT_TABLE_SIZE);

// struct indirect_table_entry f = local_sandbox_context_cache.module_indirect_table[idx];

// // FIXME: Commented out function type check because of gocr
// // assert(f.type_id == type_id);

// assert(f.func_pointer);

// return f.func_pointer;
// }
File renamed without changes.
42 changes: 42 additions & 0 deletions runtime/compiletime/table_instructions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <assert.h>

#include "types.h"

extern thread_local struct wasm_module_instance current_wasm_module_instance;

INLINE void
add_function_to_table(uint32_t idx, uint32_t type_id, char *pointer)
{
assert(idx < INDIRECT_TABLE_SIZE);
assert(local_sandbox_context_cache.module_indirect_table != NULL);

/* TODO: atomic for multiple concurrent invocations? Issue #97 */
if (local_sandbox_context_cache.module_indirect_table[idx].type_id == type_id
&& local_sandbox_context_cache.module_indirect_table[idx].func_pointer == pointer)
return;

local_sandbox_context_cache.module_indirect_table[idx] = (struct indirect_table_entry){
.type_id = type_id, .func_pointer = pointer
};
}

INLINE char *
get_function_from_table(uint32_t idx, uint32_t type_id)
{
#ifdef LOG_FUNCTION_TABLE
fprintf(stderr, "get_function_from_table(idx: %u, type_id: %u)\n", idx, type_id);
fprintf(stderr, "indirect_table_size: %u\n", INDIRECT_TABLE_SIZE);
#endif
assert(idx < INDIRECT_TABLE_SIZE);

struct indirect_table_entry f = local_sandbox_context_cache.module_indirect_table[idx];
#ifdef LOG_FUNCTION_TABLE
fprintf(stderr, "assumed type: %u, type in table: %u\n", type_id, f.type_id);
#endif
// FIXME: Commented out function type check because of gocr
// assert(f.type_id == type_id);

assert(f.func_pointer != NULL);

return f.func_pointer;
}
28 changes: 0 additions & 28 deletions runtime/src/memory/64bit_nix.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,3 @@ instruction_memory_grow(uint32_t count)

return rc;
}

/*
* Table handling functionality
* This was moved from compiletime in order to place the
* function in the callstack in GDB. It can be moved back
* to runtime/compiletime/memory/64bit_nix.c to remove the
* additional function call
*/
char *
get_function_from_table(uint32_t idx, uint32_t type_id)
{
#ifdef LOG_FUNCTION_TABLE
fprintf(stderr, "get_function_from_table(idx: %u, type_id: %u)\n", idx, type_id);
fprintf(stderr, "indirect_table_size: %u\n", INDIRECT_TABLE_SIZE);
#endif
assert(idx < INDIRECT_TABLE_SIZE);

struct indirect_table_entry f = local_sandbox_context_cache.module_indirect_table[idx];
#ifdef LOG_FUNCTION_TABLE
fprintf(stderr, "assumed type: %u, type in table: %u\n", type_id, f.type_id);
#endif
// FIXME: Commented out function type check because of gocr
// assert(f.type_id == type_id);

assert(f.func_pointer != NULL);

return f.func_pointer;
}
16 changes: 0 additions & 16 deletions runtime/src/memory/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ initialize_region(uint32_t offset, uint32_t data_count, char *data)
memcpy(get_memory_ptr_for_runtime(offset, data_count), data, data_count);
}

void
add_function_to_table(uint32_t idx, uint32_t type_id, char *pointer)
{
assert(idx < INDIRECT_TABLE_SIZE);
assert(local_sandbox_context_cache.module_indirect_table != NULL);

/* TODO: atomic for multiple concurrent invocations? Issue #97 */
if (local_sandbox_context_cache.module_indirect_table[idx].type_id == type_id
&& local_sandbox_context_cache.module_indirect_table[idx].func_pointer == pointer)
return;

local_sandbox_context_cache.module_indirect_table[idx] = (struct indirect_table_entry){
.type_id = type_id, .func_pointer = pointer
};
}

/* If we are using runtime globals, we need to populate them */
WEAK void
populate_globals()
Expand Down
2 changes: 1 addition & 1 deletion runtime/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ OPTFLAGS=-O3 -flto
SLEDGE_BASE_DIR=../../
SLEDGE_RT_DIR=${SLEDGE_BASE_DIR}/runtime/
SLEDGE_COMPILETIME_INC=${SLEDGE_RT_DIR}/include
SLEDGE_COMPILETIME_SRC=${SLEDGE_RT_DIR}/compiletime/instr.c ${SLEDGE_RT_DIR}/compiletime/memory/64bit_nix.c
SLEDGE_COMPILETIME_SRC=${SLEDGE_RT_DIR}/compiletime/*.c

ALL=fibonacci empty ekf cifar10 gocr lpd resize
ALL_COPY_DEST=$(ALL:%=../../runtime/bin/%_wasm.so)
Expand Down

0 comments on commit 6b037e3

Please sign in to comment.