Gilroy opened the scoring with his third try in two games against the Blues, and it was his Ireland Under-20 colleague Marshall who secured the bonus point with his first Magners League score.
Young full-back Dan Fish dotted down for the second successive match for Cardiff, but a lone penalty from Ceri Sweeney was all they could offer in a one-sided second half.
Ulster almost got off to a whirlwind start, with centre Nevin Spence managing to cross the visitors' whitewash in the opening minutes. But play was called back for crossing earlier in the move.
After missing a ninth minute penalty from long range, Ian Humphreys made immediate amends by setting up Gilroy's opener.
The out-half countered with a lovely chip and chase which he juggled along the left touchline at pace. With the ball firmly in his grasp, he then provided the final offload for Gilroy to romp in behind the posts, with the conversion quickly added.
Humphreys fired over a monster penalty to extend the lead to 10-0, however the Blues to quick to strike back.
Out-half Sweeney played a neat one-two with Fish, allowing the 20-year-old enough time and space to nip in by the posts from the right.
Andries Pretorius and Rhys Thomas played their part with strong carries in the build-up. Sweeney's successful conversion had the gap down to three points.
It was Ulster's turn to reply then and after a penalty had been dispatched to touch, Spence burst through to set up a concerted spell of pressure for the hosts.
The Blues' defence could not hold out and scrum half Pienaar, Ulster's hero in Llanelli last weekend, dummied past Taufa'ao Filise from close range for the province's second try which Humphreys converted.
It was nip and tuck right to the half-time whistle, with a ruck offence allowing Sweeney to make it 17-10 for the break.
But two more tries in the second period made the game safe for Ulster. Humphreys again missed an early kick after the restart, nonetheless it was the out-half's ability to craft scores in open play that came to the fore.
Humphreys' long pass put Ireland winger Trimble thundering past Tom James for a try in the right corner. Television match official Marshall Kilgore gave the green light to the score, before Humphreys pushed his conversion attempt wide.
Declan Fitzpatrick infringed at a scrum, allowing Sweeney to kick Cardiff back to within nine points of the hosts.
Then, Humphreys responded with a penalty of his own and Ulster were able to ride out Paddy McAllister's sin-binning for killing the ball. They sealed an impressive home win with Marshall's try on the hour mark.
The Ulster backs clicked into gear once again and the forwards provided the grunt to tee up the Ballymena clubman, who ran a good line onto a Humphreys pass to score his first senior try for Ulster.
Humphreys' successful conversion was the final scoring act as Brian McLaughlin's men made a serious statement of intent for the league's remaining rounds.
Speaking afterwards, McLaughlin said: "It's a huge result for us. Last week at the Scarlets, we had a tremendous victory and it was important for us to push on tonight.
"This keeps us very much in contention for our dream which is a top-four finish. With Cardiff being above us (in the table) and the fact that we got a bonus point and they got nothing, it's a big bonus for us.
"I thought we played some smashing rugby in the first half which laid the foundations for what is an absolutely outstanding victory. We're not thinking about the run-in. Every game is massive for us now."
|Ulster Rugby Score Card|
|Cardiff Blues Score Card|