Skip to content

Commit

Permalink
Merge pull request #143 from jprotze/simd
Browse files Browse the repository at this point in the history
  • Loading branch information
LChenGit authored Aug 25, 2023
2 parents a0a5f0e + bde3dd5 commit 9cb7634
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 15 deletions.
35 changes: 35 additions & 0 deletions micro-benchmarks/DRB202-simd-broadcast-yes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
Data race in vectorizable code
Adding a fixed array element to the whole array. Data race present.
Data Race Pairs, a[i]@30:5:W vs. a[64]@30:19:R
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]) {
int len = 20000;
if (argc > 1)
len = atoi(argv[1]);
double a[len];
for (int i = 0; i < len; i++)
a[i] = i;
double c = M_PI;

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len; i++)
a[i] = a[i] + a[64];

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);
return 0;
}
33 changes: 33 additions & 0 deletions micro-benchmarks/DRB203-simd-broadcast-no.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 17-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
No data race present.
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]) {
int len = 20000;
if (argc > 1)
len = atoi(argv[1]);
double a[len];
for (int i = 0; i < len; i++)
a[i] = i;
double c = M_PI;

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len; i++)
a[i] = a[i] + c;

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);
return 0;
}
39 changes: 39 additions & 0 deletions micro-benchmarks/DRB204-simd-gather-yes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
Data race in vectorizable code
Loop depencency with 64 element offset. Data race present.
Data Race Pairs, a[i + 64]@33:5:W vs. a[i * 2]@33:17:R
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int len = 20000;

if (argc > 1)
len = atoi(argv[1]);
double a[2 * len], b[len];

for (int i = 0; i < 2 * len; i++)
a[i] = i;
for (int i = 0; i < len; i++)
b[i] = i + 1;

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len; i++)
a[i + 64] = a[i * 2] + b[i];

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);

return 0;
}
37 changes: 37 additions & 0 deletions micro-benchmarks/DRB205-simd-gatherscatter-no.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 17-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
No data race present.
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int len = 20000;

if (argc > 1)
len = atoi(argv[1]);
double a[2 * len], b[len];

for (int i = 0; i < 2 * len; i++)
a[i] = i;
for (int i = 0; i < len; i++)
b[i] = i + 1;

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len; i++)
a[i * 2] = a[i * 2] + b[i];

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);

return 0;
}
39 changes: 39 additions & 0 deletions micro-benchmarks/DRB206-simd-scatter-yes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
Data race in vectorizable code
Loop depencency with 64 element offset. Data race present.
Data Race Pairs, a[i * 2]@33:5:W vs. a[i + 64]@33:17:R
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int len = 20000;

if (argc > 1)
len = atoi(argv[1]);
double a[2 * len], b[len];

for (int i = 0; i < 2 * len; i++)
a[i] = i;
for (int i = 0; i < len; i++)
b[i] = i + 1;

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len; i++)
a[i * 2] = a[i + 64] + b[i];

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);

return 0;
}
39 changes: 39 additions & 0 deletions micro-benchmarks/DRB207-simd-loadstore-yes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
Data race in vectorizable code
Loop depencency with 64 element offset. Data race present.
Data Race Pairs, a[i + 64]@34:5:W vs. a[i]@34:17:R
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int len = 20000;

if (argc > 1)
len = atoi(argv[1]);
double a[len], b[len];

for (int i = 0; i < len; i++) {
a[i] = i;
b[i] = i + 1;
}

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len - 64; i++)
a[i + 64] = a[i] + b[i];

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);

return 0;
}
37 changes: 37 additions & 0 deletions micro-benchmarks/DRB208-simd-loadstore-no.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
!!! Copyright (c) 17-20, Lawrence Livermore National Security, LLC
!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
!!!
!!! SPDX-License-Identifier: (BSD-3-Clause)
!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
*/

/*
No data race present.
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int len = 20000;

if (argc > 1)
len = atoi(argv[1]);
double a[len], b[len];

for (int i = 0; i < len; i++) {
a[i] = i;
b[i] = i + 1;
}

#pragma omp parallel for simd schedule(dynamic, 64)
for (int i = 0; i < len; i++)
a[i] = a[i] + b[i];

printf("a[0]=%f, a[%i]=%f, a[%i]=%f\n", a[0], len / 2, a[len / 2], len - 1,
a[len - 1]);

return 0;
}
32 changes: 17 additions & 15 deletions scripts/test-harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ LANGUAGE="default"
PYTHON=${PYTHON:-"python3"}
LOGPARSER="scripts/log-parser/logParser.py"

OPTIMIZATION=${OPTIMIZATION:-"-O3 -march=native"}

MEMCHECK=${MEMCHECK:-"/usr/bin/time"}
TIMEOUTCMD=${TIMEOUTCMD:-"timeout"}
VALGRIND=${VALGRIND:-"valgrind"}
VALGRIND_COMPILE_C_FLAGS="-O0 -g -std=c99 -fopenmp"
VALGRIND_COMPILE_CPP_FLAGS="-O0 -g -fopenmp"
VALGRIND_COMPILE_C_FLAGS="${OPTIMIZATION} -g -std=c99 -fopenmp"
VALGRIND_COMPILE_CPP_FLAGS="${OPTIMIZATION} -g -fopenmp"

CLANG=${CLANG:-"clang"}
TSAN_COMPILE_FLAGS="-O0 -fopenmp -fsanitize=thread -g"
TSAN_COMPILE_FLAGS="${OPTIMIZATION} -fopenmp -fsanitize=thread -g"

# Path to LLOV is fixed due to it's only available in container
LLOV_COMPILER="/home/llvm/Work/LLOV"
Expand All @@ -77,24 +79,24 @@ LLOV_COMPILE_FLAGS+=" -mllvm -polly-ignore-parameter-bounds"
LLOV_COMPILE_FLAGS+=" -mllvm -polly-dependences-on-demand"
LLOV_COMPILE_FLAGS+=" -mllvm -polly-precise-fold-accesses"
#LLOV_COMPILE_FLAGS+=" -mllvm -openmp-verify-disable-aa"
LLOV_COMPILE_FLAGS+=" -O0 -g"
LLOV_COMPILE_FLAGS+=" ${OPTIMIZATION} -g"

# Path to LLOV is fixed due to it's only available in container
FLANG_PATH=/home/llvm/installs/flang-2020-03-16

ARCHER=${ARCHER:-"clang-archer"}
ARCHER_COMPILE_FLAGS="-O0 -larcher"
ARCHER_COMPILE_FLAGS="${OPTIMIZATION} -larcher"

INSPECTOR=${INSPECTOR:-"inspxe-cl"}
ICC_COMPILE_FLAGS="-O0 -fopenmp -std=c99 -qopenmp-offload=host -g"
ICPC_COMPILE_FLAGS="-O0 -fopenmp -qopenmp-offload=host -g"
ICC_COMPILE_FLAGS="${OPTIMIZATION} -fopenmp -std=c99 -qopenmp-offload=host -g"
ICPC_COMPILE_FLAGS="${OPTIMIZATION} -fopenmp -qopenmp-offload=host -g"

ROMP_CPP_COMPILE_FLAGS="-O0 -g -std=c++11 -fopenmp -lomp"
ROMP_C_COMPILE_FLAGS="-O0 -g -fopenmp -lomp"
ROMP_CPP_COMPILE_FLAGS="${OPTIMIZATION} -g -std=c++11 -fopenmp -lomp"
ROMP_C_COMPILE_FLAGS="${OPTIMIZATION} -g -fopenmp -lomp"

FORTRAN_LINK_FLAGS="-ffree-line-length-none -fopenmp -c -fsanitize=thread"
FORTRAN_COMPILE_FLAGS="-O0 -fopenmp -fsanitize=thread -lgfortran"
IFORT_FORTRAN_FLAGS="-g -O0 -free -qopenmp -qopenmp-offload=host -Tf"
FORTRAN_COMPILE_FLAGS="${OPTIMIZATION} -fopenmp -fsanitize=thread -lgfortran"
IFORT_FORTRAN_FLAGS="-g ${OPTIMIZATION} -free -qopenmp -qopenmp-offload=host -Tf"


POLYFLAG="micro-benchmarks/utilities/polybench.c -I micro-benchmarks -I micro-benchmarks/utilities -DPOLYBENCH_NO_FLUSH_CACHE -DPOLYBENCH_TIME -D_POSIX_C_SOURCE=200112L"
Expand Down Expand Up @@ -359,7 +361,7 @@ for tool in "${TOOLS[@]}"; do
intel) icpc $ICPC_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
helgrind) g++ $VALGRIND_COMPILE_CPP_FLAGS $additional_compile_flags $test -o $exname -lm ;;
archer) clang-archer++ $ARCHER_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
coderrect) coderrect -XbcOnly clang++ -fopenmp -fopenmp-version=45 -g -O0 $additional_compile_flags $test -o $exname -lm > /dev/null 2>&1 ;;
coderrect) coderrect -XbcOnly clang++ -fopenmp -fopenmp-version=45 -g ${OPTIMIZATION} $additional_compile_flags $test -o $exname -lm > /dev/null 2>&1 ;;
openrace) clang++ -fopenmp -fopenmp-version=45 -Dmasked=master -g -S -emit-llvm $test -o $exname ;;
tsan-clang) clang++ $TSAN_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
tsan-gcc) g++ $TSAN_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
Expand All @@ -376,7 +378,7 @@ for tool in "${TOOLS[@]}"; do
intel) icc $ICC_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
helgrind) gcc $VALGRIND_COMPILE_C_FLAGS $additional_compile_flags $test -o $exname -lm ;;
archer) clang-archer $ARCHER_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
coderrect) coderrect -XbcOnly clang -fopenmp -fopenmp-version=45 -g -O0 $additional_compile_flags $test -o $exname -lm > /dev/null 2>&1 ;;
coderrect) coderrect -XbcOnly clang -fopenmp -fopenmp-version=45 -g ${OPTIMIZATION} $additional_compile_flags $test -o $exname -lm > /dev/null 2>&1 ;;
openrace) clang -fopenmp -fopenmp-version=45 -Dmasked=master -g -S -emit-llvm $test -o $exname ;;
tsan-clang) clang $TSAN_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
tsan-gcc) gcc $TSAN_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
Expand Down Expand Up @@ -564,7 +566,7 @@ for tool in "${TOOLS[@]}"; do
tsan-gcc) gfortran -fopenmp -fsanitize=thread $additional_compile_flags $test -o $exname -lm ;;
archer) gfortran $FORTRAN_LINK_FLAGS $additional_compile_flags $test -o $linkname;
clang-archer $FORTRAN_COMPILE_FLAGS $linkname $linklib -o $exname $ARCHER_COMPILE_FLAGS -lm;;
coderrect) coderrect -XbcOnly gfortran -O0 -g -fopenmp $additional_compile_flags $test -o $exname -lm > /dev/null 2>&1;
coderrect) coderrect -XbcOnly gfortran ${OPTIMIZATION} -g -fopenmp $additional_compile_flags $test -o $exname -lm > /dev/null 2>&1;
ls .coderrect/build/$exname.bc ;; # make $? to be 1 if coderrect could not compile the fortran case
inspector) ifort $IFORT_FORTRAN_FLAGS $test -o $exname -lm ;;
llov) $FLANG_PATH/bin/flang -fopenmp -S -emit-llvm "$test" -o "$exname.ll";
Expand All @@ -579,7 +581,7 @@ for tool in "${TOOLS[@]}"; do
-openmp-verify \
"$exname.resetbounds.ll" 2> $compilelog;
rm -f $exname.ll $exname.ssa.ll $exname.resetbounds.ll;;
romp) gfortran -O0 -g -fopenmp -lomp -ffree-line-length-none $additional_compile_flags $test -o $exname -lm;
romp) gfortran ${OPTIMIZATION} -g -fopenmp -lomp -ffree-line-length-none $additional_compile_flags $test -o $exname -lm;
echo $exname
InstrumentMain --program=$exname;;
esac
Expand Down

0 comments on commit 9cb7634

Please sign in to comment.