Skip to content

Commit

Permalink
add enzyme submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Mar 19, 2024
1 parent cae865b commit 2bc0669
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Enzyme"]
path = Enzyme
url = https://github.com/EnzymeAD/Enzyme.git
1 change: 1 addition & 0 deletions Enzyme
Submodule Enzyme added at 880fb3
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fn main() {
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}

// get env vars matching DEP_LLVM_*_LIBDIR regex
let llvm_dirs: Vec<_> = env::vars().filter(|(k, _)| k.starts_with("DEP_LLVM_") && k.ends_with("_LIBDIR")).collect();
// take first one
Expand All @@ -25,4 +24,5 @@ fn main() {
// compile enzyme
let libdir= compile_enzyme(llvm_dir);
println!("cargo:rustc-link-search=native={}", libdir);
println!("cargo:rerun-if-changed=build.rs");
}
28 changes: 20 additions & 8 deletions src/execution/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,28 @@ impl Compiler {
fn find_clang() -> Result<&'static str> {
find_executable(&Compiler::CLANG_VARIENTS)
}
/// search for the enzyme library in the environment variables
fn find_enzyme_lib() -> Result<String> {
// print all the environment variables
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}
match env::var("DEP_ENZYME_SYS_LIBDIR") {
Ok(lib) => Ok(lib),
Err(_) => Err(anyhow!("DEP_ENZYME_SYS_LIBDIR environment variable not set")),

let env_vars = ["LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "PATH"];
for var in env_vars.iter() {
if let Ok(val) = env::var(var) {
for path in val.split(":") {
// check that LLVMEnzype*.so exists in this directory
if let Ok(entries) = std::fs::read_dir(path) {
for entry in entries {
if let Ok(entry) = entry {
if let Some(filename) = entry.file_name().to_str() {
if filename.starts_with("LLVMEnzyme") && filename.ends_with(".so") {
return Ok(entry.path().to_str().unwrap().to_owned());
}
}
}
}
}
}
}
}
Err(anyhow!("LLVMEnzyme*.so not found in any of: {:?}", env_vars))
}
pub fn from_discrete_str(code: &str) -> Result<Self> {
let uid = Id::<u32>::new();
Expand Down
16 changes: 7 additions & 9 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use std::env;
use std::path::Path;
use std::process::Command;

use anyhow::Result;
use anyhow::anyhow;

fn is_executable_on_path(executable_name: &str) -> bool {
let output = Command::new("which")
.arg(executable_name)
.output()
.expect("failed to execute which command");

output.status.success()
for path in env::var("PATH").unwrap().split(':') {
let path = Path::new(path).join(executable_name);
if path.exists() {
return true;
}
}
false
}


pub fn find_executable<'a>(varients: &[&'a str]) -> Result<&'a str> {
let mut command = None;
for varient in varients {
Expand All @@ -29,7 +28,6 @@ pub fn find_executable<'a>(varients: &[&'a str]) -> Result<&'a str> {
}
}


pub fn find_runtime_path(libraries: &[&str] ) -> Result<String> {
// search in EMSDK lib dir and LIBRARY_PATH env variable
let emsdk_lib = env::var("EMSDK").unwrap_or("".to_owned()) + "/upstream/emscripten/cache/sysroot/lib";
Expand Down

0 comments on commit 2bc0669

Please sign in to comment.