Skip to content

Commit dd01dec

Browse files
authored
feat: add LiveView Native support (#9)
* feat: initial lvn setup * feat: add mix task for asset downloads * fix: nx_iree as a lib compilation * feat: add file download mix task * feat: improve download script * feat: add nx_iree lib and includes * feat: update headers and add initial implementation of dynamic module call * feat: working compilation for ipad * feat: send bytecode and signature to device given handle_info message * feat: add msg/reply for sending an execution to a liveview * feat: add actual cpp bridge * feat: connect lvn with iree * fix: update iree * fix: read data from buffer if data is not present * fix: constructor clause * feat: working MVP for on-device execution * feat: add automatic output decoding * feat: add camera function * wip: add image processing example * feat: first working on-device example * feat: working noise-add example * feat: working version with live preview * feat: set fixed rotation angle * feat: working demo with noise-adder * feat: reduce memory leak intensity * feat: final elixir conf code * chore: lvn->embedded * gitignore adjustments
1 parent 0392d0e commit dd01dec

File tree

480 files changed

+62429
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

480 files changed

+62429
-64
lines changed

.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Used by "mix format"
22
[
3-
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
3+
inputs: ["{mix,.formatter}.exs", "{liveview_native,config,lib,test}/**/*.{ex,exs}"]
44
]

.github/workflows/embedded_devices.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
MIX_ENV: prod
1717
NX_IREE_PREFER_PRECOMPILED: false
1818
NX_IREE_SOURCE_DIR: ./build-cache/iree
19-
IREE_GIT_REV: candidate-20240604.914
19+
IREE_GIT_REV: candidate-20240822.993
2020
strategy:
2121
fail-fast: true
2222
matrix:

.github/workflows/precompiled_nif.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
MIX_ENV: prod
1717
NX_IREE_PREFER_PRECOMPILED: false
1818
NX_IREE_SOURCE_DIR: ./build-cache/iree
19-
IREE_GIT_REV: candidate-20240604.914
19+
IREE_GIT_REV: candidate-20240822.993
2020
BUILD_IREE_RUNTIME: false
2121
strategy:
2222
fail-fast: false
@@ -83,7 +83,7 @@ jobs:
8383
MIX_ENV: prod
8484
NX_IREE_PREFER_PRECOMPILED: false
8585
NX_IREE_SOURCE_DIR: ./build-cache/iree
86-
IREE_GIT_REV: candidate-20240604.914
86+
IREE_GIT_REV: candidate-20240822.993
8787
ImageOS: ubuntu22
8888
LANG: en_US.UTF-8
8989
LANGUAGE: en_US:en

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ nx_iree-*.tar
2727

2828
/iree-runtime/
2929
/cache/
30+
31+
/priv/iree-compile
32+
/priv/iree-runtime
33+
/priv/lbnx_iree.so

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ endif
165165

166166
NX_IREE_LIB_DIR = $(MIX_APP_PATH)/priv/iree-runtime
167167
NX_IREE_LIB_LINK_PATH = $(CWD_RELATIVE_TO_PRIV_PATH)/$(NX_IREE_RUNTIME_LIB)
168-
NX_IREE_CACHE_SO_LINK_PATH = $(CWD_RELATIVE_TO_PRIV_PATH)/$(NX_IREE_CACHE_SO)
168+
NX_IREE_CACHE_SO_LINK_PATH = $(NX_IREE_CACHE_SO)
169169

170170
SOURCES = $(wildcard c_src/*.cc)
171171
HEADERS = $(wildcard c_src/*.h)

cmake/src/runtime.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ iree::runtime::Device::~Device() {
2626
}
2727
}
2828

29-
iree::runtime::IREETensor::IREETensor(iree_hal_buffer_view_t *buffer_view, iree_hal_element_type_t type) : buffer_view(buffer_view), type(type) {
29+
iree::runtime::IREETensor::IREETensor(iree_hal_buffer_view_t *buffer_view, iree_hal_element_type_t type, iree_hal_device_t *device) : buffer_view(buffer_view), type(type), device(device) {
3030
size = iree_hal_buffer_view_byte_length(buffer_view);
3131
// TODO: fill in dim metadata
3232
}
@@ -81,6 +81,19 @@ std::vector<char> *iree::runtime::IREETensor::serialize() {
8181
size_t size_size = sizeof(size);
8282
buffer->insert(buffer->end(), reinterpret_cast<const char *>(&size), reinterpret_cast<const char *>(&size) + size_size);
8383

84+
if (data == nullptr) {
85+
data = std::malloc(size);
86+
87+
if (data == nullptr) {
88+
return nullptr;
89+
}
90+
91+
auto status = read_buffer(device, buffer_view, data, size);
92+
93+
if (!iree_status_is_ok(status)) {
94+
return nullptr;
95+
}
96+
}
8497
// Serialize 'data'
8598
buffer->insert(buffer->end(), reinterpret_cast<const char *>(data), reinterpret_cast<const char *>(data) + size);
8699

@@ -341,7 +354,7 @@ call(iree_vm_instance_t *instance, iree_hal_device_t *device, std::string driver
341354
const iree_hal_dim_t *out_shape = iree_hal_buffer_view_shape_dims(output_buffer_view);
342355
iree_hal_element_type_t out_type = iree_hal_buffer_view_element_type(output_buffer_view);
343356

344-
auto tensor = new iree::runtime::IREETensor(output_buffer_view, out_type);
357+
auto tensor = new iree::runtime::IREETensor(output_buffer_view, out_type, device);
345358
tensor->dims = std::vector<iree_hal_dim_t>();
346359
for (int j = 0; j < out_shape_rank; j++) {
347360
tensor->dims.push_back(out_shape[j]);

cmake/src/runtime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ class IREETensor {
4141
std::vector<iree_hal_dim_t> dims;
4242
iree_hal_element_type_t type;
4343
iree_hal_buffer_view_t* buffer_view;
44+
iree_hal_device_t* device;
4445

4546
IREETensor(char* serialized_data);
46-
IREETensor(iree_hal_buffer_view_t* buffer_view, iree_hal_element_type_t type);
47+
IREETensor(iree_hal_buffer_view_t* buffer_view, iree_hal_element_type_t type, iree_hal_device_t* device);
4748
IREETensor(void* data, size_t size, std::vector<int64_t> in_dims, iree_hal_element_type_t type);
4849

4950
// Destructor
@@ -74,7 +75,7 @@ class IREETensor {
7475

7576
iree_vm_instance_t* create_instance();
7677
iree_hal_driver_registry_t* get_driver_registry();
77-
iree_hal_device_t* create_device(const std::string& device_uri);
78+
iree_hal_device_t* create_device(iree_hal_driver_registry_t* registry, const std::string& device_uri);
7879

7980
std::pair<iree_status_t, std::optional<std::vector<iree::runtime::IREETensor*>>>
8081
call(iree_vm_instance_t* i, iree_hal_device_t*, std::string, unsigned char*, size_t, std::vector<iree::runtime::IREETensor*>);

compiler.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Nx.Defn.default_options(compiler: NxIREE.Compiler, iree_compiler_flags: flags, i
1818

1919
f = Nx.Defn.compile(fun, args)
2020

21+
Nx.default_backend(NxIREE.Tensor)
2122
arg0 = Nx.tensor([1.0, 2.0, 3.0, 4.0])
2223
arg1 = Nx.tensor([1, -1, 1, -1])
2324
f.(arg0, arg1) |> dbg()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
import_deps: [:ecto, :ecto_sql, :phoenix],
3+
subdirectories: ["priv/*/migrations"],
4+
plugins: [Phoenix.LiveView.HTMLFormatter],
5+
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
6+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/
24+
25+
# Ignore package tarball (built via "mix hex.build").
26+
live_nx_iree-*.tar
27+
28+
# Ignore assets that are produced by build tools.
29+
/priv/static/assets/
30+
31+
# Ignore digested assets cache.
32+
/priv/static/cache_manifest.json
33+
34+
# In case you use Node.js/npm, you want to ignore these.
35+
npm-debug.log
36+
/assets/node_modules/
37+

0 commit comments

Comments
 (0)