-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I have been trying to write a kernel that outputs multiple values, and have noted that many of the return datatypes that work normally (and are currently successfully interpreted in numpy form) do not work when outputting torch tensors.
For example, it is possible to write a slang kernel with an array of vectors as a return type:
[Differentiable]
float2[6] return_vector_array(int coord) {
float2 outputs[6];
for (int i = 0; i < 6; ++i) {
outputs[i] = float2(coord, coord + i);
}
return outputs;
}
f = slang_module.return_vector_array(coord=spy.grid((13,)))
print(f.to_numpy().shape)output: (13, 6, 2)
However, if this same code is invoked with a torch tensor as output, we get the message
ValueError: Exception in kernel generation: Torch tensors do not support data type vector<float,2>[6].
Due to torch interop not supporting user-defined structs, and with it currently being unclear whether it is possible to write to an output tensor with gradient backpropagation (632, 610, 540), this leaves us with few ways to group returned data.
As an additional note, if I directly try to output to numpy by passing _result="numpy", the code above segfaults.
# Segfaults
f = slang_module.return_vector_array(coord=spy.grid((13,)), _result="numpy")