A Multi-tiered Optimization Framework for Heterogeneous Computing