Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial integration of Wasi-nn #1225

Closed
wants to merge 15 commits into from

Conversation

Ahmedounet
Copy link

Tflite Inference model Load function implementation following witx conventions of wasi-nn.

@Ahmedounet Ahmedounet closed this Jun 13, 2022
@wenyongh
Copy link
Contributor

@Ahmedounet Thanks for uploading the PR, it is really useful! Not sure why you closed the PR, is it due to the CI check failures? It might take some efforts to resolve the CI issues, I am wandering whether we can refactor the PR and upload it by ourselves? We will add you to help review once it is finished.

And of cause, you can resolve the issues and open it again by yourself. There are several suggestions:

Thanks.

@tonibofarull
Copy link
Contributor

Hi @wenyongh, Thanks for the feedback! We are working on it in our fork, you will get the PR back once it is stable and tested.

May I take this oportunity to ask some questions?

  1. In wasi-nn, the API is expecting some struct parameters, check here: https://github.com/WebAssembly/wasi-nn/blob/main/wasi-nn.wit.md. How do you expect it to be written in WAMR? As far as I know we have to serialize: https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md#pass-structured-data-or-class-object.
  2. Where do we include the tests? Any guideline on this?

Thank you very much!

@wenyongh
Copy link
Contributor

Hi @wenyongh, Thanks for the feedback! We are working on it in our fork, you will get the PR back once it is stable and tested.

May I take this oportunity to ask some questions?

  1. In wasi-nn, the API is expecting some struct parameters, check here: https://github.com/WebAssembly/wasi-nn/blob/main/wasi-nn.wit.md. How do you expect it to be written in WAMR? As far as I know we have to serialize: https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md#pass-structured-data-or-class-object.

Hi, for the structure defintions, we had better align them to the current coding style, for example:

typedef enum TensorType {
    ...
} TensorType;

typedef struct Tensor {
    TensorDimensions dimensions;
    TensorType type;
    TensorData data;
} Tensor;

For the serialization issue, my understanding is there are two isses:
(1) how to access the data structure of wasm world in native, for example, accessing Tensor structure in native api, you can refer to the implementation of libc-wasi wasi_fd_pwrite/pread and wasi_fd_write/read:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c#L412-L429
Normally the layouts in wasm and native are different, in native, we can define both of them:

struct Tensor_app { /* struct in wasm app */
    uint32 dimensions_offset;
    ...;
};
struct Tensor_native { /* struct in native */
    void *dimensions;
};

Then we can validation the app's offset firstly, and then convert it to the pointer (absolute address):

Tensor_app *tensor_app;
Tensor_native *tensor_native;
if (!validate_app_addr(tensor_app->dimensions_offset, sizeof(uint32)) {
  return_error;
}
tensor_native->dimensions = (void *)addr_app_to_native(iovec_app->dimensions_offset);
use tensor_native to call tensorflow API
  1. Where do we include the tests? Any guideline on this?

What the tests are? If it is a simple test like unit test, maybe you can put it under tests folder, if it is a workload, had better put it under samples, e.g. samples/wasi-nn.

Thank you very much!

@Ahmedounet Ahmedounet changed the title Sp 193 load Initial integration of Wasi-nn Jul 12, 2022
wenyongh pushed a commit that referenced this pull request Oct 12, 2022
Initial integration of WASI-NN based on #1225:
- Implement the library core/iwasm/libraries/wasi-nn
- Support TensorFlow, CPU, F32 at the first stage
- Add cmake variable `-DWAMR_BUILD_WASI_NN`
- Add test case based on Docker image and update document

Refer to #1573
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Initial integration of WASI-NN based on bytecodealliance#1225:
- Implement the library core/iwasm/libraries/wasi-nn
- Support TensorFlow, CPU, F32 at the first stage
- Add cmake variable `-DWAMR_BUILD_WASI_NN`
- Add test case based on Docker image and update document

Refer to bytecodealliance#1573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants