Skip to content

Commit

Permalink
Merge pull request #66 from skrakau/allow_custom_tdp_input
Browse files Browse the repository at this point in the history
Allow custom CPU TDP input file
  • Loading branch information
skrakau authored Nov 8, 2023
2 parents dec095c + 973096a commit 3ec41f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion docs/usage/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ For regions, it’s the ISO alpha-2 code for the country, followed by an identif
You can find the available data [here](../../plugins/nf-co2footprint/src/resources/CI_aggregated.v2.2.csv).
Mutually exclusive with the `ci` parameter.
- `pue`: power usage effectiveness, efficiency coefficient of the data centre.
- `powerdrawMem`: power draw from memory.
- `powerdrawMem`: power draw from memory.
- `customCpuTdpFile`: Input CSV file containing custom CPU TDP data.
This should contain the following columns: `model`,`TDP`,`n_cores`,`TDP_per_core`.
Note that this overwrites TDP values for already provided CPU models.
You can find the by default used TDP data [here](../../plugins/nf-co2footprint/src/resources/TDP_cpu.v2.2.csv).
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nextflow.co2footprint

import groovy.transform.PackageScope

import groovy.util.logging.Slf4j

/**
* This class allows model an specific configuration, extracting values from a map and converting
Expand All @@ -23,6 +23,7 @@ import groovy.transform.PackageScope
* @author Júlia Mir Pedrol <[email protected]>, Sabrina Krakau <[email protected]>
*
*/
@Slf4j
@PackageScope
class CO2FootprintConfig {

Expand Down Expand Up @@ -54,7 +55,22 @@ class CO2FootprintConfig {
return localCi
}

CO2FootprintConfig(Map map){
// Load user provided file containing custom TDP values for different CPU models
protected void loadCustomCpuTdpData(Map<String, Double> data, String customCpuTdpFile) {
new File(customCpuTdpFile).withReader(){ reader ->
String line
while( line = reader.readLine() ) {
def h = line.split(",")
if ( h[0] != 'model' ) {
if ( data.containsKey(h[0]) ) log.warn "Already existing CPU model specific TDP value for ${h[0]} is overwritten with provided custom value: ${h[3]}"
data[h[0]] = h[3].toDouble()
}
}
}
log.debug "$data"
}

CO2FootprintConfig(Map map, Map<String, Double> cpuData){
def config = map ?: Collections.emptyMap()
file = config.file ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_FILE_NAME
summaryFile = config.summaryFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME
Expand All @@ -72,6 +88,9 @@ class CO2FootprintConfig {

pue = config.pue ?: 1.67
powerdrawMem = config.powerdrawMem ?: 0.3725

if (config.customCpuTdpFile)
loadCustomCpuTdpData(cpuData, config.customCpuTdpFile)
}

String getFile() { file }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class CO2FootprintFactory implements TraceObserverFactory {

@Override
Collection<TraceObserver> create(Session session) {
this.session = session
this.config = new CO2FootprintConfig(session.config.navigate('co2footprint') as Map)
loadCpuTdpData(this.cpuData)

this.session = session
this.config = new CO2FootprintConfig(session.config.navigate('co2footprint') as Map, this.cpuData)

final result = new ArrayList(2)
// Generate CO2 footprint text output files
def co2eFile = (this.config.getFile() as Path).complete()
Expand Down

0 comments on commit 3ec41f3

Please sign in to comment.