Skip to content

Commit 95ecb39

Browse files
committed
Squashed 'src/tools/enzyme/' changes from 9530027bd44..13e8f32b0b4
13e8f32b0b4 Merge branch 'main' into enzyme-rust e1fe6adc4fc Updating subtree f530741 Update build_tarballs.jl e020a34 Add v14.0.2 to build_tarballs.jl 06a1674 Fix forward erasure (rust-lang#653) 58d27d5 Fix antialloca (rust-lang#651) 1e083a3 Fix reverse vector mode malloc (rust-lang#641) git-subtree-dir: src/tools/enzyme git-subtree-split: 13e8f32b0b451a0d95aadede32e9191eba66ac05
1 parent 655f7d3 commit 95ecb39

File tree

10 files changed

+903
-161
lines changed

10 files changed

+903
-161
lines changed

.github/workflows/enzyme-julia.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ jobs:
3939
with:
4040
version: ${{ matrix.version }}
4141
arch: ${{ matrix.arch }}
42+
4243
- name: Build libEnzyme
44+
if: ${{ matrix.os != 'macOS-latest'}}
4345
run: |
4446
julia --project=jl/deps -e 'using Pkg; Pkg.instantiate()'
4547
julia --project=jl/deps jl/deps/build_local.jl ./enzyme
48+
- name: Build libEnzyme MacOS
49+
if: ${{ matrix.os == 'macOS-latest'}}
50+
run: |
51+
julia --project=jl/deps -e 'using Pkg; Pkg.instantiate()'
52+
SDKROOT=`xcrun --show-sdk-path` julia --project=jl/deps jl/deps/build_local.jl ./enzyme
4653
- uses: julia-actions/julia-buildpkg@v1
4754
with:
4855
project: jl

.packaging/build_tarballs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repo = "https://github.com/EnzymeAD/Enzyme.git"
1111
auto_version = "%ENZYME_VERSION%"
1212
version = VersionNumber(split(auto_version, "/")[end])
1313

14-
llvm_versions = [v"11.0.1", v"12.0.1", v"13.0.1"]
14+
llvm_versions = [v"11.0.1", v"12.0.1", v"13.0.1", v"14.0.2"]
1515

1616
# Collection of sources required to build attr
1717
sources = [GitSource(repo, "%ENZYME_HASH%")]
@@ -78,6 +78,9 @@ augment_platform_block = """
7878
# determine exactly which tarballs we should build
7979
builds = []
8080
for llvm_version in llvm_versions, llvm_assertions in (false, true)
81+
if llvm_version == v"11.0.1" && llvm_assertions
82+
continue # Does not have Clang available
83+
end
8184
# Dependencies that must be installed before this package can be built
8285
llvm_name = llvm_assertions ? "LLVM_full_assert_jll" : "LLVM_full_jll"
8386
dependencies = [

.packaging/rust/main.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
use std::{path::PathBuf, process::Command};
22
#[cfg(feature = "bindgen")]
33
use {bindgen, std::fs};
4+
use std::env;
45

56
fn main() {
6-
let build_dir = PathBuf::from("/scratch/a/aspuru/drehwald/Enzyme/enzyme/build");
7-
let llvm_dir = PathBuf::from("/scratch/a/aspuru/drehwald/rust/build/x86_64-unknown-linux-gnu/llvm/lib/cmake/llvm");
8-
let llvm_dir = "-DLLVM_DIR=".to_owned() + llvm_dir.to_str().unwrap();
9-
let llvm_external_lib = "-DENZYME_EXTERNAL_SHARED_LIB=ON";
10-
let build_type = "-DCMAKE_BUILD_TYPE=Release";
11-
let mut cmake = Command::new("cmake");
12-
let mut ninja = Command::new("ninja");
7+
let base_dir = env!("CARGO_MANIFEST_DIR");
8+
let base_dir = PathBuf::from(&base_dir);
9+
let build_dir = base_dir.join("enzyme").join("build");
1310
if !std::path::Path::new(&build_dir).exists() {
1411
std::fs::create_dir(&build_dir).unwrap();
1512
}
13+
14+
let rust_build_dir = base_dir.parent().unwrap()
15+
.parent().unwrap()
16+
.parent().unwrap();
17+
let llvm_dir = rust_build_dir.join("build")
18+
.join("x86_64-unknown-linux-gnu").join("llvm");
19+
let llvm_lib_dir = llvm_dir.join("lib").join("cmake").join("llvm");
20+
let llvm_external_lib = "-DENZYME_EXTERNAL_SHARED_LIB=ON";
21+
let build_type = "-DCMAKE_BUILD_TYPE=Release";
22+
23+
let mut cmake = Command::new("cmake");
24+
let mut build = Command::new("cmake");
1625
cmake
1726
.args(&[
1827
"-G",
1928
"Ninja",
2029
"..",
2130
build_type,
2231
&llvm_external_lib,
23-
&llvm_dir,
32+
&("-DLLVM_DIR=".to_owned() + &llvm_lib_dir.to_string_lossy()),
2433
])
2534
.current_dir(&build_dir.to_str().unwrap());
26-
ninja.current_dir(&build_dir.to_str().unwrap());
35+
build.args(&["--build","."])
36+
.current_dir(&build_dir.to_str().unwrap());
2737
run_and_printerror(&mut cmake);
28-
run_and_printerror(&mut ninja);
38+
run_and_printerror(&mut build);
2939

3040
#[cfg(feature = "bindgen")]
31-
generate_bindings();
41+
generate_bindings(base_dir, llvm_dir);
3242
}
3343

3444
fn run_and_printerror(command: &mut Command) {
@@ -46,10 +56,11 @@ fn run_and_printerror(command: &mut Command) {
4656
}
4757

4858
#[cfg(feature = "bindgen")]
49-
fn generate_bindings() {
50-
let llvm_headers = PathBuf::from("/scratch/a/aspuru/drehwald/rust/build/x86_64-unknown-linux-gnu/llvm/include");
51-
let out_file = PathBuf::from("/scratch/a/aspuru/drehwald/enzyme.rs");
52-
let capi_header = PathBuf::from("/scratch/a/aspuru/drehwald/Enzyme/enzyme/Enzyme/CApi.h");
59+
fn generate_bindings(base_dir: PathBuf, llvm_dir: PathBuf) {
60+
let llvm_headers = llvm_dir.join("include");
61+
let out_file = base_dir.join("enzyme.rs");
62+
let capi_header = base_dir.join("enzyme").join("Enzyme").join("CApi.h");
63+
print!("{:?}", capi_header.display());
5364

5465
let content: String = fs::read_to_string(capi_header.clone()).unwrap();
5566

enzyme.rs

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/* automatically generated by rust-bindgen 0.59.2 */
2+
3+
pub type __uint8_t = ::std::os::raw::c_uchar;
4+
pub type __int64_t = ::std::os::raw::c_long;
5+
pub type size_t = ::std::os::raw::c_ulong;
6+
#[repr(C)]
7+
#[derive(Debug, Copy, Clone)]
8+
pub struct LLVMOpaqueType {
9+
_unused: [u8; 0],
10+
}
11+
#[doc = " Each value in the LLVM IR has a type, an LLVMTypeRef."]
12+
#[doc = ""]
13+
#[doc = " @see llvm::Type"]
14+
pub type LLVMTypeRef = *mut LLVMOpaqueType;
15+
#[repr(C)]
16+
#[derive(Debug, Copy, Clone)]
17+
pub struct LLVMOpaqueValue {
18+
_unused: [u8; 0],
19+
}
20+
#[doc = " Represents an individual value in LLVM IR."]
21+
#[doc = ""]
22+
#[doc = " This models llvm::Value."]
23+
pub type LLVMValueRef = *mut LLVMOpaqueValue;
24+
#[repr(C)]
25+
#[derive(Debug, Copy, Clone)]
26+
pub struct EnzymeOpaqueTypeAnalysis {
27+
_unused: [u8; 0],
28+
}
29+
pub type EnzymeTypeAnalysisRef = *mut EnzymeOpaqueTypeAnalysis;
30+
#[repr(C)]
31+
#[derive(Debug, Copy, Clone)]
32+
pub struct EnzymeOpaqueLogic {
33+
_unused: [u8; 0],
34+
}
35+
pub type EnzymeLogicRef = *mut EnzymeOpaqueLogic;
36+
#[repr(C)]
37+
#[derive(Debug, Copy, Clone)]
38+
pub struct EnzymeOpaqueAugmentedReturn {
39+
_unused: [u8; 0],
40+
}
41+
pub type EnzymeAugmentedReturnPtr = *mut EnzymeOpaqueAugmentedReturn;
42+
#[repr(C)]
43+
#[derive(Debug, Copy, Clone)]
44+
pub struct IntList {
45+
pub data: *mut i64,
46+
pub size: size_t,
47+
}
48+
#[test]
49+
fn bindgen_test_layout_IntList() {
50+
assert_eq!(
51+
::std::mem::size_of::<IntList>(),
52+
16usize,
53+
concat!("Size of: ", stringify!(IntList))
54+
);
55+
assert_eq!(
56+
::std::mem::align_of::<IntList>(),
57+
8usize,
58+
concat!("Alignment of ", stringify!(IntList))
59+
);
60+
assert_eq!(
61+
unsafe { &(*(::std::ptr::null::<IntList>())).data as *const _ as usize },
62+
0usize,
63+
concat!("Offset of field: ", stringify!(IntList), "::", stringify!(data))
64+
);
65+
assert_eq!(
66+
unsafe { &(*(::std::ptr::null::<IntList>())).size as *const _ as usize },
67+
8usize,
68+
concat!("Offset of field: ", stringify!(IntList), "::", stringify!(size))
69+
);
70+
}
71+
#[repr(u32)]
72+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
73+
pub enum CConcreteType {
74+
DT_Anything = 0,
75+
DT_Integer = 1,
76+
DT_Pointer = 2,
77+
DT_Half = 3,
78+
DT_Float = 4,
79+
DT_Double = 5,
80+
DT_Unknown = 6,
81+
}
82+
#[repr(C)]
83+
#[derive(Debug, Copy, Clone)]
84+
pub struct EnzymeTypeTree {
85+
_unused: [u8; 0],
86+
}
87+
pub type CTypeTreeRef = *mut EnzymeTypeTree;
88+
extern "C" {
89+
pub fn EnzymeNewTypeTree() -> CTypeTreeRef;
90+
}
91+
extern "C" {
92+
pub fn EnzymeFreeTypeTree(CTT: CTypeTreeRef);
93+
}
94+
extern "C" {
95+
pub fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
96+
}
97+
extern "C" {
98+
pub fn EnzymeSetCLInteger(arg1: *mut ::std::os::raw::c_void, arg2: i64);
99+
}
100+
#[repr(C)]
101+
#[derive(Debug, Copy, Clone)]
102+
pub struct CFnTypeInfo {
103+
#[doc = " Types of arguments, assumed of size len(Arguments)"]
104+
pub Arguments: *mut CTypeTreeRef,
105+
#[doc = " Type of return"]
106+
pub Return: CTypeTreeRef,
107+
#[doc = " The specific constant(s) known to represented by an argument, if constant"]
108+
pub KnownValues: *mut IntList,
109+
}
110+
#[test]
111+
fn bindgen_test_layout_CFnTypeInfo() {
112+
assert_eq!(
113+
::std::mem::size_of::<CFnTypeInfo>(),
114+
24usize,
115+
concat!("Size of: ", stringify!(CFnTypeInfo))
116+
);
117+
assert_eq!(
118+
::std::mem::align_of::<CFnTypeInfo>(),
119+
8usize,
120+
concat!("Alignment of ", stringify!(CFnTypeInfo))
121+
);
122+
assert_eq!(
123+
unsafe { &(*(::std::ptr::null::<CFnTypeInfo>())).Arguments as *const _ as usize },
124+
0usize,
125+
concat!("Offset of field: ", stringify!(CFnTypeInfo), "::", stringify!(Arguments))
126+
);
127+
assert_eq!(
128+
unsafe { &(*(::std::ptr::null::<CFnTypeInfo>())).Return as *const _ as usize },
129+
8usize,
130+
concat!("Offset of field: ", stringify!(CFnTypeInfo), "::", stringify!(Return))
131+
);
132+
assert_eq!(
133+
unsafe { &(*(::std::ptr::null::<CFnTypeInfo>())).KnownValues as *const _ as usize },
134+
16usize,
135+
concat!("Offset of field: ", stringify!(CFnTypeInfo), "::", stringify!(KnownValues))
136+
);
137+
}
138+
#[repr(u32)]
139+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
140+
pub enum CDIFFE_TYPE {
141+
DFT_OUT_DIFF = 0,
142+
DFT_DUP_ARG = 1,
143+
DFT_CONSTANT = 2,
144+
DFT_DUP_NONEED = 3,
145+
}
146+
#[repr(u32)]
147+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
148+
pub enum CDerivativeMode {
149+
DEM_ForwardMode = 0,
150+
DEM_ReverseModePrimal = 1,
151+
DEM_ReverseModeGradient = 2,
152+
DEM_ReverseModeCombined = 3,
153+
DEM_ForwardModeSplit = 4,
154+
}
155+
extern "C" {
156+
pub fn EnzymeCreateForwardDiff(
157+
arg1: EnzymeLogicRef,
158+
todiff: LLVMValueRef,
159+
retType: CDIFFE_TYPE,
160+
constant_args: *mut CDIFFE_TYPE,
161+
constant_args_size: size_t,
162+
TA: EnzymeTypeAnalysisRef,
163+
returnValue: u8,
164+
mode: CDerivativeMode,
165+
freeMemory: u8,
166+
width: ::std::os::raw::c_uint,
167+
additionalArg: LLVMTypeRef,
168+
typeInfo: CFnTypeInfo,
169+
_uncacheable_args: *mut u8,
170+
uncacheable_args_size: size_t,
171+
augmented: EnzymeAugmentedReturnPtr,
172+
) -> LLVMValueRef;
173+
}
174+
extern "C" {
175+
pub fn EnzymeCreatePrimalAndGradient(
176+
arg1: EnzymeLogicRef,
177+
todiff: LLVMValueRef,
178+
retType: CDIFFE_TYPE,
179+
constant_args: *mut CDIFFE_TYPE,
180+
constant_args_size: size_t,
181+
TA: EnzymeTypeAnalysisRef,
182+
returnValue: u8,
183+
dretUsed: u8,
184+
mode: CDerivativeMode,
185+
width: ::std::os::raw::c_uint,
186+
freeMemory: u8,
187+
additionalArg: LLVMTypeRef,
188+
typeInfo: CFnTypeInfo,
189+
_uncacheable_args: *mut u8,
190+
uncacheable_args_size: size_t,
191+
augmented: EnzymeAugmentedReturnPtr,
192+
AtomicAdd: u8,
193+
) -> LLVMValueRef;
194+
}
195+
extern "C" {
196+
pub fn EnzymeCreateAugmentedPrimal(
197+
arg1: EnzymeLogicRef,
198+
todiff: LLVMValueRef,
199+
retType: CDIFFE_TYPE,
200+
constant_args: *mut CDIFFE_TYPE,
201+
constant_args_size: size_t,
202+
TA: EnzymeTypeAnalysisRef,
203+
returnUsed: u8,
204+
shadowReturnUsed: u8,
205+
typeInfo: CFnTypeInfo,
206+
_uncacheable_args: *mut u8,
207+
uncacheable_args_size: size_t,
208+
forceAnonymousTape: u8,
209+
width: ::std::os::raw::c_uint,
210+
AtomicAdd: u8,
211+
) -> EnzymeAugmentedReturnPtr;
212+
}
213+
pub type CustomRuleType = ::std::option::Option<
214+
unsafe extern "C" fn(
215+
arg1: ::std::os::raw::c_int,
216+
arg2: CTypeTreeRef,
217+
arg3: *mut CTypeTreeRef,
218+
arg4: *mut IntList,
219+
arg5: size_t,
220+
arg6: LLVMValueRef,
221+
) -> u8,
222+
>;
223+
extern "C" {
224+
pub fn CreateTypeAnalysis(
225+
Log: EnzymeLogicRef,
226+
customRuleNames: *mut *mut ::std::os::raw::c_char,
227+
customRules: *mut CustomRuleType,
228+
numRules: size_t,
229+
) -> EnzymeTypeAnalysisRef;
230+
}
231+
extern "C" {
232+
pub fn ClearTypeAnalysis(arg1: EnzymeTypeAnalysisRef);
233+
}
234+
extern "C" {
235+
pub fn FreeTypeAnalysis(arg1: EnzymeTypeAnalysisRef);
236+
}
237+
extern "C" {
238+
pub fn CreateEnzymeLogic(PostOpt: u8) -> EnzymeLogicRef;
239+
}
240+
extern "C" {
241+
pub fn ClearEnzymeLogic(arg1: EnzymeLogicRef);
242+
}
243+
extern "C" {
244+
pub fn FreeEnzymeLogic(arg1: EnzymeLogicRef);
245+
}

0 commit comments

Comments
 (0)