From 0e60a20c1624b3c67772cc78d5fe287206bdc162 Mon Sep 17 00:00:00 2001 From: Frank Hunleth Date: Wed, 9 Oct 2024 15:18:56 -0400 Subject: [PATCH] Support cross-compilation for use with Nerves This moves the Makefile code that queries the system type and CUDA availability under a guard for whether things are being cross-compiled. If cross-compiled, then the settings are hardcoded. This should work in non-Nerves compilation cases too, but those weren't tested. --- exla/Makefile | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/exla/Makefile b/exla/Makefile index 42ae8cfae6..a371447d10 100644 --- a/exla/Makefile +++ b/exla/Makefile @@ -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 @@ -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 $@