U.S. stocks rose to all-time highs Wednesday as a gain in chip stocks propelled the tech sector higher.

The S&P 500 advanced 0.6 percent to close at 2,713.06 with tech rising 1.1 percent. It was also the first time the index closed above 2,700 for the first time. Energy stocks also surged 1.5 percent after U.S. crude posted its best settle since December 2014.

The Nasdaq composite jumped 0.8 percent to 7,065.53, with Advanced Micro Devices surging more than 5 percent. The tech-heavy index also completed its best start to a year since 2006.

The Dow Jones industrial average finished 98.97 points higher at 24,922.68, as it closed in on the 25,000 mark.

"The 2017 trends are continuing in 2018," said Adam Sarhan, CEO of 50 Park Investments. "You're seeing a lot of money flowing back into the semiconductors" after some profit-taking at the end of last year.

The VanEck Vectors Semiconductor exchange-traded fund (SMH) easily outperformed the broader market last year. It rose 36.5 percent while the S&P 500 gained 19.4 percent.