-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathDeviceSpecHelpers.h
More file actions
188 lines (173 loc) · 8.53 KB
/
DeviceSpecHelpers.h
File metadata and controls
188 lines (173 loc) · 8.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_DEVICESPECHELPERS_H_
#define O2_FRAMEWORK_DEVICESPECHELPERS_H_
#include "Framework/WorkflowSpec.h"
#include "Framework/ChannelConfigurationPolicy.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/ChannelSpec.h"
#include "Framework/CompletionPolicy.h"
#include "Framework/DispatchPolicy.h"
#include "Framework/DeviceControl.h"
#include "Framework/DeviceExecution.h"
#include "Framework/DeviceSpec.h"
#include "Framework/AlgorithmSpec.h"
#include "Framework/ConfigParamSpec.h"
#include "Framework/OutputRoute.h"
#include "Framework/DataProcessorInfo.h"
#include "Framework/ProcessingPolicies.h"
#include "ResourceManager.h"
#include "WorkflowHelpers.h"
#include <boost/program_options.hpp>
#include <vector>
#include <string>
#include <map>
#include <functional>
namespace o2::framework
{
struct InputChannelSpec;
struct OutputChannelSpec;
struct ConfigContext;
struct DriverConfig;
struct DeviceSpecHelpers {
/// Helper to convert from an abstract dataflow specification, @a workflow,
/// to an actual set of devices which will have to run.
static void dataProcessorSpecs2DeviceSpecs(
const WorkflowSpec& workflow,
std::vector<ChannelConfigurationPolicy> const& channelPolicies,
std::vector<CompletionPolicy> const& completionPolicies,
std::vector<DispatchPolicy> const& dispatchPolicies,
std::vector<ResourcePolicy> const& resourcePolicies,
std::vector<CallbacksPolicy> const& callbacksPolicies,
std::vector<SendingPolicy> const& sendingPolicy,
std::vector<ForwardingPolicy> const& forwardingPolicies,
std::vector<DeviceSpec>& devices,
ResourceManager& resourceManager,
std::string const& uniqueWorkflowId,
ConfigContext const& configContext,
bool optimizeTopology = false,
unsigned short resourcesMonitoringInterval = 0,
std::string const& channelPrefix = "",
OverrideServiceSpecs const& overrideServices = {});
static void validate(WorkflowSpec const& workflow);
static void dataProcessorSpecs2DeviceSpecs(
const WorkflowSpec& workflow,
std::vector<ChannelConfigurationPolicy> const& channelPolicies,
std::vector<CompletionPolicy> const& completionPolicies,
std::vector<CallbacksPolicy> const& callbacksPolicies,
std::vector<DeviceSpec>& devices,
ResourceManager& resourceManager,
std::string const& uniqueWorkflowId,
ConfigContext const& configContext,
bool optimizeTopology = false,
unsigned short resourcesMonitoringInterval = 0,
std::string const& channelPrefix = "",
OverrideServiceSpecs const& overrideServices = {})
{
std::vector<DispatchPolicy> dispatchPolicies = DispatchPolicy::createDefaultPolicies();
std::vector<ResourcePolicy> resourcePolicies = ResourcePolicy::createDefaultPolicies();
std::vector<SendingPolicy> sendingPolicies = SendingPolicy::createDefaultPolicies();
std::vector<ForwardingPolicy> forwardingPolicies = ForwardingPolicy::createDefaultPolicies();
dataProcessorSpecs2DeviceSpecs(workflow, channelPolicies, completionPolicies,
dispatchPolicies, resourcePolicies, callbacksPolicies,
sendingPolicies, forwardingPolicies, devices,
resourceManager, uniqueWorkflowId, configContext, optimizeTopology,
resourcesMonitoringInterval, channelPrefix, overrideServices);
}
/// Helper to provide the channel configuration string for an input channel
static std::string inputChannel2String(const InputChannelSpec& channel);
/// Helper to provide the channel configuration string for an output channel
static std::string outputChannel2String(const OutputChannelSpec& channel);
/// Rework a given command line option so that all the sub workflows
/// either have the same value, or they leave it unspecified.
/// @a infos the DataProcessorInfos to modify
/// @a name of the option to modify, including --
/// @a defaultValue the default value for the option. If default is nullptr, not finding the
/// option will not not add a default value.
static void reworkHomogeneousOption(std::vector<DataProcessorInfo>& infos,
char const* name, char const* defaultValue);
/// Rework a given command line option so that we pick the largest value
/// which has been specified or a default one.
/// @a defaultValueCallback a callback which returns the default value, if nullptr, the option
/// will not be added.
/// @a bestValue given to possible values of the option, return the one which should be used.
static void reworkIntegerOption(std::vector<DataProcessorInfo>& infos,
char const* name,
std::function<long long()> defaultValueCallback,
long long startValue,
std::function<long long(long long, long long)> bestValue);
/// Rework the infos so that they have a consistent --shm-section-size
/// which is the maximum of the specified value.
static void reworkShmSegmentSize(std::vector<DataProcessorInfo>& infos);
/// Helper to prepare the arguments which will be used to
/// start the various devices.
static void prepareArguments(
bool defaultQuiet,
bool defaultStopped,
bool intereactive,
unsigned short driverPort,
DriverConfig const& driverConfig,
std::vector<DataProcessorInfo> const& processorInfos,
std::vector<DeviceSpec> const& deviceSpecs,
std::vector<DeviceExecution>& deviceExecutions,
std::vector<DeviceControl>& deviceControls,
std::vector<ConfigParamSpec> const& detectedOptions,
std::string const& uniqueWorkflowId);
/// Rework the environment string
/// * Substitute {timeslice<N>} with the actual value of the timeslice.
static std::string reworkTimeslicePlaceholder(std::string const& str, DeviceSpec const& spec);
/// This takes the list of preprocessed edges of a graph
/// and creates Devices and Channels which are related
/// to the outgoing edges i.e. those which refer
/// to the act of producing data.
static void processOutEdgeActions(
ConfigContext const& configContext,
std::vector<DeviceSpec>& devices,
std::vector<DeviceId>& deviceIndex,
std::vector<DeviceConnectionId>& connections,
ResourceManager& resourceManager,
const std::vector<size_t>& outEdgeIndex,
const std::vector<DeviceConnectionEdge>& logicalEdges,
const std::vector<EdgeAction>& actions,
const WorkflowSpec& workflow,
const std::vector<OutputSpec>& outputs,
std::vector<ChannelConfigurationPolicy> const& channelPolicies,
std::vector<SendingPolicy> const& sendingPolicies,
std::vector<ForwardingPolicy> const& forwardingPolicies,
std::string const& channelPrefix,
ComputingOffer const& defaultOffer,
OverrideServiceSpecs const& overrideServices = {});
/// This takes the list of preprocessed edges of a graph
/// and creates Devices and Channels which are related
/// to the incoming edges i.e. those which refer to
/// the act of consuming data.
static void processInEdgeActions(
std::vector<DeviceSpec>& devices,
std::vector<DeviceId>& deviceIndex,
const std::vector<DeviceConnectionId>& connections,
ResourceManager& resourceManager,
const std::vector<size_t>& inEdgeIndex,
const std::vector<DeviceConnectionEdge>& logicalEdges,
const std::vector<EdgeAction>& actions,
const WorkflowSpec& workflow,
const std::vector<LogicalForwardInfo>& availableForwardsInfo,
std::vector<ChannelConfigurationPolicy> const& channelPolicies,
std::string const& channelPrefix,
ComputingOffer const& defaultOffer,
OverrideServiceSpecs const& overrideServices = {});
/// return a description of all options to be forwarded to the device
/// by default
static boost::program_options::options_description getForwardedDeviceOptions();
/// @return whether a give DeviceSpec @a spec has a label @a label
static bool hasLabel(DeviceSpec const& spec, char const* label);
};
} // namespace o2::framework
#endif // O2_FRAMEWORK_DEVICESPECHELPERS_H_