A Smooth Refinement Flow for Co-designing HW and SW Threads