Skip to content

module.entry_point() raises on generic compute shader with generic parameters #788

@cek-nv

Description

@cek-nv

Invoking module.entry_point() on a generic compute shader that takes one or more generic parameters raises a nanobind exception.

Interestingly, accessing module.entry_points prior to calling entry_point() works around the issue, even though doing so raises itself.

Repro shader and script:

// Generic entry point with generic struct parameter

struct MyData<int N>
{
    float value;
}

[shader("compute")]
[numthreads(8, 1, 1)]
void my_compute<int N>(
    uint3 tid: SV_DispatchThreadID,
    RWStructuredBuffer<MyData<N>> output
)
{
    MyData<N> data;
    data.value = float(tid.x);
    output[tid.x] = data;
}
import slangpy as spy
from pathlib import Path

device = spy.Device(
    compiler_options={
        "include_paths": [spy.SHADER_PATH, Path(__file__).parent.absolute()]
    }
)

print(f"Using device: {device.info.adapter_name}\n")

# Don't use workaround; expect failure
print("1: Call entry_point() directly")
try:
    module = device.load_module('entrypoint.slang')
    entry = module.entry_point("my_compute")
    print("Result: SUCCESS (issue not reproduced)\n")
except Exception as e:
    print(f"Result: FAILED with {e} (issue reproduced)\n")

# Use workaround; expect success
print("2: Call entry_point() after accessing entry_points")
try:
    module = device.load_module('entrypoint.slang')
    try:
        _ = module.entry_points
    except:
        pass
    entry = module.entry_point("my_compute")
    specialized = entry.specialize([spy.SpecializationArg.from_expr("4")])
    program = device.link_program(modules=[module], entry_points=[specialized])
    kernel = device.create_compute_kernel(program)
    print("Result: SUCCESS (workaround succeeded)\n")
except Exception as e:
    print(f"Result: FAILED - {e}\n")

Current output:

Using device: NVIDIA RTX PRO 6000 Blackwell Workstation Edition

1: Call entry_point() directly
Result: FAILED with nanobind::detail::nb_func_error_except(): exception could not be translated! (issue reproduced)

2: Call entry_point() after accessing entry_points
Result: SUCCESS (workaround succeeded)

Metadata

Metadata

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions