SMUCNGPerfOperator.cpp 3.91 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 60
	auto outputs = unit->getOutputs();
	for(auto& outSensor : outputs){
61
		if( outSensor->getPosition() == _metricToPosition[SMUCSensorBase::CPI]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
62 63
			std::vector<reading_t> & instructions = _buffers[0];
			std::vector<reading_t> & clocks = _buffers[1];
64 65
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, timestamp, instructions, false); //use absolute timestamp
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, clocks, false); //use absolute timestamp
66
			reading_t cpi;
67
			bool wascalced = false;
68
			if (instructions.size() > 0 && clocks.size() > 0 && calculateMetricRatio(clocks[0], instructions[0], outSensor->getScalingFactor(), cpi)) {
69
					outSensor->storeReading(cpi);
70
			}
71
		} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
72 73
			std::vector<reading_t> & clocks = _buffers[0];
			std::vector<reading_t> & clocks_ref = _buffers[1];
74 75
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, clocks, false); //use absolute timestamp
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS_REF]]->getName(), timestamp, timestamp, clocks_ref, false); //use absolute timestamp
76
			reading_t frequency;
77
			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
78
					outSensor->storeReading(frequency);
79 80
			}
		}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
81 82 83 84 85 86 87
		resetBuffers();
	}
}

void SMUCNGPerfOperator::resetBuffers(){
	for(auto &buffer: _buffers){
		buffer.clear();
88 89
	}
}