From b955402f9d05289aaf091ca9ad4828a8a4c2c986 Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Tue, 13 Apr 2021 23:42:40 +0200 Subject: [PATCH] Make the Pixel 'gpu' workflow use a GPU if available, and fall-back to CPU otherwise --- .../python/RecoPixelVertexing_cff.py | 21 +++++++----- .../python/PixelTracks_cff.py | 34 ++++++++++++------- .../python/PixelVertexes_cff.py | 7 ++-- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/RecoPixelVertexing/Configuration/python/RecoPixelVertexing_cff.py b/RecoPixelVertexing/Configuration/python/RecoPixelVertexing_cff.py index 424ac13a43627..48206c68adaa7 100644 --- a/RecoPixelVertexing/Configuration/python/RecoPixelVertexing_cff.py +++ b/RecoPixelVertexing/Configuration/python/RecoPixelVertexing_cff.py @@ -6,19 +6,24 @@ # from RecoPixelVertexing.PixelVertexFinding.PixelVertexes_cff import * #from RecoVertex.PrimaryVertexProducer.OfflinePixel3DPrimaryVertices_cfi import * -recopixelvertexingTask = cms.Task(pixelTracksTask,pixelVertices) -recopixelvertexing = cms.Sequence(recopixelvertexingTask) +recopixelvertexingTask = cms.Task(pixelTracksTask, pixelVertices) from Configuration.ProcessModifiers.gpu_cff import gpu +_recopixelvertexingTask_gpu = recopixelvertexingTask.copy() from RecoPixelVertexing.PixelVertexFinding.pixelVertexCUDA_cfi import pixelVertexCUDA +_recopixelvertexingTask_gpu.add(pixelVertexCUDA) + from RecoPixelVertexing.PixelVertexFinding.pixelVertexSoA_cfi import pixelVertexSoA -from RecoPixelVertexing.PixelVertexFinding.pixelVertexFromSoA_cfi import pixelVertexFromSoA as _pixelVertexFromSoA +_recopixelvertexingTask_gpu.add(pixelVertexSoA) -_pixelVertexingCUDATask = cms.Task(pixelTracksTask,pixelVertexCUDA,pixelVertexSoA,pixelVertices) +from RecoPixelVertexing.PixelVertexFinding.pixelVertexFromSoA_cfi import pixelVertexFromSoA as _pixelVertexFromSoA +# this is needed because the 'pixelTrack' EDAlias will not contain the 'ushorts' collections +_pixelVertexFromSoA.TrackCollection = 'pixelTrackFromSoA' +gpu.toModify(pixelVertices, + cuda = _pixelVertexFromSoA +) -# pixelVertexSoAonCPU = pixelVertexCUDA.clone() -# pixelVertexSoAonCPU.onGPU = False; +gpu.toReplaceWith(recopixelvertexingTask, _recopixelvertexingTask_gpu) -gpu.toReplaceWith(pixelVertices,_pixelVertexFromSoA) -gpu.toReplaceWith(recopixelvertexingTask,_pixelVertexingCUDATask) +recopixelvertexing = cms.Sequence(recopixelvertexingTask) diff --git a/RecoPixelVertexing/PixelTrackFitting/python/PixelTracks_cff.py b/RecoPixelVertexing/PixelTrackFitting/python/PixelTracks_cff.py index 5ff404cb603d4..244e68faba8b6 100644 --- a/RecoPixelVertexing/PixelTrackFitting/python/PixelTracks_cff.py +++ b/RecoPixelVertexing/PixelTrackFitting/python/PixelTracks_cff.py @@ -1,4 +1,5 @@ import FWCore.ParameterSet.Config as cms +from HeterogeneousCore.CUDACore.SwitchProducerCUDA import SwitchProducerCUDA from RecoLocalTracker.SiStripRecHitConverter.StripCPEfromTrackAngle_cfi import * from RecoLocalTracker.SiStripRecHitConverter.SiStripRecHitMatcher_cfi import * @@ -59,10 +60,12 @@ ) ) -pixelTracks = _pixelTracks.clone( - SeedingHitSets = "pixelTracksHitQuadruplets" +pixelTracks = SwitchProducerCUDA( + cpu = _pixelTracks.clone( + SeedingHitSets = "pixelTracksHitQuadruplets" + ) ) -trackingLowPU.toModify(pixelTracks, SeedingHitSets = "pixelTracksHitTriplets") +trackingLowPU.toModify(pixelTracks.cpu, SeedingHitSets = "pixelTracksHitTriplets") pixelTracksTask = cms.Task( pixelTracksTrackingRegions, @@ -79,7 +82,7 @@ # Use ntuple fit and substitute previous Fitter producer with the ntuple one from Configuration.ProcessModifiers.pixelNtupleFit_cff import pixelNtupleFit as ntupleFit -ntupleFit.toModify(pixelTracks, Fitter = "pixelNtupletsFitter") +ntupleFit.toModify(pixelTracks.cpu, Fitter = "pixelNtupletsFitter") _pixelTracksTask_ntupleFit = pixelTracksTask.copy() _pixelTracksTask_ntupleFit.replace(pixelFitterByHelixProjections, pixelNtupletsFitter) ntupleFit.toReplaceWith(pixelTracksTask, _pixelTracksTask_ntupleFit) @@ -88,15 +91,20 @@ from Configuration.ProcessModifiers.gpu_cff import gpu from RecoPixelVertexing.PixelTriplets.caHitNtupletCUDA_cfi import caHitNtupletCUDA from RecoPixelVertexing.PixelTrackFitting.pixelTrackSoA_cfi import pixelTrackSoA -from RecoPixelVertexing.PixelTrackFitting.pixelTrackProducerFromSoA_cfi import pixelTrackProducerFromSoA as _pixelTrackFromSoA -_pixelTracksGPUTask = cms.Task( - caHitNtupletCUDA, - pixelTrackSoA, - pixelTracks # FromSoA +from RecoPixelVertexing.PixelTrackFitting.pixelTrackProducerFromSoA_cfi import pixelTrackProducerFromSoA as pixelTrackFromSoA +_pixelTracksTask_gpu = pixelTracksTask.copy() +_pixelTracksTask_gpu.add(caHitNtupletCUDA, pixelTrackSoA, pixelTrackFromSoA) +# this is needed (instead of simply using pixelTracks.cuda = pixelTrackFromSoA.clone()) because +# the PixelTrackProducerFromSoA produces an additional 'ushorts' collection +gpu.toModify(pixelTracks, + cuda = cms.EDAlias( + pixelTrackFromSoA = cms.VPSet( + cms.PSet(type = cms.string("recoTracks")), + cms.PSet(type = cms.string("recoTrackExtras")), + cms.PSet(type = cms.string("TrackingRecHitsOwned")) + ) + ) ) - -gpu.toReplaceWith(pixelTracksTask, _pixelTracksGPUTask) -gpu.toReplaceWith(pixelTracks,_pixelTrackFromSoA) - +gpu.toReplaceWith(pixelTracksTask, _pixelTracksTask_gpu) pixelTracksSequence = cms.Sequence(pixelTracksTask) diff --git a/RecoPixelVertexing/PixelVertexFinding/python/PixelVertexes_cff.py b/RecoPixelVertexing/PixelVertexFinding/python/PixelVertexes_cff.py index 6f74899c00f03..a33d5c14af751 100644 --- a/RecoPixelVertexing/PixelVertexFinding/python/PixelVertexes_cff.py +++ b/RecoPixelVertexing/PixelVertexFinding/python/PixelVertexes_cff.py @@ -1,4 +1,7 @@ import FWCore.ParameterSet.Config as cms +from HeterogeneousCore.CUDACore.SwitchProducerCUDA import SwitchProducerCUDA -from RecoPixelVertexing.PixelVertexFinding.PixelVertexes_cfi import * - +from RecoPixelVertexing.PixelVertexFinding.PixelVertexes_cfi import pvClusterComparer, pixelVertices as _pixelVertices +pixelVertices = SwitchProducerCUDA( + cpu = _pixelVertices.clone() +)