Skip to content

Commit 35a4dac

Browse files
polvalentecocoa-xu
andauthored
feat: EMLX compiled mode (#68)
* feat: add nif_call-based function compilation * fix: make tests pass * wip * feat: working callback * wip: add benchmarks * feat: use non-modified header * chore: remove bench files * test: add compile test * chore: forat * docs: add warning on EMLX compiler * docs: show github installation * chore: update to safe nif_call version * wip: update nif_call * use nif_call v0.1.3 Signed-off-by: Cocoa <[email protected]> --------- Signed-off-by: Cocoa <[email protected]> Co-authored-by: Cocoa <[email protected]>
1 parent 6afc1a7 commit 35a4dac

File tree

12 files changed

+720
-153
lines changed

12 files changed

+720
-153
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ MLX_BUILD_DIR = $(EMLX_CACHE_DIR)/mlx/build-$(MLX_VERSION)$(MLX_VARIANT)
1111
MLX_INSTALL_DIR = $(MLX_DIR)
1212
MLX_SO = $(MLX_LIB_DIR)/libmlx.dylib
1313

14+
$(info LIBMLX_ENABLE_DEBUG=$(LIBMLX_ENABLE_DEBUG))
1415
# Build flags
1516
CFLAGS = -fPIC -I$(ERTS_INCLUDE_DIR) -I$(MLX_INCLUDE_DIR) -Wall \
1617
-std=c++17
@@ -39,6 +40,7 @@ MAKE_JOBS ?= $(MAKE_DEFAULT_JOBS)
3940

4041
# Source files
4142
SOURCES = c_src/emlx_nif.cpp
43+
HEADERS = c_src/nif_call.h c_src/nx_nif_utils.hpp
4244
OBJECTS = $(patsubst c_src/%.cpp,$(BUILD_DIR)/%.o,$(SOURCES))
4345

4446
# Main targets
@@ -48,7 +50,7 @@ all: $(MLX_SO) $(EMLX_SO)
4850
$(PRIV_DIR):
4951
@ mkdir -p $(PRIV_DIR)
5052

51-
$(BUILD_DIR)/%.o: c_src/%.cpp
53+
$(BUILD_DIR)/%.o: c_src/%.cpp $(HEADERS)
5254
@ mkdir -p $(BUILD_DIR)
5355
$(CXX) $(CFLAGS) -c $< -o $@
5456

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ To use EMLX, you can add it as a dependency in your `mix.exs`:
2323
```elixir
2424
def deps do
2525
[
26-
{:emlx, "~> 0.1.0"}
26+
{:emlx, github: "elixir-nx/emlx", branch: "main"}
2727
]
2828
end
2929
```
@@ -40,7 +40,10 @@ Nx.default_backend({EMLX.Backend, device: :cpu})
4040
Nx.default_backend({EMLX.Backend, device: :gpu})
4141
```
4242

43-
If desireable, you can also set the default compiler:
43+
If you want to use the JIT compiler, you can set the default compiler as shown below.
44+
45+
Currently, the underlying implementation is not totally safe and could lead to a deadlocked dirty NIF, so this must be used with care.
46+
Defaulting to Nx.Defn.Evaluator is the safest option for now.
4447

4548
```elixir
4649
Nx.Defn.default_options(compiler: EMLX)

0 commit comments

Comments
 (0)