Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cross-compilation for use with Nerves #1543

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
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
Comment on lines +57 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe UNAME_S should be given as an optional env flag. Linux is probably always the target, but I don't think we can assert this for sure. Maybe a different name should be used for the env var as it's now gonna be (optionally) exposed.

I also wonder if we should allow NVCC to be provided via the toolchain for systems like the nvidia jetson.

Suggested change
else
# Determine settings for cross-compiled builds like for Nerves
UNAME_S = Linux
NVCC := $(CXX)
NVCCFLAGS = $(CFLAGS)
endif
else
# Determine settings for cross-compiled builds like for Nerves
UNAME_S ?= Linux
NVCC := $(CXX)
NVCCFLAGS = $(CFLAGS)
endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, given that this is only used for checking if it's mac or not, we can merge as is. Crosscompiling for mac is highly unlikely IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only cross-compilation I've run into that hasn't been Linux is for RTOSs and the "Linux" options seem to work. It might be easier to address when it comes up.

Thanks for merging!


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
Loading