Project
Loading...
Searching...
No Matches
ResourcePolicyHelpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <regex>
16
17namespace o2::framework
18{
19
23{
24 return ResourcePolicy{
25 "trivial",
26 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
27 return std::regex_match(spec.name, matcher);
28 },
30}
31
32ResourcePolicy ResourcePolicyHelpers::cpuBoundTask(char const* s, int requestedCPUs)
33{
34 return ResourcePolicy{
35 "cpu-bound",
36 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
37 return std::regex_match(spec.name, matcher);
38 },
39 [requestedCPUs](ComputingQuotaOffer const& offer, ComputingQuotaOffer const& accumulated) -> OfferScore { return accumulated.cpu >= requestedCPUs ? OfferScore::Enough : OfferScore::More; },
40 ComputingQuotaOffer{.cpu = requestedCPUs}};
41}
42
43ResourcePolicy ResourcePolicyHelpers::rateLimitedSharedMemoryBoundTask(char const* s, int requestedSharedMemory, int requestedTimeslices)
44{
45 return ResourcePolicy{
46 "ratelimited-shm-bound",
47 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
48 return std::regex_match(spec.name, matcher);
49 },
50 [requestedSharedMemory, requestedTimeslices](ComputingQuotaOffer const& offer, ComputingQuotaOffer const& accumulated) -> OfferScore {
51 // If we have enough memory and not enough timeslices,
52 // ignore further shared memory.
53 if (accumulated.sharedMemory >= requestedSharedMemory && offer.timeslices == 0) {
55 }
56 // If we have enough timeslices and not enough shared memory
57 // ignore further timeslices.
58 if (accumulated.timeslices >= requestedTimeslices && offer.sharedMemory == 0) {
60 }
61 // If it does not offer neither shared memory nor timeslices, mark it as unneeded.
62 if (offer.sharedMemory == 0 && offer.timeslices == 0) {
64 }
65 // We have enough to process.
66 if ((accumulated.sharedMemory + offer.sharedMemory) >= requestedSharedMemory && (accumulated.timeslices + offer.timeslices) >= requestedTimeslices) {
67 return OfferScore::Enough;
68 }
69 // We need more resources
70 return OfferScore::More; },
71 ComputingQuotaOffer{.sharedMemory = requestedSharedMemory, .timeslices = requestedTimeslices}};
72}
73
74ResourcePolicy ResourcePolicyHelpers::sharedMemoryBoundTask(char const* s, int requestedSharedMemory)
75{
76 return ResourcePolicy{
77 "shm-bound",
78 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
79 return std::regex_match(spec.name, matcher);
80 },
81 [requestedSharedMemory](ComputingQuotaOffer const& offer, ComputingQuotaOffer const& accumulated) -> OfferScore {
82 if (offer.sharedMemory == 0) {
84 }
85 return (accumulated.sharedMemory + offer.sharedMemory) >= requestedSharedMemory ? OfferScore::Enough : OfferScore::More; },
86 ComputingQuotaOffer{.sharedMemory = requestedSharedMemory}};
87}
88
89} // namespace o2::framework
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
int64_t sharedMemory
How much shared memory it can allocate.
int cpu
How many cores it can use.
static ResourcePolicy rateLimitedSharedMemoryBoundTask(char const *taskMatcher, int maxMemory, int maxTimeslices)
static ResourcePolicy trivialTask(char const *taskMatcher)
static ResourcePolicy sharedMemoryBoundTask(char const *taskMatcher, int maxMemory)
static ResourcePolicy cpuBoundTask(char const *taskMatcher, int maxCPUs=1)