Summary
When building an OpenCL program with PyOpenCL compiler caching enabled, PyOpenCL emits a warning because cache compilation fails internally while trying to append the cache-defeating constant to the source.
The build appears to continue, but compiler caching is disabled for that build.
Environment
- OS: Linux
7.0.0-28-generic x86_64, glibc 2.39
- Python:
3.12.13 from conda-forge
- PyOpenCL:
2026.1.2
- OpenCL platform:
Intel(R) OpenCL Graphics
- OpenCL device:
Intel(R) Iris(R) Xe Graphics
- OpenCL version:
OpenCL 3.0 NEO
- Driver:
24.52.032224
Exception
UserWarning: PyOpenCL compiler caching failed with an exception:
[begin exception]
Traceback (most recent call last):
File ".../site-packages/pyopencl/cache.py", line 514, in create_built_program_from_source_cached
_create_built_program_from_source_cached(
File ".../site-packages/pyopencl/cache.py", line 424, in _create_built_program_from_source_cached
src = src + b"\n\n__constant int pyopencl_defeat_cache_%s = 0;" % (
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'str'
[end exception]
Suspected Cause
In pyopencl/cache.py, the source is encoded to bytes first:
if isinstance(src, str):
src = src.encode()
but then the bytes format string uses %s with uuid4().hex, which is a Python str:
src = src + b"\n\n__constant int pyopencl_defeat_cache_%s = 0;" % (
uuid4().hex)
Expected Behavior
PyOpenCL compiler caching should build and cache the program without emitting a warning.
Actual Behavior
PyOpenCL emits a warning because compiler caching fails with:
TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'str'
Summary
When building an OpenCL program with PyOpenCL compiler caching enabled, PyOpenCL emits a warning because cache compilation fails internally while trying to append the cache-defeating constant to the source.
The build appears to continue, but compiler caching is disabled for that build.
Environment
7.0.0-28-generic x86_64, glibc2.393.12.13from conda-forge2026.1.2Intel(R) OpenCL GraphicsIntel(R) Iris(R) Xe GraphicsOpenCL 3.0 NEO24.52.032224Exception
Suspected Cause
In
pyopencl/cache.py, the source is encoded to bytes first:but then the bytes format string uses
%swithuuid4().hex, which is a Pythonstr:Expected Behavior
PyOpenCL compiler caching should build and cache the program without emitting a warning.
Actual Behavior
PyOpenCL emits a warning because compiler caching fails with: