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

Difference in behavior between PYOPENCL_CTX and PYOPENCL_TEST #781

Open
matthiasdiener opened this issue Aug 26, 2024 · 1 comment
Open
Labels

Comments

@matthiasdiener
Copy link
Contributor

matthiasdiener commented Aug 26, 2024

Describe the bug
Parsing of PYOPENCL_CTX and PYOPENCL_TEST is implemented differently, leading to a different selection behavior. An example is given below. #780 is another example.

To Reproduce

$ clinfo -l
Platform #0: AMD Accelerated Parallel Processing
 `-- Device #0: gfx90a:sramecc+:xnack-

$ PYOPENCL_TEST=AMD:90 python -c "import pyopencl; pyopencl.choose_devices()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/p/lustre1/diener3/Work/enew/pyopencl/pyopencl/__init__.py", line 1561, in choose_devices
    for _plat, devs in get_test_platforms_and_devices():
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/p/lustre1/diener3/Work/enew/pyopencl/pyopencl/tools.py", line 646, in get_test_platforms_and_devices
    [find_cl_obj(devs, dev_id)
  File "/p/lustre1/diener3/Work/enew/pyopencl/pyopencl/tools.py", line 646, in <listcomp>
    [find_cl_obj(devs, dev_id)
     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/p/lustre1/diener3/Work/enew/pyopencl/pyopencl/tools.py", line 618, in find_cl_obj
    return objs[num]
           ~~~~^^^^^
IndexError: list index out of range

$ PYOPENCL_CTX=AMD:90 python -c "import pyopencl; pyopencl.choose_devices()"
$ # works fine

Expected behavior
Having the same selection logic may be beneficial.

Environment (please complete the following information):

  • OS: [e.g. Linux] Any
  • ICD Loader and version: [e.g. ocl-icd 2.3.1] ocl-icd 2.3.2
  • ICD and version: [e.g. pocl 1.8] Any
  • CPU/GPU: [e.g. Nvidia Titan V] Any
  • Python version: [e.g. 3.10] 3.11
  • PyOpenCL version: [e.g. 2021.1] 2024.2.7

Additional context
Add any other context about the problem here.

@alexfikl
Copy link
Contributor

The issue seems to be that the access to that objs array isn't guarded here:

return objs[num]

and the integer "90" in the "AMD:90" string matches that branch. The same-ish code in "choose_devices" is nicely guarded:

pyopencl/pyopencl/__init__.py

Lines 1640 to 1641 in 846fede

if 0 <= int_choice < len(devices):
return devices[int_choice]

Would probably be nice to unify that parsing 😁

@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants
@alexfikl @matthiasdiener and others