-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
python3Packages.gpuctypes: init at unstable-2023-11-26 #278187
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { lib | ||
| , buildPythonPackage | ||
| , fetchFromGitHub | ||
| , rocmPackages | ||
| , ocl-icd | ||
| }: | ||
| buildPythonPackage { | ||
| pname = "gpuctypes"; | ||
| version = "unstable-2023-11-26"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we adopt 0.2.0? |
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did ^ and I also needed to include nativeBuildInputs = [ setuptools ];
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @natsukium There is no
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said before, please read the document first. |
||
| src = fetchFromGitHub { | ||
| repo = "gpuctypes"; | ||
| owner = "tinygrad"; | ||
| rev = "3d402bb3bd5536aeb09c55da02277c339b4af089"; | ||
| hash = "sha256-bYSjCrVO6Bd/oGCLLp5AcPEe6fFUdnJwxCzRWK54AG8="; | ||
| }; | ||
|
|
||
| postPatch = '' | ||
| # patch correct path to opencl | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment seems redundant since this is a common operation. |
||
| substituteInPlace gpuctypes/opencl.py --replace "ctypes.util.find_library('OpenCL')" "'${ocl-icd}/lib/libOpenCL.so'" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We can use |
||
|
|
||
| # patch correct path to hip | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| substituteInPlace gpuctypes/hip.py --replace "/opt/rocm/lib/libamdhip64.so" "${rocmPackages.clr}/lib/libamdhip64.so" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we wrap these in a rocmSupport check to avoid having to build rocm? (lib.optionalString rocmSupport ''
substituteInPlace gpuctypes/hip.py --replace "/opt/rocm/lib/libamdhip64.so" "${rocmPackages.clr}/lib/libamdhip64.so"
substituteInPlace gpuctypes/hip.py --replace "/opt/rocm/lib/libhiprtc.so" "${rocmPackages.clr}/lib/libhiprtc.so"
'') + |
||
| substituteInPlace gpuctypes/hip.py --replace "/opt/rocm/lib/libhiprtc.so" "${rocmPackages.clr}/lib/libhiprtc.so" | ||
MatthewCroughan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ''; | ||
|
|
||
| pythonImportsCheck = [ "gpuctypes" ]; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we enable these tests with |
||
| meta = with lib; { | ||
| description = "Ctypes wrappers for HIP, CUDA, and OpenCL"; | ||
| homepage = "https://github.com/tinygrad/gpuctypes"; | ||
| license = licenses.mit; | ||
| maintainers = with maintainers; [ matthewcroughan wozeparrot ]; | ||
| }; | ||
|
|
||
| } | ||
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.
Can I bother you with adding optional cuda support? 🙃
I think you could just patch into https://github.com/tinygrad/gpuctypes/blob/77b94adaf8e27fa5ef7caa0bdd949bd528576d4b/gpuctypes/cuda.py#L146-L148
_libraries["libnvrtc.so"] = "${cudaPackages.cuda_nvrtc}/lib/libnvrtc.so"and
libcuda.sois"${addDriverRunpath.driverLink}/lib/libcuda.so"but you need to first test if itos.path.existsin case we're not running under NixOSUh oh!
There was an error while loading. Please reload this page.
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.
Also would be nice to display a nixpkgs-specific warning about
cudaSupportin thecudaSupport = falsebranch, because people might expect gpuctypes to just work but since they rely on the broken-by-design ctypes andfind_librarythey can'tThere 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.
I'd keep the
CDLLbit but make itif "libnvrtc.so" not in ...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.
Damn I'm not even sure what to suggest upstream. The thing is,
CDLL("libcuda.so")is much less broken thanCDLL(find_library("libcuda.so"))Uh oh!
There was an error while loading. Please reload this page.
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.
Adding this to a hacked up nixified version of tinygrad allows me to run on my gpu
I haven't tested it too hard, but the following works as expected
CUDA=1 DEBUG=4 python3 -c "import tinygrad; print(tinygrad.Tensor([1,3,-5]).dot(tinygrad.Tensor([4,-2,-1])).realize().numpy())"