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

Choose target ISA in @code_llvm and @code_native #52949

Open
giordano opened this issue Jan 17, 2024 · 12 comments
Open

Choose target ISA in @code_llvm and @code_native #52949

giordano opened this issue Jan 17, 2024 · 12 comments
Labels
feature Indicates new feature / enhancement requests good first issue Indicates a good issue for first-time contributors to Julia

Comments

@giordano
Copy link
Contributor

@vchuravy mentioned on slack that it should be possible to teach @code_llvm and @code_native to generate code for a different ISA (but within same architecture) than the target chosen at startup with -C (native by default), with the only caveat that it'd work only for ISAs that are equal to or smaller than the current one.

A nice use case for this would be to able to choose the target in Compiler Explorer, whose julia backend at the moment only generates code for whatever is the native CPU currently being used.

It'd be nice to have pointers of where one would need to look at, in case they were interested in tackling the issue 🙂

@giordano giordano added the feature Indicates new feature / enhancement requests label Jan 17, 2024
@gbaraldi
Copy link
Member

I'm not even sure that the ISAs need to be smaller, we should never execute this code. In essence one would need to pass the features to the LLVM module we codegen into.

@giordano
Copy link
Contributor Author

Oh, that'd be lovely as we wouldn't depend on the current host, that was a limitation mentioned by @vchuravy on slack.

@vchuravy
Copy link
Sponsor Member

That limitation only applies to -C

@giordano
Copy link
Contributor Author

Ah, I got mixed up about it then!

@vchuravy
Copy link
Sponsor Member

It'd be nice to have pointers of where one would need to look at, in case they were interested in tackling the issue

So code_native/code_llvm use jl_get_llvmf_defn which takes in CodegenParams.

In NewPM PM{jl_ExecutionEngine->cloneTargetMachine(), getOptLevel(jl_options.opt_level)}; we setup a new passmanager based on the global TargetMachine.

getTargetCPU(),

@giordano
Copy link
Contributor Author

Thanks! Just to check if I understood correctly, one strategy to accomplish this is to add a field to jl_cgparams_t and CodegenParams for the target, which by default would represent the current target, but could optionally be a different ISA, and that'd be used in jl_get_llvmf_defn_impl to create a passmanager for the desired target (handling error cases)?

@vchuravy
Copy link
Sponsor Member

Yeah that's what I would try.

@giordano giordano added the good first issue Indicates a good issue for first-time contributors to Julia label Jan 19, 2024
@giordano
Copy link
Contributor Author

giordano commented Jan 19, 2024

Thanks! I added the "good fist issue" label, sounds like a fun task for someone who wants to get started with the compiler 🙂

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 19, 2024

Only for dump_module=true though. With that flag, we can print code for pretty much any combination of compiler options, pipelines, params, CPUs and target architectures. With dump_module=false though, we can strictly only print (dis)assembly for the native machine with all of the vanilla options.

@hackingwave
Copy link

Hey team @gbaraldi @giordano @vtjnash @vtjnash .I am beginner to open source.I want to take this issue .Can you please guide me,may with some doc for above issue.

@gbaraldi
Copy link
Member

So first thing I would do is familiarize myself with the chain from code_llvm to jl_get_llvmf_defn_impl and understand how these functions work, because it's those that you will be modifying

@hackingwave
Copy link

Ohk sure @gbaraldi ,
I will go through code_llvm to jl_get_llvmf_defn_impl to gain a thorough understanding.

Thankyou.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

No branches or pull requests

5 participants