Commit 81d7b58c authored by Weronika's avatar Weronika

added the functionality required to use multiple sensors

parent 4a2c30e1
......@@ -32,6 +32,10 @@ nvmlConfigurator::nvmlConfigurator() {
* TODO
* If you want sensor or group to be named differently in the config file, you can change it here
*/
_gpuFeatureMAP["GPU_ENERGY"] = GPU_ENERGY;
_gpuFeatureMAP["GPU_POWER"] = GPU_POWER;
_groupName = "group";
_baseName = "sensor";
}
......@@ -39,13 +43,19 @@ nvmlConfigurator::nvmlConfigurator() {
nvmlConfigurator::~nvmlConfigurator() {}
void nvmlConfigurator::sensorBase(nvmlSensorBase& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for sensorBase attributes
//ADD {
*/
//ATTRIBUTE("attributeName", attributeSetter);
BOOST_FOREACH (boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "feature")) {
gpuFeatureMap_t::iterator it = _gpuFeatureMAP.find(val.second.data());
if (it != _gpuFeatureMAP.end()) {
s.setFeatureType(it->second);
} else {
LOG(warning) << " feature \"" << val.second.data() << "\" not known.";
}
}
} //
//}
}
void nvmlConfigurator::sensorGroup(nvmlSensorGroup& s, CFG_VAL config) {
......
......@@ -38,20 +38,23 @@
*/
class nvmlConfigurator : public ConfiguratorTemplate<nvmlSensorBase, nvmlSensorGroup> {
public:
typedef std::map<std::string, unsigned int> gpuFeatureMap_t;
public:
nvmlConfigurator();
virtual ~nvmlConfigurator();
protected:
protected:
/* Overwritten from ConfiguratorTemplate */
void sensorBase(nvmlSensorBase& s, CFG_VAL config) override;
void sensorGroup(nvmlSensorGroup& s, CFG_VAL config) override;
//TODO implement if required
//void global(CFG_VAL config) override;
//void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override;
virtual void printConfiguratorConfig(LOG_LEVEL ll) final override;
private:
gpuFeatureMap_t _gpuFeatureMAP;
};
extern "C" ConfiguratorInterface* create() {
......
......@@ -29,7 +29,7 @@
* @defgroup nvml nvml plugin
* @ingroup pusherplugins
*
* @brief Describe your plugin in one sentence
* Collect data from the nvml interface.e
*/
#ifndef NVML_NVMLSENSORBASE_H_
......@@ -37,47 +37,43 @@
#include "sensorbase.h"
/*
* TODO
* Add plugin specific includes
*/
enum GPU_FEATURE {
GPU_ENERGY = 0,
GPU_POWER = 1,
};
/**
* @brief SensorBase specialization for this plugin.
* @brief
*
*
* @ingroup nvml
*/
class nvmlSensorBase : public SensorBase {
public:
public:
nvmlSensorBase(const std::string& name) :
SensorBase(name) {
/*
* TODO
* Initialize plugin specific attributes
*/
SensorBase(name), _featureType(static_cast<GPU_FEATURE>(999)) {
}
nvmlSensorBase(const nvmlSensorBase& other) :
SensorBase(other) {
/*
* TODO
* Copy construct plugin specific attributes
*/
nvmlSensorBase(const nvmlSensorBase &other)
: SensorBase(other),
_featureType(other._featureType) {}
virtual ~nvmlSensorBase() {}
int getFeatureType() const {
return _featureType;
}
virtual ~nvmlSensorBase() {
/*
* TODO
* If necessary, deconstruct plugin specific attributes
*/
void setFeatureType(int featureType){
_featureType = static_cast<GPU_FEATURE>(featureType);
}
nvmlSensorBase& operator=(const nvmlSensorBase& other) {
SensorBase::operator=(other);
/*
* TODO
* Implement assignment operator for plugin specific attributes
*/
_featureType = other._featureType;
return *this;
}
......@@ -87,15 +83,30 @@ public:
* Getters and Setters for plugin specific attributes
*/
void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) {
/*
* TODO
* Log attributes here for debug reasons
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 5;
std::string leading(leadingSpaces, ' ');
std::string feature("unknown");
switch (_featureType) {
case GPU_ENERGY:
feature = "GPU_ENERGY";
break;
case GPU_POWER:
feature = "GPU_POWER";
break;
}
LOG_VAR(ll) << leading << " Feature type: " << feature;
}
protected:
protected:
GPU_FEATURE _featureType;
/*
* TODO
* Add plugin specific attributes here
......
......@@ -33,22 +33,42 @@
// between calls to the read function
static int isfirsttime=0;
// We need the energy values to be global too
unsigned long long energy_initial;
unsigned long long energy_current;
unsigned long long energy_previous;
//unsigned long long energy_initial;
//unsigned long long energy_current;
//unsigned long long energy_previous;
// FR defn of env was global in our test case
struct env_t {
struct env_t {
nvmlDevice_t device;
} env;
} env;
// FR
struct counters_t {
// unsigned long long energy_start;
// unsigned long long energy_stop;
unsigned long long energy_initial;
unsigned long long energy_current;
unsigned long long energy_previous;
// unsigned int freq1;
// unsigned int freq2;
// unsigned int freq3;
unsigned int temperature;
unsigned int fanspeed;
// unsigned int clockspeed_graphics;
// unsigned int clockspeed_sm;
// unsigned int clockspeed_mem;
nvmlMemory_t memory;
unsigned int power;
unsigned long long ecc_counts;
// nvmlUtilization_t utilization;
} counters;
nvmlSensorGroup::nvmlSensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
/*
* TODO
* Construct attributes
*/
}
}
nvmlSensorGroup::nvmlSensorGroup(const nvmlSensorGroup& other) :
SensorGroupTemplate(other) {
......@@ -56,7 +76,7 @@ nvmlSensorGroup::nvmlSensorGroup(const nvmlSensorGroup& other) :
* TODO
* Copy construct attributes
*/
}
}
nvmlSensorGroup::~nvmlSensorGroup() {
/*
......@@ -87,19 +107,14 @@ void nvmlSensorGroup::execOnInit() {
err = nvmlInit();
err = nvmlDeviceGetHandleByIndex(0,&(env.device));
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(energy_initial));
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(counters.energy_initial));
// FR
}
bool nvmlSensorGroup::execOnStart() {
/*
* TODO
* Implement logic before the group starts polling here
* (e.g. open a file descriptor) or remove this method if not required.
*/
// FR
//FR
cudaError_t cerr;
cerr = cudaProfilerStart();
// FR
......@@ -128,28 +143,30 @@ void nvmlSensorGroup::read() {
// FR
try {
for(auto s : _sensors) {
// reading.value = /*
// * TODO
// * Read a value for every sensor affiliated with this group and store
// * it with the appropriate sensor.
// */ 0;
// FR
switch(s->getFeatureType()){
case(GPU_ENERGY):
// Need to measure the difference in energy used between calls to the read function
if (isfirsttime==0){
// First time through we use the initial value to set previous and get the new energy into current
energy_previous = energy_initial;
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(energy_current));
counters.energy_previous = counters.energy_initial;
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(counters.energy_current));
isfirsttime=1;
}
else {
// Otherwise, set previous energy to whatever it was before and get the new value
energy_previous=energy_current;
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(energy_current));
counters.energy_previous=counters.energy_current;
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(counters.energy_current));
}
temp=energy_current - energy_previous; // Take difference and compute energy in millijoules
temp=counters.energy_current - counters.energy_previous; // Take difference and compute energy in millijoules
// You might want to consider putting this in the else block so we always measure something?
reading.value = temp;
// FR
break;
case(GPU_POWER):
err = nvmlDeviceGetPowerUsage(env.device,&(counters.power));
reading.value = counters.power;
break;
}
s->storeReading(reading);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\"";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment