Summary: | dev-python/pyopencl: enable FEATURES=test using dev-libs/pocl to run OpenCL code | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Chris Kerr <chris.kerr> |
Component: | Current packages | Assignee: | Marek Szuba (RETIRED) <marecki> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | CC: | chris.kerr, sam |
Priority: | Normal | Keywords: | PATCH |
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Bug Depends on: | 861113 | ||
Bug Blocks: | |||
Attachments: |
Patch to pyopencl ebuild
Patch to pyopencl ebuild Patch to pyopencl ebuild Patch with signoff line Patch with merge conflicts resolved |
Description
Chris Kerr
2022-07-26 14:57:22 UTC
If multiple OpenCL implementations are present, we probably want to ensure that it runs the tests using pocl and doesn't try to access any GPUs. The environment variable PYOPENCL_CTX can be used for this, but its format is "{platform number}:{device number}" so we need to query the numbers. Here is a snippet of Python that will do that: import sys import pyopencl for i, platform in enumerate(pyopencl.get_platforms()): if platform.name == "Portable Computing Language": for j, device in enumerate(platform.get_devices()): if device.available: print(f"{i}:{j}") sys.exit(0) print("POCL has no available devices", file=sys.stderr) sys.exit(1) print("PyOpenCL could not find POCL platform", file=sys.stderr) sys.exit(1) The src_test function needs to run that snippet in an environment where python can import the pyopencl module from the build directory - I'm not sure how to do this. The stdout should be assigned to the PYOPENCL_CTX environment variable and this environment variable should be passed to the pytest command that actually runs the tests. Looking at the CI jobs in the PyOpenCL source, I found a better alternative: there is also a PYOPENCL_TEST environment variable which allows specifying devices by name. So instead of setting the PYOPENCL_CTX environment variable we should set: PYOPENCL_TEST="portable:pthread" Created attachment 794636 [details, diff]
Patch to pyopencl ebuild
Partial implementation. Using this patch, the test fails because it cannot import the compiled `pyopencl._cl` module. Probably I need to add some command to ensure that python can import compiled modules from the build directory, but I am not sure how to do this.
Created attachment 794639 [details, diff]
Patch to pyopencl ebuild
I found the solution by looking at the pyopencl CI scripts: change to the 'test' subdirectory before running pytest, so that it does not try to import the module from the current directory.
If there is a reliable way of getting the --jobs count from $MAKEOPTS or similar, then we could also pass this in the POCL_MAX_PTHREAD_COUNT environment variable to limit the number of threads used by the pocl library for running the tests. (In reply to Chris Kerr from comment #6) > If there is a reliable way of getting the --jobs count from $MAKEOPTS or > similar, then we could also pass this in the POCL_MAX_PTHREAD_COUNT > environment variable to limit the number of threads used by the pocl library > for running the tests. multiprocessing.eclass will help. Created attachment 794855 [details, diff]
Patch to pyopencl ebuild
Use multiprocessing.eclass to set the pocl thread count based on MAKEOPTS.
For future reference, when proposing updates to ebuilds like I am here, is it better to send a patch against the existing ebuild or to upload the complete .ebuild file? Apart from the fact pushd and popd calls need a || die guard, which I'll add myself, LGTM. Thank you! Will test this shortly. ...and I've spoken too soon. I am afraid I have to ask you to add a sign-off line to this patch before we can merge it. Created attachment 795862 [details, diff] Patch with signoff line I read the copyright policy at https://www.gentoo.org/glep/glep-0076.html#certificate-of-origin and added a git Signed-Off-By line. Created attachment 796012 [details, diff]
Patch with merge conflicts resolved
I rebased against master and fixed a merge conflict.
Do you need anything more from me? The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5e3534894ed3ab98d7a6782977228b72daebdf53 commit 5e3534894ed3ab98d7a6782977228b72daebdf53 Author: Christopher Kerr <chris.kerr@mykolab.ch> AuthorDate: 2022-07-31 09:30:13 +0000 Commit: Marek Szuba <marecki@gentoo.org> CommitDate: 2022-08-21 01:16:41 +0000 dev-python/pyopencl: Enable FEATURES=test using dev-libs/pocl as OpenCL implementation Use multiprocessing eclass to set thread count based on MAKEOPTS Closes: https://bugs.gentoo.org/861251 Signed-off-by: Christopher Kerr <chris.kerr@mykolab.ch> Signed-off-by: Marek Szuba <marecki@gentoo.org> dev-python/pyopencl/pyopencl-2022.1.6.ebuild | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) |