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

add support for am processor, and option to use arm performance library #3

Open
wants to merge 9 commits 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
9 changes: 9 additions & 0 deletions HPC_Sparse_Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
#ifndef HPC_SPARSE_MATRIX_H
#define HPC_SPARSE_MATRIX_H

#if defined(USE_ARMPL)
#include <armpl.h>
#define LIBRARY_NAME "ArmPL"
#endif

// These constants are upper bounds that might need to be changes for
// pathological matrices, e.g., those with nearly dense rows/columns.

Expand All @@ -65,6 +70,10 @@ struct HPC_Sparse_Matrix_STRUCT {
int ** ptr_to_inds_in_row;
double ** ptr_to_diags;

#if defined(USE_ARMPL)
armpl_spmat_t mat_armpl;
#endif

#ifdef USING_MPI
int num_external;
int num_send_neighbors;
Expand Down
17 changes: 17 additions & 0 deletions HPC_sparsemv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,27 @@ using std::endl;
#include <cmath>
#include "HPC_sparsemv.hpp"

#if defined(USE_ARMPL)
#include <armpl.h>
#define LIBRARY_NAME "ArmPL"
#endif

int HPC_sparsemv( HPC_Sparse_Matrix *A,
const double * const x, double * const y)
{

const int nrow = (const int) A->local_nrow;

#if defined(USE_ARMPL)
double alpha = 1.0, beta = 0.0;
armpl_status_t info = armpl_spmv_exec_d(ARMPL_SPARSE_OPERATION_NOTRANS, alpha, A->mat_armpl, x, beta, y);
if (info!=ARMPL_STATUS_SUCCESS)
{
cerr << "ERROR: armpl_spmv_exec_d returned %d\n";
exit(1);
}

#else
#ifdef USING_OMP
#pragma omp parallel for
#endif
Expand All @@ -87,5 +102,7 @@ int HPC_sparsemv( HPC_Sparse_Matrix *A,
sum += cur_vals[j]*x[cur_inds[j]];
y[i] = sum;
}
#endif
return(0);
}

29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
#
# 0) Specify compiler and linker:

CXX=/usr/local/bin/g++
LINKER=/usr/local/bin/g++
include config.mk

#CXX=
LINKER=mpicxx
#CXX=mpicxx
#LINKER=mpicxx

Expand All @@ -57,7 +59,7 @@ LINKER=/usr/local/bin/g++
# If you want to run the program with MPI, make sure USE_MPI is set
# to -DUSING_MPI

USE_MPI =
USE_MPI = -DUSING_MPI
#USE_MPI = -DUSING_MPI


Expand All @@ -68,17 +70,19 @@ USE_MPI =
# - Are not using MPI compiler wrappers
# Then specify the path to your MPI header file (include a -I)

#MPI_INC = -I/usr/MPICH/SDK.gcc/include
MPI_INC = -I/opt/amazon/openmpi/include


# 3) Specify C++ compiler optimization flags (if any)
# Typically some reasonably high level of optimization should be used to
# enhance performance.

#IA32 with GCC:
#CPP_OPT_FLAGS = -O3 -funroll-all-loops -malign-double
##CPP_OPT_FLAGS = -O3 -funroll-all-loops -malign-double
CPP_OPT_FLAGS = -O3 -ftree-vectorize -ftree-vectorizer-verbose=2

ifeq (arm,$(COMPILER))
CPP_OPT_FLAGS = $(CFLAGS_OPT) -fPIC # add -g for profiler
endif
#
# 4) MPI library:
# If you:
Expand All @@ -87,7 +91,7 @@ CPP_OPT_FLAGS = -O3 -ftree-vectorize -ftree-vectorizer-verbose=2
# - Are not using MPI compiler wrappers for linking
# Then specify the path to your MPI library (include -L and -l directives)

#MPI_LIB = -L/usr/MPICH/SDK.gcc/lib -lmpich
MPI_LIB = -L/opt/amazon/openmpi/lib

#
# 5) Build with OpenMP or not?
Expand All @@ -110,13 +114,18 @@ USE_OMP =
SYS_LIB =-lm

#
# 6) Specify name if executable (optional):
# 8) Arm PL library
ifeq (arm,$(COMPILER))
ARMPL_LIB = -larmpl -L/shared/arm/armpl/armpl_22.0.2_gcc-11.2/lib
endif
#
# 9) Specify name if executable (optional):

TARGET = test_HPCCG

################### Derived Quantities (no modification required) ##############

CXXFLAGS= $(CPP_OPT_FLAGS) $(OMP_FLAGS) $(USE_OMP) $(USE_MPI) $(MPI_INC)
CXXFLAGS= $(CPP_OPT_FLAGS) $(OMP_FLAGS) $(CXXFLAGS_LIBRARY) $(USE_OMP) $(USE_MPI) $(MPI_INC)

LIB_PATHS= $(SYS_LIB)

Expand All @@ -129,7 +138,7 @@ TEST_CPP = main.cpp generate_matrix.cpp read_HPC_row.cpp \
TEST_OBJ = $(TEST_CPP:.cpp=.o)

$(TARGET): $(TEST_OBJ)
$(LINKER) $(CPP_OPT_FLAGS) $(OMP_FLAGS) $(TEST_OBJ) $(LIB_PATHS) -o $(TARGET)
$(LINKER) $(CPP_OPT_FLAGS) $(OMP_FLAGS) $(TEST_OBJ) $(LIB_PATHS) $(ARMPL_LIB) -o $(TARGET)

test:
@echo "Not implemented yet..."
Expand Down
207 changes: 207 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#------------------------------------------------------------------------------------
# Copyright (C) Arm Limited, 2019-2020 All rights reserved.
#
# The example code is provided to you as an aid to learning when working
# with Arm-based technology, including but not limited to programming tutorials.
#
# Arm hereby grants to you, subject to the terms and conditions of this Licence,
# a non-exclusive, non-transferable, non-sub-licensable, free-of-charge copyright
# licence, to use, copy and modify the Software solely for the purpose of internal
# demonstration and evaluation.
#
# You accept that the Software has not been tested by Arm therefore the Software
# is provided "as is", without warranty of any kind, express or implied. In no
# event shall the authors or copyright holders be liable for any claim, damages
# or other liability, whether in action or contract, tort or otherwise, arising
# from, out of or in connection with the Software or the use of Software.
#------------------------------------------------------------------------------------

COMPILER ?= arm

#############################################################################
# GNU compiler flags
#############################################################################
ifeq (gnu,$(COMPILER))

LIBRARY ?= none

CC = gcc
CXX = g++
FC = gfortran

FLAGS_VERSION = --version

CFLAGS_OPT = -Ofast -mcpu=native

CXXFLAGS_OPT = $(CFLAGS_OPT)

FFLAGS_OPT = $(CFLAGS_OPT)

else
#############################################################################
# Arm compiler flags
#############################################################################
ifeq (arm,$(COMPILER))

LIBRARY ?= armpl

CC = armclang
CXX = armclang++
FC = armflang

FLAGS_VERSION = --version

CFLAGS_OPT = -Ofast -mcpu=native

CXXFLAGS_OPT = $(CFLAGS_OPT)

FFLAGS_OPT = $(CFLAGS_OPT)

else
#############################################################################
# Fujitsu compiler flags
#############################################################################
ifeq (fujitsu,$(COMPILER))

LIBRARY ?= ssl2

CC = fcc
CXX = FCC
FC = frt

FLAGS_VERSION = --version

CFLAGS_OPT = -Kfast

CXXFLAGS_OPT = $(CFLAGS_OPT)

FFLAGS_OPT = $(CFLAGS_OPT)

else
#############################################################################
# Cray compiler flags
#############################################################################
ifeq (cray,$(COMPILER))

LIBRARY ?= cblas

CC = cc
CXX = CC
fc = ftn

FLAGS_VERSION = --version

CFLAGS_OPT = -O3

CXXFLAGS_OPT = $(CFLAGS_OPT)

FFLAGS_OPT = $(CFLAGS_OPT)

else
#############################################################################
# Help message
#############################################################################
ifeq (help,$(COMPILER))

$(info COMPILER can be one of: gnu, arm, fujitsu, cray)
$(info * gnu: GNU Compiler)
$(info * arm: Arm Compiler for Linux)
$(info * fujitsu: Fujitsu Compiler)
$(info * cray: Cray Compiler)
$(error )

else
#############################################################################
# Error handling
#############################################################################

$(error Invalid parameter: COMPILER=$(COMPILER))

#############################################################################
endif
endif
endif
endif
endif
#############################################################################


#############################################################################
# Generic CBLAS library flags
#############################################################################
ifeq (none,$(LIBRARY))

CFLAGS_LIBRARY =
CXXFLAGS_LIBRARY =
FFLAGS_LIBRARY =
LDFLAGS_LIBRARY = -lm

else
#############################################################################
# Arm Performance Library (ArmPL) library flags
#############################################################################
ifeq (armpl,$(LIBRARY))

ifeq (arm,$(COMPILER))
# The Arm compiler automatically knows where to find ArmPL and will
# automatically enable OpenMP if the -fopenmp flag is present
CFLAGS_LIBRARY = -armpl -DUSE_ARMPL
CXXFLAGS_LIBRARY = -armpl -DUSE_ARMPL
FFLAGS_LIBRARY = -armpl -DUSE_ARMPL
LDFLAGS_LIBRARY = -armpl
else
# If not using the Arm compiler, make sure to load the ArmPL module.
# ARMPL_INCLUDES and ARMPL_LIBRARIES are set by the ArmPL modulefile
CFLAGS_LIBRARY = -I$(ARMPL_INCLUDES) -DUSE_ARMPL
CXXFLAGS_LIBRARY = -I$(ARMPL_INCLUDES) -DUSE_ARMPL
FFLAGS_LIBRARY = -I$(ARMPL_INCLUDES) -DUSE_ARMPL
LDFLAGS_LIBRARY = -L$(ARMPL_LIBRARIES) -larmpl -lamath -lastring
endif

else
#############################################################################
# Fujitsu SSL II library flags
#############################################################################
ifeq (ssl2,$(LIBRARY))

ifeq (fujitsu,$(COMPILER))
CFLAGS_LIBRARY = -SSL2 -DUSE_SSL2
CXXFLAGS_LIBRARY = -SSL2 -DUSE_SSL2
FFLAGS_LIBRARY = -SSL2 -DUSE_SSL2
LDFLAGS_LIBRARY = -SSL2
else
$(error SSL2 can only be used with the Fujitsu compiler)
endif

else
#############################################################################
# Error handling
#############################################################################

$(error Invalid parameter: LIBRARY=$(LIBRARY))

#############################################################################
endif
endif
endif
#############################################################################

#############################################################################
# ArmIE Configuration
#############################################################################

ARMIE_EXE = armie
ARMIE_SVE_VECTOR_BITS ?= 512
ARMIE = $(ARMIE_EXE) -msve-vector-bits=$(ARMIE_SVE_VECTOR_BITS)
ARMIE_MEMTRACE = $(ARMIE_EXE) -e libmemtrace_sve_$(ARMIE_SVE_VECTOR_BITS).so

#############################################################################
# Functions
#############################################################################


print_hline = @echo "------------------------------------------------"
print_version = $(CC) $(FLAGS_VERSION)
print_banner = $(call print_hline) @echo $1 $(call print_hline)


Loading