clad
clad copied to clipboard
LLVM crashing when nested void functions are used in conjunction with multiple double* input values
I have recently been running an experiment and LLVM crashes. Running the function on its own provides the correct answer, but if I however try and run the script with clad::gradient on this function it crashes. Hopefully you can point me in the right direction.
I just have a couple of questions.
1.) Can clad accommodate nested functions containing void functions, with passing by reference and generate the derivative function thereof ? ie lets say of the following form :
__host__ void fnOne(double* &rate) {
input[0] = input[0]*12;
input[1] = input[1]*24;
input[2] = input[2]*36;
}
__host__ void fnTwo(double* &rate) {
input[0] = input[0]+ 12;
input[1] = input[1]/24;
input[2] = input[2] +0.058;
}
double fn (double* rate) {
fnOne (rate); //void
fnTwo(rate); //void
double ret = fnThree(rate);
}
When I call the following function for clad::gradient(), I get an error of : "not viable: no known conversion from 'clad::array_ref
2.) I have a question regarding functions with multiple double* as inputs. Lets say the function has the form of the following :
double fn(double* IntRates, double* randomNumbers, double* fxRates) {
fnOne (randomNumbers, IntRates ); //void
fnTwo(fxRates, IntRates); //void
double ret = fnThree(IntRates);
}
firstly, can clad accomodate this if we only wanted to derive the function w.r.t the input double* intRates ? And if possible how would one specify this to the clad::gradient function ? I have tried the following and it crashes.
int main() {
double* intRates = (double*)malloc(120*sizeof(double));
double* randomNumbers= (double*)malloc(120*sizeof(double));
double* fxRates= (double*)malloc(120*sizeof(double));
//Values are then assigned to the various slots
auto fn_grad = clad::gradient(fn, "IntRates"); //Running this command alone crashes clad so I suspect I am doing something wrong here
double dx[120] = {0};
clad::array_ref<double> dx_ref(dx, 120);
fn_grad.execute(IntRates, randomNumbers, fxRates, dx_ref);
return 0;
}
The above script is what crashes the program.
Originally posted by @stebos100 in https://github.com/vgvassilev/clad/discussions/701#discussioncomment-8280191
Hi @stebos100, thanks for submitting the issue.
1.) It seems that pointer reference type parameters were not supported previously. I'm working on fixing this in #906. Thank you for pointing this out.
2.) You did everything correctly. However, not differentiating w.r.t. an array/pointer type parameter used to cause a crash. Even though the crash is fixed now, it's still recommended to differentiate w.r.t. all array/pointer type parameters. Do otherwise only if the array is just an array of constants (has no differentiable effect). I think we should add clear warnings about this before closing the issue.
I'll write a new comment once the issues are fixed.
@PetroZarytskyi, it seems that you have addressed the issue in part, what else is still missing and do we have an eta for it?