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
mesa: restore OpenCL support. #82729
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone can tell me how to best test this, I'll give it a go!
Edit: Also cmd+enter triggering the "approve" button is not the wisest choice, github
@athas As you said, this should be behind a guard like I would suggest to create a package
If you build mesa from you nixpkgs checkout, you can install it in you system by using the (internal) To test wheter the openCL driver can be loaded you can use |
I had trouble using a For the same reason, it's also a little tricky to debug, since the ICD loader only seems to pick up stuff in |
Thanks for the tips, @rnhmjoj! This works for me with a 5700XT: {
hardware.opengl = let
opencl_pr = import (builtins.fetchTarball {
name = "opencl_pr";
url = "https://github.com/athas/nixpkgs/archive/f92a2a9b69eba9909d25ffaab6ded4d6f0f4efad.tar.gz";
}) { };
in {
enable = true;
driSupport32Bit = true;
package = opencl_pr.mesa.drivers;
extraPackages = [ opencl_pr.mesa ];
};
}
=== CL_PROGRAM_BUILD_LOG ===
fatal error: cannot open file '/nix/store/l81x3yfwahahhxmfk4wbg2ki025v451p-libclc-2019-06-09/lib/clc/gfx1010-amdgcn-mesa-mesa3d.bc': No such file or directory
Preferred work group size multiple <getWGsizes:1200: create kernel : error -46> Not sure if I should worry about that. |
I think the |
Oh, apparently Mesa OpenCL doesn't support Navi cards at all... |
Oh, that's too bad! This is what clinfo tell me now, but I don't really have a clue what everything means. $ clinfo
Number of platforms 1
Platform Name Clover
Platform Vendor Mesa
Platform Version OpenCL 1.1 Mesa 19.3.3
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd
Platform Extensions function suffix MESA
Platform Name Clover
Number of devices 1
Device Name AMD NAVI10 (DRM 3.36.0, 5.5.9, LLVM 9.0.1)
Device Vendor AMD
Device Vendor ID 0x1002
Device Version OpenCL 1.1 Mesa 19.3.3
Driver Version 19.3.3
Device OpenCL C Version OpenCL C 1.1
Device Type GPU
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Max compute units 40
Max clock frequency 2100MHz
Max work item dimensions 3
Max work item sizes 256x256x256
Max work group size 256
=== CL_PROGRAM_BUILD_LOG ===
fatal error: cannot open file '/nix/store/l81x3yfwahahhxmfk4wbg2ki025v451p-libclc-2019-06-09/lib/clc/gfx1010-amdgcn-mesa-mesa3d.bc': No such file or directory
Preferred work group size multiple <getWGsizes:1200: create kernel : error -46>
Preferred / native vector sizes
char 16 / 16
short 8 / 8
int 4 / 4
long 2 / 2
half 8 / 8 (cl_khr_fp16)
float 4 / 4
double 2 / 2 (cl_khr_fp64)
Half-precision Floating-point support (cl_khr_fp16)
Denormals No
Infinity and NANs Yes
Round to nearest Yes
Round to zero No
Round to infinity No
IEEE754-2008 fused multiply-add No
Support is emulated in software No
Single-precision Floating-point support (core)
Denormals No
Infinity and NANs Yes
Round to nearest Yes
Round to zero No
Round to infinity No
IEEE754-2008 fused multiply-add No
Support is emulated in software No
Correctly-rounded divide and sqrt operations No
Double-precision Floating-point support (cl_khr_fp64)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Address bits 64, Little-Endian
Global memory size 8589934592 (8GiB)
Error Correction support No
Max memory allocation 6871947673 (6.4GiB)
Unified memory for Host and Device No
Minimum alignment for any data type 128 bytes
Alignment of base address 32768 bits (4096 bytes)
Global Memory cache type None
Image support No
Local memory type Local
Local memory size 32768 (32KiB)
Max number of constant args 16
Max constant buffer size 2147483647 (2GiB)
Max size of kernel argument 1024
Queue properties
Out-of-order execution No
Profiling Yes
Profiling timer resolution 0ns
Execution capabilities
Run OpenCL kernels Yes
Run native kernels No
Device Extensions cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp64 cl_khr_fp16
NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) Clover
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) Success [MESA]
clCreateContext(NULL, ...) [default] Success [MESA]
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) Success (1)
Platform Name Clover
Device Name AMD NAVI10 (DRM 3.36.0, 5.5.9, LLVM 9.0.1)
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) Success (1)
Platform Name Clover
Device Name AMD NAVI10 (DRM 3.36.0, 5.5.9, LLVM 9.0.1)
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) Success (1)
Platform Name Clover
Device Name AMD NAVI10 (DRM 3.36.0, 5.5.9, LLVM 9.0.1)
ICD loader properties
ICD loader Name OpenCL ICD Loader
ICD loader Vendor OCL Icd free software
ICD loader Version 2.2.10
ICD loader Profile OpenCL 2.1 |
I think that means that all the infrastructure works. The OpenCL ICD loader can find the Mesa ICD and talk to the hardware. It just can't compile any kernels, because some GPU-specific library files are missing. Here is a small OpenCL test program that compiles and launches a kernel. Compile with
and then run with
I don't expect it'll work on your machine. It also doesn't work on my Vega 64, as the kernel launch hangs forever. That's an improvement, though: Mesa OpenCL used to reboot my computer, even on non-NixOS distributions. The general buggyness of Mesa OpenCL is going to be an obstacle to testing this... |
That looks good. In case the driver is not found you would simply get:
|
@athas yep, doesn't start, "fatal error: cannot open file '/nix/store/l81x3yfwahahhxmfk4wbg2ki025v451p-libclc-2019-06-09/lib/clc/gfx1010-amdgcn-mesa-mesa3d.bc': No such file or directory". |
I added the code from #82729 (comment) to my
Even BOINC detects the GPU now: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works, changes looks OK as far as i can judge
@vcunat can you take a look at this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good but openCL support should be optional to avoid a large closure size increase.
For convenience, a mesa-opencl
package could be added so that users don't have to rebuild mesa.
I tried it, but blender doesn't report my videocard (540X) as a usable device. Is that normal? |
@cab404 i also don't see my AMD Radeon RX 480 as supported. so might be blender specific |
@athas May you rebase this please? |
I'll try over the weekend, but I won't have the spare life cycles to actually test it. |
Cool @athas. https://github.com/mohe2015/nixpkgs/tree/mesa-opencl may or may not be a correct rebase (nonsquashed, only the first three commits as I did some further tests). Feel free to use it (without me as an author is fine as it's just a rebase) I'm building now but it seems like it's almost a full rebuild... |
Can you please fix the merge conflict and target staging with the mass rebuild? |
I also added the code from the comment to my |
I have rebased on top of master. Haven't tried running it, but by inspection of the files, it looks OK. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/openvx-opencl-setup-for-amd-cpu-and-gpu/10383/1 |
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Please target staging and squash the commits. |
I also used the workaround above, but it doesn't work now. Unfortunately, rocm does not work on many platforms, as it requires hardware support for the processor. |
fi | ||
|
||
# We construct our own .icd file that contains an absolute path. | ||
rm -rf $out/etc/OpenCL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm -rf $out/etc/OpenCL | |
rm -r $out/etc/OpenCL |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-get-opecl-working-on-amdgpu/11786/2 |
I also used this workaround, since may last year and noticed now that it does not work anymore. I don't see any OpenCL device:
Maybe this needs an update? |
Could we merge it under |
I rebased the PR (and the included patch against mesa) onto the latest master and added a switch for making OpenCL support optional (as @rnhmjoj suggested): https://github.com/sbruder/nixpkgs/commits/mesa-opencl and tested the PR cherry-picked onto 21.05 with the following config: { pkgs, ... }:
{
hardware.opengl =
let
pkgsMesaClover = import
(pkgs.fetchFromGitHub {
owner = "sbruder";
repo = "nixpkgs";
rev = "41d33334ec2d07da8f5bd0f3749949241c42266b";
sha256 = "sha256-sA/kwZ8kXuRC/sLjja2ISpyTnlEwZjifyYeiz9hFWRE=";
})
{ inherit (pkgs) system; };
in
{
package = pkgsMesaClover.mesa-opencl.drivers;
extraPackages = [
pkgsMesaClover.mesa-opencl
];
};
} After a rebuild Some programs that work include @athas’ rot13 example, hashcat (with Besides that, some programs that do work show warnings like this, which probably are not problematic, but seems like it’s not fully working yet:
|
@sbruder can you make a new pull request (against staging) with your patch? |
Motivation for this change
This is a first shot at addressing #62933. In practice, OpenCL support should probably be hidden behind an option, because it takes up a significant chunk of space (requires a full LLVM at run-time).
Currently I put all the OpenCL stuff in the
drivers
output, because at leastmesa.icd
needs to be available via/run/opengl-driver
.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)