enzymead / cmake-template Goto Github PK
View Code? Open in Web Editor NEW๐จ A template for using Enzyme with CMake
License: MIT License
๐จ A template for using Enzyme with CMake
License: MIT License
E.g. with an enzyme-print
flag.
I'll try to add this (and verify if it works, no success yet..) after my exams this week if no one beats me to it. cc @ZuseZ4
I tried to run this template example using clang 16.0.6 (build from source) and the latest Enzyme.
The only modification to this template was removing the legacy-pm-flag.
โ build git:(main) โ cmake .. -G Ninja -DEigen3_INCLUDE_DIR=/home/drehwald/.local/include/eigen3 -DCMAKE_BUILD_TYPE=Release -DEIGEN_USE_BLAS=1 -DCMAKE_INSTALL_PREFIX=/home/drehwald/.local -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
CMake Warning (dev) at /home/drehwald/prog/Enzyme/enzyme/buildDbg16/EnzymeTargets.cmake:49 (add_library):
ADD_LIBRARY called with MODULE option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
Call Stack (most recent call first):
/home/drehwald/prog/Enzyme/enzyme/buildDbg16/EnzymeConfig.cmake:15 (include)
CMakeLists.txt:3 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at /home/drehwald/prog/Enzyme/enzyme/buildDbg16/EnzymeTargets.cmake:52 (add_library):
ADD_LIBRARY called with MODULE option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
Call Stack (most recent call first):
/home/drehwald/prog/Enzyme/enzyme/buildDbg16/EnzymeConfig.cmake:15 (include)
CMakeLists.txt:3 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at /home/drehwald/prog/Enzyme/enzyme/buildDbg16/EnzymeTargets.cmake:66 (add_library):
ADD_LIBRARY called with MODULE option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
Call Stack (most recent call first):
/home/drehwald/prog/Enzyme/enzyme/buildDbg16/EnzymeConfig.cmake:15 (include)
CMakeLists.txt:3 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
LLVM Version: 16
Found LLVM at: /home/drehwald/prog/llvm-16/build
Found Enzyme at: /home/drehwald/prog/Enzyme/enzyme/buildDbg16/Enzyme/ClangEnzyme-16.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/drehwald/prog/CMake-Template/build
โ build git:(main) โ ninja
[1/3] Building C object CMakeFiles/example.dir/myblas.c.o
clang-16: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]
[2/3] Building C object CMakeFiles/example.dir/multisource.c.o
clang-16: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]
[3/3] Linking C executable example
FAILED: example
: && /home/drehwald/prog/llvm-16/build/bin/clang -fuse-ld=lld -flto -O3 -DNDEBUG -fuse-ld=lld -flto -Wl,-mllvm=-load=/home/drehwald/prog/Enzyme/enzyme/buildDbg16/Enzyme/ClangEnzyme-16.so CMakeFiles/example.dir/multisource.c.o CMakeFiles/example.dir/myblas.c.o -o example && :
Error opening '/home/drehwald/prog/Enzyme/enzyme/buildDbg16/Enzyme/ClangEnzyme-16.so': /home/drehwald/prog/Enzyme/enzyme/buildDbg16/Enzyme/ClangEnzyme-16.so: undefined symbol: _ZN5clang17ASTFrontendAction13ExecuteActionEv
-load request ignored.
ld.lld: error: undefined symbol: __enzyme_autodiff
>>> referenced by ld-temp.o
>>> lto.tmp:(main)
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
@tgymnich I remember I was able to use this template in the past succesfully, but it's not working under clang-16 / the latest Enzyme anymore. I suspect it might be due to @wsmoses latests experiments to improve the c frontend and use the clang ast a bit more?
For context, I try to get the following repo to compile, with these small cmake adjustments: https://github.com/mherb/kalman
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b78acb9..2891400 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,14 @@
cmake_minimum_required(VERSION 2.8)
+
+find_package(Enzyme REQUIRED)
+
+message("LLVM Version: " ${Enzyme_LLVM_VERSION_MAJOR})
+message("Found LLVM at: " ${Enzyme_LLVM_BINARY_DIR})
+
+# C and C++ Compilers can only be configured before project(...)
+set(CMAKE_C_COMPILER "${Enzyme_LLVM_BINARY_DIR}/bin/clang")
+set(CMAKE_CXX_COMPILER "${Enzyme_LLVM_BINARY_DIR}/bin/clang")
+
project(Kalman CXX)
# TODO: Use VERSION argument to project command after raising the minimum
@@ -16,8 +26,20 @@ option(KALMAN_BUILD_EXAMPLES "Build the Kalman examples" ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
+find_package(Enzyme REQUIRED COMPONENTS ClangEnzyme)
+
+get_target_property(ClangEnzyme ClangEnzyme-${Enzyme_LLVM_VERSION_MAJOR} LOCATION)
+
+message("Found Enzyme at: " ${ClangEnzyme})
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fuse-ld=lld -flto")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=lld -flto")
+set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld -flto -Wl,-mllvm=-load=${ClangEnzyme}")
+set(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=lld -flto -Wl,-mllvm=-load=${ClangEnzyme}")
+
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.