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

Fix auto-diff synthesized method naming conventions #4714

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions source/slang/slang-ir-autodiff-transcriber-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,20 @@ IRInst* getActualInstToTranscribe(IRInst* inst)
return inst;
}

void handleNameHint(IRBuilder* builder, IRInst* primal, IRInst* diff)
{
// Ignore types that already have a name hint.
if (as<IRType>(diff) && diff->findDecoration<IRNameHintDecoration>())
return;

if (auto nameHint = primal->findDecoration<IRNameHintDecoration>())
{
StringBuilder sb;
sb << "s_diff_" << nameHint->getName();
builder->addNameHintDecoration(diff, sb.getUnownedSlice());
}
}

IRInst* AutoDiffTranscriberBase::transcribe(IRBuilder* builder, IRInst* origInst)
{
// If a differential instruction is already mapped for
Expand Down Expand Up @@ -1124,12 +1138,7 @@ IRInst* AutoDiffTranscriberBase::transcribe(IRBuilder* builder, IRInst* origInst
break;
default:
// Generate name hint for the inst.
if (auto primalNameHint = primalInst->findDecoration<IRNameHintDecoration>())
{
StringBuilder sb;
sb << "s_diff_" << primalNameHint->getName();
builder->addNameHintDecoration(pair.differential, sb.getUnownedSlice());
}
handleNameHint(builder, pair.primal, pair.differential);

// Automatically tag the primal and differential results
// if they haven't already been handled by the
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ir-autodiff-unzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ IRFunc* DiffUnzipPass::extractPrimalFunc(
}
if (auto originalNameHint = originalFunc->findDecoration<IRNameHintDecoration>())
{
auto primalName = String("s_bwd_primal_") + UnownedStringSlice(originalNameHint->getName());
auto primalName = String("s_primal_ctx_") + UnownedStringSlice(originalNameHint->getName());
builder.addNameHintDecoration(primalFunc, builder.getStringValue(primalName.getUnownedSlice()));
}

Expand Down
Loading