-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate code for Enzyme autodiff for functions with Pointer/array ar…
…guments For functions of type double myfunction(double* arr){...}; OR double myfunction(double arr[3]){...}; we generate derivative code of type: void d_myfunction(double* arr, clad::array_ref<double> _d_arr){ double* d_arr = _d_arr.ptr(); __enzyme_autodiff_myfunction(myfunction, arr, d_arr); } Further on enzyme will handle the function differentiation This Commit also Downloads and Installs Enzyme in the Clad Directory, if the flag "-DENABLE_ENZYME_BACKEND=On" is passed to cmake during project configuration. This commit also contains tests for the above feature in test/Gradient/Enzyme.C This commit also adds the enzyme pass to the llvm optimisation pipeline so that it can run at the right moment.
- Loading branch information
1 parent
b5bfdb9
commit 828baf7
Showing
13 changed files
with
283 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/build | ||
/.vscode | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
From b2451b5910d556c291330ca4d51903b57537b2e0 Mon Sep 17 00:00:00 2001 | ||
From: Vassil Vassilev <[email protected]> | ||
Date: Fri, 29 Jul 2022 08:30:24 +0000 | ||
Subject: [PATCH] Simplify integration in Clad | ||
|
||
--- | ||
enzyme/CMakeLists.txt | 22 +++++++++++----------- | ||
enzyme/Enzyme/CMakeLists.txt | 9 +++++++++ | ||
2 files changed, 20 insertions(+), 11 deletions(-) | ||
|
||
diff --git a/enzyme/CMakeLists.txt b/enzyme/CMakeLists.txt | ||
index 4095147..09edfb0 100644 | ||
--- a/enzyme/CMakeLists.txt | ||
+++ b/enzyme/CMakeLists.txt | ||
@@ -181,7 +181,7 @@ add_subdirectory(test) | ||
|
||
# The benchmarks data are not in git-exported source archives to minimize size. | ||
# Only add the benchmarks if the directory exists. | ||
-if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/benchmarks") | ||
+if (ENZYME_ENABLE_BENCHMARKS) | ||
add_subdirectory(benchmarks) | ||
endif() | ||
|
||
@@ -202,8 +202,8 @@ export(TARGETS ClangEnzyme-${LLVM_VERSION_MAJOR} | ||
APPEND FILE "${PROJECT_BINARY_DIR}/EnzymeTargets.cmake") | ||
endif() | ||
|
||
-export(TARGETS LLDEnzyme-${LLVM_VERSION_MAJOR} | ||
- APPEND FILE "${PROJECT_BINARY_DIR}/EnzymeTargets.cmake") | ||
+#export(TARGETS LLDEnzyme-${LLVM_VERSION_MAJOR} | ||
+# APPEND FILE "${PROJECT_BINARY_DIR}/EnzymeTargets.cmake") | ||
|
||
export(PACKAGE Enzyme) | ||
|
||
@@ -223,12 +223,12 @@ configure_file(cmake/EnzymeConfig.cmake.in | ||
|
||
configure_file(cmake/EnzymeConfigVersion.cmake.in | ||
"${PROJECT_BINARY_DIR}/EnzymeConfigVersion.cmake" @ONLY) | ||
- | ||
-install(FILES | ||
- "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/EnzymeConfig.cmake" | ||
- "${PROJECT_BINARY_DIR}/EnzymeConfigVersion.cmake" | ||
- DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) | ||
- | ||
-install(EXPORT EnzymeTargets DESTINATION | ||
- "${INSTALL_CMAKE_DIR}" COMPONENT dev) | ||
+ | ||
+#install(FILES | ||
+# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/EnzymeConfig.cmake" | ||
+# "${PROJECT_BINARY_DIR}/EnzymeConfigVersion.cmake" | ||
+# DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) | ||
+# | ||
+#install(EXPORT EnzymeTargets DESTINATION | ||
+# "${INSTALL_CMAKE_DIR}" COMPONENT dev) | ||
|
||
diff --git a/enzyme/Enzyme/CMakeLists.txt b/enzyme/Enzyme/CMakeLists.txt | ||
index 78891b5..13fdb9c 100644 | ||
--- a/enzyme/Enzyme/CMakeLists.txt | ||
+++ b/enzyme/Enzyme/CMakeLists.txt | ||
@@ -13,6 +13,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
list(APPEND ENZYME_SRC SCEV/ScalarEvolutionExpander.cpp) | ||
list(APPEND ENZYME_SRC TypeAnalysis/TypeTree.cpp TypeAnalysis/TypeAnalysis.cpp TypeAnalysis/TypeAnalysisPrinter.cpp TypeAnalysis/RustDebugInfo.cpp) | ||
|
||
+if (ENZYME_BUILD_STATIC_ONLY) | ||
+ add_llvm_library( LLVMEnzyme-${LLVM_VERSION_MAJOR} | ||
+ ${ENZYME_SRC} | ||
+ DEPENDS | ||
+ intrinsics_gen | ||
+ ) | ||
+ return() | ||
+endif() | ||
+ | ||
if (${LLVM_VERSION_MAJOR} LESS 8) | ||
add_llvm_loadable_module( LLVMEnzyme-${LLVM_VERSION_MAJOR} | ||
${ENZYME_SRC} | ||
-- | ||
2.17.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %cladclang %s -I%S/../../include -oReverseMode.out | FileCheck %s | ||
// RUN: ./ReverseMode.out | FileCheck -check-prefix=CHECK-EXEC %s | ||
// CHECK-NOT: {{.*error|warning|note:.*}} | ||
// REQUIRES: Enzyme | ||
|
||
#include "clad/Differentiator/Differentiator.h" | ||
|
||
double f(double* arr) { return arr[0] * arr[1]; } | ||
|
||
// CHECK: void f_grad_enzyme(double *arr, clad::array_ref<double> _d_arr) { | ||
// CHECK-NEXT: double *d_arr = _d_arr.ptr(); | ||
// CHECK-NEXT: __enzyme_autodiff_f(f, arr, d_arr); | ||
// CHECK-NEXT:} | ||
|
||
int main() { | ||
auto f_grad = clad::gradient<clad::opts::use_enzyme>(f); | ||
double v[2] = {3, 4}; | ||
double g[2] = {0}; | ||
f_grad.execute(v, g); | ||
printf("d_x = %.2f, d_y = %.2f", g[0], g[1]); // CHECK-EXEC: d_x = 4.00, d_y = 3.00 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.