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

RFC: CodegenHooks for external language implementations #19290

Merged
merged 1 commit into from
Dec 28, 2016

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Nov 10, 2016

Summary: extends the codegen parameters from #19046, adding a hooks struct for users to put callback routines in. If any of the hooks is set, the compiler will call said method instead of emitting code. By using a package like LLVM.jl, those callback routines can then emit code themselves.
See here for example use of this functionality.

Similar to the codegen hooks, this functionality might not be top-notch yet, but I'd prefer to be developing on top of master instead of maintaining my own forks. I'll keep on improving this interface, figuring out exactly which hooks are important, and what the parameters should be (eg. how much of jl_codectx_t should be exposed?). Tests and proper documentation are to follow after that, I don't want to set anything in stone for now.

Except for some patches to LLVM (and a bump to 3.9, see my tb/cuda branch), this is the last required part of functionality for CUDAnative.jl to work on vanilla master.

cc @vchuravy

@maleadt maleadt added the compiler:codegen Generation of LLVM IR and native code label Nov 10, 2016
argv[0] = hook;
for (int i = 0; i < N; i++)
argv[i+1] = args[i];
jl_apply(argv, N+1);
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I don't think we want to be adding calls to the runtime system inside codegen. It should actually be OK, since we aren't going to be adding this the result to the JIT, but we should make sure that the interface enforces that you can't add a function to the JIT that has been generated via a hook.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a check to compile_linfo:

if (params != &jl_default_cgparams /* fast path */ &&
    !compare_cgparams(params, &jl_default_cgparams) && params->cached)
    jl_error("functions compiled with custom codegen params mustn't be cached");

@maleadt maleadt force-pushed the tb/codegen_hooks branch 4 times, most recently from 4bc043f to 9673821 Compare November 15, 2016 16:53
@maleadt maleadt changed the title RFC/WIP: CodegenHooks for external language implementations RFC: CodegenHooks for external language implementations Nov 18, 2016
@maleadt maleadt force-pushed the tb/codegen_hooks branch 2 times, most recently from 2d7bb5a to f3ccae6 Compare December 19, 2016 14:58
@ViralBShah
Copy link
Member

Bump - should we merge this? Would be nice to have CUDANative.jl on master.

@ViralBShah ViralBShah added the gpu Affects running Julia on a GPU label Dec 19, 2016
@maleadt
Copy link
Member Author

maleadt commented Dec 19, 2016

I just started working on this again, needs some love after #19416. I'll finish this up before the end of the week.

@maleadt
Copy link
Member Author

maleadt commented Dec 21, 2016

Should be good to go, unless somebody has some comments / ideas for improvements.
I'm not all too happy with how it turned out, but normal compilation should be totally unaffected and I hope to be able to replace some of these hooks with better APIs in the future.

@tkelman
Copy link
Contributor

tkelman commented Dec 21, 2016

@nanosoldier runbenchmarks(ALL, vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 21, 2016

lgtm. I would like to merge on top of #17057 though, since there's going to be a trivial conflict with the module_activation hook.

@vchuravy
Copy link
Member

The error on i686 looks like a timeout so I restarted the build (backup of the log at https://gist.github.com/vchuravy/adaae760b733b513535fc5e047d31256)

@vchuravy
Copy link
Member

@maleadt @vtjnash ready to merge?

@vchuravy vchuravy added this to the 0.6.0 milestone Dec 28, 2016
@maleadt
Copy link
Member Author

maleadt commented Dec 28, 2016

Yeah should be good to go. Let me do a final rebase + CI, and merge if that turns out good.

@maleadt maleadt merged commit 546bfa3 into master Dec 28, 2016
@vchuravy vchuravy deleted the tb/codegen_hooks branch December 28, 2016 16:11
@vchuravy
Copy link
Member

Yeah! 🎆 🍾

@ViralBShah
Copy link
Member

Epic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code gpu Affects running Julia on a GPU
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants