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

Linking Example fails with LLD error: #2241

Open
spookyGh0st opened this issue Feb 11, 2025 · 2 comments
Open

Linking Example fails with LLD error: #2241

spookyGh0st opened this issue Feb 11, 2025 · 2 comments

Comments

@spookyGh0st
Copy link

I have the following code copied from the c++ examples

int enzyme_out;
struct double2{ double x, y; };
double f(double x, double y) { return x * y + 1.0 / y; }
TEST(EnzymeTest, test_variables) {
    double x = 3.0;
    double y = 2.0;
    auto [mu_x, mu_y] = __enzyme_autodiff<double2>((void*)f, enzyme_out, x, enzyme_out, y);
}
FAILED: /home/user/uni/inf_ma_sem5/lab/src/bin/khaki-test test/khaki-test[1]_tests.cmake /home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/test/khaki-test[1]_tests.cmake 
: && /usr/bin/clang++ -g -fuse-ld=lld -Wl,-mllvm -Wl,-load=/home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/external/Enzyme/enzyme/Enzyme/LLDEnzyme-19.so -Wl,--load-pass-plugin=/home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/external/Enzyme/enzyme/Enzyme/LLDEnzyme-19.so -Xlinker --dependency-file=test/CMakeFiles/khaki-test.dir/link.d test/CMakeFiles/khaki-test.dir/enzymeTest.cpp.o test/CMakeFiles/khaki-test.dir/main.cpp.o test/CMakeFiles/khaki-test.dir/membrane.cpp.o test/CMakeFiles/khaki-test.dir/repulsive.cpp.o test/CMakeFiles/khaki-test.dir/splineTest.cpp.o -o /home/user/uni/inf_ma_sem5/lab/src/bin/khaki-test  -Wl,-rpath,/home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/Build/lib  libatcg_lib.a  lib/libgtest.a  external/glfw/src/libglfw3.a  /usr/lib/librt.a  -lm  -ldl  libimgui.a  libimplot.a  libglad.a  /usr/lib/libGLX.so  /usr/lib/libOpenGL.so  Build/lib/libOpenMeshToolsd.so.11.0  Build/lib/libOpenMeshCored.so.11.0  -lginac && cd /home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/test && /usr/bin/cmake -D TEST_TARGET=khaki-test -D TEST_EXECUTABLE=/home/user/uni/inf_ma_sem5/lab/src/bin/khaki-test -D TEST_EXECUTOR= -D TEST_WORKING_DIR=/home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/test -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_FILTER= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=khaki-test_TESTS -D CTEST_FILE=/home/user/uni/inf_ma_sem5/lab/src/cmake-build-debug/test/khaki-test[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -D TEST_DISCOVERY_EXTRA_ARGS= -D TEST_XML_OUTPUT_DIR= -P /usr/share/cmake/Modules/GoogleTestAddTests.cmake

This works if i let enzyme autodetect x, y to be Output arguments. If I explicitly add the enzyme_out parameter however, I get the following error:

ld.lld: error: test/enzymeTest.cpp:111:25: in function _ZN30EnzymeTest_test_variables_Test8TestBodyEv void (ptr): Enzyme: Cannot cast __enzyme_autodiff primal argument 1, found i32 0, type i32 (simplified to i32 0 )  - to arg 0, double

I have enzyme installed as a git submodule and add it to my project as follows:

set(ENZYME_STATIC_LIB "true")
add_subdirectory(external/Enzyme/enzyme)
target_link_library(khaki PUBLIC LLDEnzymeFlags)

It seems to me that enzyme cannot detect and substitute the special names.

@wsmoses
Copy link
Member

wsmoses commented Feb 12, 2025

What if you pass in &enzyme_out instead of enzyme_out

@spookyGh0st
Copy link
Author

Hmm I can try if i find the time, but I currently have a deadline coming up. I have since switched to linking ClangEnzymeFlags instead, which fixed the issues. Note that all my tests were on llvm20.

I have also observed that the autodetection of the clang_Dir failed for me. I had to set it to set(Clang_DIR "/usr/lib/cmake/clang-20")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants