2

我正在尝试编写一个构建在3 个系统上的代码,这些系统主要根据它们的寄存器长度进行区分:

  1. SSE(128 位)
  2. AVX(256 位)
  3. MIC(英特尔骑士角 512 位)

我的Makefile根据选择的系统构建可执行文件,可以从config.mk中选择,如下所示:

MIC=0           # 0 = no MIC kernels        | 1 = build MIC kernels
AVX=0           # 0 = no AVX kernels        | 1 = build AVX kernels
SSE=0           # 0 = no SSE kernels        | 1 = build SSE kernels

我的主要 Makefile 是:

#   CONFIGURE BUILD SYSTEM
include config.mk
CXXFLAGS = -O2 -g -pedantic -Wextra -Wno-format -Wall

ifeq '$(strip $(SSE))' '1'
    CXXFLAGS += -msse4.2
    TAG = LIMA
    #@echo "$(CXXFLAGS)"
endif

ifeq '$(strip $(AVX))' '1'
    CXXFLAGS += -mavx
    TAG = SANDY
    #@echo "$(CXXFLAGS)"
endif

ifeq '$(strip $(MIC))' '1'
    CXXFLAGS += -mmic
    TAG = MIC
    #@echo "$(CXXFLAGS)"
endif

CC       = icc
CXX      = icpc
INCLUDES = -I./src/includes
CXXFLAGS := $(CXXFLAGS) $(DEFINES) $(INCLUDES)
DEFINES  = -D_GNU_SOURCE -DDEBUG
LINKER   = $(CXX) -liomp5 -lpthread
LIBS     = 
LFLAGS   = 

#   BUILD PARAMETERS
TARGET     = SpMvM_$(TAG)
SRC_DIR    = ./src
MAKE_DIR   = ./
Q         ?= @
BUILD_DIR  = ./$(TAG)

VPATH = $(SRC_DIR)
OBJ = $(addprefix $(BUILD_DIR)/,$(notdir $(patsubst %.cpp,%.o, $(wildcard $(SRC_DIR)/*.cpp)) ))

${TARGET}: $(BUILD_DIR) $(OBJ)
    @echo "===>  LINKING  $(TARGET)"
    @echo "$(Q)${LINKER} ${LFLAGS} -o $(TARGET) $(OBJ) $(LIBS)"
    $(Q)${LINKER} ${LFLAGS} -o $(TARGET) $(OBJ) $(LIBS)

$(BUILD_DIR)/%.o:  %.cpp
    @echo "===>  COMPILE  $@"
    @echo "$(Q)$(CXX) $(CXXFLAGS) -c $< -o $@"
    $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 

$(BUILD_DIR):
    @mkdir $(BUILD_DIR)

.PHONY: clean distclean

clean:
    @echo "===>  CLEAN"
    @rm -rf $(BUILD_DIR)
    @rm -f tags
    @rm -f $(TARGET)
    @rm -f *~

distclean: clean
    @echo "===> DIST CLEAN"
    @rm -f $(TARGET)
    @rm -f tags

clean_dir:
    @echo "===> CLEAN DIR"
    @rm -rf LIMA/ SANDY/ MIC/

clean_all:
    @echo "===> CLEAN ALL"
    @rm -f  SpMvM_LIMA SpMvM_SANDY
    @rm -rf LIMA/ SANDY/ MIC/

config.mk有助于选择正确的编译器标志(-msse4.2、-mavx、-mmic)。

测试代码是一个简单的C++“HELLO WORLD”应用程序。它可以在SSEAVX系统上正常工作。

当我尝试在MIC上编译时,出现以下错误:

===>  COMPILE  MIC/main.o
@icpc -O2 -g -pedantic -Wextra -Wno-format -Wall -openmp -mmic  -I./src/includes -c ./src/main.cpp  -o MIC/main.o
===>  LINKING  SpMvM_MIC
@icpc -liomp5 -lpthread -o SpMvM_MIC ./MIC/main.o
ipo: warning #11010: file format not recognized for ./MIC/main.o
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
ld: ./MIC/main.o: Relocations in generic ELF (EM: 181)
./MIC/main.o: could not read symbols: File in wrong format
make: *** [SpMvM_MIC] Error 1

我已经搜索到足以了解ipo错误与在不同系统上编译和链接有关。但这对我来说没有意义。可执行文件 (SpMvM_$(TAG)) 和对象文件 ($(BUILD_DIR)/) 是在每个系统上创建的,并且它们都以足够的名称命名 ($(TAG) = LIMA, SANDY, MIC),具体取决于要使用的系统用过的。因此,来自一个系统的目标文件在与另一个系统的链接或使用方面重叠

有人可以告诉我有什么问题吗?

4

0 回答 0