Skip to content

Commit

Permalink
Merge pull request #113 from EnzymeAD/format-main
Browse files Browse the repository at this point in the history
Format code of branch "main"
  • Loading branch information
avik-pal authored Sep 21, 2024
2 parents bca7438 + d6e7726 commit 6506040
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 59 deletions.
6 changes: 3 additions & 3 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ for depth in [11, 13, 16, 19]
end setup = begin
vgg = Vision.VGG($depth; pretrained=false, batchnorm=false)
ps, st = Lux.setup(Random.default_rng(), vgg)
ps_concrete = ps |> Reactant.to_rarray
st_concrete = st |> Lux.testmode |> Reactant.to_rarray
x = rand(Float32, 224, 224, 3, 16) |> Reactant.to_rarray
ps_concrete = Reactant.to_rarray(ps)
st_concrete = Reactant.to_rarray(Lux.testmode(st))
x = Reactant.to_rarray(rand(Float32, 224, 224, 3, 16))
end
end

Expand Down
43 changes: 30 additions & 13 deletions deps/ReactantExtra/make.jl
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
import BinaryBuilderBase: PkgSpec, Prefix, temp_prefix, setup_dependencies, cleanup_dependencies, destdir
import BinaryBuilderBase:
PkgSpec, Prefix, temp_prefix, setup_dependencies, cleanup_dependencies, destdir
using Clang.Generators

options = load_options(joinpath(@__DIR__, "wrap.toml"))

function rewrite!(dag::ExprDAG)
end
function rewrite!(dag::ExprDAG) end

@add_def off_t
@add_def MlirTypesCallback

let options = deepcopy(options)
options["general"]["output_file_path"] = ARGS[end]

include_dir = joinpath(splitpath(ARGS[1])[1:end-4]...)
include_dir = joinpath(splitpath(ARGS[1])[1:(end - 4)]...)
args = Generators.get_default_args()
ll_include_dir = joinpath(splitpath(ARGS[2])[1:end-2]...)
ll_include_dir = joinpath(splitpath(ARGS[2])[1:(end - 2)]...)

genarg = first(eachsplit(ARGS[3], " "))

gen_include_dir = joinpath(splitpath(genarg)[1:end-3]...)

hlo_include_dir = joinpath(splitpath(ARGS[end-1])[1:end-1]...)

append!(args, ["-I", include_dir, "-I", ll_include_dir,"-I", gen_include_dir,"-I", hlo_include_dir, "-x", "c++"])

headers = [detect_headers(include_dir, args, Dict(), endswith("Python/Interop.h"))..., detect_headers(hlo_include_dir, args, Dict())...]
gen_include_dir = joinpath(splitpath(genarg)[1:(end - 3)]...)

hlo_include_dir = joinpath(splitpath(ARGS[end - 1])[1:(end - 1)]...)

append!(
args,
[
"-I",
include_dir,
"-I",
ll_include_dir,
"-I",
gen_include_dir,
"-I",
hlo_include_dir,
"-x",
"c++",
],
)

headers = [
detect_headers(include_dir, args, Dict(), endswith("Python/Interop.h"))...,
detect_headers(hlo_include_dir, args, Dict())...,
]

ctx = create_context(headers, args, options)

Expand All @@ -35,4 +52,4 @@ let options = deepcopy(options)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
end
end
40 changes: 29 additions & 11 deletions deps/build_local.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ Pkg.activate(; temp=true)
# Build!
@info "Building" source_dir scratch_dir
run(`mkdir -p $(scratch_dir)`)
run(Cmd(`$(Base.julia_cmd().exec[1]) --project=. -e "using Pkg; Pkg.instantiate()"`, dir=source_dir))
run(
Cmd(
`$(Base.julia_cmd().exec[1]) --project=. -e "using Pkg; Pkg.instantiate()"`;
dir=source_dir,
),
)

#--repo_env TF_NEED_ROCM=1
#--define=using_rocm=true --define=using_rocm_hipcc=true
Expand All @@ -45,7 +50,7 @@ end

build_kind = if length(ARGS) == 1
kind = ARGS[1]
if kind ("dbg", "opt")
if kind ("dbg", "opt")
error("Invalid build kind $(kind). Valid options are 'dbg' and 'opt'")
end
kind
Expand All @@ -56,20 +61,33 @@ end
@info "Building JLL with -c $(build_kind)"

if isempty(arg)
run(Cmd(`bazel build -c $(build_kind) --action_env=JULIA=$(Base.julia_cmd().exec[1])
run(
Cmd(
`bazel build -c $(build_kind) --action_env=JULIA=$(Base.julia_cmd().exec[1])
--repo_env HERMETIC_PYTHON_VERSION="3.10"
--check_visibility=false --verbose_failures :libReactantExtra.so :Builtin.inc.jl :Arith.inc.jl :Affine.inc.jl :Func.inc.jl :Enzyme.inc.jl :StableHLO.inc.jl :CHLO.inc.jl :VHLO.inc.jl`, dir=source_dir,
))
--check_visibility=false --verbose_failures :libReactantExtra.so :Builtin.inc.jl :Arith.inc.jl :Affine.inc.jl :Func.inc.jl :Enzyme.inc.jl :StableHLO.inc.jl :CHLO.inc.jl :VHLO.inc.jl`;
dir=source_dir,
),
)
else
run(Cmd(`bazel build $(arg) -c $(build_kind) --action_env=JULIA=$(Base.julia_cmd().exec[1])
run(
Cmd(
`bazel build $(arg) -c $(build_kind) --action_env=JULIA=$(Base.julia_cmd().exec[1])
--repo_env HERMETIC_PYTHON_VERSION="3.10"
--check_visibility=false --verbose_failures :libReactantExtra.so :Builtin.inc.jl :Arith.inc.jl :Affine.inc.jl :Func.inc.jl :Enzyme.inc.jl :StableHLO.inc.jl :CHLO.inc.jl :VHLO.inc.jl`, dir=source_dir,
))
--check_visibility=false --verbose_failures :libReactantExtra.so :Builtin.inc.jl :Arith.inc.jl :Affine.inc.jl :Func.inc.jl :Enzyme.inc.jl :StableHLO.inc.jl :CHLO.inc.jl :VHLO.inc.jl`;
dir=source_dir,
),
)
end
# env=Dict("HOME"=>ENV["HOME"], "PATH"=>joinpath(source_dir, "..")*":"*ENV["PATH"])))

run(Cmd(`rm -f libReactantExtra.dylib`, dir=joinpath(source_dir, "bazel-bin")))
run(Cmd(`ln -s libReactantExtra.so libReactantExtra.dylib`, dir=joinpath(source_dir, "bazel-bin")))
run(Cmd(`rm -f libReactantExtra.dylib`; dir=joinpath(source_dir, "bazel-bin")))
run(
Cmd(
`ln -s libReactantExtra.so libReactantExtra.dylib`;
dir=joinpath(source_dir, "bazel-bin"),
),
)

# Discover built libraries
built_libs = filter(readdir(joinpath(source_dir, "bazel-bin"))) do file
Expand All @@ -84,6 +102,6 @@ set_preferences!(
joinpath(dirname(@__DIR__), "LocalPreferences.toml"),
"Reactant_jll",
"libReactantExtra_path" => lib_path,
"libReactantDialects_path" => joinpath(source_dir, "bazel-bin"),
"libReactantDialects_path" => joinpath(source_dir, "bazel-bin");
force=true,
)
81 changes: 49 additions & 32 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function Remotes.fileurl(::TestRemote, ::Any, filename, linerange)
L1, L2 = first(linerange), last(linerange)
return "https://github.com/JuliaBinaryWrappers/Reactant_jll.jl/$(filename)#L$(L1)-$(L2)"
end
Remotes.issueurl(::TestRemote, issue) = "https://github.com/EnzymeAD/Reactant.jl/blob/$(issue)"
function Remotes.issueurl(::TestRemote, issue)
return "https://github.com/EnzymeAD/Reactant.jl/blob/$(issue)"
end

DocMeta.setdocmeta!(Reactant, :DocTestSetup, :(using Reactant); recursive=true)

Expand All @@ -25,51 +27,66 @@ examples = Pair{String,String}[]

for (_, name) in examples
example_filepath = joinpath(EXAMPLES_DIR, string(name, ".jl"))
Literate.markdown(example_filepath, OUTPUT_DIR, documenter = true)
Literate.markdown(example_filepath, OUTPUT_DIR; documenter=true)
end

run(Cmd(`rm -rf .git`, dir=Reactant_jll.artifact_dir))
run(Cmd(`git init`, dir=Reactant_jll.artifact_dir))
run(Cmd(`git config user.name ReactantDocs`, dir=Reactant_jll.artifact_dir))
run(Cmd(`git config user.email ReactantDocs@wsmoses.com`, dir=Reactant_jll.artifact_dir))
run(Cmd(`git remote add origin https://github.com/EnzymeAD/Reactant.jl`, dir=Reactant_jll.artifact_dir))
run(Cmd(`git add -A`, dir=Reactant_jll.artifact_dir))
run(Cmd(`git commit -m "Initial commit"`, dir=Reactant_jll.artifact_dir))
run(Cmd(`rm -rf .git`; dir=Reactant_jll.artifact_dir))
run(Cmd(`git init`; dir=Reactant_jll.artifact_dir))
run(Cmd(`git config user.name ReactantDocs`; dir=Reactant_jll.artifact_dir))
run(Cmd(`git config user.email ReactantDocs@wsmoses.com`; dir=Reactant_jll.artifact_dir))
run(
Cmd(
`git remote add origin https://github.com/EnzymeAD/Reactant.jl`;
dir=Reactant_jll.artifact_dir,
),
)
run(Cmd(`git add -A`; dir=Reactant_jll.artifact_dir))
run(Cmd(`git commit -m "Initial commit"`; dir=Reactant_jll.artifact_dir))

examples = [title => joinpath("generated", string(name, ".md")) for (title, name) in examples]
examples = [
title => joinpath("generated", string(name, ".md")) for (title, name) in examples
]

gh = Documenter.Remotes.GitHub("EnzymeAD", "Reactant.jl")

makedocs(;
modules=[Reactant, Reactant.XLA, Reactant.MLIR, Reactant.MLIR.API, Reactant.MLIR.IR, Reactant.MLIR.Dialects.chlo, Reactant.MLIR.Dialects.vhlo, Reactant.MLIR.Dialects.stablehlo, Reactant.MLIR.Dialects.enzyme, Reactant.MLIR.Dialects.arith, Reactant.MLIR.Dialects.func, Reactant.MLIR.Dialects.affine, Reactant.MLIR.Dialects.builtin],
modules=[
Reactant,
Reactant.XLA,
Reactant.MLIR,
Reactant.MLIR.API,
Reactant.MLIR.IR,
Reactant.MLIR.Dialects.chlo,
Reactant.MLIR.Dialects.vhlo,
Reactant.MLIR.Dialects.stablehlo,
Reactant.MLIR.Dialects.enzyme,
Reactant.MLIR.Dialects.arith,
Reactant.MLIR.Dialects.func,
Reactant.MLIR.Dialects.affine,
Reactant.MLIR.Dialects.builtin,
],
authors="William Moses <wsmoses@illinois.edu>, Valentin Churavy <vchuravy@mit.edu>",
remotes=Dict(
# Just non-repository directories
joinpath(@__DIR__, "..") => gh,
Reactant_jll.artifact_dir => TestRemote(),
# Just non-repository directories
joinpath(@__DIR__, "..") => gh,
Reactant_jll.artifact_dir => TestRemote(),
),
sitename="Reactant.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://enzymead.github.io/Reactant.jl/",
size_threshold_ignore = ["api.md"],
assets = [
asset("https://plausible.io/js/plausible.js",
class=:js,
attributes=Dict(Symbol("data-domain") => "enzyme.mit.edu", :defer => "")
)
],
size_threshold_ignore=["api.md"],
assets=[
asset(
"https://plausible.io/js/plausible.js";
class=:js,
attributes=Dict(Symbol("data-domain") => "enzyme.mit.edu", :defer => ""),
),
],
),
pages = [
"Home" => "index.md",
"API reference" => "api.md",
],
doctest = true,
warnonly = true,
pages=["Home" => "index.md", "API reference" => "api.md"],
doctest=true,
warnonly=true,
)

deploydocs(;
repo="github.com/EnzymeAD/Reactant.jl",
devbranch = "main",
push_preview = true,
)
deploydocs(; repo="github.com/EnzymeAD/Reactant.jl", devbranch="main", push_preview=true)

0 comments on commit 6506040

Please sign in to comment.