Skip to content

Kompute Reinterprets push_consts int32 NumPy Array as float array #425

@filip-sakel

Description

@filip-sakel

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions