SMUCNGPerfOperator.cpp 3.87 KB
Newer Older
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
//================================================================================
// Name        : SMUCNGPerfOperator.cpp
// Author      : Carla Guillen
// Contact     : info@dcdb.it
// Copyright   : Leibniz Supercomputing Centre
// Description : Template implementing features to use Units in Operators.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
27

Carla Guillen Carias's avatar
Carla Guillen Carias committed
28
#include "../../includes/DerivedMetrics.h"
29
#include "SMUCNGPerfOperator.h"
30

31
SMUCNGPerfOperator::SMUCNGPerfOperator(const std::string& name): OperatorTemplate(name) {
32
	_buffers.resize(10);
33
34
}

35
SMUCNGPerfOperator::~SMUCNGPerfOperator() {
36
37
}

38
39
40
41
42
43
44
45
46
47
SMUCNGPerfOperator::SMUCNGPerfOperator(const SMUCNGPerfOperator& other) : OperatorTemplate(other){
	this->_buffers = other._buffers;
}

SMUCNGPerfOperator& SMUCNGPerfOperator::operator=(const SMUCNGPerfOperator& other){
	OperatorTemplate::operator =(other);
	this->_buffers = other._buffers;
	return *this;
}

48
void SMUCNGPerfOperator::printConfig(LOG_LEVEL ll) {
49
50
51
52
53
    OperatorTemplate<SMUCSensorBase>::printConfig(ll);
    LOG_VAR(ll) << " metric to position map: ";
    for(auto &kv : _metricToPosition){
    	LOG_VAR(ll) << "Metric = " << kv.first << "Position = " << kv.second;
    }
54
55
}

56
void SMUCNGPerfOperator::compute(U_Ptr unit) {
57
58
	auto inputs = unit->getInputs();
	auto timestamp = getTimestamp(); //ToDo timestamp minus some time...
59
	for(auto& outSensor : unit->getOutputs()){
60
		if( outSensor->getPosition() == _metricToPosition[SMUCSensorBase::CPI]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
61
62
			std::vector<reading_t> & instructions = _buffers[0];
			std::vector<reading_t> & clocks = _buffers[1];
63
64
			query(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, instructions);
			query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, clocks);
65
			bool wascalced = false;
66
			reading_t cpi;
67
			if (instructions.size() > 0 && clocks.size() > 0 && calculateMetricRatio(clocks[0], instructions[0], outSensor->getScalingFactor(), cpi)) {
68
					outSensor->storeReading(cpi);
69
			}
70
		} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
71
72
			std::vector<reading_t> & clocks = _buffers[0];
			std::vector<reading_t> & clocks_ref = _buffers[1];
73
74
			query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, clocks);
			query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS_REF]]->getName(), timestamp, clocks_ref);
75
			reading_t frequency;
76
			if( clocks.size() > 0 && clocks_ref.size() > 0 && calculateFrequency(clocks_ref[0],clocks[0], MIN_FREQ_MHZ, MAX_FREQ_MHZ, frequency)) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
77
					outSensor->storeReading(frequency);
78
79
			}
		}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
80
81
82
83
		resetBuffers();
	}
}

Carla Guillen's avatar
Carla Guillen committed
84
void SMUCNGPerfOperator::query(const std::string & sensor_name, const uint64_t timestamp, vector<reading_t> &buffer){
85
86
87
	_queryEngine.querySensor(sensor_name, timestamp, timestamp, buffer, false); //use absolute timestamp and always false
}

Carla Guillen Carias's avatar
Carla Guillen Carias committed
88
89
90
void SMUCNGPerfOperator::resetBuffers(){
	for(auto &buffer: _buffers){
		buffer.clear();
91
92
	}
}