Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointers as parameters to differentiable functions cause compiler to crash #5805

Closed
natevm opened this issue Dec 9, 2024 · 2 comments · Fixed by #5976
Closed

Pointers as parameters to differentiable functions cause compiler to crash #5805

natevm opened this issue Dec 9, 2024 · 2 comments · Fixed by #5976
Assignees
Labels
goal:client support Feature or fix needed for a current slang user. kind:bug something doesn't work like it should

Comments

@natevm
Copy link
Contributor

natevm commented Dec 9, 2024

Here's a little reproducer on Slang playground

It seems that whenever I pass a slang pointer to a differentiable function, the compiler crashes.

This occurs regardless of if I mark that pointer with no_diff or not.

It also occurs regardless independently from whether that pointer is actually touched by the code or not. In the example above, I don't actually read from the pointer, but I still see the issue.

@natevm
Copy link
Contributor Author

natevm commented Dec 9, 2024

In my case, I'm working on migrating away from my variable descriptor array pattern, and towards Slang's buffer pointers.

I have a differentiable slang test, which optimizes the rotation of an oriented bounding box by doing gradient descent on the surface area.

That function looks like this:

[Differentiable] float computeOBB(float3 eul, no_diff float3 a, no_diff float3 b, no_diff float3 c, no_diff gprt::Buffer aabbBuffer, no_diff float3 *aabbsPtr)

I'm migrating away from this gprt::Buffer aabbBuffer type, and towards a direct float3* type.

In Vulkan, I can see that I'm getting the following validation error:

VUID-VkShaderModuleCreateInfo-pCode-08737(ERROR / SPEC): msgNum: -1520283006 - Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-08737 ] | MessageID = 0xa5625282 | vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error):
OpFunctionCall Argument '2133[%2133]'s type does not match Function '313[%313]'s parameter type.
%2140 = OpFunctionCall %float %s_primal_ctx_computeOBB %2139 %2126 %2127 %2128 %2129 %2133 %2137
The Vulkan spec states: If pCode is a pointer to SPIR-V code, pCode must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-08737)

@natevm natevm added the kind:bug something doesn't work like it should label Dec 9, 2024
@natevm natevm assigned natevm and saipraveenb25 and unassigned natevm Dec 9, 2024
@saipraveenb25 saipraveenb25 added the goal:client support Feature or fix needed for a current slang user. label Dec 10, 2024
@csyonghe csyonghe added this to the Q4 2024 (Fall) milestone Dec 11, 2024
@bmillsNV bmillsNV assigned kaizhangNV and unassigned saipraveenb25 Dec 11, 2024
@kaizhangNV
Copy link
Contributor

It looks like the IR code for the fwd_diff is wrong:
this function

float sumOfSquares(float x, float y, no_diff float* test)

generates following IR for fwd_diff:

func %sx5Ffwdx5FsumOfSquares : Func(DiffPairUserCode(Float, %70), DiffPairUserCode(Float, %70), DiffPairUserCode(Float, %70), Attributed(DiffPairUserCode(Float, %70)))

The last parameter should be something like:

Attributed(Ptr(Float, 0 : UInt64), %no_diff)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Feature or fix needed for a current slang user. kind:bug something doesn't work like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants