Process GPU calibration on server.

This commit is contained in:
Bartosz Taudul 2020-07-07 21:09:37 +02:00
parent 1b6bc1b69a
commit 21f4981f38
2 changed files with 50 additions and 11 deletions

View File

@ -565,6 +565,10 @@ struct GpuCtxData
float period; float period;
GpuContextType type; GpuContextType type;
bool hasPeriod; bool hasPeriod;
bool hasCalibration;
int64_t calibratedGpuTime;
int64_t calibratedCpuTime;
double calibrationMod;
unordered_flat_map<uint64_t, GpuCtxThreadData> threadData; unordered_flat_map<uint64_t, GpuCtxThreadData> threadData;
short_ptr<GpuEvent> query[64*1024]; short_ptr<GpuEvent> query[64*1024];
}; };

View File

@ -4891,14 +4891,19 @@ void Worker::ProcessGpuNewContext( const QueueGpuNewContext& ev )
gpuTime = int64_t( double( ev.period ) * ev.gpuTime ); // precision loss gpuTime = int64_t( double( ev.period ) * ev.gpuTime ); // precision loss
} }
const auto cpuTime = TscTime( ev.cpuTime - m_data.baseTime );
auto gpu = m_slab.AllocInit<GpuCtxData>(); auto gpu = m_slab.AllocInit<GpuCtxData>();
memset( gpu->query, 0, sizeof( gpu->query ) ); memset( gpu->query, 0, sizeof( gpu->query ) );
gpu->timeDiff = TscTime( ev.cpuTime - m_data.baseTime ) - gpuTime; gpu->timeDiff = cpuTime - gpuTime;
gpu->thread = ev.thread; gpu->thread = ev.thread;
gpu->period = ev.period; gpu->period = ev.period;
gpu->count = 0; gpu->count = 0;
gpu->type = ev.type; gpu->type = ev.type;
gpu->hasPeriod = ev.period != 1.f; gpu->hasPeriod = ev.period != 1.f;
gpu->hasCalibration = ev.flags & GpuContextCalibration;
gpu->calibratedGpuTime = gpuTime;
gpu->calibratedCpuTime = cpuTime;
gpu->calibrationMod = 1.;
m_data.gpuData.push_back( gpu ); m_data.gpuData.push_back( gpu );
m_gpuCtxMap[ev.context] = gpu; m_gpuCtxMap[ev.context] = gpu;
} }
@ -5032,11 +5037,25 @@ void Worker::ProcessGpuTime( const QueueGpuTime& ev )
int64_t gpuTime; int64_t gpuTime;
if( !ctx->hasPeriod ) if( !ctx->hasPeriod )
{ {
gpuTime = t; if( !ctx->hasCalibration )
{
gpuTime = t + ctx->timeDiff;
} }
else else
{ {
gpuTime = int64_t( double( ctx->period ) * t ); // precision loss gpuTime = int64_t( ( t - ctx->calibratedGpuTime ) * ctx->calibrationMod + ctx->calibratedCpuTime );
}
}
else
{
if( !ctx->hasCalibration )
{
gpuTime = int64_t( double( ctx->period ) * t ) + ctx->timeDiff; // precision loss
}
else
{
gpuTime = int64_t( ( double( ctx->period ) * t - ctx->calibratedGpuTime ) * ctx->calibrationMod + ctx->calibratedCpuTime );
}
} }
auto zone = ctx->query[ev.queryId]; auto zone = ctx->query[ev.queryId];
@ -5045,28 +5064,44 @@ void Worker::ProcessGpuTime( const QueueGpuTime& ev )
if( zone->GpuStart() < 0 ) if( zone->GpuStart() < 0 )
{ {
const auto time = ctx->timeDiff + gpuTime; zone->SetGpuStart( gpuTime );
zone->SetGpuStart( time ); if( m_data.lastTime < gpuTime ) m_data.lastTime = gpuTime;
if( m_data.lastTime < time ) m_data.lastTime = time;
ctx->count++; ctx->count++;
} }
else else
{ {
auto time = ctx->timeDiff + gpuTime; if( gpuTime < zone->GpuStart() )
if( time < zone->GpuStart() )
{ {
auto tmp = zone->GpuStart(); auto tmp = zone->GpuStart();
std::swap( time, tmp ); std::swap( gpuTime, tmp );
zone->SetGpuStart( tmp ); zone->SetGpuStart( tmp );
} }
zone->SetGpuEnd( time ); zone->SetGpuEnd( gpuTime );
if( m_data.lastTime < time ) m_data.lastTime = time; if( m_data.lastTime < gpuTime ) m_data.lastTime = gpuTime;
} }
} }
void Worker::ProcessGpuCalibration( const QueueGpuCalibration& ev ) void Worker::ProcessGpuCalibration( const QueueGpuCalibration& ev )
{ {
auto ctx = m_gpuCtxMap[ev.context];
assert( ctx );
assert( ctx->hasCalibration );
int64_t gpuTime;
if( !ctx->hasPeriod )
{
gpuTime = ev.gpuTime;
}
else
{
gpuTime = int64_t( double( ctx->period ) * ev.gpuTime ); // precision loss
}
const auto cpuDelta = ev.cpuDelta;
const auto gpuDelta = gpuTime - ctx->calibratedGpuTime;
ctx->calibrationMod = double( cpuDelta ) / gpuDelta;
ctx->calibratedGpuTime = gpuTime;
ctx->calibratedCpuTime = TscTime( ev.cpuTime - m_data.baseTime );
} }
void Worker::ProcessMemAlloc( const QueueMemAlloc& ev ) void Worker::ProcessMemAlloc( const QueueMemAlloc& ev )