Skip to content

Conversation

@ZuseZ4
Copy link
Collaborator

@ZuseZ4 ZuseZ4 commented Jul 20, 2022

llvm's copyFunctionInto won't add constantexpr to the vmap, since It can be shared, similar to constantData.

fixes #721

@ZuseZ4 ZuseZ4 requested a review from wsmoses July 20, 2022 19:48
@ZuseZ4
Copy link
Collaborator Author

ZuseZ4 commented Jul 20, 2022

@wsmoses MacOs fails, but not sure what the error should tell me?

@ZuseZ4
Copy link
Collaborator Author

ZuseZ4 commented Jul 20, 2022

I also had an issue on Linux on an earlier commit here: https://github.com/EnzymeAD/Enzyme/runs/7436868577?check_suite_focus=true
Maybe it's just the infrastructure having a bad day?
Can someone working on MacOS test it? I took the run command from the Reverse/constant.ll example, so I see no reason why my new test should fail on macOS.

@tgymnich
Copy link
Member

I was able to reproduce the issue on my machine. I will look into it soon.

@tgymnich
Copy link
Member

tgymnich commented Jul 21, 2022

It seems like the inversionAllocs are marked unreachable and successively deleted (EnzymeLogic.cpp:2235). The crash then happens when we want to access inversionAllocs the next time at EnzymeLogic.cpp:2301. shadowReturnUsed seems to be true on macOS and false on Linux.

@wsmoses
Copy link
Member

wsmoses commented Jul 21, 2022

@ZuseZ4 the solution then is to move the invertpointer calls (

if (shadowReturnUsed) {
) prior to the deletion/move of inversionAllocas

@ZuseZ4
Copy link
Collaborator Author

ZuseZ4 commented Jul 21, 2022

Thanks @tgymnich @wsmoses.

@ZuseZ4 ZuseZ4 enabled auto-merge (squash) July 21, 2022 19:19
@ZuseZ4 ZuseZ4 merged commit 4eb8421 into main Jul 21, 2022
@tgymnich
Copy link
Member

tgymnich commented Jul 28, 2022

@ZuseZ4 Your added test still triggers assertions. They just don't show up in our CI.

    for (auto pair : toVirtual) {
      auto CI = pair.first;
      Constant *fn = dyn_cast<Constant>(CI->getArgOperand(0));
      if (!fn) {
        EmitFailure("IllegalVirtual", CI->getDebugLoc(), CI,
                    "Cannot create virtual version of non-constant value ", *CI,
                    *CI->getArgOperand(0));
        return false;
      }
      TypeAnalysis TA(Logic.PPC.FAM);

      auto Arch =
          llvm::Triple(
              CI->getParent()->getParent()->getParent()->getTargetTriple())
              .getArch();

      bool AtomicAdd = Arch == Triple::nvptx || Arch == Triple::nvptx64 ||
                       Arch == Triple::amdgcn;

      auto val = GradientUtils::GetOrCreateShadowConstant(
          Logic, TLI, TA, fn, pair.second, /*width*/ 1, AtomicAdd);
      CI->replaceAllUsesWith(ConstantExpr::getPointerCast(val, CI->getType()));
      CI->eraseFromParent();
      Changed = true;
    }

CI->getType() => void
val->getType() => i8*

@tgymnich tgymnich deleted the fix-vmap branch October 23, 2022 22:45
@vchuravy vchuravy mentioned this pull request Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion `VMap[invertedRetPs[ri]]' failed

4 participants