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

DCE eliminates empty functions even if they have user-defined derivatives #5755

Open
saipraveenb25 opened this issue Dec 4, 2024 · 3 comments · May be fixed by #6272
Open

DCE eliminates empty functions even if they have user-defined derivatives #5755

saipraveenb25 opened this issue Dec 4, 2024 · 3 comments · May be fixed by #6272
Assignees
Labels
goal:client support Feature or fix needed for a current slang user.

Comments

@saipraveenb25
Copy link
Collaborator

saipraveenb25 commented Dec 4, 2024

Test-case to reproduce this behavior

//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

void foo_bwd(float a, inout DifferentialPair<float> dpx)
{
    outputBuffer[2] = 2.f;
}

[Differentiable, BackwardDerivative(foo_bwd)]
void foo(no_diff float a, float x)
{ }

[Differentiable]
float outerFunc(no_diff float a, float x)
{
    foo(a, x);
    return 1.f;
}

[numthreads(1, 1, 1)]
[shader("compute")]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    float a = 10.0;
    DifferentialPair<float> dpx = DifferentialPair<float>(4.f, 1.f);
    bwd_diff(outerFunc)(a, dpx, 1.0);
    
    // Expect 2.0 in outputBuffer[2]
}
@bmillsNV bmillsNV added the goal:client support Feature or fix needed for a current slang user. label Dec 4, 2024
@kaizhangNV
Copy link
Contributor

I think DCE might not be the only problem, I found out that we might generate wrong code for the output write instruction in the bwd functions. Please just take a notice about that.

@bmillsNV
Copy link
Collaborator

bmillsNV commented Feb 3, 2025

@saipraveenb25 sounds like Tony needs some help from you on this. Can you help?

@saipraveenb25
Copy link
Collaborator Author

This test actually doesn't reproduce this behavior..

Turns out our tests are run with -g on, which inserts DebugVar insts for debugging and when these are around, a lot of functions are not DCE'd.

To reproduce the result, you should run the test with the top line replaced with:
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -g0

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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants