From 886a61525c6bf55c9bcbff4c2b190491586e5bdd Mon Sep 17 00:00:00 2001 From: timkaler Date: Fri, 11 Oct 2019 17:40:54 -0400 Subject: [PATCH] add functional c tests via check-enzyme-c command (#15) * add functional c tests via check-enzyme-c command * add functional c tests to github workflows * fix hardcoded path * test paths again * another attempt at fix * another attempt to fix clang path in ci * install clang * test loops in build system * another build test * change return type of externed builtinautodiff to fix build * think it works with build system now? * Add an expected fail test * make ifcrash.ll be expect fail * make tests use clang instead of clang++ for c * only run functional tests on llvm 7 --- .github/workflows/functional_tests.yml | 32 ++++++ enzyme/CMakeLists.txt | 1 + enzyme/functional_tests_c/.gitignore | 1 + enzyme/functional_tests_c/CMakeLists.txt | 24 ++++ .../FAIL_insertsort_sum_alt.c | 99 +++++++++++++++++ enzyme/functional_tests_c/Makefile | 88 +++++++++++++++ enzyme/functional_tests_c/gentests.py | 10 ++ enzyme/functional_tests_c/insertsort_sum.c | 103 ++++++++++++++++++ enzyme/functional_tests_c/lit.cfg.py | 73 +++++++++++++ enzyme/functional_tests_c/lit.site.cfg.py.in | 51 +++++++++ enzyme/functional_tests_c/loops.c | 61 +++++++++++ enzyme/functional_tests_c/loopsdouble.c | 57 ++++++++++ enzyme/functional_tests_c/loopstriple.c | 51 +++++++++ enzyme/functional_tests_c/recurse.c | 50 +++++++++ enzyme/functional_tests_c/setup.sh | 8 ++ enzyme/functional_tests_c/test.template | 5 + .../FAIL_insertsort_sum_alt-enzyme0.test | 5 + .../FAIL_insertsort_sum_alt-enzyme1.test | 5 + .../FAIL_insertsort_sum_alt-enzyme2.test | 5 + .../FAIL_insertsort_sum_alt-enzyme3.test | 5 + .../testfiles/insertsort_sum-enzyme0.test | 5 + .../testfiles/insertsort_sum-enzyme1.test | 5 + .../testfiles/insertsort_sum-enzyme2.test | 5 + .../testfiles/insertsort_sum-enzyme3.test | 5 + .../testfiles/loops-enzyme0.test | 5 + .../testfiles/loops-enzyme1.test | 5 + .../testfiles/loops-enzyme2.test | 5 + .../testfiles/loops-enzyme3.test | 5 + .../testfiles/loopsdouble-enzyme0.test | 5 + .../testfiles/loopsdouble-enzyme1.test | 5 + .../testfiles/loopsdouble-enzyme2.test | 5 + .../testfiles/loopsdouble-enzyme3.test | 5 + .../testfiles/loopstriple-enzyme0.test | 5 + .../testfiles/loopstriple-enzyme1.test | 5 + .../testfiles/loopstriple-enzyme2.test | 5 + .../testfiles/loopstriple-enzyme3.test | 5 + .../testfiles/recurse-enzyme0.test | 5 + .../testfiles/recurse-enzyme1.test | 5 + .../testfiles/recurse-enzyme2.test | 5 + .../testfiles/recurse-enzyme3.test | 5 + enzyme/test/Enzyme/ifcrash.ll | 56 ++++++++++ 41 files changed, 890 insertions(+) create mode 100644 .github/workflows/functional_tests.yml create mode 100644 enzyme/functional_tests_c/.gitignore create mode 100644 enzyme/functional_tests_c/CMakeLists.txt create mode 100644 enzyme/functional_tests_c/FAIL_insertsort_sum_alt.c create mode 100644 enzyme/functional_tests_c/Makefile create mode 100644 enzyme/functional_tests_c/gentests.py create mode 100644 enzyme/functional_tests_c/insertsort_sum.c create mode 100644 enzyme/functional_tests_c/lit.cfg.py create mode 100644 enzyme/functional_tests_c/lit.site.cfg.py.in create mode 100644 enzyme/functional_tests_c/loops.c create mode 100644 enzyme/functional_tests_c/loopsdouble.c create mode 100644 enzyme/functional_tests_c/loopstriple.c create mode 100644 enzyme/functional_tests_c/recurse.c create mode 100755 enzyme/functional_tests_c/setup.sh create mode 100644 enzyme/functional_tests_c/test.template create mode 100644 enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme0.test create mode 100644 enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme1.test create mode 100644 enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme2.test create mode 100644 enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme3.test create mode 100644 enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme0.test create mode 100644 enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme1.test create mode 100644 enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme2.test create mode 100644 enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme3.test create mode 100644 enzyme/functional_tests_c/testfiles/loops-enzyme0.test create mode 100644 enzyme/functional_tests_c/testfiles/loops-enzyme1.test create mode 100644 enzyme/functional_tests_c/testfiles/loops-enzyme2.test create mode 100644 enzyme/functional_tests_c/testfiles/loops-enzyme3.test create mode 100644 enzyme/functional_tests_c/testfiles/loopsdouble-enzyme0.test create mode 100644 enzyme/functional_tests_c/testfiles/loopsdouble-enzyme1.test create mode 100644 enzyme/functional_tests_c/testfiles/loopsdouble-enzyme2.test create mode 100644 enzyme/functional_tests_c/testfiles/loopsdouble-enzyme3.test create mode 100644 enzyme/functional_tests_c/testfiles/loopstriple-enzyme0.test create mode 100644 enzyme/functional_tests_c/testfiles/loopstriple-enzyme1.test create mode 100644 enzyme/functional_tests_c/testfiles/loopstriple-enzyme2.test create mode 100644 enzyme/functional_tests_c/testfiles/loopstriple-enzyme3.test create mode 100644 enzyme/functional_tests_c/testfiles/recurse-enzyme0.test create mode 100644 enzyme/functional_tests_c/testfiles/recurse-enzyme1.test create mode 100644 enzyme/functional_tests_c/testfiles/recurse-enzyme2.test create mode 100644 enzyme/functional_tests_c/testfiles/recurse-enzyme3.test create mode 100644 enzyme/test/Enzyme/ifcrash.ll diff --git a/.github/workflows/functional_tests.yml b/.github/workflows/functional_tests.yml new file mode 100644 index 0000000000000..ae183aa641501 --- /dev/null +++ b/.github/workflows/functional_tests.yml @@ -0,0 +1,32 @@ +name: Functional Tests CI + +on: [push] + +jobs: + build: + name: Test on os ${{ matrix.os }} and llvm ${{ matrix.llvm }} mode ${{ matrix.build }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + llvm: ["7"] + build: ["Release", "Debug"] # "RelWithDebInfo" + os: [ubuntu-18.04] + + steps: + - name: add llvm + run: sudo apt-get install -y llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools clang-${{ matrix.llvm }} + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: mkdir + run: cd enzyme && mkdir build + - name: cmake + run: | + cd enzyme/build + cmake .. -DLLVM_EXTERNAL_LIT=/usr/lib/llvm-${{ matrix.llvm }}/build/utils/lit/lit.py -DCMAKE_BUILD_TYPE=${{ matrix.build }} -DLLVM_DIR=/usr/lib/llvm-${{ matrix.llvm }}/lib/cmake/llvm + - name: make + run: cd enzyme/build && make + - name: make check-enzyme-c + run: cd enzyme/build && make check-enzyme-c diff --git a/enzyme/CMakeLists.txt b/enzyme/CMakeLists.txt index 6b828a792c538..a85ba9ce84b83 100644 --- a/enzyme/CMakeLists.txt +++ b/enzyme/CMakeLists.txt @@ -48,3 +48,4 @@ message("found llvm version " ${LLVM_VERSION_MAJOR}) add_subdirectory(Enzyme) add_subdirectory(test) +add_subdirectory(functional_tests_c) diff --git a/enzyme/functional_tests_c/.gitignore b/enzyme/functional_tests_c/.gitignore new file mode 100644 index 0000000000000..a007feab071f4 --- /dev/null +++ b/enzyme/functional_tests_c/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/enzyme/functional_tests_c/CMakeLists.txt b/enzyme/functional_tests_c/CMakeLists.txt new file mode 100644 index 0000000000000..08b938a75d05e --- /dev/null +++ b/enzyme/functional_tests_c/CMakeLists.txt @@ -0,0 +1,24 @@ +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py +) + +set(ENZYME_TEST_DEPS LLVMEnzyme-${LLVM_VERSION_MAJOR}) + +set(ENZYME_TESTSUITES) +list(APPEND ${CMAKE_CURRENT_BINARY_DIR}/lit.cfg) + +# Run regression and unit tests +add_lit_testsuite(check-enzyme-c "Running enzyme regression tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${ENZYME_TEST_DEPS} + ARGS -v +) + +set_target_properties(check-enzyme-c PROPERTIES FOLDER "Tests") + +#add_lit_testsuites(ENZYME ${CMAKE_CURRENT_SOURCE_DIR} + # DEPENDS ${ENZYME_TEST_DEPS} +#) diff --git a/enzyme/functional_tests_c/FAIL_insertsort_sum_alt.c b/enzyme/functional_tests_c/FAIL_insertsort_sum_alt.c new file mode 100644 index 0000000000000..5da874095ac72 --- /dev/null +++ b/enzyme/functional_tests_c/FAIL_insertsort_sum_alt.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include + +#define __builtin_autodiff __enzyme_autodiff +double __enzyme_autodiff(void*, ...); +//float man_max(float* a, float* b) { +// if (*a > *b) { +// return *a; +// } else { +// return *b; +// } +//} + + +// size of array +float* unsorted_array_init(int N) { + float* arr = (float*) malloc(sizeof(float) * N); + for (int i = 0; i < N; i++) { + arr[i] = 1.0*(i%2); + } + return arr; +} + +__attribute__((noinline)) +void insertion_sort_inner(float* array, int i) { + int j = i; + while (j > 0 && array[j-1] > array[j]) { + float tmp = array[j]; + array[j] = array[j-1]; + array[j-1] = tmp; + j -= 1; + } +} + +// sums the first half of a sorted array. +void insertsort_sum (float* array, int N, float* ret) { + float sum = 0; + //qsort(array, N, sizeof(float), cmp); + + for (int i = 1; i < N; i++) { + insertion_sort_inner(array, i); + } + + + for (int i = 0; i < N/2; i++) { + //printf("Val: %f\n", array[i]); + sum += array[i]; + } + *ret = sum; +} + + + + +int main(int argc, char** argv) { + + + + float a = 2.0; + float b = 3.0; + + + + float da = 0;//(float*) malloc(sizeof(float)); + float db = 0;//(float*) malloc(sizeof(float)); + + + float ret = 0; + float dret = 1.0; + + int N = 10; + int dN = 0; + float* array = unsorted_array_init(N); + float* d_array = (float*) malloc(sizeof(float)*N); + for (int i = 0; i < N; i++) { + d_array[i] = 0.0; + } + + printf("The total sum is %f\n", ret); + + __builtin_autodiff(insertsort_sum, array, d_array, N, &ret, &dret); + + for (int i = 0; i < N; i++) { + printf("Diffe for index %d is %f\n", i, d_array[i]); + if (i%2 == 0) { + assert(d_array[i] == 0.0); + } else { + assert(d_array[i] == 1.0); + } + } + + //assert(da == 100*1.0f); + //assert(db == 100*1.0f); + + //printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); + return 0; +} diff --git a/enzyme/functional_tests_c/Makefile b/enzyme/functional_tests_c/Makefile new file mode 100644 index 0000000000000..2690fba117695 --- /dev/null +++ b/enzyme/functional_tests_c/Makefile @@ -0,0 +1,88 @@ + +.PHONY: all clean + +OBJ := $(wildcard *.c) + +#ENZYME_PLUGIN := ./../build/Enzyme/LLVMEnzyme-7.so +#export PATH = "$(PATH):$(LLVM_DIR)" + +#ifeq ($(CLANG_BIN_PATH),) +#CLANG_BIN_PATH=${CLANG_BIN_PATH} +#endif +# +#ifeq ($(ENZYME_PLUGIN),) +#ENZYME_PLUGIN=${ENZYME_PLUGIN} +#endif + +#CLANG_BIN_PATH := + +all: $(patsubst %.c,build/%-enzyme0,$(OBJ)) $(patsubst %.c,build/%-enzyme1,$(OBJ)) $(patsubst %.c,build/%-enzyme2,$(OBJ)) $(patsubst %.c,build/%-enzyme3,$(OBJ)) + +POST_ENZYME_FLAGS := -mem2reg -sroa -adce -simplifycfg + +#all: $(patsubst %.c,build/%-enzyme1,$(OBJ)) $(patsubst %.c,build/%-enzyme2,$(OBJ)) $(patsubst %.c,build/%-enzyme3,$(OBJ)) +#clean: +# rm -f main main-* main.ll +# rm -f compilercrash compilercrash-* compilercrash.ll +# rm -f segfault segfault-* segfault.ll +# rm -f silent_failure silent_failure-* silent_failure.ll + +#ENZYME_PLUGIN = $(ENZYME_PLUGIN) + +#EXTRA_FLAGS = -indvars -loop-simplify -loop-rotate + +# NOTE(TFK): Optimization level 0 is broken right now. +build/%-enzyme0: %.c + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 -O1 $(patsubst %.c,%,$<).c -S -emit-llvm -o $@.ll + @./setup.sh $(CLANG_BIN_PATH)/opt $@.ll $(EXTRA_FLAGS) -load=$(ENZYME_PLUGIN) -enzyme -o $@.bc + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -S -emit-llvm -o $@-final.ll + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -o $@ + +build/%-enzyme1: %.c + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 -O1 $(patsubst %.c,%,$<).c -S -emit-llvm -o $@.ll + @./setup.sh $(CLANG_BIN_PATH)/opt $@.ll $(EXTRA_FLAGS) -load=$(ENZYME_PLUGIN) -enzyme -o $@.bc + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -S -emit-llvm -o $@-final.ll + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -o $@ + +build/%-enzyme2: %.c + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 -O2 $(patsubst %.c,%,$<).c -S -emit-llvm -o $@.ll + @./setup.sh $(CLANG_BIN_PATH)/opt $@.ll $(EXTRA_FLAGS) -load=$(ENZYME_PLUGIN) -enzyme -o $@.bc + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -S -emit-llvm -o $@-final.ll + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -o $@ + +build/%-enzyme3: %.c + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 -O3 $(patsubst %.c,%,$<).c -S -emit-llvm -o $@.ll + @./setup.sh $(CLANG_BIN_PATH)/opt $@.ll $(EXTRA_FLAGS) -load=$(ENZYME_PLUGIN) -enzyme $(POST_ENZYME_FLAGS) -o $@.bc + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -S -emit-llvm -o $@-final.ll + @./setup.sh $(CLANG_BIN_PATH)/clang -std=c11 $@.bc -o $@ + + +%-enzyme-test0: build/%-enzyme0 + @./$< 2> /dev/null 1> /dev/null && echo "success" || echo "FAILURE" + +%-enzyme-test1: build/%-enzyme1 + @./$< 2> /dev/null 1> /dev/null && echo "success" || echo "FAILURE" + +%-enzyme-test2: build/%-enzyme2 + @./$< 2> /dev/null 1> /dev/null && echo "success" || echo "FAILURE" + +%-enzyme-test3: build/%-enzyme3 + @./$< 2> /dev/null 1> /dev/null && echo "success" || echo "FAILURE" + +test: $(patsubst %.c,%-enzyme-test0,$(OBJ)) $(patsubst %.c,%-enzyme-test1,$(OBJ)) $(patsubst %.c,%-enzyme-test2,$(OBJ)) $(patsubst %.c,%-enzyme-test3,$(OBJ)) +#test: $(patsubst %.c,%-enzyme-test1,$(OBJ)) $(patsubst %.c,%-enzyme-test2,$(OBJ)) $(patsubst %.c,%-enzyme-test3,$(OBJ)) + +generate-testfiles: + rm testfiles/* + python gentests.py $(patsubst %.c,%-enzyme0,$(OBJ)) + python gentests.py $(patsubst %.c,%-enzyme1,$(OBJ)) + python gentests.py $(patsubst %.c,%-enzyme2,$(OBJ)) + python gentests.py $(patsubst %.c,%-enzyme3,$(OBJ)) + +clean-%: + rm -f build/%* + +clean: + rm -f build/* + + diff --git a/enzyme/functional_tests_c/gentests.py b/enzyme/functional_tests_c/gentests.py new file mode 100644 index 0000000000000..ccbe7d8ae5279 --- /dev/null +++ b/enzyme/functional_tests_c/gentests.py @@ -0,0 +1,10 @@ +import sys + +for i in range(1,len(sys.argv)): + content = open('test.template').read() + content = content.replace("@NAME@", sys.argv[i]) + if sys.argv[i].startswith('FAIL_'): + content = content.replace("@EXPECTFAIL@", "; XFAIL: *") + else: + content = content.replace("@EXPECTFAIL@", "") + open('./testfiles/'+sys.argv[i]+".test", 'w+').write(content) diff --git a/enzyme/functional_tests_c/insertsort_sum.c b/enzyme/functional_tests_c/insertsort_sum.c new file mode 100644 index 0000000000000..875bf620077c1 --- /dev/null +++ b/enzyme/functional_tests_c/insertsort_sum.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include + +#define __builtin_autodiff __enzyme_autodiff + +double __enzyme_autodiff(void*, ...); + +// size of array +float* unsorted_array_init(int N) { + float* arr = (float*) malloc(sizeof(float) * N); + for (int i = 0; i < N; i++) { + arr[i] = 1.0*(i%2); + } + return arr; +} + +// sums the first half of a sorted array. +void insertsort_sum (float* array, int N, float* ret) { + float sum = 0; + //qsort(array, N, sizeof(float), cmp); + + for (int i = 1; i < N; i++) { + int j = i; + while (j > 0 && array[j-1] < array[j]) { + float tmp = array[j]; + array[j] = array[j-1]; + array[j-1] = tmp; + j -= 1; + } + } + + + for (int i = 0; i < N/2; i++) { + printf("Val: %f\n", array[i]); + sum += array[i]; + } + *ret = sum; +} + + + + +int main(int argc, char** argv) { + + + + float a = 2.0; + float b = 3.0; + + + + float da = 0; + float db = 0; + + + float ret = 0; + float dret = 1.0; + + int N = 10; + int dN = 0; + float* array = unsorted_array_init(N); + float* d_array = (float*) malloc(sizeof(float)*N); + for (int i = 0; i < N; i++) { + d_array[i] = 0.0; + } + + printf("Array before sorting:\n"); + for (int i = 0; i < N; i++) { + printf("%d:%f\n", i, array[i]); + } + + //insertsort_sum(array, N, &ret); + + printf("Array after sorting:\n"); + for (int i = 0; i < N; i++) { + printf("%d:%f\n", i, array[i]); + } + + + printf("The total sum is %f\n", ret); + + __builtin_autodiff(insertsort_sum, array, d_array, N, &ret, &dret); + + for (int i = 0; i < N; i++) { + printf("Diffe for index %d is %f\n", i, d_array[i]); + if (i%2 == 0) { + assert(d_array[i] == 0.0); + } else { + assert(d_array[i] == 1.0); + } + } + + //__builtin_autodiff(compute_loops, &a, &da, &b, &db, &ret, &dret); + + + //assert(da == 100*1.0f); + //assert(db == 100*1.0f); + + //printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); + return 0; +} diff --git a/enzyme/functional_tests_c/lit.cfg.py b/enzyme/functional_tests_c/lit.cfg.py new file mode 100644 index 0000000000000..af1573f9f7dc7 --- /dev/null +++ b/enzyme/functional_tests_c/lit.cfg.py @@ -0,0 +1,73 @@ +# -*clang- Python -*- + +import os +import platform +import re +import subprocess + +import lit.formats +import lit.util + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = 'Enzyme-c-tests' + +# testFormat: The test format to use to interpret tests. +# +# For now we require '&&' between commands, until they get globally killed and +# the test runner updated. +execute_external = platform.system() != 'Windows' +config.test_format = lit.formats.ShTest(execute_external) + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = ['.test'] + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.dirname(__file__) + + +print("config.test_source_root is " + config.test_source_root) + +# test_exec_root: The root path where tests should be run. +config.test_exec_root = os.path.join(config.enzyme_obj_root, 'functional_tests_c') + +# Tweak the PATH to include the tools dir and the scripts dir. +base_paths = [config.llvm_tools_dir, config.environment['PATH']] +path = os.path.pathsep.join(base_paths) # + config.extra_paths) +config.environment['PATH'] = path + +path = os.path.pathsep.join((config.llvm_libs_dir, + config.environment.get('LD_LIBRARY_PATH',''))) +config.environment['LD_LIBRARY_PATH'] = path + +#export TAPIR_PREFIX=./../../llvm/build4 +#export ENZYME_PLUGIN=./../build4/Enzyme/LLVMEnzyme-7.so + +#config.environment['TAPIR_PREFIX'] = config.llvm_src_root +config.environment['ENZYME_PLUGIN'] = config.enzyme_obj_root +'/Enzyme/LLVMEnzyme-' + config.llvm_ver + config.llvm_shlib_ext + +# opt knows whether it is compiled with -DNDEBUG. +import subprocess +try: + opt_cmd = subprocess.Popen([os.path.join(config.llvm_tools_dir, 'opt'), '-version'], + stdout = subprocess.PIPE, + env=config.environment) +except OSError: + print("Could not find opt in " + config.llvm_tools_dir) + exit(42) + +if re.search(r'with assertions', opt_cmd.stdout.read().decode('ascii')): + config.available_features.add('asserts') +opt_cmd.wait() + +try: + llvm_config_cmd = subprocess.Popen([os.path.join( + config.llvm_tools_dir, + 'llvm-config'), + '--targets-built'], + stdout = subprocess.PIPE, + env=config.environment) +except OSError: + print("Could not find llvm-config in " + config.llvm_tools_dir) + exit(42) diff --git a/enzyme/functional_tests_c/lit.site.cfg.py.in b/enzyme/functional_tests_c/lit.site.cfg.py.in new file mode 100644 index 0000000000000..fb597214820cb --- /dev/null +++ b/enzyme/functional_tests_c/lit.site.cfg.py.in @@ -0,0 +1,51 @@ +@LIT_SITE_CFG_IN_HEADER@ + +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.llvm_ver = "@LLVM_VERSION_MAJOR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = "@LLVM_TOOLS_BINARY_DIR@" +config.llvm_libs_dir = "@LLVM_LIBS_DIR@" +config.enzyme_obj_root = "@ENZYME_BINARY_DIR@" +config.target_triple = "@TARGET_TRIPLE@" + +config.llvm_shlib_ext = "@LLVM_SHLIBEXT@" + +config.targets_to_build = "@TARGETS_TO_BUILD@" + +## Check the current platform with regex +import re +EAT_ERR_ON_X86 = ' ' +if (re.match(r'^x86_64*', '@TARGET_TRIPLE@') == None) : + EAT_ERR_ON_X86 = '|| echo \"error is eaten\"' + +for arch in config.targets_to_build.split(): + config.available_features.add(arch.lower() + '-registered-target') + +# Support substitution of the tools and libs dirs with user parameters. This is +# used when we can't determine the tool dir at configuration time. +try: + config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params + config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params +except KeyError: + e = sys.exc_info()[1] + key, = e.args + lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) + +# excludes: A list of directories to exclude from the testsuite. The 'Inputs' +# subdirectories contain auxiliary inputs for various tests in their parent +# directories. +config.excludes = ['Inputs'] + +config.substitutions.append(('%shlibext', config.llvm_shlib_ext)) +config.substitutions.append(('%loadEnzyme', '' + + '@ENZYME_BINARY_DIR@/Enzyme/LLVMEnzyme-' + config.llvm_ver + config.llvm_shlib_ext + )) + +config.substitutions.append(('%clangBinPath', '@LLVM_BINARY_DIR@/bin')) +config.substitutions.append(('%desired_wd', '' + + "@ENZYME_SOURCE_DIR@/functional_tests_c" + )) + + +# Let the main config do the real work. +lit_config.load_config(config, "@ENZYME_SOURCE_DIR@/functional_tests_c/lit.cfg.py") diff --git a/enzyme/functional_tests_c/loops.c b/enzyme/functional_tests_c/loops.c new file mode 100644 index 0000000000000..0c1ffcea6f6d8 --- /dev/null +++ b/enzyme/functional_tests_c/loops.c @@ -0,0 +1,61 @@ +#include +#include +#include + +#define __builtin_autodiff __enzyme_autodiff + + +double __enzyme_autodiff(void*, ...); + +//float man_max(float* a, float* b) { +// if (*a > *b) { +// return *a; +// } else { +// return *b; +// } +//} +void compute_loops(float* a, float* b, float* ret) { + double sum0 = 0.0; + for (int i = 0; i < 100; i++) { + //double sum1 = 0.0; + //for (int j = 0; j < 100; j++) { + // //double sum2 = 0.0; + // //for (int k = 0; k < 100; k++) { + // // sum2 += *a+*b; + // //} + // sum1 += *a+*b; + //} + sum0 += *a + *b; + } + *ret = sum0; +} + + + +int main(int argc, char** argv) { + + + + float a = 2.0; + float b = 3.0; + + + + float da = 0;//(float*) malloc(sizeof(float)); + float db = 0;//(float*) malloc(sizeof(float)); + + + float ret = 0; + float dret = 1.0; + + //compute_loops(&a, &b, &ret); + + __builtin_autodiff(compute_loops, &a, &da, &b, &db, &ret, &dret); + + + assert(da == 100*1.0f); + assert(db == 100*1.0f); + + printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); + return 0; +} diff --git a/enzyme/functional_tests_c/loopsdouble.c b/enzyme/functional_tests_c/loopsdouble.c new file mode 100644 index 0000000000000..67712b2256dbb --- /dev/null +++ b/enzyme/functional_tests_c/loopsdouble.c @@ -0,0 +1,57 @@ +#include +#include +#include +#define __builtin_autodiff __enzyme_autodiff +double __enzyme_autodiff(void*, ...); +//float man_max(float* a, float* b) { +// if (*a > *b) { +// return *a; +// } else { +// return *b; +// } +//} +void compute_loops(float* a, float* b, float* ret) { + double sum0 = 0.0; + for (int i = 0; i < 100; i++) { + double sum1 = 0.0; + for (int j = 0; j < 100; j++) { + //double sum2 = 0.0; + //for (int k = 0; k < 100; k++) { + // sum2 += *a+*b; + //} + sum1 += *a+*b; + } + sum0 += sum1; + } + *ret = sum0; +} + + + +int main(int argc, char** argv) { + + + + float a = 2.0; + float b = 3.0; + + + + float da = 0;//(float*) malloc(sizeof(float)); + float db = 0;//(float*) malloc(sizeof(float)); + + + float ret = 0; + float dret = 1.0; + + //compute_loops(&a, &b, &ret); + + __builtin_autodiff(compute_loops, &a, &da, &b, &db, &ret, &dret); + + + assert(da == 100*100*1.0f); + assert(db == 100*100*1.0f); + + printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); + return 0; +} diff --git a/enzyme/functional_tests_c/loopstriple.c b/enzyme/functional_tests_c/loopstriple.c new file mode 100644 index 0000000000000..ceb71802a8340 --- /dev/null +++ b/enzyme/functional_tests_c/loopstriple.c @@ -0,0 +1,51 @@ +#include +#include +#include + +#define __builtin_autodiff __enzyme_autodiff +double __enzyme_autodiff(void*, ...); +void compute_loops(float* a, float* b, float* ret) { + double sum0 = 0.0; + for (int i = 0; i < 100; i++) { + double sum1 = 0.0; + for (int j = 0; j < 100; j++) { + double sum2 = 0.0; + for (int k = 0; k < 100; k++) { + sum2 += *a+*b; + } + sum1 += sum2; + } + sum0 += sum1; + } + *ret = sum0; +} + + + +int main(int argc, char** argv) { + + + + float a = 2.0; + float b = 3.0; + + + + float da = 0;//(float*) malloc(sizeof(float)); + float db = 0;//(float*) malloc(sizeof(float)); + + + float ret = 0; + float dret = 1.0; + + //compute_loops(&a, &b, &ret); + + __builtin_autodiff(compute_loops, &a, &da, &b, &db, &ret, &dret); + + + assert(da == 100*100*100*1.0f); + assert(db == 100*100*100*1.0f); + + printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); + return 0; +} diff --git a/enzyme/functional_tests_c/recurse.c b/enzyme/functional_tests_c/recurse.c new file mode 100644 index 0000000000000..fe02b21bbb58a --- /dev/null +++ b/enzyme/functional_tests_c/recurse.c @@ -0,0 +1,50 @@ +#include +#include +#include +#define __builtin_autodiff __enzyme_autodiff +double __enzyme_autodiff(void*, ...); +int counter = 0; +double recurse_max_helper(float* a, float* b, int N) { + if (N <= 0) { + return *a + *b; + } + return recurse_max_helper(a,b,N-1) + recurse_max_helper(a,b,N-2); +} +void recurse_max(float* a, float* b, float* ret, int N) { + *ret = recurse_max_helper(a,b,N); +} + + + +int main(int argc, char** argv) { + + + + float a = 2.0; + float b = 3.0; + + + + float da = 0;//(float*) malloc(sizeof(float)); + float db = 0;//(float*) malloc(sizeof(float)); + + + float ret = 0; + float dret = 2.0; + + recurse_max(&a, &b, &ret, 20); + + int N = 20; + int dN = 0; + + __builtin_autodiff(recurse_max, &a, &da, &b, &db, &ret, &dret, 20); + + + assert(da == 17711.0*2); + assert(db == 17711.0*2); + + + + printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); + return 0; +} diff --git a/enzyme/functional_tests_c/setup.sh b/enzyme/functional_tests_c/setup.sh new file mode 100755 index 0000000000000..2d35d8a847452 --- /dev/null +++ b/enzyme/functional_tests_c/setup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# NOTE(TFK): Uncomment for local testing. +export CLANG_BIN_PATH=./../../llvm/build/bin +export ENZYME_PLUGIN=./../build/Enzyme/LLVMEnzyme-7.so + +mkdir -p build +$@ diff --git a/enzyme/functional_tests_c/test.template b/enzyme/functional_tests_c/test.template new file mode 100644 index 0000000000000..32543cea6d567 --- /dev/null +++ b/enzyme/functional_tests_c/test.template @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-@NAME@ ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/@NAME@ ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/@NAME@ +@EXPECTFAIL@ diff --git a/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme0.test b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme0.test new file mode 100644 index 0000000000000..c607888ad19a7 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme0.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-FAIL_insertsort_sum_alt-enzyme0 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/FAIL_insertsort_sum_alt-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/FAIL_insertsort_sum_alt-enzyme0 +; XFAIL: * diff --git a/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme1.test b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme1.test new file mode 100644 index 0000000000000..50e2f23527135 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme1.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-FAIL_insertsort_sum_alt-enzyme1 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/FAIL_insertsort_sum_alt-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/FAIL_insertsort_sum_alt-enzyme1 +; XFAIL: * diff --git a/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme2.test b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme2.test new file mode 100644 index 0000000000000..c181c6697205b --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme2.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-FAIL_insertsort_sum_alt-enzyme2 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/FAIL_insertsort_sum_alt-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/FAIL_insertsort_sum_alt-enzyme2 +; XFAIL: * diff --git a/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme3.test b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme3.test new file mode 100644 index 0000000000000..4b7204fb15a0b --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/FAIL_insertsort_sum_alt-enzyme3.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-FAIL_insertsort_sum_alt-enzyme3 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/FAIL_insertsort_sum_alt-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/FAIL_insertsort_sum_alt-enzyme3 +; XFAIL: * diff --git a/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme0.test b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme0.test new file mode 100644 index 0000000000000..6b986f522c169 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme0.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-insertsort_sum-enzyme0 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/insertsort_sum-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/insertsort_sum-enzyme0 + diff --git a/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme1.test b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme1.test new file mode 100644 index 0000000000000..4cc3a0434f748 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme1.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-insertsort_sum-enzyme1 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/insertsort_sum-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/insertsort_sum-enzyme1 + diff --git a/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme2.test b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme2.test new file mode 100644 index 0000000000000..6c26169e6351f --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme2.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-insertsort_sum-enzyme2 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/insertsort_sum-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/insertsort_sum-enzyme2 + diff --git a/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme3.test b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme3.test new file mode 100644 index 0000000000000..e8191e3b64904 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/insertsort_sum-enzyme3.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-insertsort_sum-enzyme3 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/insertsort_sum-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/insertsort_sum-enzyme3 + diff --git a/enzyme/functional_tests_c/testfiles/loops-enzyme0.test b/enzyme/functional_tests_c/testfiles/loops-enzyme0.test new file mode 100644 index 0000000000000..c3d6e32644092 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loops-enzyme0.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loops-enzyme0 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loops-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loops-enzyme0 + diff --git a/enzyme/functional_tests_c/testfiles/loops-enzyme1.test b/enzyme/functional_tests_c/testfiles/loops-enzyme1.test new file mode 100644 index 0000000000000..30d0181c9d8ed --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loops-enzyme1.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loops-enzyme1 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loops-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loops-enzyme1 + diff --git a/enzyme/functional_tests_c/testfiles/loops-enzyme2.test b/enzyme/functional_tests_c/testfiles/loops-enzyme2.test new file mode 100644 index 0000000000000..31cee1430f25b --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loops-enzyme2.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loops-enzyme2 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loops-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loops-enzyme2 + diff --git a/enzyme/functional_tests_c/testfiles/loops-enzyme3.test b/enzyme/functional_tests_c/testfiles/loops-enzyme3.test new file mode 100644 index 0000000000000..efe40ae994fad --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loops-enzyme3.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loops-enzyme3 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loops-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loops-enzyme3 + diff --git a/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme0.test b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme0.test new file mode 100644 index 0000000000000..7bf0ae18a1c96 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme0.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopsdouble-enzyme0 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopsdouble-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopsdouble-enzyme0 + diff --git a/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme1.test b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme1.test new file mode 100644 index 0000000000000..2f4b926a67fdf --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme1.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopsdouble-enzyme1 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopsdouble-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopsdouble-enzyme1 + diff --git a/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme2.test b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme2.test new file mode 100644 index 0000000000000..49df6855201b9 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme2.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopsdouble-enzyme2 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopsdouble-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopsdouble-enzyme2 + diff --git a/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme3.test b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme3.test new file mode 100644 index 0000000000000..1d633e8f8bae1 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopsdouble-enzyme3.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopsdouble-enzyme3 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopsdouble-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopsdouble-enzyme3 + diff --git a/enzyme/functional_tests_c/testfiles/loopstriple-enzyme0.test b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme0.test new file mode 100644 index 0000000000000..d1c9f1a0d098c --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme0.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopstriple-enzyme0 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopstriple-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopstriple-enzyme0 + diff --git a/enzyme/functional_tests_c/testfiles/loopstriple-enzyme1.test b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme1.test new file mode 100644 index 0000000000000..07be2cca8dc9a --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme1.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopstriple-enzyme1 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopstriple-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopstriple-enzyme1 + diff --git a/enzyme/functional_tests_c/testfiles/loopstriple-enzyme2.test b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme2.test new file mode 100644 index 0000000000000..3c3c7a7fa4a07 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme2.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopstriple-enzyme2 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopstriple-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopstriple-enzyme2 + diff --git a/enzyme/functional_tests_c/testfiles/loopstriple-enzyme3.test b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme3.test new file mode 100644 index 0000000000000..fd0c341b1549d --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/loopstriple-enzyme3.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-loopstriple-enzyme3 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/loopstriple-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/loopstriple-enzyme3 + diff --git a/enzyme/functional_tests_c/testfiles/recurse-enzyme0.test b/enzyme/functional_tests_c/testfiles/recurse-enzyme0.test new file mode 100644 index 0000000000000..5271a9c77950b --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/recurse-enzyme0.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-recurse-enzyme0 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/recurse-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/recurse-enzyme0 + diff --git a/enzyme/functional_tests_c/testfiles/recurse-enzyme1.test b/enzyme/functional_tests_c/testfiles/recurse-enzyme1.test new file mode 100644 index 0000000000000..23154f09d2215 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/recurse-enzyme1.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-recurse-enzyme1 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/recurse-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/recurse-enzyme1 + diff --git a/enzyme/functional_tests_c/testfiles/recurse-enzyme2.test b/enzyme/functional_tests_c/testfiles/recurse-enzyme2.test new file mode 100644 index 0000000000000..4ab7663f12846 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/recurse-enzyme2.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-recurse-enzyme2 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/recurse-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/recurse-enzyme2 + diff --git a/enzyme/functional_tests_c/testfiles/recurse-enzyme3.test b/enzyme/functional_tests_c/testfiles/recurse-enzyme3.test new file mode 100644 index 0000000000000..1e8082704e013 --- /dev/null +++ b/enzyme/functional_tests_c/testfiles/recurse-enzyme3.test @@ -0,0 +1,5 @@ +; RUN: cd %desired_wd +; RUN: make clean-recurse-enzyme3 ENZYME_PLUGIN=%loadEnzyme +; RUN: make build/recurse-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath +; RUN: build/recurse-enzyme3 + diff --git a/enzyme/test/Enzyme/ifcrash.ll b/enzyme/test/Enzyme/ifcrash.ll new file mode 100644 index 0000000000000..ace8db30e53cd --- /dev/null +++ b/enzyme/test/Enzyme/ifcrash.ll @@ -0,0 +1,56 @@ +; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -enzyme_print=1 -mem2reg -instsimplify -adce -loop-deletion -correlated-propagation -simplifycfg -S | FileCheck %s + + +; Function Attrs: norecurse nounwind uwtable +define dso_local float @insertsort_sum(float* nocapture %array) #0 { +entry: + %arrayidx = getelementptr inbounds float, float* %array, i64 2 + %0 = load float, float* %arrayidx, align 4, !tbaa !2 + %arrayidx2 = getelementptr inbounds float, float* %array, i64 3 + %1 = load float, float* %arrayidx2, align 4, !tbaa !2 + %cmp = fcmp olt float %0, %1 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + store float %0, float* %arrayidx2, align 4, !tbaa !2 + store float %1, float* %arrayidx, align 4, !tbaa !2 + br label %if.end + +if.end: ; preds = %if.then, %entry + %.in = phi float [ %1, %if.then ], [ %0, %entry ] + %arrayidx11 = getelementptr inbounds float, float* %array, i64 1 + %2 = load float, float* %arrayidx11, align 4, !tbaa !2 + %cmp14 = fcmp olt float %2, %.in + br i1 %cmp14, label %if.then15, label %if.end21 + +if.then15: ; preds = %if.end + store float %2, float* %arrayidx, align 4, !tbaa !2 + store float %.in, float* %arrayidx11, align 4, !tbaa !2 + br label %if.end21 + +if.end21: ; preds = %if.then15, %if.end + %3 = load float, float* %array, align 4, !tbaa !2 + ret float %3 +} + +; Function Attrs: uwtable +define dso_local i32 @_Z10derivativePfS_(float* %array, float* %d_array) local_unnamed_addr #1 { +entry: + %call = tail call double (...) @__enzyme_autodiff(float (float*)* nonnull @insertsort_sum, float* %array, float* %d_array) + ret i32 0 +} + +declare dso_local double @__enzyme_autodiff(...) local_unnamed_addr + +attributes #0 = { norecurse nounwind uwtable } +attributes #1 = { uwtable } + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{!"clang version 7.1.0 "} +!2 = !{!3, !3, i64 0} +!3 = !{!"float", !4, i64 0} +!4 = !{!"omnipotent char", !5, i64 0} +!5 = !{!"Simple C++ TBAA"} + +; CHECK: define internal { float } @diffeinsertsort_sum(float* nocapture %array +; XFAIL: *