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.
add differential pointer return c test (#29)
* add differential pointer return c test * change all tests to do approx fp comparisons, will be needed for more complex tests
- Loading branch information
Showing
13 changed files
with
126 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include <assert.h> | ||
|
||
#include "test_utils.h" | ||
|
||
#define __builtin_autodiff __enzyme_autodiff | ||
double __enzyme_autodiff(void*, ...); | ||
|
||
double f_read(double* x) { | ||
double product = (*x) * (*x); | ||
return product; | ||
} | ||
|
||
double* g_write(double* x, double product) { | ||
*x = (*x) * product; | ||
return x; | ||
} | ||
|
||
double h_read(double* x) { | ||
return *x; | ||
} | ||
|
||
double readwriteread_helper(double* x) { | ||
double product = f_read(x); | ||
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(approx_fp_equality_float(*dx, 3*2.0*2.0, 1e-10)); | ||
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
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,13 @@ | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
#include <math.h> | ||
|
||
static bool approx_fp_equality_float(float f1, float f2, double threshold) { | ||
if (fabs(f1-f2) > threshold) return false; | ||
return true; | ||
} | ||
|
||
static bool approx_fp_equality_double(double f1, double f2, double threshold) { | ||
if (fabs(f1-f2) > threshold) return false; | ||
return true; | ||
} |
6 changes: 6 additions & 0 deletions
6
enzyme/functional_tests_c/testfiles/differential_pointer_return-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-differential_pointer_return-enzyme0 ENZYME_PLUGIN=%loadEnzyme | ||
; RUN: make build/differential_pointer_return-enzyme0 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath | ||
; RUN: build/differential_pointer_return-enzyme0 | ||
; RUN: make clean-differential_pointer_return-enzyme0 ENZYME_PLUGIN=%loadEnzyme | ||
|
Oops, something went wrong.