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

initial riscv import #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
76 changes: 59 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# GPL LICENSE SUMMARY
#
# Copyright(c) 2024 Tactical Computing Labs, LLC
# Copyright(c) 2021 Cornelis Networks.
# Copyright(c) 2017 Intel Corporation.
#
Expand Down Expand Up @@ -131,19 +132,35 @@ INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/ptl_ips -I$(OUTDIR)

ifneq (x86_64,$(arch))
ifneq (i386,$(arch))
anerr := $(error Unsupported architecture $(arch))
ifneq (riscv64,$(arch))
anerr := $(error Unsupported architecture $(arch))
endif
endif
endif

ifndef LIBDIR
ifeq (${arch},x86_64)
INSTALL_LIB_TARG=/usr/lib64
else
INSTALL_LIB_TARG=/usr/lib
ifeq (${arch},riscv64)
INSTALL_LIB_TARG=/usr/lib64
else
INSTALL_LIB_TARG=/usr/lib
endif
endif
else
INSTALL_LIB_TARG=${LIBDIR}
endif

ifeq (${arch},riscv64)
LINUX_ARCH=riscv64
INSTALL_ARCH=riscv
endif
ifeq (${arch},x86_64)
LINUX_ARCH=i386
INSTALL_ARCH=x86_64
endif

export DESTDIR
export INSTALL_LIB_TARG

Expand All @@ -168,14 +185,21 @@ nthreads := $(shell echo $$(( `nproc` * 2 )) )

DISTRO := $(shell . /etc/os-release; if [ "$$ID" = "sle_hpc" ]; then ID="sles"; fi; echo $$ID)

UDEVDIR := $(shell $(PKG_CONFIG) --variable=udevdir udev 2>/dev/null)
ifndef UDEVDIR
UDEVDIR = /lib/udev
endif

export UDEVDIR

# By default the following two variables have the following values:
LIBPSM2_COMPAT_CONF_DIR := /etc
LIBPSM2_COMPAT_SYM_CONF_DIR := /etc
# We can't set SPEC_FILE_RELEASE_DIST to an empty value, a space will result.
# It then messes up sed operations for PSM_CUDA=1.
# So leaving the commented out line here as documentation to NOT set it.
# SPEC_FILE_RELEASE_DIST :=
UDEV_40_PSM_RULES := %{_udevrulesdir}/40-psm.rules
UDEV_40_PSM_RULES := $(UDEVDIR)/40-psm.rules

ifeq (fedora,$(DISTRO))
# On Fedora, we change these two variables to these values:
Expand Down Expand Up @@ -252,13 +276,6 @@ LDLIBS := -lrt -ldl -lnuma ${EXTRA_LIBS} -pthread

PKG_CONFIG ?= pkg-config

UDEVDIR := $(shell $(PKG_CONFIG) --variable=udevdir udev 2>/dev/null)
ifndef UDEVDIR
UDEVDIR = /lib/udev
endif

export UDEVDIR

# The DIST variable is a name kernel corresponding to:
# 1. The name of the directory containing the source code distribution
# (see dist: target below).
Expand Down Expand Up @@ -393,11 +410,11 @@ $(OUTDIR):
mkdir -p ${OUTDIR}

symlinks:
@test -L $(top_srcdir)/include/linux-x86_64 || \
ln -sf linux-i386 $(top_srcdir)/include/linux-x86_64
@test -L $(top_srcdir)/include/linux-$(arch) || \
ln -sf linux-$(LINUX_ARC) $(top_srcdir)/include/linux-$(arch)

cleanlinks:
rm -rf $(top_srcdir)/include/linux-x86_64
rm -rf $(top_srcdir)/include/linux-$(arch)

install: all
for subdir in $(SUBDIRS) ; do \
Expand All @@ -416,14 +433,16 @@ install: all
install -m 0644 -D psm2.h ${DESTDIR}/usr/include/psm2.h
install -m 0644 -D psm2_mq.h ${DESTDIR}/usr/include/psm2_mq.h
install -m 0644 -D psm2_am.h ${DESTDIR}/usr/include/psm2_am.h
ifneq (fedora,${DISTRO})
ifeq (fedora,${DISTRO})
install -m 0644 -D 40-psm.rules ${DESTDIR}$(UDEVDIR)/rules.d/40-psm.rules
else
install -m 0644 -D 40-psm.rules ${DESTDIR}$(UDEVDIR)/40-psm.rules
endif
# The following files and dirs were part of the noship rpm:
mkdir -p ${DESTDIR}/usr/include/hfi1diag
mkdir -p ${DESTDIR}/usr/include/hfi1diag/linux-x86_64
install -m 0644 -D include/linux-x86_64/bit_ops.h ${DESTDIR}/usr/include/hfi1diag/linux-x86_64/bit_ops.h
install -m 0644 -D include/linux-x86_64/sysdep.h ${DESTDIR}/usr/include/hfi1diag/linux-x86_64/sysdep.h
mkdir -p ${DESTDIR}/usr/include/hfi1diag/linux-$(arch)
install -m 0644 -D include/linux-${INSTALL_ARCH}/bit_ops.h ${DESTDIR}/usr/include/hfi1diag/linux-${INSTALL_ARCH}/bit_ops.h
install -m 0644 -D include/linux-${INSTALL_ARCH}/sysdep.h ${DESTDIR}/usr/include/hfi1diag/linux-${INSTALL_ARCH}/sysdep.h
install -m 0644 -D include/opa_udebug.h ${DESTDIR}/usr/include/hfi1diag/opa_udebug.h
install -m 0644 -D include/opa_debug.h ${DESTDIR}/usr/include/hfi1diag/opa_debug.h
install -m 0644 -D include/opa_intf.h ${DESTDIR}/usr/include/hfi1diag/opa_intf.h
Expand All @@ -446,6 +465,7 @@ endif
install -m 0644 -D psm_hal_gen1/hfi1_deprecated_gen1.h ${DESTDIR}/usr/include/hfi1diag/hfi1_deprecated.h
rm -fr $(TEMP_INST_DIR)

ifeq (fedora,${DISTRO})
specfile: specfile_clean | $(OUTDIR)
sed -e 's/@VERSION@/'${VERSION_RELEASE}'/g' libpsm2.spec.in | \
sed -e 's/@TARGLIB@/'${TARGLIB}'/g' \
Expand All @@ -466,6 +486,28 @@ specfile: specfile_clean | $(OUTDIR)
else \
sed -i 's;@40_PSM_RULES@;'${UDEV_40_PSM_RULES}';g' ${OUTDIR}/${RPM_NAME}.spec; \
fi
else
specfile: specfile_clean | $(OUTDIR)
sed -e 's/@VERSION@/'${VERSION_RELEASE}'/g' libpsm2.spec.in | \
sed -e 's/@TARGLIB@/'${TARGLIB}'/g' \
-e 's/@RPM_NAME@/'${RPM_NAME}'/g' \
-e 's/@RPM_NAME_BASEEXT@/'${RPM_NAME_BASEEXT}'/g' \
-e 's/@COMPATLIB@/'${COMPATLIB}'/g' \
-e 's/@COMPATMAJOR@/'${COMPATMAJOR}'/g' \
-e 's;@UDEVDIR@;'${UDEVDIR}';g' \
-e 's/@MAJOR@/'${MAJOR}'/g' \
-e 's/@MINOR@/'${MINOR}'/g' \
-e 's:@LIBPSM2_COMPAT_CONF_DIR@:'${LIBPSM2_COMPAT_CONF_DIR}':g' \
-e 's:@LIBPSM2_COMPAT_SYM_CONF_DIR@:'${LIBPSM2_COMPAT_SYM_CONF_DIR}':g' \
-e 's;@SPEC_FILE_RELEASE_DIST@;'${SPEC_FILE_RELEASE_DIST}';g' \
-e 's/@DIST_SHA@/'${DIST_SHA}'/g' > \
${OUTDIR}/${RPM_NAME}.spec
if [ -f /etc/redhat-release ] && [ `grep -o "[0-9.]*" /etc/redhat-release | cut -d"." -f1` -lt 7 ]; then \
sed -i 's;@40_PSM_RULES@;'${UDEVDIR}'/40-psm.rules;g' ${OUTDIR}/${RPM_NAME}.spec; \
else \
sed -i 's;@40_PSM_RULES@;'${UDEV_40_PSM_RULES}';g' ${OUTDIR}/${RPM_NAME}.spec; \
fi
endif

# We can't totally prevent two make dist calls in a row from packaging
# the previous make dist, unless we switch to using a dedicated ./src folder
Expand Down
87 changes: 53 additions & 34 deletions buildflags.mak
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# GPL LICENSE SUMMARY
#
# Copyright(c) 2024 Tactical Computing Labs, LLC
# Copyright(c) 2021 Cornelis Networks.
# Copyright(c) 2016 Intel Corporation.
#
Expand Down Expand Up @@ -74,6 +75,13 @@ else
anerr := $(error Unknown Fortran compiler arch: ${FCARCH})
endif # gfortran

ifeq (${arch},riscv64)
ARCH=riscv64
endif
ifeq (${arch},x86_64)
ARCH=i386
endif

BASECFLAGS := $(BASE_FLAGS) -pthread
LDFLAGS += $(BASE_FLAGS)
ASFLAGS += $(BASE_FLAGS)
Expand All @@ -88,7 +96,16 @@ LINKER_SCRIPT := -Wl,--version-script $(LINKER_SCRIPT_FILE)
endif

WERROR := -Werror
INCLUDES := -I$(top_srcdir)/include -I$(top_srcdir)/mpspawn -I$(top_srcdir)/include/$(os)-$(arch)

ifeq (${arch},riscv64)
ARCH_INCLUDES=linux-riscv
endif

ifeq (${arch},x86_64)
ARCH_INCLUDES=linux-i386
endif

INCLUDES := -I$(top_srcdir)/include -I$(top_srcdir)/include/$(ARCH_INCLUDES) -I$(top_srcdir)/mpspawn -I$(top_srcdir)/include/$(os)-$(arch)

#
# use IFS provided hfi1_user.h if installed.
Expand All @@ -101,48 +118,50 @@ BASECFLAGS +=-Wall $(WERROR)
#
# test if compiler supports 32B(AVX2)/64B(AVX512F) move instruction.
#
ifeq (${CC},icc)
ifeq ($(PSM_DISABLE_AVX2),)
MAVX2=-xATOM_SSE4.2 -DPSM_AVX512
else
MAVX2=-march=core-avx-i
endif
else
ifeq ($(PSM_DISABLE_AVX2),)
MAVX2=-mavx2
ifeq (${arch},x86_64)
ifeq (${CC},icc)
ifeq ($(PSM_DISABLE_AVX2),)
MAVX2=-xATOM_SSE4.2 -DPSM_AVX512
else
MAVX2=-march=core-avx-i
endif
else
MAVX2=-mavx
ifeq ($(PSM_DISABLE_AVX2),)
MAVX2=-mavx2
else
MAVX2=-mavx
endif
endif
endif

ifneq (icc,${CC})
ifeq ($(PSM_DISABLE_AVX2),)
RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX2 ; echo $$?)
else
RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX ; echo $$?)
anerr := $(warning ***NOTE TO USER**** Disabling AVX2 will harm performance)
endif
ifneq (icc,${CC})
ifeq ($(PSM_DISABLE_AVX2),)
RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX2 ; echo $$?)
else
RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX ; echo $$?)
anerr := $(warning ***NOTE TO USER**** Disabling AVX2 will harm performance)
endif

ifeq (0,${RET})
BASECFLAGS += ${MAVX2}
ifeq (0,${RET})
BASECFLAGS += ${MAVX2}
else
anerr := $(error Compiler does not support ${MAVX2} )
endif
else
anerr := $(error Compiler does not support ${MAVX2} )
endif
else
BASECFLAGS += ${MAVX2}
endif
endif

# This support is dynamic at runtime, so is OK to enable as long as compiler can generate
# the code.
ifneq (,${PSM_AVX512})
ifneq (icc,${CC})
RET := $(shell echo "int main() {}" | ${CC} -mavx512f -E -dM -xc - 2>&1 | grep -q AVX512 ; echo $$?)
ifeq (0,${RET})
BASECFLAGS += -mavx512f
else
anerr := $(error Compiler does not support AVX512 )
ifneq (,${PSM_AVX512})
ifneq (icc,${CC})
RET := $(shell echo "int main() {}" | ${CC} -mavx512f -E -dM -xc - 2>&1 | grep -q AVX512 ; echo $$?)
ifeq (0,${RET})
BASECFLAGS += -mavx512f
else
anerr := $(error Compiler does not support AVX512 )
endif
BASECFLAGS += -DPSM_AVX512
endif
BASECFLAGS += -DPSM_AVX512
endif
endif

Expand Down Expand Up @@ -183,8 +202,8 @@ endif
ifneq (,${PSM_PROFILE})
BASECFLAGS += -DPSM_PROFILE
endif
BASECFLAGS += -DNVIDIA_GPU_DIRECT
ifneq (,${PSM_CUDA})
BASECFLAGS += -DNVIDIA_GPU_DIRECT
BASECFLAGS += -DPSM_CUDA
CUDA_HOME ?= /usr/local/cuda
INCLUDES += -I$(CUDA_HOME)/include
Expand Down
9 changes: 9 additions & 0 deletions compat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# GPL LICENSE SUMMARY
#
# Copyright(c) 2024 Tactical Computing Labs, LLC
# Copyright(c) 2015 Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -69,11 +70,19 @@ DEPS:= $(${COMPATLIB}-objs:.o=.d)

all .DEFAULT: ${${COMPATLIB}-objs} $(OUTDIR)/${COMPATLIB}.so.${MAJOR}

ifeq (fedora,${DISTRO})
install: all
install -m 0644 -D 40-psm-compat.rules ${DESTDIR}$(UDEVDIR)/rules.d/40-psm-compat.rules
install -m 0644 -D libpsm2-compat.conf ${DESTDIR}${LIBPSM2_COMPAT_CONF_DIR}/modprobe.d/libpsm2-compat.conf
install -m 0755 -D libpsm2-compat.cmds ${DESTDIR}/usr/lib/libpsm2/libpsm2-compat.cmds
install -D $(OUTDIR)/${COMPATLIB}.so.${MAJOR} ${DESTDIR}${COMPAT_LIB_TARG}/${COMPATLIB}.so.${MAJOR}
else
install: all
install -m 0644 -D 40-psm-compat.rules ${DESTDIR}$(UDEVDIR)/40-psm-compat.rules
install -m 0644 -D libpsm2-compat.conf ${DESTDIR}${LIBPSM2_COMPAT_CONF_DIR}/modprobe.d/libpsm2-compat.conf
install -m 0755 -D libpsm2-compat.cmds ${DESTDIR}/usr/lib/libpsm2/libpsm2-compat.cmds
install -D $(OUTDIR)/${COMPATLIB}.so.${MAJOR} ${DESTDIR}${COMPAT_LIB_TARG}/${COMPATLIB}.so.${MAJOR}
endif

$(OUTDIR)/%.o: $(compat_build_dir)/%.c
$(CC) $(CFLAGS) $(BASECFLAGS) $(INCLUDES) -MMD -c $< -o $@
Expand Down
3 changes: 2 additions & 1 deletion compat/buildflags.mak
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# GPL LICENSE SUMMARY
#
# Copyright(c) 2024 Tactical Computing Labs, LLC
# Copyright(c) 2015 Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -54,7 +55,7 @@ $(error top_srcdir must be set to include makefile fragment)
endif

export os ?= $(shell uname -s | tr '[A-Z]' '[a-z]')
export arch := $(shell uname -m | sed -e 's,\(i[456]86\|athlon$$\),i386,')
export arch := $(shell uname -m | sed -e 's,\(i[456]86\|athlon$$\),i386,riscv64')
export CCARCH ?= gcc

ifeq (${CCARCH},$(filter ${CCARCH},gcc gcc4 icc clang))
Expand Down
2 changes: 2 additions & 0 deletions debian/libpsm2-dev.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/usr/include/hfi1diag/hfi1_deprecated_gen1.h
/usr/include/hfi1diag/linux-x86_64/bit_ops.h
/usr/include/hfi1diag/linux-x86_64/sysdep.h
/usr/include/hfi1diag/linux-riscv/bit_ops.h
/usr/include/hfi1diag/linux-riscv/sysdep.h
/usr/include/hfi1diag/opa_udebug.h
/usr/include/hfi1diag/opa_debug.h
/usr/include/hfi1diag/opa_intf.h
Expand Down
Loading