-
Notifications
You must be signed in to change notification settings - Fork 145
Import Julia source and redo CI for 1.3 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| *.swp | ||
| *.swo | ||
| build | ||
| .vscode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright © 2019 William Moses, Valentin Churavy, and other contributors | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name = "Enzyme" | ||
| uuid = "7da242da-08ed-463a-9acd-ee780be4f1d9" | ||
| authors = ["William Moses <wmoses@mit.edu>", "Valentin Churavy <vchuravy@mit.edu>"] | ||
| version = "0.1.0" | ||
|
|
||
| [deps] | ||
| LLVM = "929cbde3-209d-540e-8aea-75f648917ca0" | ||
| Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | ||
| MCAnalyzer = "a81df072-f4bb-11e8-03d3-cfaeda626d18" | ||
|
|
||
| [compat] | ||
| julia = "1.3" | ||
| LLVM = "1.3" | ||
| MCAnalyzer = "0.1" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| module Enzyme | ||
|
|
||
| export autodiff | ||
|
|
||
| using LLVM | ||
| using LLVM.Interop | ||
| import MCAnalyzer: irgen | ||
|
|
||
| include("utils.jl") | ||
| include("ad.jl") | ||
| include("opt.jl") | ||
|
|
||
| using .Opt: optimize! | ||
|
|
||
| function emit(f, args) | ||
| # Obtain the function and all it's dependencies in one handy module | ||
| diffetypes = [] | ||
| autodifftypes = Type[f] | ||
| i = 1 | ||
| while i <= length(args) | ||
| push!(autodifftypes, args[i]) | ||
| dt = whatType(args[i]) | ||
| push!(diffetypes, dt) | ||
| if dt == "diffe_dup" | ||
| i+=1 | ||
| end | ||
| i+=1 | ||
| end | ||
| mod, ccf = irgen(Tuple{autodifftypes...}) | ||
|
|
||
| ctx = context(mod) | ||
| rettype = convert(LLVMType, Float64) | ||
|
|
||
| #argtypes2 = LLVMType[convert(LLVMType, T, true) for T in args] | ||
| argtypes2 = LLVMType[] | ||
|
|
||
| i = 1 | ||
| j = 1 | ||
| orig_params = parameters(ccf) | ||
| for p in orig_params | ||
| push!(argtypes2, llvmtype(p)) | ||
| if diffetypes[i] == "diffe_dup" | ||
| push!(argtypes2, llvmtype(p)) | ||
| i+=2 | ||
| else | ||
| i+=1 | ||
| end | ||
| end | ||
|
|
||
| # TODO get function type from ccf | ||
| ft2 = LLVM.FunctionType(rettype, argtypes2) | ||
|
|
||
| # create a wrapper Function that we will inline into the llvmcall | ||
| # generated by in the end `call_function` | ||
| llvmf = LLVM.Function(mod, "enzyme_entry", ft2) | ||
| push!(function_attributes(llvmf), EnumAttribute("alwaysinline", 0, ctx)) | ||
|
|
||
| # Create the FunctionType and funtion decleration for the intrinsic | ||
| pt = LLVM.PointerType(LLVM.Int8Type(ctx)) | ||
| ftd = LLVM.FunctionType(rettype, LLVMType[pt], true) | ||
| autodiff = LLVM.Function(mod, "__enzyme_autodiff", ftd) | ||
|
|
||
| params = LLVM.Value[] | ||
| i = 1 | ||
| j = 1 | ||
| llvm_params = parameters(llvmf) | ||
| while j <= length(args) | ||
| push!(params, MDString(diffetypes[i])) | ||
| if diffetypes[i] == "diffe_dup" | ||
| push!(params, llvm_params[j]) | ||
| j+=1 | ||
| end | ||
| push!(params, llvm_params[j]) | ||
| j += 1 | ||
| i += 1 | ||
| end | ||
|
|
||
| Builder(ctx) do builder | ||
| entry = BasicBlock(llvmf, "entry", ctx) | ||
| position!(builder, entry) | ||
|
|
||
| tc = bitcast!(builder, ccf, pt) | ||
| pushfirst!(params, tc) | ||
|
|
||
| val = call!(builder, autodiff, params) | ||
|
|
||
| #if T === Nothing | ||
| # ret!(builder) | ||
| #else | ||
| ret!(builder, val) | ||
| #end | ||
| end | ||
|
|
||
| llvmf, mod | ||
| end | ||
|
|
||
| @generated function autodiff(f, args...) | ||
| llvmf, mod = emit(f, args) | ||
|
|
||
| # Run pipeline and Enzyme pass | ||
| optimize!(mod) | ||
| strip_debuginfo!(mod) | ||
|
|
||
| _args = (:(args[$i]) for i in 1:length(args)) | ||
| call_function(llvmf, Float64, Tuple{args...}, Expr(:tuple, _args...)) | ||
| end | ||
|
|
||
| end # module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| @enum Diffe begin | ||
| Duplicate = 1 | ||
| Output = 2 | ||
| Constant = 3 | ||
| end | ||
|
|
||
| function whatType(@nospecialize(dt)) | ||
| if <:(dt, Array) | ||
| sub = whatType(eltype(dt)) | ||
| if sub == "diffe_dup" | ||
| return "diffe_dup" | ||
| elseif sub == "diffe_out" | ||
| return "diffe_dup" | ||
| else | ||
| @assert(sub == "diffe_const") | ||
| return "diffe_const" | ||
| end | ||
| end | ||
| if <:(dt, Real) | ||
| return "diffe_out" | ||
| end | ||
| if <:(dt, Int) | ||
| return "diffe_const" | ||
| end | ||
| if <:(dt, String) | ||
| return "diffe_const" | ||
| end | ||
|
|
||
| if !hasfieldcount(dt) | ||
| # just be safe for now | ||
| return "diffe_dup" | ||
| end | ||
|
|
||
| @assert(hasfieldcount(dt)) | ||
| @assert(isstructtype(dt)) | ||
| passpointer = true | ||
| if passpointer | ||
| ty = "diffe_const" | ||
| for (ft, fn) in zip(fieldtypes(dt), fieldnames(dt)) | ||
| sub = whatType(ft) | ||
| if sub == "diffe_dup" | ||
| ty = "diffe_dup" | ||
| elseif sub == "diffe_out" | ||
| ty = "diffe_dup" | ||
| else | ||
| @assert(sub == "diffe_const") | ||
| end | ||
| end | ||
| return ty | ||
| else | ||
| ty = "diffe_const" | ||
| for (ft, fn) in zip(fieldtypes(dt), fieldnames(dt)) | ||
| sub = whatType(ft) | ||
| if sub == "diffe_dup" | ||
| ty = "diffe_dup" | ||
| elseif sub == "diffe_out" | ||
| if ty != "diffe_dup" | ||
| ty = "diffe_out" | ||
| end | ||
| else | ||
| @assert(sub == "diffe_const") | ||
| end | ||
| end | ||
| return ty | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.