-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nvidia/query): pass events store to shared poller
Signed-off-by: Gyuho Lee <[email protected]>
- Loading branch information
Showing
7 changed files
with
275 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
components/accelerator/nvidia/query/nvml/options_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package nvml | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
|
||
"github.com/NVIDIA/go-nvml/pkg/nvml" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
events_db "github.com/leptonai/gpud/components/db" | ||
) | ||
|
||
func TestOpOptions(t *testing.T) { | ||
t.Run("default values", func(t *testing.T) { | ||
op := &Op{} | ||
err := op.applyOpts([]OpOption{}) | ||
require.NoError(t, err) | ||
|
||
// Check that default in-memory databases are created | ||
assert.NotNil(t, op.dbRW) | ||
assert.NotNil(t, op.dbRO) | ||
assert.Nil(t, op.xidEventsStore) | ||
assert.Nil(t, op.hwslowdownEventsStore) | ||
assert.Nil(t, op.gpmMetricsIDs) | ||
}) | ||
|
||
t.Run("custom values", func(t *testing.T) { | ||
mockDB := &sql.DB{} | ||
mockStore := &mockEventsStore{} | ||
testMetrics := []nvml.GpmMetricId{ | ||
nvml.GPM_METRIC_SM_OCCUPANCY, | ||
nvml.GPM_METRIC_FP32_UTIL, | ||
} | ||
|
||
op := &Op{} | ||
err := op.applyOpts([]OpOption{ | ||
WithDBRW(mockDB), | ||
WithDBRO(mockDB), | ||
WithXidEventsStore(mockStore), | ||
WithHWSlowdownEventsStore(mockStore), | ||
WithGPMMetricsID(testMetrics...), | ||
}) | ||
require.NoError(t, err) | ||
|
||
// Check custom values | ||
assert.Equal(t, mockDB, op.dbRW) | ||
assert.Equal(t, mockDB, op.dbRO) | ||
assert.Equal(t, mockStore, op.xidEventsStore) | ||
assert.Equal(t, mockStore, op.hwslowdownEventsStore) | ||
|
||
// Check GPM metrics | ||
assert.NotNil(t, op.gpmMetricsIDs) | ||
assert.Len(t, op.gpmMetricsIDs, len(testMetrics)) | ||
for _, metric := range testMetrics { | ||
_, exists := op.gpmMetricsIDs[metric] | ||
assert.True(t, exists, "Metric %v should exist in gpmMetricsIDs", metric) | ||
} | ||
}) | ||
|
||
t.Run("partial options", func(t *testing.T) { | ||
mockDB := &sql.DB{} | ||
testMetrics := []nvml.GpmMetricId{nvml.GPM_METRIC_SM_OCCUPANCY} | ||
|
||
op := &Op{} | ||
err := op.applyOpts([]OpOption{ | ||
WithDBRW(mockDB), | ||
WithGPMMetricsID(testMetrics...), | ||
}) | ||
require.NoError(t, err) | ||
|
||
// Check mixed custom and default values | ||
assert.Equal(t, mockDB, op.dbRW) | ||
assert.NotNil(t, op.dbRO) // Should create default read-only DB | ||
assert.Nil(t, op.xidEventsStore) | ||
assert.Nil(t, op.hwslowdownEventsStore) | ||
|
||
// Check GPM metrics | ||
assert.NotNil(t, op.gpmMetricsIDs) | ||
assert.Len(t, op.gpmMetricsIDs, 1) | ||
_, exists := op.gpmMetricsIDs[nvml.GPM_METRIC_SM_OCCUPANCY] | ||
assert.True(t, exists) | ||
}) | ||
|
||
t.Run("multiple GPM metrics", func(t *testing.T) { | ||
op := &Op{} | ||
// Add metrics in multiple calls to test accumulation | ||
err := op.applyOpts([]OpOption{ | ||
WithGPMMetricsID(nvml.GPM_METRIC_SM_OCCUPANCY), | ||
WithGPMMetricsID(nvml.GPM_METRIC_FP32_UTIL), | ||
}) | ||
require.NoError(t, err) | ||
|
||
assert.Len(t, op.gpmMetricsIDs, 2) | ||
_, exists := op.gpmMetricsIDs[nvml.GPM_METRIC_SM_OCCUPANCY] | ||
assert.True(t, exists) | ||
_, exists = op.gpmMetricsIDs[nvml.GPM_METRIC_FP32_UTIL] | ||
assert.True(t, exists) | ||
}) | ||
} | ||
|
||
// mockEventsStore implements events_db.Store interface for testing | ||
type mockEventsStore struct { | ||
events_db.Store | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package query | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
|
||
events_db "github.com/leptonai/gpud/components/db" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOpOptions(t *testing.T) { | ||
t.Run("default values", func(t *testing.T) { | ||
op := &Op{} | ||
err := op.applyOpts([]OpOption{}) | ||
assert.NoError(t, err) | ||
|
||
// Check default values | ||
assert.Equal(t, "nvidia-smi", op.nvidiaSMICommand) | ||
assert.Equal(t, "nvidia-smi --query", op.nvidiaSMIQueryCommand) | ||
assert.Equal(t, "ibstat", op.ibstatCommand) | ||
assert.Equal(t, "/sys/class/infiniband", op.infinibandClassDirectory) | ||
assert.False(t, op.debug) | ||
}) | ||
|
||
t.Run("custom values", func(t *testing.T) { | ||
mockDB := &sql.DB{} | ||
mockStore := &mockEventsStore{} | ||
|
||
op := &Op{} | ||
err := op.applyOpts([]OpOption{ | ||
WithDBRW(mockDB), | ||
WithDBRO(mockDB), | ||
WithXidEventsStore(mockStore), | ||
WithHWSlowdownEventsStore(mockStore), | ||
WithNvidiaSMICommand("/custom/nvidia-smi"), | ||
WithNvidiaSMIQueryCommand("/custom/nvidia-smi-query"), | ||
WithIbstatCommand("/custom/ibstat"), | ||
WithInfinibandClassDirectory("/custom/infiniband"), | ||
WithDebug(true), | ||
}) | ||
|
||
assert.NoError(t, err) | ||
|
||
// Check custom values | ||
assert.Equal(t, mockDB, op.dbRW) | ||
assert.Equal(t, mockDB, op.dbRO) | ||
assert.Equal(t, mockStore, op.xidEventsStore) | ||
assert.Equal(t, mockStore, op.hwslowdownEventsStore) | ||
assert.Equal(t, "/custom/nvidia-smi", op.nvidiaSMICommand) | ||
assert.Equal(t, "/custom/nvidia-smi-query", op.nvidiaSMIQueryCommand) | ||
assert.Equal(t, "/custom/ibstat", op.ibstatCommand) | ||
assert.Equal(t, "/custom/infiniband", op.infinibandClassDirectory) | ||
assert.True(t, op.debug) | ||
}) | ||
|
||
t.Run("partial options", func(t *testing.T) { | ||
op := &Op{} | ||
err := op.applyOpts([]OpOption{ | ||
WithNvidiaSMICommand("/custom/nvidia-smi"), | ||
WithDebug(true), | ||
}) | ||
|
||
assert.NoError(t, err) | ||
|
||
// Check mixed default and custom values | ||
assert.Equal(t, "/custom/nvidia-smi", op.nvidiaSMICommand) | ||
assert.Equal(t, "nvidia-smi --query", op.nvidiaSMIQueryCommand) | ||
assert.Equal(t, "ibstat", op.ibstatCommand) | ||
assert.Equal(t, "/sys/class/infiniband", op.infinibandClassDirectory) | ||
assert.True(t, op.debug) | ||
}) | ||
} | ||
|
||
// mockEventsStore implements events_db.Store interface for testing | ||
type mockEventsStore struct { | ||
events_db.Store | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters