It's a simple enough question, but depending on how accurate you want the anwer, how accurate you want to know for the non-mountain stages, getting the solution can get very complex and will lead you into the wonderful world of fractal geometry
Three examples with increasing complexity:
- If you have a mountain time trial with the road only going up from 500mtrs to 1500 mtrs, it's a simple mathematical calculation of subtracting two numbers (elevation of start and finish) and the result is 1000mtrs of total vertical ascent.
- If, however, you have a mountain with some descends, you have to add the height difference of every descent as well. So suppose the road goes down 3 times, each for 100mtrs, the total vertical ascent is 1300 mtrs.
- If you have a rolling landscape, you can have 100ths of stretches going up. To calculate the total ascend, one has to have very detailed profiles of each stage. Most of the times, the organizers don't have those, and they don't care. If you have 1000 sections in a race with a 1 mtr ascent, you can have 1000 mtrs of total vertical ascent, but frankly, most riders won't even notice those vertical meters, and most digital elevation models are based on sattelite images that have a measuring accuracy of 1 meter. So in the end, the best way to find out is to measure it in the field, and even in this way, some measurements (like GPS) are not accurate enough.
Conclusion:
What you want to know is is hard to know, as it depends on measuring accuracy, and fractal dimension. It's easy to do it (still roughly) right for mountain stages, but it gets complicated and less relevant for flat stages.
And I know you aren't looking for my personal opinion, but as I showed in the 3rd example, the total vertical ascent in 'flat' stages is often not relevant. It gets relevant in those hilly stages with very few categorized climbs but a lot of terrain going up and down, like we see in Strade Bianchi, in the Massif Central,... There must be tools to draw those stages and get the elevational profiles (from which you should be able to roughly calculate the total vertical ascent, given that you get altitude data together with distance on the road), but I haven't looked to deep into that.