SMUCNGPerfOperator.cpp 3.96 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) {
Carla Guillen's avatar
Carla Guillen committed
32
    _buffers.resize(10);
33 34
}

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

38
SMUCNGPerfOperator::SMUCNGPerfOperator(const SMUCNGPerfOperator& other) : OperatorTemplate(other){
Carla Guillen's avatar
Carla Guillen committed
39 40
    this->_buffers = other._buffers;
    this->_metricToPosition = other._metricToPosition;
41 42 43
}

SMUCNGPerfOperator& SMUCNGPerfOperator::operator=(const SMUCNGPerfOperator& other){
Carla Guillen's avatar
Carla Guillen committed
44 45 46 47
    OperatorTemplate::operator =(other);
    this->_buffers = other._buffers;
    this->_metricToPosition = other._metricToPosition;
    return *this;
48 49
}

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

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

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

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