clad icon indicating copy to clipboard operation
clad copied to clipboard

Unable to Load Plugin on Compilation

Open ishaanamahajan opened this issue 1 year ago • 13 comments

I am trying to compile my code with clad but am running into issues. clad-error Any help would be appreciated!

ishaanamahajan avatar May 22 '23 15:05 ishaanamahajan

Hi @ishaanamahajan

Can you please make sure that you are using the same standard C++ library (-lstdc++, -lc++) for building clad plugin (clad.so) and your example, main.cpp.

parth-07 avatar May 23 '23 06:05 parth-07

Hi @parth-07 ,

I built my clad.so using conda following commands on here - https://github.com/vgvassilev/clad. I am also using the flags in my compilation statement (shown in the screenshot), that you mentioned. Am I missing something?

ishaanamahajan avatar May 23 '23 13:05 ishaanamahajan

Hi @ishaanamahajan

I think there's some issue in -fplugin option. Can you please try the below command to run clad?

clang++ -o main.elf main.cpp -Xclang -add-plugin -Xclang clad -Xclang -load -Xclang /path/to/clad.so -I/path/to/clad/include -xc++

parth-07 avatar May 23 '23 18:05 parth-07

I get the same error message, just one of them this time though -

clad2

ishaanamahajan avatar May 23 '23 19:05 ishaanamahajan

When can I expect another follow-up on the above?

ishaanamahajan avatar May 26 '23 16:05 ishaanamahajan

What does clang -version say?

vgvassilev avatar May 26 '23 18:05 vgvassilev

this is the output I get -

clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

ishaanamahajan avatar May 26 '23 19:05 ishaanamahajan

You seem to be using clang 15 and clad 1.0. Clad 1.0 is incompatible with clang 15 as it appeared later. Could you try with clad 1.2? Or get earlier version of clang?

vgvassilev avatar May 26 '23 20:05 vgvassilev

Hi @ishaanamahajan

The Clad plugin has a strict dependency on the runtime Clang version. If the Clad plugin is built for Clang 10, then it can only be used with Clang 10, and so on. Based on the path clad-1.0-clang5_hbd05ba3_0/lib/clad.so, it seems like the version of Clad downloaded from Conda was built for Clang 5. This also explains the error that you are seeing. Can you please try building Clad from the source for the Clang version installed on your system?

parth-07 avatar May 27 '23 15:05 parth-07

the clad readme says 15.0.7 is supported.. which llvm/clang versions are supported currently?

davidlange6 avatar May 28 '23 07:05 davidlange6

ah - nevermind - the readme is for 1.2... maybe we need a small table of supported versions..

davidlange6 avatar May 28 '23 07:05 davidlange6

Screenshot from 2023-05-30 16-34-22 I built clad from source, reinstalled clang, and this is what I get now. I also wanted to make sure I am using clad right -

double integrate(VehStates& v_st, const VehParam& v_params, const std::vector <double>& controls){

    v_st._x = v_st._x + cos(v_st._theta)*v_st._v*v_params._step; // x update
    v_st._y = v_st._y + sin(v_st._theta)*v_st._v*v_params._step; // y update
    v_st._theta = v_st._theta + (tan(controls[1]) / v_params._l) * v_st._v *v_params._step; // theta update

    double rGamma = v_params._R * v_params._gamma;
    double f1 = v_params._tau0 * controls[2] - (v_params._tau0 * v_st._v / (v_params._omega0 * rGamma));
    double f0 = v_st._v * v_params._c1 / rGamma + v_params._c0;
    v_st._v = v_st._v +  ((rGamma / v_params._I) * (f1 - f0))*v_params._step; // V update
    return v_st._x;
    
}

void solve(VehStates& v_st, const VehParam& v_params, const std::vector <double>& controls){
    // compute jacobian anlytically

    clad::differentiate(integrate, v_st);
}

Also, side note but clad is 1.2 and clang is 14.0 now

ishaanamahajan avatar May 30 '23 21:05 ishaanamahajan

We have released Clad v1.2 recently and we have updated the documentation how we could use it with recent clang compilers: clang++ -std=c++11 -I /full/path/to/include/ -fplugin=/full/path/to/lib/clad.so Sourcefile.cpp. Could you re-try and let us know if that still does not work for you?

vgvassilev avatar Jul 23 '23 14:07 vgvassilev

Let's close this. We have a separate issue tracking the example that failed. The current issue seems to be resolved by passing the right flags as demonstrated in the documentation.

vgvassilev avatar May 21 '24 06:05 vgvassilev