From f53e736a75493e7ad29fbf377850b026ae6a2d28 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Fri, 26 Jul 2024 16:48:29 -0700 Subject: [PATCH] chore: run formatter --- deps/ReactantExtra/make.jl | 43 ++++++++++++++------ deps/build_local.jl | 31 +++++++++++---- docs/make.jl | 81 +++++++++++++++++++++++--------------- test/basic_tests.jl | 21 +++++----- test/lux_tests.jl | 4 +- test/struct_tests.jl | 5 ++- 6 files changed, 118 insertions(+), 67 deletions(-) diff --git a/deps/ReactantExtra/make.jl b/deps/ReactantExtra/make.jl index df23c2e21..17ef9c4f4 100644 --- a/deps/ReactantExtra/make.jl +++ b/deps/ReactantExtra/make.jl @@ -1,10 +1,10 @@ -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 @@ -12,19 +12,36 @@ end 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) @@ -35,4 +52,4 @@ let options = deepcopy(options) # print build!(ctx, BUILDSTAGE_PRINTING_ONLY) -end \ No newline at end of file +end diff --git a/deps/build_local.jl b/deps/build_local.jl index defab0e40..ac7037c35 100644 --- a/deps/build_local.jl +++ b/deps/build_local.jl @@ -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 @@ -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, ) diff --git a/docs/make.jl b/docs/make.jl index d32557c97..3063a9bcd 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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) @@ -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 , Valentin Churavy ", 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) diff --git a/test/basic_tests.jl b/test/basic_tests.jl index 9df410027..2b764868b 100644 --- a/test/basic_tests.jl +++ b/test/basic_tests.jl @@ -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)) @@ -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)) @@ -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)) @@ -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) @@ -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) @@ -100,7 +99,7 @@ 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,)) @@ -108,7 +107,7 @@ end @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,)) @@ -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)) @@ -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 diff --git a/test/lux_tests.jl b/test/lux_tests.jl index 66286b2b0..aabe7b6b8 100644 --- a/test/lux_tests.jl +++ b/test/lux_tests.jl @@ -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 @@ -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) diff --git a/test/struct_tests.jl b/test/struct_tests.jl index edcf57f8b..17af513bd 100644 --- a/test/struct_tests.jl +++ b/test/struct_tests.jl @@ -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) @@ -92,4 +93,4 @@ @test isapprox(y, only(y3)) end end -end \ No newline at end of file +end