Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions backends/openvino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ Before you begin, ensure you have openvino installed and configured on your syst

2. Extract the release package from the archive and set the environment variables.

For Linux
```bash
tar -zxf openvino_toolkit_<your_release_configuration>.tgz
cd openvino_toolkit_<your_release_configuration>
source setupvars.sh
```

For Windows (Powershell)
```powershell
tar -zxf openvino_toolkit_<your_release_configuration>.zip
cd openvino_toolkit_<your_release_configuration>
. ./setupvars.ps1
```

### (Optional) Build OpenVINO from Source

```bash
Expand All @@ -82,23 +90,54 @@ For more information about OpenVINO build, refer to the [OpenVINO Build Instruct

Follow the steps below to setup your build environment:


1. **Create a Virtual Environment**
- Create a virtual environment and activate it by executing the commands below.
For Linux
```bash
python -m venv env
source env/bin/activate
```

For Windows (Powershell)
```powershell
python -m venv env
env/Scripts/activate
```

2. **Clone ExecuTorch Repository from Github**
- Clone Executorch repository by executing the command below.
- On windows, make sure to enable symlinks before cloning. Refer to [Building from Source](https://docs.pytorch.org/executorch/main/using-executorch-building-from-source.html#environment-setup) for more details.
```bash
git clone --recurse-submodules https://github.com/pytorch/executorch.git
```
3. **Build ExecuTorch with OpenVINO Backend**
- Ensure that you are inside `executorch/backends/openvino/scripts` directory. The following command builds and installs ExecuTorch with the OpenVINO backend, also compiles the C++ runtime libraries and binaries into `<executorch_root>/cmake-out` for quick inference testing.
- The following commands build and install ExecuTorch with the OpenVINO backend, also compiles the C++ runtime libraries and binaries into `<executorch_root>/cmake-out` for quick inference testing.
```bash
openvino_build.sh
# cd to the root of executorch repo
cd executorch

# Get a clean cmake-out directory
./install_executorch.sh --clean
mkdir cmake-out

#Configure cmake
cmake \
-DCMAKE_INSTALL_PREFIX=cmake-out \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
-DEXECUTORCH_BUILD_OPENVINO=ON \
-DEXECUTORCH_ENABLE_LOGGING=ON \
-DPYTHON_EXECUTABLE=python \
-DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON \
-Bcmake-out .

# We can then build the runtime components with
cmake --build cmake-out --target install --config Release
```

- Optionally, `openvino_build.sh` script can be used to build python package or C++ libraries/binaries seperately.

**Build OpenVINO Backend Python Package with Pybindings**: To build and install the OpenVINO backend Python package with Python bindings, run the `openvino_build.sh` script with the `--enable_python` argument as shown in the below command. This will compile and install the ExecuTorch Python package with the OpenVINO backend into your Python environment. This option will also enable python bindings required to execute OpenVINO backend tests and `aot_optimize_and_infer.py` script inside `executorch/examples/openvino` folder.
Expand Down
16 changes: 8 additions & 8 deletions backends/openvino/runtime/OpenvinoBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,21 @@ void OpenvinoBackend::destroy(exr::DelegateHandle* handle) const {
}

ov::element::Type OpenvinoBackend::convert_to_openvino_type(
exa::ScalarType scalar_type) const {
exat::ScalarType scalar_type) const {
switch (scalar_type) {
case exa::ScalarType::Float:
case exat::ScalarType::Float:
return ov::element::f32;
case exa::ScalarType::Half:
case exat::ScalarType::Half:
return ov::element::f16;
case exa::ScalarType::Int:
case exat::ScalarType::Int:
return ov::element::i32;
case exa::ScalarType::Char:
case exat::ScalarType::Char:
return ov::element::i8;
case exa::ScalarType::Byte:
case exat::ScalarType::Byte:
return ov::element::u8;
case exa::ScalarType::Long:
case exat::ScalarType::Long:
return ov::element::i64;
case exa::ScalarType::Bool:
case exat::ScalarType::Bool:
return ov::element::boolean;
default:
throw std::runtime_error("Unsupported scalar type");
Expand Down
6 changes: 3 additions & 3 deletions backends/openvino/runtime/OpenvinoBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include <executorch/runtime/core/exec_aten/util/dim_order_util.h>
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>

using namespace std;
namespace exr = executorch::runtime;
namespace exa = executorch::aten;
namespace exat = executorch::aten;

using namespace std;

namespace executorch {
namespace backends {
Expand Down Expand Up @@ -49,7 +49,7 @@ class OpenvinoBackend final : public ::exr::BackendInterface {
void destroy(exr::DelegateHandle* handle) const override;

private:
ov::element::Type convert_to_openvino_type(exa::ScalarType scalar_type) const;
ov::element::Type convert_to_openvino_type(exat::ScalarType scalar_type) const;
};

} // namespace openvino
Expand Down
Loading