-
Notifications
You must be signed in to change notification settings - Fork 10
/
NUMAPlacementScheme.cpp
85 lines (71 loc) · 2.8 KB
/
NUMAPlacementScheme.cpp
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
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
**/
#include "catalog/NUMAPlacementScheme.hpp"
#include <unordered_map>
#include <utility>
#include "catalog/Catalog.pb.h"
#include "glog/logging.h"
namespace quickstep {
bool NUMAPlacementScheme::ProtoIsValid(
const serialization::NUMAPlacementScheme &proto) {
// Check that proto is fully initialized.
if (!proto.IsInitialized()) {
return false;
}
// Check if the number of numa nodes is non-zero.
if (proto.num_numa_nodes() <= 0) {
return false;
}
// Protobuf for NUMAPlacementScheme is valid.
return true;
}
serialization::NUMAPlacementScheme NUMAPlacementScheme::getProto() const {
serialization::NUMAPlacementScheme proto;
// Serialize the number of numa nodes.
proto.set_num_numa_nodes(getNumNUMANodes());
// Serialize the block to NUMA node map.
for (std::unordered_map<block_id, int>::const_iterator block_to_node_iter =
block_to_numa_node_map_.begin();
block_to_node_iter != block_to_numa_node_map_.end();
++block_to_node_iter) {
serialization::NUMAPlacementScheme_BlockToNUMANodeEntry *entry =
proto.add_block_to_numa_node_map();
entry->set_block_id(block_to_node_iter->first);
entry->set_numa_node(block_to_node_iter->second);
}
return proto;
}
NUMAPlacementScheme* NUMAPlacementScheme::ReconstructFromProto(
const serialization::NUMAPlacementScheme &proto,
const std::size_t num_partitions) {
// This call to the constructor will populate the values of partition-to-NUMA
// node map.
NUMAPlacementScheme *placement_scheme = new NUMAPlacementScheme(num_partitions);
DCHECK(ProtoIsValid(proto))
<< "Attempted to create NUMAPlacementScheme from an invalid proto description:\n"
<< proto.DebugString();
// Deserialize block to NUMA node mapping.
for (int i = 0; i < proto.block_to_numa_node_map_size(); ++i) {
placement_scheme->addBlockToNUMANodeMap(
proto.block_to_numa_node_map(i).block_id(),
proto.block_to_numa_node_map(i).numa_node());
}
return placement_scheme;
}
} // namespace quickstep