Commit 81d7b58c authored by Weronika's avatar Weronika

added the functionality required to use multiple sensors

parent 4a2c30e1
...@@ -28,41 +28,51 @@ ...@@ -28,41 +28,51 @@
#include "nvmlConfigurator.h" #include "nvmlConfigurator.h"
nvmlConfigurator::nvmlConfigurator() { nvmlConfigurator::nvmlConfigurator() {
/* /*
* TODO * TODO
* If you want sensor or group to be named differently in the config file, you can change it here * If you want sensor or group to be named differently in the config file, you can change it here
*/ */
_groupName = "group";
_baseName = "sensor"; _gpuFeatureMAP["GPU_ENERGY"] = GPU_ENERGY;
_gpuFeatureMAP["GPU_POWER"] = GPU_POWER;
_groupName = "group";
_baseName = "sensor";
} }
nvmlConfigurator::~nvmlConfigurator() {} nvmlConfigurator::~nvmlConfigurator() {}
void nvmlConfigurator::sensorBase(nvmlSensorBase& s, CFG_VAL config) { void nvmlConfigurator::sensorBase(nvmlSensorBase& s, CFG_VAL config) {
ADD { //ADD {
/* */
* TODO BOOST_FOREACH (boost::property_tree::iptree::value_type &val, config) {
* Add ATTRIBUTE macros for sensorBase attributes if (boost::iequals(val.first, "feature")) {
*/ gpuFeatureMap_t::iterator it = _gpuFeatureMAP.find(val.second.data());
//ATTRIBUTE("attributeName", attributeSetter); 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) { void nvmlConfigurator::sensorGroup(nvmlSensorGroup& s, CFG_VAL config) {
ADD { ADD {
/* /*
* TODO * TODO
* Add ATTRIBUTE macros for sensorGroup attributes * Add ATTRIBUTE macros for sensorGroup attributes
*/ */
} }
} }
void nvmlConfigurator::printConfiguratorConfig(LOG_LEVEL ll) { void nvmlConfigurator::printConfiguratorConfig(LOG_LEVEL ll) {
/* /*
* TODO * TODO
* Log attributes here for debug reasons or delete this method if there are * Log attributes here for debug reasons or delete this method if there are
* not attributes to log. * not attributes to log.
*/ */
LOG_VAR(ll) << " NumSpacesAsIndention: " << 2; LOG_VAR(ll) << " NumSpacesAsIndention: " << 2;
} }
...@@ -38,28 +38,31 @@ ...@@ -38,28 +38,31 @@
*/ */
class nvmlConfigurator : public ConfiguratorTemplate<nvmlSensorBase, nvmlSensorGroup> { class nvmlConfigurator : public ConfiguratorTemplate<nvmlSensorBase, nvmlSensorGroup> {
public: typedef std::map<std::string, unsigned int> gpuFeatureMap_t;
nvmlConfigurator();
virtual ~nvmlConfigurator();
protected: public:
/* Overwritten from ConfiguratorTemplate */ nvmlConfigurator();
void sensorBase(nvmlSensorBase& s, CFG_VAL config) override; virtual ~nvmlConfigurator();
void sensorGroup(nvmlSensorGroup& s, CFG_VAL config) override;
//TODO implement if required protected:
//void global(CFG_VAL config) override; /* Overwritten from ConfiguratorTemplate */
//void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override; void sensorBase(nvmlSensorBase& s, CFG_VAL config) override;
void sensorGroup(nvmlSensorGroup& s, CFG_VAL config) override;
virtual void printConfiguratorConfig(LOG_LEVEL ll) final override;
private:
gpuFeatureMap_t _gpuFeatureMAP;
virtual void printConfiguratorConfig(LOG_LEVEL ll) final override;
}; };
extern "C" ConfiguratorInterface* create() { extern "C" ConfiguratorInterface* create() {
return new nvmlConfigurator; return new nvmlConfigurator;
} }
extern "C" void destroy(ConfiguratorInterface* c) { extern "C" void destroy(ConfiguratorInterface* c) {
delete c; delete c;
} }
#endif /* NVML_NVMLCONFIGURATOR_H_ */ #endif /* NVML_NVMLCONFIGURATOR_H_ */
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* @defgroup nvml nvml plugin * @defgroup nvml nvml plugin
* @ingroup pusherplugins * @ingroup pusherplugins
* *
* @brief Describe your plugin in one sentence * Collect data from the nvml interface.e
*/ */
#ifndef NVML_NVMLSENSORBASE_H_ #ifndef NVML_NVMLSENSORBASE_H_
...@@ -37,69 +37,80 @@ ...@@ -37,69 +37,80 @@
#include "sensorbase.h" #include "sensorbase.h"
/* enum GPU_FEATURE {
* TODO GPU_ENERGY = 0,
* Add plugin specific includes GPU_POWER = 1,
*/ };
/** /**
* @brief SensorBase specialization for this plugin. * @brief
*
* *
* @ingroup nvml * @ingroup nvml
*/ */
class nvmlSensorBase : public SensorBase { class nvmlSensorBase : public SensorBase {
public: public:
nvmlSensorBase(const std::string& name) : nvmlSensorBase(const std::string& name) :
SensorBase(name) { SensorBase(name), _featureType(static_cast<GPU_FEATURE>(999)) {
/* }
* TODO
* Initialize plugin specific attributes nvmlSensorBase(const nvmlSensorBase &other)
*/ : SensorBase(other),
} _featureType(other._featureType) {}
nvmlSensorBase(const nvmlSensorBase& other) :
SensorBase(other) { virtual ~nvmlSensorBase() {}
/*
* TODO int getFeatureType() const {
* Copy construct plugin specific attributes return _featureType;
*/ }
}
void setFeatureType(int featureType){
virtual ~nvmlSensorBase() { _featureType = static_cast<GPU_FEATURE>(featureType);
/*
* TODO }
* If necessary, deconstruct plugin specific attributes
*/
} nvmlSensorBase& operator=(const nvmlSensorBase& other) {
SensorBase::operator=(other);
nvmlSensorBase& operator=(const nvmlSensorBase& other) { _featureType = other._featureType;
SensorBase::operator=(other);
/* return *this;
* TODO }
* Implement assignment operator for plugin specific attributes
*/ /*
* TODO
return *this; * Getters and Setters for plugin specific attributes
} */
/*
* TODO
* Getters and Setters for plugin specific attributes
*/ void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) {
/*
void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) { * TODO
/* * Log attributes here for debug reasons
* TODO */
* Log attributes here for debug reasons
*/ std::string leading(leadingSpaces, ' ');
LOG_VAR(ll) << " NumSpacesAsIndention: " << 5; std::string feature("unknown");
} switch (_featureType) {
case GPU_ENERGY:
protected: feature = "GPU_ENERGY";
/* break;
* TODO case GPU_POWER:
* Add plugin specific attributes here feature = "GPU_POWER";
*/ break;
}
LOG_VAR(ll) << leading << " Feature type: " << feature;
}
protected:
GPU_FEATURE _featureType;
/*
* TODO
* Add plugin specific attributes here
*/
}; };
......
...@@ -33,138 +33,155 @@ ...@@ -33,138 +33,155 @@
// between calls to the read function // between calls to the read function
static int isfirsttime=0; static int isfirsttime=0;
// We need the energy values to be global too // We need the energy values to be global too
unsigned long long energy_initial; //unsigned long long energy_initial;
unsigned long long energy_current; //unsigned long long energy_current;
unsigned long long energy_previous; //unsigned long long energy_previous;
// FR defn of env was global in our test case // FR defn of env was global in our test case
struct env_t { struct env_t {
nvmlDevice_t device; nvmlDevice_t device;
} env; } env;
// FR // 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) : nvmlSensorGroup::nvmlSensorGroup(const std::string& name) :
SensorGroupTemplate(name) { SensorGroupTemplate(name) {
/* /*
* TODO * TODO
* Construct attributes * Construct attributes
*/ */
} }
nvmlSensorGroup::nvmlSensorGroup(const nvmlSensorGroup& other) : nvmlSensorGroup::nvmlSensorGroup(const nvmlSensorGroup& other) :
SensorGroupTemplate(other) { SensorGroupTemplate(other) {
/* /*
* TODO * TODO
* Copy construct attributes * Copy construct attributes
*/ */
} }
nvmlSensorGroup::~nvmlSensorGroup() { nvmlSensorGroup::~nvmlSensorGroup() {
/* /*
* TODO * TODO
* Tear down attributes * Tear down attributes
*/ */
} }
nvmlSensorGroup& nvmlSensorGroup::operator=(const nvmlSensorGroup& other) { nvmlSensorGroup& nvmlSensorGroup::operator=(const nvmlSensorGroup& other) {
SensorGroupTemplate::operator=(other); SensorGroupTemplate::operator=(other);
/* /*
* TODO * TODO
* Implement assignment operator * Implement assignment operator
*/ */
return *this; return *this;
} }
void nvmlSensorGroup::execOnInit() { void nvmlSensorGroup::execOnInit() {
/* /*
* TODO * TODO
* Implement one time initialization logic for this group here * Implement one time initialization logic for this group here
* (e.g. allocate memory for buffer) or remove this method if not * (e.g. allocate memory for buffer) or remove this method if not
* required. * required.
*/ */
// FR Add the contents of init_environment in here // FR Add the contents of init_environment in here
nvmlReturn_t err; nvmlReturn_t err;
err = nvmlInit(); err = nvmlInit();
err = nvmlDeviceGetHandleByIndex(0,&(env.device)); err = nvmlDeviceGetHandleByIndex(0,&(env.device));
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(energy_initial)); err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(counters.energy_initial));
// FR // FR
} }
bool nvmlSensorGroup::execOnStart() { bool nvmlSensorGroup::execOnStart() {
/* //FR
* TODO cudaError_t cerr;
* Implement logic before the group starts polling here cerr = cudaProfilerStart();
* (e.g. open a file descriptor) or remove this method if not required. // FR
*/
// FR return true;
cudaError_t cerr;
cerr = cudaProfilerStart();
// FR
return true;
} }
void nvmlSensorGroup::execOnStop() { void nvmlSensorGroup::execOnStop() {
/* /*
* TODO * TODO
* Implement logic when the group stops polling here * Implement logic when the group stops polling here
* (e.g. close a file descriptor) or remove this method if not required. * (e.g. close a file descriptor) or remove this method if not required.
*/ */
// FR // FR
cudaError_t cerr; cudaError_t cerr;
cerr = cudaProfilerStop(); cerr = cudaProfilerStop();
// FR // FR
} }
void nvmlSensorGroup::read() { void nvmlSensorGroup::read() {
reading_t reading; reading_t reading;
reading.timestamp = getTimestamp(); reading.timestamp = getTimestamp();
// FR // FR
nvmlReturn_t err; nvmlReturn_t err;
unsigned long long temp; unsigned long long temp;
// FR // FR
try { try {
for(auto s : _sensors) { for(auto s : _sensors) {
// reading.value = /* switch(s->getFeatureType()){
// * TODO case(GPU_ENERGY):
// * Read a value for every sensor affiliated with this group and store // Need to measure the difference in energy used between calls to the read function
// * it with the appropriate sensor. if (isfirsttime==0){
// */ 0; // First time through we use the initial value to set previous and get the new energy into current
// FR counters.energy_previous = counters.energy_initial;
// Need to measure the difference in energy used between calls to the read function err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(counters.energy_current));
if (isfirsttime==0){ isfirsttime=1;
// First time through we use the initial value to set previous and get the new energy into current }
energy_previous = energy_initial; else {
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(energy_current)); // Otherwise, set previous energy to whatever it was before and get the new value
isfirsttime=1; counters.energy_previous=counters.energy_current;
} err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(counters.energy_current));
else { }
// Otherwise, set previous energy to whatever it was before and get the new value temp=counters.energy_current - counters.energy_previous; // Take difference and compute energy in millijoules
energy_previous=energy_current; // You might want to consider putting this in the else block so we always measure something?
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(energy_current)); reading.value = temp;
} // FR
temp=energy_current - energy_previous; // Take difference and compute energy in millijoules break;
// You might want to consider putting this in the else block so we always measure something? case(GPU_POWER):
reading.value = temp; err = nvmlDeviceGetPowerUsage(env.device,&(counters.power));
// FR reading.value = counters.power;
s->storeReading(reading); break;
}
s->storeReading(reading);
#ifdef DEBUG #ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\""; LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\"";
#endif #endif
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what(); LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
} }
} }
void nvmlSensorGroup::printGroupConfig(LOG_LEVEL ll, unsigned int leadingSpaces) { void nvmlSensorGroup::printGroupConfig(LOG_LEVEL ll, unsigned int leadingSpaces) {
/* /*
* TODO * TODO
* Log attributes here for debug reasons * Log attributes here for debug reasons
*/ */
LOG_VAR(ll) << " NumSpacesAsIndention: " << 12; LOG_VAR(ll) << " NumSpacesAsIndention: " << 12;
} }
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