Skip to content

Commit

Permalink
Support cross-compilation for use with Nerves (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhunleth authored Oct 10, 2024
1 parent 21d9d4a commit 3a92566
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions exla/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,28 @@ endif

LDFLAGS = -L$(XLA_EXTENSION_LIB) -lxla_extension -shared

ifeq ($(shell uname -s), Darwin)
ifeq ($(CROSSCOMPILE),)
# Interrogate the system for local compilation
UNAME_S = $(shell uname -s)

NVCC_RESULT := $(shell which nvcc 2> /dev/null)
NVCC_TEST := $(notdir $(NVCC_RESULT))

ifeq ($(NVCC_TEST),nvcc)
NVCC := nvcc
NVCCFLAGS += -DCUDA_ENABLED
else
NVCC := $(CXX)
NVCCFLAGS = $(CFLAGS)
endif
else
# Determine settings for cross-compiled builds like for Nerves
UNAME_S = Linux
NVCC := $(CXX)
NVCCFLAGS = $(CFLAGS)
endif

ifeq ($(UNAME_S), Darwin)
LDFLAGS += -flat_namespace -undefined dynamic_lookup -rpath @loader_path/xla_extension/lib
else
# Use a relative RPATH, so at runtime libexla.so looks for libxla_extension.so
Expand All @@ -67,17 +88,6 @@ HEADERS = $(EXLA_DIR)/exla_mlir.h $(EXLA_DIR)/custom_calls/qr.h $(EXLA_DIR)/cust
OBJECTS = $(patsubst $(EXLA_DIR)/%.cc,$(EXLA_CACHE_OBJ_DIR)/%.o,$(SOURCES)) $(EXLA_CACHE_OBJ_DIR)/exla_cuda.o


NVCC_RESULT := $(shell which nvcc 2> /dev/null)
NVCC_TEST := $(notdir $(NVCC_RESULT))

ifeq ($(NVCC_TEST),nvcc)
NVCC := nvcc
NVCCFLAGS += -DCUDA_ENABLED
else
NVCC := $(CXX)
NVCCFLAGS = $(CFLAGS)
endif

$(EXLA_CACHE_OBJ_DIR)/exla_cuda.o: $(EXLA_DIR)/exla_cuda.cc $(EXLA_DIR)/exla_cuda.h
@ mkdir -p $(EXLA_CACHE_OBJ_DIR)
$(NVCC) $(NVCCFLAGS) -c $< -o $@
Expand Down

0 comments on commit 3a92566

Please sign in to comment.