Skip to content
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

Use function type in fspec instead of value #320

Merged
merged 12 commits into from
Apr 27, 2022
Merged

Conversation

wsmoses
Copy link
Contributor

@wsmoses wsmoses commented Apr 18, 2022

This is necessary to precompile function closures from the type alone, whose value may not be available yet.

Specifically, for use within Enzyme.

cc @vchuravy

Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like this to be as least invasive as possible.
So if we can auto-upgrade the user instead of requiring the interface to change
that would be much better.

wsmoses and others added 2 commits April 19, 2022 01:03
@maleadt
Copy link
Member

maleadt commented Apr 25, 2022

LGTM, but as I commented inline I'd prefer if we try to create nicer functions that accept function types instead of instances, and them try to upstream those.

@wsmoses
Copy link
Contributor Author

wsmoses commented Apr 25, 2022

LGTM, but as I commented inline I'd prefer if we try to create nicer functions that accept function types instead of instances, and them try to upstream those.

I concur, though since I presume we can't backport that all the way to 1.6 (Enzyme.jl's minimum test), I presume we'd need it here at minimum (in addition to upstream in later versions)?

@vchuravy
Copy link
Member

Yes normally we add compatibility shims for older Julia versions and then use the new APIs on new Julia versions.

@vchuravy vchuravy merged commit 3a73ef5 into JuliaGPU:master Apr 27, 2022
Copy link
Member

@maleadt maleadt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I never submitted my review...

else
rt = Base.return_types(job.source.f, job.source.tt, interp)[1]

for m in Base._methods_by_ftype(tt, -1, job.source.world)::Vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -2,26 +2,36 @@

export InvalidIRError

function get_method_matches(@nospecialize(job::CompilerJob))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the kind of definition we want to upstream, generalizing Base.methods to work with function types, wouldn't it be better to name it like that and pass a signature type instead of a CompilerJob?

rt = Base.return_types(job.source.f, job.source.tt, interp)[1]
end
m = only(ms)
ty = Core.Compiler.typeinf_type(interp, m.method, m.spec_types, m.sparams)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, maybe it's better to use a local version of return_types that accepts function types and work on upstreaming that.

@@ -47,6 +47,11 @@ end
code_lowered(@nospecialize(job::CompilerJob); kwargs...) =
InteractiveUtils.code_lowered(job.source.f, job.source.tt; kwargs...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code_lowered(::CompilerJob) uses job.source.f and is now broken.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code_warntype below is also not adapted.

@@ -83,11 +83,10 @@ end
kernel() = return

ir = sprint(io->ptx_code_llvm(io, kernel, Tuple{}))
@test occursin(r"@.*kernel.+\(\)", ir)
@test any(occursin(r"@.*kernel.+\(\)", a) for a in split(ir, "\n"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these changes required?

@maleadt
Copy link
Member

maleadt commented Apr 28, 2022

Actually testing this with a GPU back-end revealed issues; I've commented on a couple, but there's other unadjusted uses of job.source.f (e.g. the MethodError in cache.jl which will now report the wrong function, the use of Cthulhu, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants