forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable cache reads by default, which is needed for correctness. * Selectively omit caching for reads whose value does not change after the load instruction. Loads that are modified after the load instruction are called "uncacheable" in the code. * Propagate the uncacheable status of pointer arguments to calls. * readwriteread C test illustrates behavior of code.
- Loading branch information
Showing
21 changed files
with
639 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include <assert.h> | ||
#define __builtin_autodiff __enzyme_autodiff | ||
double __enzyme_autodiff(void*, ...); | ||
|
||
double f_read(double* x) { | ||
double product = (*x) * (*x); | ||
return product; | ||
} | ||
|
||
void g_write(double* x, double product) { | ||
*x = (*x) * product; | ||
} | ||
|
||
double h_read(double* x) { | ||
return *x; | ||
} | ||
|
||
double readwriteread_helper(double* x) { | ||
double product = f_read(x); | ||
g_write(x, product); | ||
double ret = h_read(x); | ||
return ret; | ||
} | ||
|
||
void readwriteread(double*__restrict x, double*__restrict ret) { | ||
*ret = readwriteread_helper(x); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
double ret = 0; | ||
double dret = 1.0; | ||
double* x = (double*) malloc(sizeof(double)); | ||
double* dx = (double*) malloc(sizeof(double)); | ||
*x = 2.0; | ||
*dx = 0.0; | ||
|
||
__builtin_autodiff(readwriteread, x, dx, &ret, &dret); | ||
|
||
|
||
printf("dx is %f ret is %f\n", *dx, ret); | ||
assert(*dx == 3*2.0*2.0); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# NOTE(TFK): Uncomment for local testing. | ||
export CLANG_BIN_PATH=./../../build-dbg/bin | ||
export ENZYME_PLUGIN=./../mkdebug/Enzyme/LLVMEnzyme-7.so | ||
export CLANG_BIN_PATH=./../../llvm/build/bin/ | ||
export ENZYME_PLUGIN=./../build/Enzyme/LLVMEnzyme-7.so | ||
|
||
mkdir -p build | ||
$@ |
6 changes: 6 additions & 0 deletions
6
enzyme/functional_tests_c/testfiles/readwriteread-enzyme0.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; RUN: cd %desired_wd | ||
; RUN: make clean-readwriteread-enzyme0 ENZYME_PLUGIN=%loadEnzyme | ||
; RUN: make build/readwriteread-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath | ||
; RUN: build/readwriteread-enzyme0 | ||
; RUN: make clean-readwriteread-enzyme0 ENZYME_PLUGIN=%loadEnzyme | ||
|
6 changes: 6 additions & 0 deletions
6
enzyme/functional_tests_c/testfiles/readwriteread-enzyme1.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; RUN: cd %desired_wd | ||
; RUN: make clean-readwriteread-enzyme1 ENZYME_PLUGIN=%loadEnzyme | ||
; RUN: make build/readwriteread-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath | ||
; RUN: build/readwriteread-enzyme1 | ||
; RUN: make clean-readwriteread-enzyme1 ENZYME_PLUGIN=%loadEnzyme | ||
|
6 changes: 6 additions & 0 deletions
6
enzyme/functional_tests_c/testfiles/readwriteread-enzyme2.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; RUN: cd %desired_wd | ||
; RUN: make clean-readwriteread-enzyme2 ENZYME_PLUGIN=%loadEnzyme | ||
; RUN: make build/readwriteread-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath | ||
; RUN: build/readwriteread-enzyme2 | ||
; RUN: make clean-readwriteread-enzyme2 ENZYME_PLUGIN=%loadEnzyme | ||
|
6 changes: 6 additions & 0 deletions
6
enzyme/functional_tests_c/testfiles/readwriteread-enzyme3.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; RUN: cd %desired_wd | ||
; RUN: make clean-readwriteread-enzyme3 ENZYME_PLUGIN=%loadEnzyme | ||
; RUN: make build/readwriteread-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath | ||
; RUN: build/readwriteread-enzyme3 | ||
; RUN: make clean-readwriteread-enzyme3 ENZYME_PLUGIN=%loadEnzyme | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.