Skip to content

Commit

Permalink
chore: run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Jul 26, 2024
1 parent 53ac644 commit f53e736
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 67 deletions.
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
31 changes: 24 additions & 7 deletions deps/build_local.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,32 @@ 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,
),
)
# --action_env TF_CUDA_COMPUTE_CAPABILITIES="sm_50,sm_60,sm_70,sm_80,compute_90"
run(Cmd(`bazel build -c dbg --action_env=JULIA=$(Base.julia_cmd().exec[1])
run(
Cmd(
`bazel build -c dbg --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,
env=Dict("HOME"=>ENV["HOME"], "PATH"=>joinpath(source_dir, "..")*":"*ENV["PATH"])))
--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,
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 @@ -41,6 +58,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 [email protected]`, 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 [email protected]`; 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 <[email protected]>, Valentin Churavy <[email protected]>",
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)
21 changes: 10 additions & 11 deletions test/basic_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export fastmax, sinexp, sinexpbc, sumexp, mysoftmax, sumcos, grad_ip, resgrad_ip

end

@testitem "2D sum" setup=[BasicTestSetup] begin
@testitem "2D sum" setup = [BasicTestSetup] begin
r_res = sum(ones(2, 10))

a = Reactant.ConcreteRArray(ones(2, 10))
Expand All @@ -45,7 +45,7 @@ end
@test f_res r_res
end

@testitem "Basic reduce max" setup=[BasicTestSetup] begin
@testitem "Basic reduce max" setup = [BasicTestSetup] begin
r_res = fastmax(ones(2, 10))

a = Reactant.ConcreteRArray(ones(2, 10))
Expand All @@ -60,8 +60,7 @@ end
@test f_res r_res
end


@testitem "Broadcast combined" setup=[BasicTestSetup] begin
@testitem "Broadcast combined" setup = [BasicTestSetup] begin
r_res = sinexpbc(ones(2, 10))

a = Reactant.ConcreteRArray(ones(2, 10))
Expand All @@ -76,7 +75,7 @@ end
@test f_res r_res
end

@testitem "Basic mapreduce" setup=[BasicTestSetup] begin
@testitem "Basic mapreduce" setup = [BasicTestSetup] begin
x = ones(Float32, 10)
a = Reactant.ConcreteRArray(x)
r_res = sumexp(x)
Expand All @@ -87,7 +86,7 @@ end
@test f_res r_res
end

@testitem "Basic softmax" setup=[BasicTestSetup] begin
@testitem "Basic softmax" setup = [BasicTestSetup] begin
in = ones(2, 10)
r_res = mysoftmax(in)

Expand All @@ -100,15 +99,15 @@ end
@test f_res r_res
end

@testitem "Basic cos" setup=[BasicTestSetup] begin
@testitem "Basic cos" setup = [BasicTestSetup] begin
c = Reactant.ConcreteRArray(ones(3, 2))

f = Reactant.compile(cos, (c,))
r = f(c)
@test r cos.(ones(3, 2))
end

@testitem "Basic grad cos" setup=[BasicTestSetup] begin
@testitem "Basic grad cos" setup = [BasicTestSetup] begin
c = Reactant.ConcreteRArray(ones(3, 2))

f = Reactant.compile(grad_ip, (c,))
Expand All @@ -123,7 +122,7 @@ end
@test r -sin.(ones(3, 2))
end

@testitem "Basic grad cos mul" setup=[BasicTestSetup] begin
@testitem "Basic grad cos mul" setup = [BasicTestSetup] begin
c = Reactant.ConcreteRArray(ones(50, 70))
d = Reactant.ConcreteRArray(ones(70, 30))

Expand All @@ -133,12 +132,12 @@ end
@test r mul(ones(50, 70), ones(70, 30))
end

@testitem "ConcreteRArray" setup=[BasicTestSetup] begin
@testitem "ConcreteRArray" setup = [BasicTestSetup] begin
c = Reactant.ConcreteRArray(ones(50, 70))
similar(c)
end

@testitem "Reactant.@code_hlo" setup=[BasicTestSetup] begin
@testitem "Reactant.@code_hlo" setup = [BasicTestSetup] begin
W = Reactant.ConcreteRArray(randn(Float32, 10, 20))
x = Reactant.ConcreteRArray(randn(Float32, 20, 5))
res = Reactant.@code_hlo W * x
Expand Down
4 changes: 2 additions & 2 deletions test/lux_tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testitem "Lux" skip=:(VERSION < v"1.10") begin
@testitem "Lux" begin
using Lux, Random, Statistics, Enzyme, Test, BenchmarkTools
using MLUtils, OneHotArrays, Optimisers

Expand Down Expand Up @@ -36,7 +36,7 @@

target = onehotbatch(truth, [true, false]) # 2×1000 OneHotMatrix
ctarget = Reactant.ConcreteRArray(Array{Float32}(target))
loader = DataLoader((noisy, target); batchsize=64, shuffle=true);
loader = DataLoader((noisy, target); batchsize=64, shuffle=true)
# # 16-element DataLoader with first element: (2×64 Matrix{Float32}, 2×64 OneHotMatrix)

opt = Optimisers.Adam(0.01f0)
Expand Down
5 changes: 3 additions & 2 deletions test/struct_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
inds::Vector{Symbol}
end

MockTensor(data::A, inds) where {T,N,A<:AbstractArray{T,N}} = MockTensor{T,N,A}(data, inds)
MockTensor(data::A, inds) where {T,N,A<:AbstractArray{T,N}} =
MockTensor{T,N,A}(data, inds)
Base.parent(t::MockTensor) = t.data

Base.cos(x::MockTensor) = MockTensor(cos(parent(x)), x.inds)
Expand Down Expand Up @@ -92,4 +93,4 @@
@test isapprox(y, only(y3))
end
end
end
end

0 comments on commit f53e736

Please sign in to comment.