Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
81d7b58c
Commit
81d7b58c
authored
Feb 20, 2020
by
Weronika Filinger
Browse files
added the functionality required to use multiple sensors
parent
4a2c30e1
Changes
4
Hide whitespace changes
Inline
Side-by-side
dcdbpusher/sensors/nvml/nvmlConfigurator.cpp
View file @
81d7b58c
...
...
@@ -28,41 +28,51 @@
#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"
;
/*
* 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"
;
}
nvmlConfigurator
::~
nvmlConfigurator
()
{}
void
nvmlConfigurator
::
sensorBase
(
nvmlSensorBase
&
s
,
CFG_VAL
config
)
{
ADD
{
/*
* TODO
* Add ATTRIBUTE macros for sensorBase attributes
*/
//ATTRIBUTE("attributeName", attributeSetter);
}
//ADD {
*/
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
)
{
ADD
{
/*
* TODO
* Add ATTRIBUTE macros for sensorGroup attributes
*/
}
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
;
/*
* TODO
* Log attributes here for debug reasons or delete this method if there are
* not attributes to log.
*/
LOG_VAR
(
ll
)
<<
" NumSpacesAsIndention: "
<<
2
;
}
dcdbpusher/sensors/nvml/nvmlConfigurator.h
View file @
81d7b58c
...
...
@@ -38,28 +38,31 @@
*/
class
nvmlConfigurator
:
public
ConfiguratorTemplate
<
nvmlSensorBase
,
nvmlSensorGroup
>
{
public:
nvmlConfigurator
();
virtual
~
nvmlConfigurator
();
typedef
std
::
map
<
std
::
string
,
unsigned
int
>
gpuFeatureMap_t
;
protected:
/* Overwritten from ConfiguratorTemplate */
void
sensorBase
(
nvmlSensorBase
&
s
,
CFG_VAL
config
)
override
;
void
sensorGroup
(
nvmlSensorGroup
&
s
,
CFG_VAL
config
)
override
;
public:
nvmlConfigurator
();
virtual
~
nvmlConfigurator
();
//TODO implement if required
//void global(CFG_VAL config) override;
//void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override;
protected:
/* Overwritten from ConfiguratorTemplate */
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
()
{
return
new
nvmlConfigurator
;
return
new
nvmlConfigurator
;
}
extern
"C"
void
destroy
(
ConfiguratorInterface
*
c
)
{
delete
c
;
delete
c
;
}
#endif
/* NVML_NVMLCONFIGURATOR_H_ */
dcdbpusher/sensors/nvml/nvmlSensorBase.h
View file @
81d7b58c
...
...
@@ -29,7 +29,7 @@
* @defgroup nvml nvml plugin
* @ingroup pusherplugins
*
*
@brief Describe your plugin in one sentenc
e
*
Collect data from the nvml interface.
e
*/
#ifndef NVML_NVMLSENSORBASE_H_
...
...
@@ -37,69 +37,80 @@
#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:
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
*/
public:
nvmlSensorBase
(
const
std
::
string
&
name
)
:
SensorBase
(
name
),
_featureType
(
static_cast
<
GPU_FEATURE
>
(
999
))
{
}
nvmlSensorBase
(
const
nvmlSensorBase
&
other
)
:
SensorBase
(
other
),
_featureType
(
other
.
_featureType
)
{}
virtual
~
nvmlSensorBase
()
{}
int
getFeatureType
()
const
{
return
_featureType
;
}
void
setFeatureType
(
int
featureType
){
_featureType
=
static_cast
<
GPU_FEATURE
>
(
featureType
);
}
nvmlSensorBase
&
operator
=
(
const
nvmlSensorBase
&
other
)
{
SensorBase
::
operator
=
(
other
);
_featureType
=
other
.
_featureType
;
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
*/
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:
GPU_FEATURE
_featureType
;
/*
* TODO
* Add plugin specific attributes here
*/
};
...
...
dcdbpusher/sensors/nvml/nvmlSensorGroup.cpp
View file @
81d7b58c
...
...
@@ -33,138 +33,155 @@
// 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
{
nvmlDevice_t
device
;
}
env
;
struct
env_t
{
nvmlDevice_t
device
;
}
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
*/
}
SensorGroupTemplate
(
name
)
{
/*
* TODO
* Construct attributes
*/
}
nvmlSensorGroup
::
nvmlSensorGroup
(
const
nvmlSensorGroup
&
other
)
:
SensorGroupTemplate
(
other
)
{
/*
* TODO
* Copy construct attributes
*/
}
SensorGroupTemplate
(
other
)
{
/*
* TODO
* Copy construct attributes
*/
}
nvmlSensorGroup
::~
nvmlSensorGroup
()
{
/*
* TODO
* Tear down attributes
*/
/*
* TODO
* Tear down attributes
*/
}
nvmlSensorGroup
&
nvmlSensorGroup
::
operator
=
(
const
nvmlSensorGroup
&
other
)
{
SensorGroupTemplate
::
operator
=
(
other
);
/*
* TODO
* Implement assignment operator
*/
SensorGroupTemplate
::
operator
=
(
other
);
/*
* TODO
* Implement assignment operator
*/
return
*
this
;
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
;
/*
* 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
));
err
=
nvmlInit
();
err
=
nvmlDeviceGetHandleByIndex
(
0
,
&
(
env
.
device
));
err
=
nvmlDeviceGetTotalEnergyConsumption
(
env
.
device
,
&
(
counters
.
energy_initial
));
// FR
// 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
;
//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
/*
* 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
);
reading_t
reading
;
reading
.
timestamp
=
getTimestamp
();
// FR
nvmlReturn_t
err
;
unsigned
long
long
temp
;
// FR
try
{
for
(
auto
s
:
_sensors
)
{
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
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
counters
.
energy_previous
=
counters
.
energy_current
;
err
=
nvmlDeviceGetTotalEnergyConsumption
(
env
.
device
,
&
(
counters
.
energy_current
));
}
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
<<
"
\"
"
;
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
();
}
}
}
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
*/
/*
* TODO
* Log attributes here for debug reasons
*/
LOG_VAR
(
ll
)
<<
" NumSpacesAsIndention: "
<<
12
;
LOG_VAR
(
ll
)
<<
" NumSpacesAsIndention: "
<<
12
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment