kompute icon indicating copy to clipboard operation
kompute copied to clipboard

Kompute Reinterprets `push_consts` int32 NumPy Array as float array

Open filip-sakel opened this issue 7 months ago • 1 comments

I have the following push consts:

constants: np.ndarray = np.array([
    image.shape[1],  # image_width
    image.shape[0],  # image_height
    1,               # image_depth (since we are using a single 2D slice
    
    window_half_size,
    2 * window_half_size + 1, # window_dim
    (2 * window_half_size + 1) ** 2 // 2, # vector_count

    padded_image.shape[1], # padded_image_width
    padded_image.shape[0], # padded_image_height
], dtype=np.int32)
print("constants", constants)

# Create the algorithm
algo = mgr.algorithm(
    tensors=tensors,
    spirv=spirv_shader,
    workgroup=[1, 1, 1],
    push_consts=constants,
)

And then my GLSL accepts:

// === Push Constants ===
layout(std430, push_constant) uniform PushConsts {
    int image_width;
    int image_height;
    int image_depth;

    int window_half_size;
    int window_dim;
    int vector_count;

    int padded_image_width;
    int padded_image_height;
} pc;

This type-checks and Kompute doesn't warn me about the NumPy array's dtype being int32. However, when I run my compute shader, the array elements seem to be reinterpreted as floats. E.g. passing in the constant image_width==1 (as an int), is then interpreted as pc.image_width==1065353216 (i.e. the float representation of my int).

filip-sakel avatar Jun 23 '25 09:06 filip-sakel

There was a bug in the push/spec consts fixed via https://github.com/KomputeProject/kompute/pull/430 - could you try again?

axsaucedo avatar Jul 12 '25 10:07 axsaucedo