They were rapidly running out of money, and running a competitive fab requires billions of investment every year. They could no longer sustain their fab operations, so they spun them off and sold them to ATIC (which is part of the Abu Dhabi investment fund, which is a project by Abu Dhabi meant to turn their oil revenues into something sustainably profitable for when the oil runs out).
In order to make the fab seem like something someone would want to buy, AMD tied their futures into it by entering into a wafer supply agreement where they will buy certain amounts of GloFo:s production whether they need it or not.
This agreement was a millstone around AMD's neck during the worst years. It means that AMD absolutely wants to sell at least a certain amount of silicon, even at negative margin if necessary.