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

slice activity analysis #2209

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Changes from all 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
35 changes: 35 additions & 0 deletions enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -579,6 +579,11 @@ bool ActivityAnalyzer::isFunctionArgumentConstant(CallInst *CI, Value *val) {
if (Name == "jl_reshape_array" || Name == "ijl_reshape_array")
return val != CI->getArgOperand(1);

// Only the 0-th arg impacts activity
if (Name == "jl_genericmemory_copy_slice" ||
Name == "ijl_genericmemory_copy_slice")
return val != CI->getArgOperand(0);

// Allocations, deallocations, and c++ guards don't impact the activity
// of arguments
if (isAllocationFunction(Name, TLI) || isDeallocationFunction(Name, TLI))
@@ -660,6 +665,13 @@ static inline void propagateArgumentInformation(
return;
}

// Only the 0-th arg impacts activity
if (Name == "jl_genericmemory_copy_slice" ||
Name == "ijl_genericmemory_copy_slice") {
propagateFromOperand(CI.getArgOperand(1));
return;
}

// Only the 1-th arg impacts activity
if (Name == "jl_reshape_array" || Name == "ijl_reshape_array") {
propagateFromOperand(CI.getArgOperand(1));
@@ -1601,6 +1613,29 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
return true;
}

if (funcName == "jl_genericmemory_copy_slice" ||
funcName == "ijl_genericmemory_copy_slice") {
if (directions == UP) {
if (isConstantValue(TR, op->getArgOperand(0))) {
InsertConstantValue(TR, Val);
return true;
}
} else {
if (UpHypothesis->isConstantValue(TR, op->getArgOperand(0))) {
InsertConstantValue(TR, Val);
insertConstantsFrom(TR, *UpHypothesis);
return true;
}
}
if (EnzymeEnableRecursiveHypotheses) {
ReEvaluateValueIfInactiveValue[op->getArgOperand(0)].insert(Val);
if (TmpOrig != Val) {
ReEvaluateValueIfInactiveValue[op->getArgOperand(0)].insert(
TmpOrig);
}
}
}

// If requesting empty unknown functions to be considered inactive,
// abide by those rules
if (called && EnzymeEmptyFnInactive && called->empty() &&