Compilation Failure : "could not deduce type of integer"
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 22
Description
Hello,
I'm currently trying to investigate a bug about Jacobian-Vector product, and the way to compute them with enzyme.
And I encountered a compilation failure on the way.
`bugRotation.cpp`
```
#include
#include
using namespace std;
extern int enzyme_dup;
extern int enzyme_dupnoneed;
extern int enzyme_out;
extern int enzyme_const;
void __enzyme_autodiff(...);
inline void printVector( double* x, int n )
{
for( int i = 0 ; i < n ; i++)
{
cout << x[i] << endl;
}
cout << endl;
}
inline void printMatrix( double* A, int n1, int n2 )
{
for( int i = 0 ; i < n1 ; i++ )
{
for( int j = 0 ; j < n2 ; j++)
{
cout << A[i*n2+j] << " ";
}
cout << endl;
}
}
inline void matvprod( double* A, double * v, double*out, int n, int m )
{
for( int i = 0 ; i < n ; i++)
{
out[i] = 0.0;
for( int j = 0 ; j < m ; j++)
{
out[i] += A[i*m+j]*v[j];
}
}
}
inline void Rz( double ang, double *out)
{
double mat[] = {cos(ang), sin(ang),0.0 ,
-sin(ang), cos(ang),0.0,
0.0,0.0,1.0};
for( int i = 0 ; i < 9 ; i++)
out[i] = mat[i];
}
template
void compute( double * x, double* out);
#define declare(F) class F{};template<> void compute
declare(Fun4)( double*x, double *out)
{
double v[3] = {1.0,0.0,0.0};
//eulerRotate( x,v, out); //The Jv product is not computed properly
double rotMat[9];
Rz( x[0], rotMat );
matvprod( rotMat,v,out,3,3); //Fails to compile
//Works when I inline the matvprod
/*
for( int i = 0; i < 3 ; i++)
{
out[i] = 0.0;
for(int j=0; j< 3 ; j++)
{
out[i] += rotMat[i*3+j]*v[j];
}
}*/
/*
printf("rotMat \n %f %f %f \n %f %f %f \n %f %f %f \n",
rotMat[0], rotMat[1],rotMat[2],
rotMat[3], rotMat[4],rotMat[5],
rotMat[6], rotMat[7],rotMat[8]);*/
}
template
void fi( double *x, double *out , int i)
{
double fullout[3] = {0.0};
compute( x, fullout );
out[0] = fullout[i];
}
template
void jacTvp( double* x, double* v, double* out)
{
double J[9] = {0.0};
for(int i = 0; i < 3 ; i ++)
{
double dvc[3] = {0.0};
dvc[i] = 1.0;
double fout[3] = {0.0};
double fiout = 0.0;
double dfiout = 1.0;
__enzyme_autodiff(fi, enzyme_dup, x, &J[3*i],
enzyme_dup, &fiout, &dfiout,
enzyme_const, i);
}
for( int i = 0 ; i < 3 ; i++)
{
out[i] = 0.0;
for( int j = 0; j < 3 ; j++)
{
out[i] += J[3*j+i]*v[j];
}
}
cout << "J " << endl;
printMatrix(J,3,3);
cout << endl;
}
template
void demo()
{
double x[3] = {0.1, 0.2, 0.3};
double out[3] = {0.0};
compute( x, out );
cout << "out " << endl;
cout << out[0] << " " << out [1] << " " << out[2] << endl;
double v[3] = {1.,2.,3.};
double jacTvpout[3] = {0.0,0.0,0.0};
jacTvp( x, v, jacTvpout );
cout << "jacTvpout " << endl;
printVector(jacTvpout,3);
}
int main(int argc, char** argv )
{
cout << "bugRotation" << endl;
cout << "Fun4 "<< endl;
demo();
return 0;
}
```
Compilation with
`clang bugRotation.cpp -lstdc++ -lm -Rpass=enzyme -Xclang -load -Xclang /usr/local/lib/ClangEnzyme-12.so -O2 -o bugRotation -fno-exceptions`
Fails to compile with :
```
could not deduce type of integer %2 = bitcast double* %arrayidx.i.2.i to i64*, !dbg !23 num:8 q:{[]:Pointer}
bugRotation.cpp:41:14: warning: failed to deduce type of value %2 = bitcast double* %arrayidx.i.2.i to i64*, !dbg !23 [-Wpass-failed=enzyme]
out[i] += A[i*m+j]*v[j];
^
clang-12: ../Enzyme/TypeAnalysis/TypeAnalysis.cpp:4318: ConcreteType TypeAnalysis::firstPointer(size_t, llvm::Value*, const FnTypeInfo&, bool, bool): Assertion `0 && "could not deduce type of integer"' failed.
```
Full output log :
[bugrotation.log](https://github.com/wsmoses/Enzyme/files/6912515/bugrotation.log)
Contributor guide
Assessment
This issue has not been assessed yet.