Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale energy estimate by resource allocation in Teads model #5

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/__tests__/unit/lib/teads-curve/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ describe('teads:configure test', () => {
},
]);
});
test('scale with vcpu usage', async () => {
const outputModel = new TeadsCurveModel();
await outputModel.configure({
'thermal-design-power': 200,
});
await expect(
outputModel.execute([
{
duration: 3600,
'cpu-util': 50.0,
timestamp: '2021-01-01T00:00:00Z',
'vcpus-allocated': 1,
'vcpus-total': 64,
},
])
).resolves.toStrictEqual([
{
'energy-cpu': 0.00234375,
duration: 3600,
'cpu-util': 50.0,
timestamp: '2021-01-01T00:00:00Z',
'vcpus-allocated': 1,
'vcpus-total': 64,
},
]);
});
test('teads:initialize with params:spline', async () => {
const outputModel = new TeadsCurveModel();
await outputModel.configure({
Expand Down
4 changes: 4 additions & 0 deletions src/lib/teads-curve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ IF recognizes the Teads CPU model as `teads-curve`.
- `energy-cpu`: The energy used by the CPU, in kWh


> **Note** If `vcpus-allocated` and `vcpus-total` are available, these data will be used to scale the CPU energy usage. If they are not present, we assume the entire processor is being used. For example, if only 1 out of 64 available vCPUS are allocated, we scale the processor TDP by 1/64.



## Implementation

### Linear Interpolation
Expand Down
35 changes: 23 additions & 12 deletions src/lib/teads-curve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ export class TeadsCurveModel implements ModelPluginInterface {
this.tdp = staticParams['thermal-design-power'] as number;
}

// if ('curve' in staticParams && 'points' in staticParams) {
// this.curve = staticParams?.curve as number[];
// this.points = staticParams?.points as number[];
// if (this.curve.length !== this.points.length) {
// throw new Error(
// 'Number of points and curve values must be the same length'
// );
// }
// this.spline = new Spline(this.points, this.curve);
// }

if ('interpolation' in staticParams) {
this.interpolation = staticParams?.interpolation as Interpolation;
}
Expand All @@ -72,7 +61,29 @@ export class TeadsCurveModel implements ModelPluginInterface {
}
return inputs.map((input: KeyValuePair) => {
this.configure(input);
input['energy-cpu'] = this.calculateEnergy(input);
let energy = this.calculateEnergy(input);
let total: number;
let allocated: number;
if ('vcpus-allocated' in input && 'vcpus-total' in input) {
if (typeof input['vcpus-allocated'] === 'string') {
allocated = parseFloat(input['vcpus-allocated']);
} else if (typeof input['vcpus-allocated'] === 'number') {
allocated = input['vcpus-allocated'];
} else {
throw new Error('invalid type for vcpus-allocated');
}

if (typeof input['vcpus-total'] === 'string') {
total = parseFloat(input['vcpus-total']);
} else if (typeof input['vcpus-total'] === 'number') {
total = input['vcpus-total'];
} else {
throw new Error('invalid type for vcpus-total');
}

energy = energy * (allocated / total);
}
input['energy-cpu'] = energy;
return input;
});
}
Expand Down