The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
GPUAvalancheSchedulerSimpleTest.py
Go to the documentation of this file.
1#!/usr/bin/env gaudirun.py
2
12"""
13Reference optionfile which shows in a simple way how to take advantage of the
14Gaudi components desicated to concurrency.
15The components are:
16 o HiveWhiteBoard: a convenient way to collect several TES (one per "processing
17 slot"), accessible in a thread safe way, keeps a catalogue of the products
18 written on each processing slot. The number of slots in the whiteboard
19 determines also the number of events processed simultaneously by the scheduler.
20 o AvalancheSchedulerSvc: state machine of the algorithms interfaced with the
21 TBB runtime. It is responsible for the submission of the algorithms. An
22 algorithm is marked ready for submission when its needed input is available.
23 It deals the asynchronous termination of algorithms with a "receiver" thread
24 and a thread safe queue.
25 o HiveSlimEventLoopMgr: an event factory. Pushes new events and pops finished
26 events to/from the scheduler. It does not manage algorithms/streams.
27 o AlgResourcePool: Service managing the creation of algorithms (through the
28 algorithm manager), including clones. It also manages the algorithms according
29 to the resources they need (parameter NeededResources - vector of strings - of
30 the Algorithm class).
31 o InertMessageSvc: as the TBBMsgSvc, it manages the printing of the messages in
32 a multithreaded environment.
33
34The CPUCruncher is not a component dealing with concurrency, but a useful
35entity to test it. It's an algorithm that simply wastes cpu.
36
37"""
38
39from Configurables import (
40 AlgResourcePool,
41 AvalancheSchedulerSvc,
42 ContextEventCounterData,
43 ContextEventCounterPtr,
44 CPUCruncher,
45 GPUCruncher,
46 CPUCrunchSvc,
47 HiveSlimEventLoopMgr,
48 HiveWhiteBoard,
49)
50from Gaudi.Configuration import *
51
52# metaconfig -------------------------------------------------------------------
53# It's confortable to collect the relevant parameters at the top of the optionfile
54evtslots = 48
55evtMax = 30000
56cardinality = 16
57threads = 16
58gpuThreads = 4
59# -------------------------------------------------------------------------------
60
61# The configuration of the whiteboard ------------------------------------------
62# It is useful to call it EventDataSvc to replace the usual data service with
63# the whiteboard transparently.
64
65whiteboard = HiveWhiteBoard("EventDataSvc", EventSlots=evtslots)
66
67# -------------------------------------------------------------------------------
68
69# Event Loop Manager -----------------------------------------------------------
70# It's called slim since it has less functionalities overall than the good-old
71# event loop manager. Here we just set its outputlevel to DEBUG.
72
73slimeventloopmgr = HiveSlimEventLoopMgr(
74 SchedulerName="AvalancheSchedulerSvc", OutputLevel=WARNING
75)
76
77# -------------------------------------------------------------------------------
78
79# AvalancheScheduler -----------------------------------------------------------
80# We just decide how many algorithms in flight we want to have and how many
81# threads in the pool. The default value is -1, which is for TBB equivalent
82# to take over the whole machine.
83
85 ThreadPoolSize=threads, NumOffloadThreads=gpuThreads, OutputLevel=WARNING
86)
87
88# -------------------------------------------------------------------------------
89
90# Algo Resource Pool -----------------------------------------------------------
91# Nothing special here, we just set the debug level.
92AlgResourcePool(OutputLevel=WARNING)
93
94CPUCrunchSvc(shortCalib=True)
95
96# -------------------------------------------------------------------------------
97
98# Set up of the crunchers, daily business --------------------------------------
99
100a1 = CPUCruncher("A1")
101a1.outKeys = ["/Event/a1"]
102
103a2 = CPUCruncher("A2")
104a2.inpKeys = ["/Event/a1"]
105a2.outKeys = ["/Event/a2"]
106
107a3 = CPUCruncher("A3")
108a3.inpKeys = ["/Event/a1"]
109a3.outKeys = ["/Event/a3"]
110
111ga1 = GPUCruncher("GA1")
112ga1.inpKeys = ["/Event/a1"]
113ga1.outKeys = ["/Event/ga1"]
114
115ga2 = GPUCruncher("GA2")
116ga2.inpKeys = ["/Event/ga1"]
117ga2.outKeys = ["/Event/ga2"]
118
119a4 = CPUCruncher("A4")
120a4.inpKeys = ["/Event/a2", "/Event/a3", "/Event/ga2"]
121# a4.inpKeys = ["/Event/a2", "/Event/a3",]
122a4.outKeys = ["/Event/a4"]
123
124for algo in [a1, a2, a3, a4, ga1, ga2]:
125 algo.Cardinality = cardinality
126 algo.OutputLevel = INFO
127 algo.varRuntime = 0.001
128 algo.avgRuntime = 0.001
129
130for algo in [ga1, ga2]:
131 algo.avgRuntime = 10.0
132 algo.varRuntime = 1.00
133 algo.Cardinality = 0
134
135ctrp = ContextEventCounterPtr("CNT*", Cardinality=1, OutputLevel=INFO)
136ctrd = ContextEventCounterData("CNT&", Cardinality=1, OutputLevel=INFO)
137
138# Application Manager ----------------------------------------------------------
139# We put everything together and change the type of message service
140
142 EvtMax=evtMax,
143 EvtSel="NONE",
144 ExtSvc=[whiteboard],
145 EventLoop=slimeventloopmgr,
146 TopAlg=[a1, a2, a3, a4, ga1, ga2, ctrp, ctrd],
147 # TopAlg=[a1, a2, a3, a4, ctrp, ctrd],
148 MessageSvcType="InertMessageSvc",
149)
150
151# -------------------------------------------------------------------------------
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
The Application Manager class.
A class that implements a search for prime numbers.
Definition CPUCruncher.h:30
A test asynchronous algorithm on the GPU.
Definition GPUCruncher.h:26
Data service base class.