forked from WasmEdge/WasmEdge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YiYing He <[email protected]>
- Loading branch information
Showing
12 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2019-2022 Second State INC | ||
|
||
#pragma once | ||
|
||
namespace WasmEdge { | ||
namespace Host { | ||
|
||
class WasiNNContext { | ||
public: | ||
WasiNNContext() = default; | ||
~WasiNNContext() = default; | ||
// context for implementing WASI-NN | ||
// Add and implement the context data here. | ||
}; | ||
|
||
} // namespace Host | ||
} // namespace WasmEdge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2019-2022 Second State INC | ||
|
||
#pragma once | ||
|
||
#include "common/errcode.h" | ||
#include "host/wasi_nn/wasinncontext.h" | ||
#include "runtime/hostfunc.h" | ||
#include "runtime/instance/memory.h" | ||
|
||
namespace WasmEdge { | ||
namespace Host { | ||
|
||
template <typename T> class WasiNN : public Runtime::HostFunction<T> { | ||
public: | ||
WasiNN(WasiNNContext &HostCtx) : Runtime::HostFunction<T>(0), Ctx(HostCtx) {} | ||
|
||
protected: | ||
WasiNNContext &Ctx; | ||
}; | ||
|
||
class WasiNNLoad : public WasiNN<WasiNNLoad> { | ||
public: | ||
WasiNNLoad(WasiNNContext &HostCtx) : WasiNN(HostCtx) {} | ||
Expect<uint32_t> body(Runtime::Instance::MemoryInstance *, | ||
uint32_t BuilderPtr, uint32_t BuilderLen, | ||
uint32_t Encoding, uint32_t Target, uint32_t GraphPtr); | ||
}; | ||
|
||
class WasiNNInitExecCtx : public WasiNN<WasiNNInitExecCtx> { | ||
public: | ||
WasiNNInitExecCtx(WasiNNContext &HostCtx) : WasiNN(HostCtx) {} | ||
Expect<uint32_t> body(Runtime::Instance::MemoryInstance *, uint32_t Graph, | ||
uint32_t ContextPtr); | ||
}; | ||
|
||
class WasiNNSetInput : public WasiNN<WasiNNSetInput> { | ||
public: | ||
WasiNNSetInput(WasiNNContext &HostCtx) : WasiNN(HostCtx) {} | ||
Expect<uint32_t> body(Runtime::Instance::MemoryInstance *, uint32_t Context, | ||
uint32_t Index, uint32_t TensorPtr); | ||
}; | ||
|
||
class WasiNNGetOuput : public WasiNN<WasiNNGetOuput> { | ||
public: | ||
WasiNNGetOuput(WasiNNContext &HostCtx) : WasiNN(HostCtx) {} | ||
Expect<uint32_t> body(Runtime::Instance::MemoryInstance *, uint32_t Context, | ||
uint32_t Index, uint32_t OutBuffer, | ||
uint32_t OutBufferMaxSize, uint32_t BytesWrittenPtr); | ||
}; | ||
|
||
class WasiNNCompute : public WasiNN<WasiNNCompute> { | ||
public: | ||
WasiNNCompute(WasiNNContext &HostCtx) : WasiNN(HostCtx) {} | ||
Expect<uint32_t> body(Runtime::Instance::MemoryInstance *, uint32_t Context); | ||
}; | ||
|
||
} // namespace Host | ||
} // namespace WasmEdge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2019-2022 Second State INC | ||
|
||
#pragma once | ||
|
||
#include "host/wasi_nn/wasinncontext.h" | ||
#include "runtime/importobj.h" | ||
|
||
namespace WasmEdge { | ||
namespace Host { | ||
|
||
class WasiNNModule : public Runtime::ImportObject { | ||
public: | ||
WasiNNModule(); | ||
|
||
private: | ||
WasiNNContext Ctx; | ||
}; | ||
|
||
} // namespace Host | ||
} // namespace WasmEdge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
# SPDX-FileCopyrightText: 2019-2022 Second State INC | ||
|
||
add_subdirectory(wasi) | ||
add_subdirectory(wasi_nn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
wasmedge_add_library(wasmedgeHostModuleWasiNN | ||
wasinnfunc.cpp | ||
wasinnmodule.cpp | ||
) | ||
|
||
target_link_libraries(wasmedgeHostModuleWasiNN | ||
PUBLIC | ||
wasmedgeCommon | ||
wasmedgeSystem | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2019-2022 Second State INC | ||
|
||
#include "host/wasi_nn/wasinnfunc.h" | ||
#include "common/errcode.h" | ||
#include "runtime/hostfunc.h" | ||
#include "runtime/instance/memory.h" | ||
|
||
namespace WasmEdge { | ||
namespace Host { | ||
|
||
Expect<uint32_t> WasiNNLoad::body(Runtime::Instance::MemoryInstance *MemInst | ||
[[maybe_unused]], | ||
uint32_t BuilderPtr [[maybe_unused]], | ||
uint32_t BuilderLen [[maybe_unused]], | ||
uint32_t Encoding [[maybe_unused]], | ||
uint32_t Target [[maybe_unused]], | ||
uint32_t GraphPtr [[maybe_unused]]) { | ||
return 0; | ||
} | ||
|
||
Expect<uint32_t> WasiNNInitExecCtx::body( | ||
Runtime::Instance::MemoryInstance *MemInst [[maybe_unused]], | ||
uint32_t Graph [[maybe_unused]], uint32_t ContextPtr [[maybe_unused]]) { | ||
return 0; | ||
} | ||
|
||
Expect<uint32_t> WasiNNSetInput::body(Runtime::Instance::MemoryInstance *MemInst | ||
[[maybe_unused]], | ||
uint32_t Context [[maybe_unused]], | ||
uint32_t Index [[maybe_unused]], | ||
uint32_t TensorPtr [[maybe_unused]]) { | ||
return 0; | ||
} | ||
|
||
Expect<uint32_t> WasiNNGetOuput::body( | ||
Runtime::Instance::MemoryInstance *MemInst [[maybe_unused]], | ||
uint32_t Context [[maybe_unused]], uint32_t Index [[maybe_unused]], | ||
uint32_t OutBuffer [[maybe_unused]], | ||
uint32_t OutBufferMaxSize [[maybe_unused]], | ||
uint32_t BytesWrittenPtr [[maybe_unused]]) { | ||
return 0; | ||
} | ||
|
||
Expect<uint32_t> WasiNNCompute::body(Runtime::Instance::MemoryInstance *MemInst | ||
[[maybe_unused]], | ||
uint32_t Context [[maybe_unused]]) { | ||
return 0; | ||
} | ||
|
||
} // namespace Host | ||
} // namespace WasmEdge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2019-2022 Second State INC | ||
|
||
#include "host/wasi_nn/wasinnmodule.h" | ||
#include "host/wasi_nn/wasinnfunc.h" | ||
|
||
namespace WasmEdge { | ||
namespace Host { | ||
|
||
WasiNNModule::WasiNNModule() : ImportObject("wasi_ephemeral_nn") { | ||
addHostFunc("load", std::make_unique<WasiNNLoad>(Ctx)); | ||
addHostFunc("init_execution_context", | ||
std::make_unique<WasiNNInitExecCtx>(Ctx)); | ||
addHostFunc("set_input", std::make_unique<WasiNNSetInput>(Ctx)); | ||
addHostFunc("get_output", std::make_unique<WasiNNGetOuput>(Ctx)); | ||
addHostFunc("compute", std::make_unique<WasiNNCompute>(Ctx)); | ||
} | ||
|
||
} // namespace Host | ||
} // namespace WasmEdge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters