Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add differential pointer return c test #29

Merged
merged 2 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions enzyme/functional_tests_c/differential_pointer_return.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#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;
}

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(*dx == 3*2.0*2.0);
timkaler marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: cd %desired_wd
; RUN: make clean-differential_pointer_return-enzyme1 ENZYME_PLUGIN=%loadEnzyme
; RUN: make build/differential_pointer_return-enzyme1 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath
; RUN: build/differential_pointer_return-enzyme1
; RUN: make clean-differential_pointer_return-enzyme1 ENZYME_PLUGIN=%loadEnzyme

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: cd %desired_wd
; RUN: make clean-differential_pointer_return-enzyme2 ENZYME_PLUGIN=%loadEnzyme
; RUN: make build/differential_pointer_return-enzyme2 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath
; RUN: build/differential_pointer_return-enzyme2
; RUN: make clean-differential_pointer_return-enzyme2 ENZYME_PLUGIN=%loadEnzyme

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: cd %desired_wd
; RUN: make clean-differential_pointer_return-enzyme3 ENZYME_PLUGIN=%loadEnzyme
; RUN: make build/differential_pointer_return-enzyme3 ENZYME_PLUGIN=%loadEnzyme CLANG_BIN_PATH=%clangBinPath
; RUN: build/differential_pointer_return-enzyme3
; RUN: make clean-differential_pointer_return-enzyme3 ENZYME_PLUGIN=%loadEnzyme