Skip to content

Kernel set_arg does not accept None #897

@nlse2

Description

@nlse2

Describe the bug
The function set_arg called on a kernel does not accept None as an argument even though this is the recommended way to pass a null pointer according to the documentation.

To Reproduce
The following script triggers the problem.

import numpy as np 
import pyopencl as cl 

ctx = cl.create_some_context() 
queue = cl.CommandQueue(ctx) 
mf = cl.mem_flags 

prg = cl.Program(ctx, """ 
__kernel void sum( 
   __global const float *a_g, __global const float *b_g, __global float *res_g) 
{ 
 int gid = get_global_id(0); 
 res_g[gid] = a_g[gid] + b_g[gid]; 
} 
""").build() 

res_g = cl.Buffer(ctx, mf.WRITE_ONLY, 1000) 
knl = prg.sum  # Use this Kernel object for repeated calls 

knl.set_arg(0, res_g) 
knl.set_arg(0, None)

Expected behavior

I expect the code to run without errors but instead I get the following:

Traceback (most recent call last):
File "/root/cl_test.py", line 21, in
knl.set_arg(0, None)

TypeError: set_arg(): incompatible function arguments. The following argument types are supported: 
1. set_arg(self, arg0: int, arg1: object, /) -> None 

Invoked with types: pyopencl._cl.Kernel, int, NoneType

**Environment (please complete the following information):**
- OS: Ubuntu 25.10
- ICD Loader and version: ocl-icd 2.3.3
- ICD and version: pocl 6.0
- CPU/GPU: [e.g. Nvidia Titan V]
- Python version: 3.13.7
- PyOpenCL version: 2026.1.2

**Additional context**
The above script works correctly in pyopencl 2022

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions