ifndef ASCEND_HOME_PATH
$(error "ASCEND_HOME_PATH is not set, please ensure CANN is properly installed and \
source environment variables by running `source /path/to/Ascend/cann/set_env.sh`")
endif
ifndef MPI_HOME
$(error "MPI_HOME is not set, please ensure MPI is properly installed and \
set environment variable by running `export MPI_HOME=/path/to/mpi`")
endif
CXXFLAGS := -std=c++17 \
-Werror \
-fstack-protector-strong \
-fPIE -pie \
-O2 \
-s \
-Wl,-z,relro \
-Wl,-z,now \
-Wl,-z,noexecstack \
-Wl,--copy-dt-needed-entries
SOURCES = main.cc
ASCEND_INC_DIR = ${ASCEND_HOME_PATH}/include
ASCEND_LIB_DIR = ${ASCEND_HOME_PATH}/lib64
MPI_INC_DIR = ${MPI_HOME}/include
MPI_LIB_DIR = ${MPI_HOME}/lib
LIBS = -L$(ASCEND_LIB_DIR) -lhccl -lascendcl \
-L$(MPI_LIB_DIR) -lmpi
INCS = -I$(ASCEND_INC_DIR) -I$(MPI_INC_DIR)
TARGET = one_device_per_process
N ?= 8
all:
g++ $(CXXFLAGS) $(SOURCES) $(INCS) $(LIBS) -o ${TARGET}
@echo "${TARGET} compile completed"
test:
export LD_LIBRARY_PATH=${MPI_LIB_DIR}:${LD_LIBRARY_PATH}; \
${MPI_HOME}/bin/mpirun -n $(N) ./${TARGET}
clean:
rm ${TARGET}
help:
@echo ""
@echo "HCCL Example: One device per process"
@echo "===================================="
@echo ""
@echo "This example shows how to use HcclCommInitRootInfoConfig() to create"
@echo "communicators for multiple NPUs using MPI."
@echo ""
@echo "Targets:"
@echo " all - Build the example (default)"
@echo " test - Build and run test"
@echo " clean - Remove build artifacts"
@echo " help - Show this help"
@echo ""
.PHONY: all test clean help