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

chore: load cpu architecture dependent models #1800

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Binary file modified pkg/bpf/kepler_bpfeb.o
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these files shouldn't change at all 🤔

Binary file not shown.
Binary file modified pkg/bpf/kepler_bpfel.o
Binary file not shown.
Binary file modified pkg/bpftest/test_bpfeb.o
Binary file not shown.
Binary file modified pkg/bpftest/test_bpfel.o
Binary file not shown.
14 changes: 12 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,18 @@ func setModelServerReqEndpoint() string {

// return local path to power model weight
// e.g., /var/lib/kepler/data/model_weight/acpi_AbsPowerModel.json
func GetDefaultPowerModelURL(modelOutputType, energySource string) string {
return fmt.Sprintf(`/var/lib/kepler/data/model_weight/%s_%sModel.json`, energySource, modelOutputType)
func GetDefaultPowerModelURL(modelOutputType, energySource, cpuArch string) string {
// strip white space or new line from cpuArch
cpuArch = strings.TrimSuffix(cpuArch, "\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TrimSpace should remove \n characters and white space, so you can remove this line

cpuArch = strings.TrimSpace(cpuArch)
fullPath := fmt.Sprintf(`/var/lib/kepler/data/%s/model_weight/%s_%sModel.json`, cpuArch, energySource, modelOutputType)
// if the model does not exist, return the default model
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this result in a possible race condition? If you can guarantee that after the os.Stat the file exists, then ignore this comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a minor note, os.isNotExist(err) might be misleading as os.Stat can return other types of errors which is not the same as a file/model not existing.

klog.Warningf("model %s does not exist, using default model", fullPath)
return fmt.Sprintf(`/var/lib/kepler/data/model_weight/%s_%sModel.json`, energySource, modelOutputType)
}
// otherwise, return the full path
return fullPath
}

func logBoolConfigs() {
Expand Down
19 changes: 10 additions & 9 deletions pkg/model/estimator/local/regressor/regressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"github.com/sustainable-computing-io/kepler/pkg/config"
"github.com/sustainable-computing-io/kepler/pkg/model/types"
"github.com/sustainable-computing-io/kepler/pkg/node"
"github.com/sustainable-computing-io/kepler/pkg/sensors/components/source"
)

Expand Down Expand Up @@ -142,7 +143,7 @@ func genRegressor(outputType types.ModelOutputType, energySource, modelServerEnd

func GetNodePlatformPowerFromDummyServer(handler http.HandlerFunc, trainer string) (power []uint64) {
testServer := httptest.NewServer(handler)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.PlatformEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.PlatformEnergySource, node.CPUArchitecture())
r := genRegressor(types.AbsPower, types.PlatformEnergySource, testServer.URL, "", modelWeightFilepath, trainer)
err := r.Start()
Expect(err).To(BeNil())
Expand All @@ -156,7 +157,7 @@ func GetNodePlatformPowerFromDummyServer(handler http.HandlerFunc, trainer strin

func GetNodeComponentsPowerFromDummyServer(handler http.HandlerFunc, trainer string) (compPowers []source.NodeComponentsEnergy) {
testServer := httptest.NewServer(handler)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.ComponentEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.ComponentEnergySource, node.CPUArchitecture())
r := genRegressor(types.AbsPower, types.ComponentEnergySource, testServer.URL, "", modelWeightFilepath, trainer)
err := r.Start()
Expect(err).To(BeNil())
Expand Down Expand Up @@ -184,7 +185,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {

It("Get Process Platform Power By Default Regression Estimator with ModelServerEndpoint", func() {
testServer := httptest.NewServer(DummyWeightHandler)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.PlatformEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.PlatformEnergySource, node.CPUArchitecture())
r := genRegressor(types.DynPower, types.PlatformEnergySource, testServer.URL, "", modelWeightFilepath, "")
err := r.Start()
Expect(err).To(BeNil())
Expand All @@ -205,7 +206,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {

It("Get Process Components Power By Default Regression Estimator with ModelServerEndpoint", func() {
testServer := httptest.NewServer(DummyWeightHandler)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.ComponentEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.ComponentEnergySource, node.CPUArchitecture())
r := genRegressor(types.DynPower, types.ComponentEnergySource, testServer.URL, "", modelWeightFilepath, "")
err := r.Start()
Expect(err).To(BeNil())
Expand All @@ -229,7 +230,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {
Context("without model server", func() {
It("Get Node Platform Power By Default Regression Estimator without ModelServerEndpoint", func() {
/// Estimate Node Components Power using Linear Regression
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.ComponentEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.ComponentEnergySource, node.CPUArchitecture())
initModelURL := "https://raw.githubusercontent.com/sustainable-computing-io/kepler-model-db/main/models/v0.6/nx12/std_v0.6/acpi/AbsPower/BPFOnly/SGDRegressorTrainer_1.json"
r := genRegressor(types.AbsPower, types.PlatformEnergySource, "", initModelURL, modelWeightFilepath, "")
err := r.Start()
Expand All @@ -242,7 +243,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {

It("Get Node Components Power By Default Regression Estimator without ModelServerEndpoint", func() {
/// Estimate Node Components Power using Linear Regression
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.ComponentEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.AbsPower.String(), types.ComponentEnergySource, node.CPUArchitecture())
initModelURL := "https://raw.githubusercontent.com/sustainable-computing-io/kepler-model-db/main/models/v0.6/nx12/std_v0.6/rapl/AbsPower/BPFOnly/SGDRegressorTrainer_1.json"
r := genRegressor(types.AbsPower, types.ComponentEnergySource, "", initModelURL, modelWeightFilepath, "")
err := r.Start()
Expand All @@ -255,7 +256,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {

It("Get Process Components Power By Default Regression Estimator without ModelServerEndpoint", func() {
// Estimate Process Components Power using Linear Regression
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.ComponentEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.ComponentEnergySource, node.CPUArchitecture())
initModelURL := "https://raw.githubusercontent.com/sustainable-computing-io/kepler-model-db/main/models/v0.6/nx12/std_v0.6/acpi/DynPower/BPFOnly/SGDRegressorTrainer_1.json"
r := genRegressor(types.DynPower, types.PlatformEnergySource, "", initModelURL, modelWeightFilepath, "")
err := r.Start()
Expand All @@ -270,7 +271,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {

It("Get Process Components Power By Default Regression Estimator without ModelServerEndpoint", func() {
// Estimate Process Components Power using Linear Regression
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.ComponentEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.ComponentEnergySource, node.CPUArchitecture())
initModelURL := "https://raw.githubusercontent.com/sustainable-computing-io/kepler-model-db/main/models/v0.6/nx12/std_v0.6/rapl/DynPower/BPFOnly/SGDRegressorTrainer_1.json"
r := genRegressor(types.DynPower, types.ComponentEnergySource, "", initModelURL, modelWeightFilepath, "")
err := r.Start()
Expand All @@ -288,7 +289,7 @@ var _ = Describe("Test Regressor Weight Unit (default trainer)", func() {
DescribeTable("Test core ratio computation", func(discoveredCore, modelCores int, expectedCoreRatio float64) {
ModelCores = modelCores
testServer := httptest.NewServer(DummyWeightHandler)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.PlatformEnergySource)
modelWeightFilepath := config.GetDefaultPowerModelURL(types.DynPower.String(), types.PlatformEnergySource, node.CPUArchitecture())
r := genRegressor(types.DynPower, types.PlatformEnergySource, testServer.URL, "", modelWeightFilepath, "")
r.DiscoveredMachineSpec = &config.MachineSpec{
Cores: discoveredCore,
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/node_component_energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func createNodeComponentPowerModelConfig(nodeFeatureNames []string) *types.Model
systemMetaDataFeatureValues := node.MetadataFeatureValues()
modelConfig := CreatePowerModelConfig(config.NodeComponentsPowerKey())
if modelConfig.InitModelURL == "" {
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), types.ComponentEnergySource)
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), types.ComponentEnergySource, node.CPUArchitecture())
}
modelConfig.NodeFeatureNames = nodeFeatureNames
modelConfig.SystemMetaDataFeatureNames = systemMetaDataFeatureNames
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/node_platform_energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func CreateNodePlatformPoweEstimatorModel(nodeFeatureNames []string) {
if !platform.IsSystemCollectionSupported() {
modelConfig := CreatePowerModelConfig(config.NodePlatformPowerKey())
if modelConfig.InitModelURL == "" {
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), types.PlatformEnergySource)
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), types.PlatformEnergySource, node.CPUArchitecture())
}
modelConfig.NodeFeatureNames = nodeFeatureNames
modelConfig.SystemMetaDataFeatureNames = systemMetaDataFeatureNames
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/process_energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func createProcessPowerModelConfig(powerSourceTarget string, processFeatureNames
return nil
}
if modelConfig.InitModelURL == "" {
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), energySource)
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), energySource, node.CPUArchitecture())
}
modelConfig.ProcessFeatureNames = processFeatureNames
modelConfig.SystemMetaDataFeatureNames = systemMetaDataFeatureNames
Expand Down
Loading