Comments (6)
Ah yup, fixed and merged.
Though can you post the log of the issue you found here so we can fix the cause of it upstream?
from enzyme.
Thanks a lot!
The core of the issue appears to be:
%19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.1.2, i32 noundef %15, i32 noundef %1) #37, !dbg !1106
number of arg operands != function parameters
ld.lld: error: a.c:374:5: in function preprocess_compute_dataspheres_potential void (i32, i32, ptr, i32, double, ptr, ptr, ptr, ptr, ptr): Enzyme: Number of arg operands !=
function parameters
%19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.1.2, i32 noundef %15, i32 noundef %1) #37, !dbg !1106
ld.lld: error: a.c:374:5: in function preprocess_compute_dataspheres_potential void (i32, i32, ptr, i32, double, ptr, ptr, ptr, ptr, ptr): Enzyme: overwritten_args.size() [0] != todiff->arg_size()
todiff: ; Function Attrs: nofree nounwind
declare !dbg !2473 noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #19
at context: %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.1.2, i32 noundef %15, i32 noundef %1) #37, !dbg !1106
Maybe obvious from the log, but worth mentioning explicitly, this is with LLDEnzyme because it's in a multisource context.
I tried and I failed to reproduce the issue on a simple test case with an identical fprintf
invocation. That would be
fprintf(stderr, "something %d and %d", func_returning_an_integer(), other_func_returning_an_integer())
Commenting that particular line of code from my source, it would fail at a subsequent fprintf
invocation, where different arguments are used.
from enzyme.
from enzyme.
Okay, so I did manage to reproduce the problem just (literally) messing around with the multisource example.
The code is a bit of a mess and in fact it fails on a different call, but with identical error message. As in most of my previous reports it may be user incompetence more than Enzyme issue, but here you go.
Makefile:
LINKER = clang -fuse-ld=lld # ld.lld
CFLAGS += -fopenmp=libomp -flto
LIBS += -lomp
#ENZLLD = ${HOME}/repositories/ENZYME/Enzyme-v0.0.103/enzyme/build-v0.0.104-with-llvm-v18.1.1-and-compiler-wrapper/Enzyme/LLDEnzyme-18.so
ENZLLD = ${HOME}/repositories/ENZYME/Enzyme-v0.0.103/enzyme/build-head-debug/Enzyme/LLDEnzyme-18.so
#ENZCLANG = ${HOME}/repositories/ENZYME/Enzyme-v0.0.103/enzyme/build-v0.0.104-with-llvm-v18.1.1-and-compiler-wrapper/Enzyme/ClangEnzyme-18.so
ENZCLANG = ${HOME}/repositories/ENZYME/Enzyme-v0.0.103/enzyme/build-head-debug/Enzyme/ClangEnzyme-18.so
all : func.o main.o
$(LINKER) -flto $(LDFLAGS) $(INLC) $? -o test.exe -v -Wl,--load-pass-plugin=$(ENZLLD)
main.o : main.c
$(CC) $(CFLAGS) $(INCL) -c $?
func.o : func.c
$(CC) $(CFLAGS) $(INCL) -c $?
.PHONY : clean
clean :
rm -f *.o *.exe
func.c
#include <stdio.h>
#include <stdlib.h>
#define DEBUG_PRINT_MACRO if ( getenv( "MY_VERBOSE" ) != NULL && atoi(getenv("MY_VERBOSE")) != 0 )
struct complex {
double r;
double i;
};
struct complex myblas_cdot(struct complex* x, struct complex *y, int n) {
struct complex sum = { 0, 0 };
for (int i=0; i<n; i++) {
sum.r += x[i].r * y[i].r - x[i].i * y[i].i;
sum.i += x[i].r * y[i].i + x[i].i * y[i].r;
}
DEBUG_PRINT_MACRO
fprintf( stdout, " whatever ( %g, %g, %d )\n", x[0], y[0], n );
return sum;
}
double myblas_cabs(struct complex x) {
return x.r * x.r + x.i * x.i;
}
main.c
#include <stdio.h>
#include <stdlib.h>
struct complex {
double r;
double i;
};
struct complex myblas_cdot(struct complex* x, struct complex *y, int n);
double myblas_cabs(struct complex x);
void __enzyme_autodiff(void*, ...);
double dotabs(struct complex* alpha, struct complex* beta, int n) {
struct complex prod = myblas_cdot(alpha, beta, n);
return myblas_cabs(prod);
}
int main(int argc, char *argv[]) {
int n = 3;
struct complex *A = (struct complex*)malloc(sizeof(struct complex) * n);
for(int i=0; i<n; i++)
A[i] = (struct complex){(i+1), (i+2)};
struct complex *grad_A = (struct complex*)malloc(sizeof(struct complex) * n);
for(int i=0; i<n; i++)
grad_A[i] = (struct complex){0,0};
struct complex *B = (struct complex*)malloc(sizeof(struct complex) * n);
for(int i=0; i<n; i++)
B[i] = (struct complex){-3-i, 2*i};
struct complex *grad_B = (struct complex*)malloc(sizeof(struct complex) * n);
for(int i=0; i<n; i++)
grad_B[i] = (struct complex){0,0};
__enzyme_autodiff((void*)dotabs, A, grad_A, B, grad_B, n);
printf("Value dotabs(A)[0] = %f\n", A[0].r);
printf("Gradient dotabs(A)[0] = %f\n", grad_A[0].r);
printf("Value dotabs(B)[0] = %f\n", B[0].r);
printf("Gradient dotabs(B)[0] = %f\n", grad_B[0].r);
return 0;
}
from enzyme.
@davidedelvento shjould be fixed by #1844 please reopen if it persists
from enzyme.
This particular problem is indeed solved. For my big code, it is now failing again, but the additional printing you included make it very clear why: Enzyme: No augmented forward pass found for
a few more functions, namely getenv
, strtol
, fwrite
.
Unless you advise differently, I'll look to what you have done with fprintf
and attempt to do the same for these others and if successful make a PR, since there is no point to differentiate them (well maybe besides strtol
if one is doing weird math things with strings)
from enzyme.
Related Issues (20)
- Bug in Enzyme gsl branch HOT 6
- compilation slowdown associated with PreserveNVVMNewPM HOT 1
- Is this N/3 correct? HOT 10
- incorrect derivative of function that returns struct HOT 2
- C++ interface templates appear to be broken HOT 9
- `std::vector.push_back()` causes segementation fault in Enzyme HOT 4
- EnzymeCreateForwardDiff missing from CApi.h HOT 1
- Clarify usage through linking HOT 10
- Failing unittest Enzyme/ReverseMode/gsl_sf_legendre_array_e.ll
- Enzyme C++ sugar for vector input/outputs HOT 2
- Batching for Vector Intrinsics
- Syntax for custom forward rule in C? HOT 4
- How to use enzyme in my makefile? HOT 2
- Compiling with -O{1,2,3} breaks custom rule that works with -O0 HOT 2
- incorrect gradient for if statement HOT 2
- Failure with new c++ sugar
- Enzyme TA expectations/issues HOT 5
- C++ interface TODO list HOT 13
- No pass found for various GSL FFT and Statistics methods
- Enzyme derivatives attempting to free stack allocations HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enzyme.