diff --git a/LICENSE b/LICENSE index 8b23445..22314c7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 +Copyright (c) 2019 RRZE, University Erlangen-Nuremberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9618914 --- /dev/null +++ b/Makefile @@ -0,0 +1,85 @@ +TAG = GCC + +#CONFIGURE BUILD SYSTEM +TARGET = bwbench-$(TAG) +BUILD_DIR = ./$(TAG) +SRC_DIR = ./src +MAKE_DIR = ./ +Q ?= @ + +#DO NOT EDIT BELOW +include $(MAKE_DIR)/include_$(TAG).mk +INCLUDES += -I./src/includes + +VPATH = $(SRC_DIR) +ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.c)) +ASM += $(patsubst $(SRC_DIR)/%.f90, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.f90)) +OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c)) +OBJ += $(patsubst $(SRC_DIR)/%.cc, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.cc)) +OBJ += $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.cpp)) +OBJ += $(patsubst $(SRC_DIR)/%.f90, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.f90)) +OBJ += $(patsubst $(SRC_DIR)/%.F90, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.F90)) +CPPFLAGS := $(CPPFLAGS) $(DEFINES) $(INCLUDES) + + +${TARGET}: $(BUILD_DIR) $(OBJ) + @echo "===> LINKING $(TARGET)" + $(Q)${LINKER} ${LFLAGS} -o $(TARGET) $(OBJ) $(LIBS) + +asm: $(BUILD_DIR) $(ASM) + +$(BUILD_DIR)/%.o: %.c + @echo "===> COMPILE $@" + $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + $(Q)$(CC) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/$*.d + +$(BUILD_DIR)/%.s: %.c + @echo "===> GENERATE ASM $@" + $(Q)$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.s: %.f90 + @echo "===> COMPILE $@" + $(Q)$(FC) -S $(FCFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: %.cc + @echo "===> COMPILE $@" + $(Q)$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ + $(Q)$(CXX) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/$*.d + +$(BUILD_DIR)/%.o: %.cpp + @echo "===> COMPILE $@" + $(Q)$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ + $(Q)$(CXX) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/$*.d + +$(BUILD_DIR)/%.o: %.f90 + @echo "===> COMPILE $@" + $(Q)$(FC) -c $(FCFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: %.F90 + @echo "===> COMPILE $@" + $(Q)$(FC) -c $(CPPFLAGS) $(FCFLAGS) $< -o $@ + +tags: + @echo "===> GENERATE TAGS" + $(Q)ctags -R + + +$(BUILD_DIR): + @mkdir $(BUILD_DIR) + +ifeq ($(findstring $(MAKECMDGOALS),clean),) +-include $(OBJ:.o=.d) +endif + +.PHONY: clean distclean + +clean: + @echo "===> CLEAN" + @rm -rf $(BUILD_DIR) + @rm -f tags + +distclean: clean + @echo "===> DIST CLEAN" + @rm -f $(TARGET) + @rm -f tags + diff --git a/include_CLANG.mk b/include_CLANG.mk new file mode 100644 index 0000000..d4b111b --- /dev/null +++ b/include_CLANG.mk @@ -0,0 +1,9 @@ +CC = clang +LINKER = $(CC) + +OPENMP = #-fopenmp +CFLAGS = -Ofast -std=c99 $(OPENMP) +LFLAGS = $(OPENMP) +DEFINES = -D_GNU_SOURCE +INCLUDES = +LIBS = diff --git a/include_GCC.mk b/include_GCC.mk new file mode 100644 index 0000000..1e89b90 --- /dev/null +++ b/include_GCC.mk @@ -0,0 +1,9 @@ +CC = gcc +LINKER = $(CC) + +OPENMP = # -fopenmp +CFLAGS = -Ofast -std=c11 $(OPENMP) +LFLAGS = $(OPENMP) +DEFINES = -D_GNU_SOURCE +INCLUDES = +LIBS = diff --git a/include_ICC.mk b/include_ICC.mk new file mode 100644 index 0000000..09613ac --- /dev/null +++ b/include_ICC.mk @@ -0,0 +1,9 @@ +CC = icc +LINKER = $(CC) + +OPENMP = -qopenmp +CFLAGS = -Ofast -xhost -std=c11 $(OPENMP) +LFLAGS = $(OPENMP) +DEFINES = -D_GNU_SOURCE +INCLUDES = +LIBS = diff --git a/src/allocate.c b/src/allocate.c new file mode 100644 index 0000000..3b63fa3 --- /dev/null +++ b/src/allocate.c @@ -0,0 +1,58 @@ +/* + * ======================================================================================= + * + * Author: Jan Eitzinger (je), jan.treibig@gmail.com + * Copyright (c) 2019 RRZE, University Erlangen-Nuremberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE.#include + * + * ======================================================================================= + */ + +#include +#include +#include + +void* allocate (int alignment, size_t bytesize) +{ + int errorCode; + void* ptr; + + errorCode = posix_memalign(&ptr, alignment, bytesize); + + if (errorCode) { + if (errorCode == EINVAL) { + fprintf(stderr, + "Error: Alignment parameter is not a power of two\n"); + exit(EXIT_FAILURE); + } + if (errorCode == ENOMEM) { + fprintf(stderr, + "Error: Insufficient memory to fulfill the request\n"); + exit(EXIT_FAILURE); + } + } + + if (ptr == NULL) { + fprintf(stderr, "Error: posix_memalign failed!\n"); + exit(EXIT_FAILURE); + } + + return ptr; +} diff --git a/src/copy.c b/src/copy.c new file mode 100644 index 0000000..4f037c6 --- /dev/null +++ b/src/copy.c @@ -0,0 +1,46 @@ +/* + * ======================================================================================= + * + * Author: Jan Eitzinger (je), jan.treibig@gmail.com + * Copyright (c) 2019 RRZE, University Erlangen-Nuremberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE.#include + * + * ======================================================================================= + */ + +#include + +double copy( + double * restrict a, + double * restrict b, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#include + +double daxpy( + double * restrict a, + double * restrict b, + double scalar, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#ifndef __ALLOCATE_H_ +#define __ALLOCATE_H_ + +extern void* allocate (int alignment, size_t bytesize); + +#endif diff --git a/src/includes/timing.h b/src/includes/timing.h new file mode 100644 index 0000000..71114a5 --- /dev/null +++ b/src/includes/timing.h @@ -0,0 +1,35 @@ +/* + * ======================================================================================= + * + * Author: Jan Eitzinger (je), jan.treibig@gmail.com + * Copyright (c) 2019 RRZE, University Erlangen-Nuremberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE.#include + * + * ======================================================================================= + */ + +#ifndef __TIMING_H_ +#define __TIMING_H_ + +extern double getTimeStamp(); +extern double getTimeResolution(); +extern double getTimeStamp_(); + +#endif diff --git a/src/init.c b/src/init.c new file mode 100644 index 0000000..501acd0 --- /dev/null +++ b/src/init.c @@ -0,0 +1,46 @@ +/* + * ======================================================================================= + * + * Author: Jan Eitzinger (je), jan.treibig@gmail.com + * Copyright (c) 2019 RRZE, University Erlangen-Nuremberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE.#include + * + * ======================================================================================= + */ + +#include + +double init( + double * restrict a, + double scalar, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#include +#include +#include +#include +#include + +#ifdef _OPENMP +#include +#endif + +#include + +#define ARRAY_ALIGNMENT 64 +#define SIZE 20000000ull +#define NTIMES 10 + +# define HLINE "-------------------------------------------------------------\n" + +#ifndef MIN +#define MIN(x,y) ((x)<(y)?(x):(y)) +#endif +#ifndef MAX +#define MAX(x,y) ((x)>(y)?(x):(y)) +#endif +#ifndef ABS +#define ABS(a) ((a) >= 0 ? (a) : -(a)) +#endif + +typedef enum benchmark { + INIT = 0, + SUM, + COPY, + UPDATE, + TRIAD, + DAXPY, + STRIAD, + SDAXPY, + NUMBENCH +} benchmark; + +extern double init(double*, double, int); +extern double sum(double*, int); +extern double copy(double*, double*, int); +extern double update(double*, double, int); +extern double triad(double*, double*, double*, double, int); +extern double daxpy(double*, double*, double, int); +extern double striad(double*, double*, double*, double*, int); +extern double sdaxpy(double*, double*, double*, int); + +void check(double*, double*, double*, double*, int); + +int main (int argc, char** argv) +{ + size_t bytesPerWord = sizeof(double); + size_t N = SIZE; + double *a, *b, *c, *d; + double scalar, tmp; + + double avgtime[NUMBENCH], + maxtime[NUMBENCH], + mintime[NUMBENCH]; + + double times[NUMBENCH][NTIMES]; + + double bytes[NUMBENCH] = { + 1 * sizeof(double) * N, /* init */ + 1 * sizeof(double) * N, /* sum */ + 2 * sizeof(double) * N, /* copy */ + 2 * sizeof(double) * N, /* update */ + 3 * sizeof(double) * N, /* triad */ + 3 * sizeof(double) * N, /* daxpy */ + 4 * sizeof(double) * N, /* striad */ + 4 * sizeof(double) * N /* sdaxpy */ + }; + + char *label[NUMBENCH] = { + "Init: ", + "Sum: ", + "Copy: ", + "Update: ", + "Triad: ", + "Daxpy: ", + "STriad: ", + "SDaxpy: "}; + + a = (double*) allocate( ARRAY_ALIGNMENT, N * bytesPerWord ); + b = (double*) allocate( ARRAY_ALIGNMENT, N * bytesPerWord ); + c = (double*) allocate( ARRAY_ALIGNMENT, N * bytesPerWord ); + d = (double*) allocate( ARRAY_ALIGNMENT, N * bytesPerWord ); + + for (int i=0; i epsilon) { + printf ("Failed Validation on array a[]\n"); + printf (" Expected : %f \n",aj); + printf (" Observed : %f \n",asum); + } + else if (ABS(bj-bsum)/bsum > epsilon) { + printf ("Failed Validation on array b[]\n"); + printf (" Expected : %f \n",bj); + printf (" Observed : %f \n",bsum); + } + else if (ABS(cj-csum)/csum > epsilon) { + printf ("Failed Validation on array c[]\n"); + printf (" Expected : %f \n",cj); + printf (" Observed : %f \n",csum); + } + else if (ABS(dj-dsum)/dsum > epsilon) { + printf ("Failed Validation on array d[]\n"); + printf (" Expected : %f \n",dj); + printf (" Observed : %f \n",dsum); + } + else { + printf ("Solution Validates\n"); + } +} diff --git a/src/sdaxpy.c b/src/sdaxpy.c new file mode 100644 index 0000000..a68ae8e --- /dev/null +++ b/src/sdaxpy.c @@ -0,0 +1,47 @@ +/* + * ======================================================================================= + * + * Author: Jan Eitzinger (je), jan.treibig@gmail.com + * Copyright (c) 2019 RRZE, University Erlangen-Nuremberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE.#include + * + * ======================================================================================= + */ + +#include + +double sdaxpy( + double * restrict a, + double * restrict b, + double * restrict c, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#include + +double striad( + double * restrict a, + double * restrict b, + double * restrict c, + double * restrict d, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#include + +double sum( + double * restrict a, + int N + ) +{ + double S, E; + double sum = 0.0; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#include +#include + +double getTimeStamp() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (double)ts.tv_sec + (double)ts.tv_nsec * 1.e-9; +} + +double getTimeResolution() +{ + struct timespec ts; + clock_getres(CLOCK_MONOTONIC, &ts); + return (double)ts.tv_sec + (double)ts.tv_nsec * 1.e-9; +} + +double getTimeStamp_() +{ + return getTimeStamp(); +} + diff --git a/src/triad.c b/src/triad.c new file mode 100644 index 0000000..287d8b8 --- /dev/null +++ b/src/triad.c @@ -0,0 +1,48 @@ +/* + * ======================================================================================= + * + * Author: Jan Eitzinger (je), jan.treibig@gmail.com + * Copyright (c) 2019 RRZE, University Erlangen-Nuremberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE.#include + * + * ======================================================================================= + */ + +#include + +double triad( + double * restrict a, + double * restrict b, + double * restrict c, + double scalar, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i + * + * ======================================================================================= + */ + +#include + +double update( + double * restrict a, + double scalar, + int N + ) +{ + double S, E; + + S = getTimeStamp(); +#pragma omp parallel for + for (int i=0; i