Commit 4a2c30e1 authored by Weronika's avatar Weronika

fixed the intial version of the nvml plugin

parent 7201e142
......@@ -3,7 +3,7 @@ DCDBDEPSPATH ?= $(DCDBBASEPATH)/deps
DCDBDEPLOYPATH ?= $(DCDBBASEPATH)/install
# dcdbpusher plugins to be built
PLUGINS = sysfs perfevent ipmi pdu bacnet snmp procfs tester gpfsmon opa msr
PLUGINS = sysfs perfevent ipmi pdu bacnet snmp procfs tester gpfsmon opa msr nvml
# data analytics plugins to be built
OPERATORS = aggregator smoothing regressor clustering job_aggregator testeroperator filesink smucngperf persystsql
......
......@@ -117,3 +117,7 @@ libdcdbplugin_msr.$(LIBEXT): sensors/msr/MSRSensorGroup.o sensors/msr/MSRConfigu
libdcdbplugin_caliper.$(LIBEXT): sensors/caliper/CaliperSensorGroup.o sensors/caliper/CaliperConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
# nvcc compiler and extra flags to enable the linking and creating of .so file to work:
libdcdbplugin_nvml.$(LIBEXT): sensors/nvml/nvmlSensorGroup.o sensors/nvml/nvmlConfigurator.o
$(NVCC) -shared --compiler-options '-fPIC' -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lnvidia-ml
//================================================================================
// Name : nvmlConfigurator.cpp
// Author : Weronika Filinger, EPCC @ The University of Edinburgh
// Contact :
// Copyright :
// Description : Source file for nvml plugin configurator class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 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.
//================================================================================
#include "nvmlConfigurator.h"
nvmlConfigurator::nvmlConfigurator() {
/*
* TODO
* If you want sensor or group to be named differently in the config file, you can change it here
*/
_groupName = "group";
_baseName = "sensor";
}
nvmlConfigurator::~nvmlConfigurator() {}
void nvmlConfigurator::sensorBase(nvmlSensorBase& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for sensorBase attributes
*/
//ATTRIBUTE("attributeName", attributeSetter);
}
}
void nvmlConfigurator::sensorGroup(nvmlSensorGroup& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for sensorGroup attributes
*/
}
}
void nvmlConfigurator::printConfiguratorConfig(LOG_LEVEL ll) {
/*
* TODO
* Log attributes here for debug reasons or delete this method if there are
* not attributes to log.
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 2;
}
//================================================================================
// Name : nvmlConfigurator.h
// Author : Weronika Filinger, EPCC @ The University of Edinburgh
// Contact :
// Copyright :
// Description : Header file for nvml plugin configurator class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 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.
//================================================================================
#ifndef NVML_NVMLCONFIGURATOR_H_
#define NVML_NVMLCONFIGURATOR_H_
#include "../../includes/ConfiguratorTemplate.h"
#include "nvmlSensorGroup.h"
/**
* @brief ConfiguratorTemplate specialization for this plugin.
*
* @ingroup nvml
*/
class nvmlConfigurator : public ConfiguratorTemplate<nvmlSensorBase, nvmlSensorGroup> {
public:
nvmlConfigurator();
virtual ~nvmlConfigurator();
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;
};
extern "C" ConfiguratorInterface* create() {
return new nvmlConfigurator;
}
extern "C" void destroy(ConfiguratorInterface* c) {
delete c;
}
#endif /* NVML_NVMLCONFIGURATOR_H_ */
//================================================================================
// Name : nvmlSensorBase.h
// Author : Weronika Filinger, EPCC @ The University of Edinburgh
// Contact :
// Copyright :
// Description : Sensor base class for nvml plugin.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 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.
//================================================================================
/**
* @defgroup nvml nvml plugin
* @ingroup pusherplugins
*
* @brief Describe your plugin in one sentence
*/
#ifndef NVML_NVMLSENSORBASE_H_
#define NVML_NVMLSENSORBASE_H_
#include "sensorbase.h"
/*
* TODO
* Add plugin specific includes
*/
/**
* @brief SensorBase specialization for this plugin.
*
* @ingroup nvml
*/
class nvmlSensorBase : public SensorBase {
public:
nvmlSensorBase(const std::string& name) :
SensorBase(name) {
/*
* TODO
* Initialize plugin specific attributes
*/
}
nvmlSensorBase(const nvmlSensorBase& other) :
SensorBase(other) {
/*
* TODO
* Copy construct plugin specific attributes
*/
}
virtual ~nvmlSensorBase() {
/*
* TODO
* If necessary, deconstruct plugin specific attributes
*/
}
nvmlSensorBase& operator=(const nvmlSensorBase& other) {
SensorBase::operator=(other);
/*
* TODO
* Implement assignment operator for plugin specific attributes
*/
return *this;
}
/*
* TODO
* 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;
}
protected:
/*
* TODO
* Add plugin specific attributes here
*/
};
#endif /* NVML_NVMLSENSORBASE_H_ */
//================================================================================
// Name : nvmlSensorGroup.cpp
// Author : Fiona Reid, Weronika Filinger, EPCC @ The University of Edinburgh
// Contact :
// Copyright :
// Description : Source file for nvml sensor group class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 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.
//================================================================================
#include "nvmlSensorGroup.h"
#include "timestamp.h"
// Used to ensure we get a sensible value of energy by computing the difference
// 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;
// FR defn of env was global in our test case
struct env_t {
nvmlDevice_t device;
} env;
// FR
nvmlSensorGroup::nvmlSensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
/*
* TODO
* Construct attributes
*/
}
nvmlSensorGroup::nvmlSensorGroup(const nvmlSensorGroup& other) :
SensorGroupTemplate(other) {
/*
* TODO
* Copy construct attributes
*/
}
nvmlSensorGroup::~nvmlSensorGroup() {
/*
* TODO
* Tear down attributes
*/
}
nvmlSensorGroup& nvmlSensorGroup::operator=(const nvmlSensorGroup& other) {
SensorGroupTemplate::operator=(other);
/*
* TODO
* Implement assignment operator
*/
return *this;
}
void nvmlSensorGroup::execOnInit() {
/*
* TODO
* Implement one time initialization logic for this group here
* (e.g. allocate memory for buffer) or remove this method if not
* required.
*/
// FR Add the contents of init_environment in here
nvmlReturn_t err;
err = nvmlInit();
err = nvmlDeviceGetHandleByIndex(0,&(env.device));
err = nvmlDeviceGetTotalEnergyConsumption(env.device,&(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
cudaError_t cerr;
cerr = cudaProfilerStart();
// FR
return true;
}
void nvmlSensorGroup::execOnStop() {
/*
* TODO
* Implement logic when the group stops polling here
* (e.g. close a file descriptor) or remove this method if not required.
*/
// FR
cudaError_t cerr;
cerr = cudaProfilerStop();
// FR
}
void nvmlSensorGroup::read() {
reading_t reading;
reading.timestamp = getTimestamp();
// FR
nvmlReturn_t err;
unsigned long long temp;
// 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
// 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));
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));
}
temp=energy_current - 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
s->storeReading(reading);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\"";
#endif
}
} catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
}
}
void nvmlSensorGroup::printGroupConfig(LOG_LEVEL ll, unsigned int leadingSpaces) {
/*
* TODO
* Log attributes here for debug reasons
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 12;
}
//================================================================================
// Name : nvmlSensorGroup.h
// Author : Fiona Reid, Weronika Filinger, EPCC @ The University of Edinburgh
// Contact :
// Copyright :
// Description : Header file for nvml sensor group class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 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.
//================================================================================
#ifndef NVML_NVMLSENSORGROUP_H_
#define NVML_NVMLSENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "nvmlSensorBase.h"
// FR Include files needed for NVML etc
#include <nvml.h>
#include <cuda_profiler_api.h>
// FR
/**
* @brief SensorGroupTemplate specialization for this plugin.
*
* @ingroup nvml
*/
class nvmlSensorGroup : public SensorGroupTemplate<nvmlSensorBase> {
public:
nvmlSensorGroup(const std::string& name);
nvmlSensorGroup(const nvmlSensorGroup& other);
virtual ~nvmlSensorGroup();
nvmlSensorGroup& operator=(const nvmlSensorGroup& other);
void execOnInit() final override;
bool execOnStart() final override;
void execOnStop() final override;
/*
* TODO
* Add getter and setters for group attributes if required
*/
void printGroupConfig(LOG_LEVEL ll, unsigned int leadingSpaces) final override;
private:
void read() final override;
/*
* TODO
* Add group internal attributes
*/
};
#endif /* NVML_NVMLSENSORGROUP_H_ */
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