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

Add intel-compute-runtime / Intel NEO driver stack #63705

Merged
merged 5 commits into from Sep 27, 2019
Merged

Conversation

gloaming
Copy link
Contributor

@gloaming gloaming commented Jun 23, 2019

Motivation for this change

Add intel-compute-runtime aka NEO, Intel's new open-source OpenCL GPGPU driver, which replaces Beignet for newer Intel processors.

TO INSTALL

hardware.opengl.extraPackages = with pkgs; [ intel-compute-runtime ];

Note that this driver may be installed in parallel with intel-ocl. The latter provides an OpenCL device for the CPU, not the iGPU; relative performance may differ depending on workload.

TODO:

  • Update to later versions as much as possible
  • Finalise changes to cc-wrapper.sh and push them into build-support on staging
  • Find a way to automatically make gmmlib and IGC available to the driver instead of requiring the user to add them to opengl.extraPackages
  • Assess if there is a saner way to package opencl-clang and its patches
  • Push .cmake patches upstream?
  • Prepare for opencl-clang_8 etc.
  • Would it make sense to put this under llvmPackages?
  • Check and fix tests where possible

NOTES

  • The SPIRV-LLVM-Translator and OpenCL Clang projects have seperate branches and releases depending on LLVM version; I targeted LLVM 7 as that's what we have in release now. On my system I am running these patches rebased onto release-19.03 and it appears to be working well.
  • Built largely as per instructions here: https://github.com/JacekDanecki/compute-runtime/wiki/How-to-build-Neo-components-(system-llvm-clang-7)
  • cc-wrapper.sh has to be modified as the extra options it passes cause Clang to barf with errors about unrecognised flags when attempting to compile with -cc1
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option 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 nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

cc @volth @OpenSourceAnarchist

@gloaming gloaming changed the title [WIP] Intel NEO driver stack [WIP] Add intel-compute-runtime / Intel NEO driver stack Jul 1, 2019
@gloaming
Copy link
Contributor Author

gloaming commented Jul 1, 2019

Marking for review as I think it's nearly ready and it would be good to have feedback.
Also, I'm not sure how to fix the opengl.extraPackages issue.

@gloaming
Copy link
Contributor Author

Now updated to latest release versions targeting LLVM 8.

Tested on unstable (b5f5c97), but something seems to have changed with the openGL rpath handling; before, I thought I had /run/opengl-driver in LD_LIBRARY_PATH, but now my LD_LIBRARY_PATH is empty.

How do we sort this out? Any OpenCL program which loads Neo will need to access the libraries from intel-gmmlib and intel-graphics-compiler. Do we need to use addOpenGLRunpath on every OpenCL client executable? I hope not. Ping @abbradar @ambrop72

@gloaming
Copy link
Contributor Author

I would love to get some traction on this.
@volth @dtzWill @Ericson2314 @worldofpeace
Would anyone volunteer to review or take ownership of this PR?

@ambrop72
Copy link
Contributor

@gloaming Yes we got rid of LD_LIBRARY_PATH. If an application needs to load vendor-specific libraries from there (as opposed to using standard APIs like OpenGL, Vulkan, OpenCL), it needs to use addOpenGLRunpath. Any application that dlopens some library needs suitable RUNPATH (or a wrapper setting LD_LIBRARY_PATH), and these driver libraries should not be special.

@ambrop72
Copy link
Contributor

@gloaming Just to be clear, standard OpenCL programs that don't themselves depend on Intel libraries should be able to work with any OpenCL runtime including this one. If this is not the case, something is wrong and needs to be addressed. I'm not familiar with the details but I'll try to give it a test.

@gloaming
Copy link
Contributor Author

@ambrop72 Thanks for explaining! Yes, the problem is that the intel runtime itself (libigdrcl.so) dlopens the other Intel libraries. I did try using addOpenGLRunpath $out/lib/* before.. But I didn't realise there was another folder inside lib! addOpenGLRunpath $out/lib/intel-opencl/libigdrcl.so did the job.

However, I think it would be better to add just the Intel libraries to libigdrcl.so's RUNPATH rather than use addOpenGLRunpath. It's cleaner, and avoids the impurity of /run/opengl-driver. Do you agree?

@Mic92
Copy link
Member

Mic92 commented Jul 29, 2019

However, I think it would be better to add just the Intel libraries to libigdrcl.so's RUNPATH rather than use addOpenGLRunpath. It's cleaner, and avoids the impurity of /run/opengl-driver. Do you agree?

Yes. We only have /run/opengl-driver in order to switch between opengl driver without recompiling. Dependencies within a driver can be resolved straight away without this hack.

@ambrop72
Copy link
Contributor

@ambrop72 Thanks for explaining! Yes, the problem is that the intel runtime itself (libigdrcl.so) dlopens the other Intel libraries. I did try using addOpenGLRunpath $out/lib/* before.. But I didn't realise there was another folder inside lib! addOpenGLRunpath $out/lib/intel-opencl/libigdrcl.so did the job.

However, I think it would be better to add just the Intel libraries to libigdrcl.so's RUNPATH rather than use addOpenGLRunpath. It's cleaner, and avoids the impurity of /run/opengl-driver. Do you agree?

Yes, just add appropriate absolute RUNPATH to the libraries so that they find their internal dependencies. I actually ran into the same problem with the NVidia driver when I was getting rid of the LD_LIBRARY_PATH, it worked only because the internal libraries happened to be found via LD_LIBRARY_PATH.

@gloaming
Copy link
Contributor Author

RUNPATH fixed and tested. Looks good.

@gloaming
Copy link
Contributor Author

https://github.com/NixOS/nixpkgs/blob/675927dbfc9078c502884e7966b4fd55ba89ca41/pkgs/development/libraries/opencl-clang/cc-wrapper.patch#L26-L33

This is a bit of an essay. Would it be better to create an issue and replace it with a short comment and a link?

@gloaming
Copy link
Contributor Author

ping @Mic92 @Ericson2314

@gloaming
Copy link
Contributor Author

gloaming commented Sep 1, 2019

Updated to latest versions, including unstable for opencl-clang so as not to require the patch-fixing mess.

@ofborg ofborg bot requested a review from np September 1, 2019 16:16
@davidtwco
Copy link
Member

I'm really excited to see this in nixpkgs! Is there anything stopping this from getting merged?

@Mic92
Copy link
Member

Mic92 commented Sep 27, 2019

@GrahamcOfBorg eval

@Mic92 Mic92 merged commit c0cba22 into NixOS:staging Sep 27, 2019
@Mic92
Copy link
Member

Mic92 commented Sep 27, 2019

Thanks!

dtzWill pushed a commit to dtzWill/nixpkgs that referenced this pull request Sep 30, 2019
Add intel-compute-runtime / Intel NEO driver stack

(cherry picked from commit c0cba22)
dtzWill added a commit to dtzWill/nixpkgs that referenced this pull request Sep 30, 2019
dtzWill added a commit to dtzWill/nixpkgs that referenced this pull request Oct 2, 2019
@mhhf
Copy link

mhhf commented Oct 12, 2019

Not sure if this is the right place to ask but i'm struggling making opencl work: while this PR successfully finds a opencl platform with opencl-info (output), it fails to do so with clinfo and any other tool depending on opencl:

$ clinfo
Number of platforms                               0

however, strace tells me that it could successfully locate the correct icd and lib:

$ strace clinfo
...
openat(AT_FDCWD, "/run/opengl-driver/etc/OpenCL/vendors/intel-neo.icd", O_RDONLY) = 4
...
openat(AT_FDCWD, "/nix/store/y6ip2sw1g2l796n7hvxr72hf6pcrp9rm-intel-compute-runtime-19.34.13959/lib/intel-opencl/libigdrcl.so", O_RDONLY|O_CLOEXEC) = 4

am i missing something trivial?
@gloaming

@gloaming
Copy link
Contributor Author

@mhhf Sorry for the slow response - I'm not aware of anything obvious. Do you also see openats for libigdrcl.so, libva.so etc? If this is still happening, best to open an issue rather than discuss here.

@mhhf
Copy link

mhhf commented May 29, 2020

In case anyone is having the same issue, the problem was with libstdc++.so.6 not being found by clinfo and other tools. Extending the LD_LIBRARY_PATH in a shell.nix (e.g. LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib64:$LD_LIBRARY_PATH";) solved that issue.

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

6 participants