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

impureUseNativeOptimizations: add stdenv adapter #37600

Merged
merged 1 commit into from Oct 13, 2018

Conversation

abbradar
Copy link
Member

@abbradar abbradar commented Mar 21, 2018

Motivation for this change

This allows one to force a compiler to use native machine optimizations. This
goes contrary to all the usual guarantees of Nix and so should be used only by
end-user and only in specific cases when they know what are they doing.

In my case this is needed to get a noticeable FPS boost in RPCS3 which is a very
CPU-hungry PlayStation 3 emulator.

I'm torn on whether to have this in upstream nixpkgs, hence PR.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@dtzWill
Copy link
Member

dtzWill commented Mar 22, 2018

Just wondering--do you need to build all dependencies this way too? If not, a trick I've used in the past is to build a variants with different architecture assumptions (supported vector instructions, etc.). Not always possible and possibly more of a hassle but it does retain Nix purity :).

@abbradar
Copy link
Member Author

@dtzWill No, I don't -- all the hotpath is in the emulator. I'm not sure how much of that optimization comes from specific instructions and how much from -mtune (usage of specific opcodes vs others etc.) -- it's an interesting question (but I don't have motivation to check this now, maybe later).

Copy link
Member

@lukateras lukateras left a comment

Choose a reason for hiding this comment

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

This is clearly useful.

NIX_CFLAGS_COMPILE = toString (args.NIX_CFLAGS_COMPILE or "") + " -march=native";
NIX_ENFORCE_NO_NATIVE = false;
});
};
Copy link
Member

Choose a reason for hiding this comment

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

preferLocalBuild = true; seems to be appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, fixed!

This allows one to force a compiler to use native machine optimizations. This
goes contrary to all the usual guarantees of Nix and so should be used only by
end-user and only in specific cases when they know what are they doing.

In my case this is needed to get a noticeable FPS boost in RPCS3 which is very
CPU-hungry PlayStation 3 emulator.
@soredake
Copy link

ping

@lukateras
Copy link
Member

I'd like to merge this in the following few days unless anyone minds.

@lukateras lukateras self-assigned this May 26, 2018
@lukateras lukateras merged commit cd0c873 into NixOS:master Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants