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

Implement base for Walrus WASI #105

Merged
merged 1 commit into from
Aug 25, 2023
Merged

Conversation

kulcsaradam
Copy link
Contributor

I have started working on implemeting WASI in Walrus.

As I have seen WASI is in a change right now where they are abandoning their witx format for wit. They are in a constant change and it could be troublesome to import other WASI systems in Walrus, as all other WebAssembly runtimes implemented their own version too as I have seen (on the basis of the official c-api).

This base can help us start implementing our own version too. This is just a rough base though, and needs some working.

My basic thought were:

  • only import functions that are used by the module

  • have a constant list with our implemented functions (this needs work, but I am open to other structures too)

  • be easily expendable

The function list right now is just for example, I do not mean to actually implement it this way.

@kulcsaradam
Copy link
Contributor Author

kulcsaradam commented Jun 16, 2023

Please give your insgihts on this if this is an accpetable approach @ksh8281 @clover2123 @zherczeg .

src/api/wasm.cpp Outdated Show resolved Hide resolved
src/runtime/Object.h Outdated Show resolved Hide resolved
src/wasi/Wasi.cpp Outdated Show resolved Hide resolved
@clover2123
Copy link
Collaborator

It looks good to support Wasi as Wasi functions are widely used.
But, IMHO implementing JITC and SIMD have the highest priority now
Of course, it would be great if Wasi is supported together while JITC and SIMD are updated too

@zherczeg I wonder your opinion and development plan as well

@kulcsaradam
Copy link
Contributor Author

It was closed by mistake.

@kulcsaradam
Copy link
Contributor Author

@clover2123 please check out this version of a base for wasi.

src/shell/Shell.cpp Outdated Show resolved Hide resolved
src/wasi/Wasi.h Outdated
FuncEnd,
};

static FunctionType* determineFuncionType(std::string str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo Funcion in this method name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more)
Instead of creating each FunctionType for WASI function
What about reusing SpecTestFunctionTypes defined in Shell.cpp?

Copy link
Contributor Author

@kulcsaradam kulcsaradam Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be done, I am just unsure if there are wasi functions where either the amount of arguments or results can be variable and we need to create new FunctionTypes, so just in case I created this function.

Shall I just change it to reuse SpecTestFunctionTypes ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please reuse SpecTestFunctionTypes as we already share a lot of it.
If we need new FunctionTypes in the future, then we can just add types on SpecTestFunctionTypes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved SpecTestFunctionTypes to a different file and also reworked the wasi functions to use those types. I am also thinking that renaming those to something like ConstantFunctionTypes could help to understand the code later down the line. What is your opinion on that?

src/shell/Shell.cpp Outdated Show resolved Hide resolved
src/shell/Shell.cpp Outdated Show resolved Hide resolved
Comment on lines 140 to 141
Walrus::WASI wasi = Walrus::WASI();
wasi.fillWasiFuncTable();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WASI instance and its function table are created whenever executeWASM called.
But can we allocate WASI once and share it in each executeWASM call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a rookie mistake on my part, but yes, we can. I moved it into main after the creation of Store. If you'd like we could add a flag so that wasi is only allocated if it needs to be used.

src/shell/Shell.cpp Outdated Show resolved Hide resolved
auto ft = functionTypes[SpecTestFunctionTypes::I32];
Walrus::WASI::WasiFunc* wasiImportFunc = wasi->find(import->fieldName());
if (wasiImportFunc == nullptr) {
break;
Copy link
Collaborator

@clover2123 clover2123 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to just stop (break) the whole importing process when an unimplemented wasi function is imported?
What if the remained import elements (importTypes) are valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I honestly did not think about the unimplemented functions as I plan to implement all of preview1.

As far as I remember the documentation doesn't really mention this, I would believe it is left to the implementing environment. I would like your opinion on this matter. Which would you prefer to just communicate the error to the user and continue or should we leave it as it is now ( exit with error Insufficient import ) ? I am open to any other ideas too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about handling unimplemented WASI features simply?
I mean that importing only supported WASI functions and just ignoring others.

if (wasiImportFunc  != nullptr) {
// import wasi function
...
}
// continue importing of next element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with this and have updated the patch to implement it.

Implement basic structure of wasi functions and also update test runner
to run wasi tests with the 'wasi' argument.

Signed-off-by: Adam Laszlo Kulcsar <[email protected]>
Copy link
Collaborator

@clover2123 clover2123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clover2123 clover2123 merged commit f1781b7 into Samsung:interp Aug 25, 2023
9 checks passed
@kulcsaradam kulcsaradam deleted the wasi branch August 28, 2023 12:30
@kulcsaradam kulcsaradam restored the wasi branch August 28, 2023 12:31
@kulcsaradam kulcsaradam deleted the wasi branch August 28, 2023 12:31
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.

2 participants