Skip to content

Commit ebf9496

Browse files
sriram-30y2kenny-amd
authored andcommitted
ParseTopologyPropertiesString helper function
Added a helper function for parsing topology properties file for string values which will be used in the next commit to parse unique_id field and added corresponding UT similar to existing UT for TestParseTopologyProperties
1 parent 0c31bd2 commit ebf9496

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

internal/pkg/amdgpu/amdgpu.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,33 @@ func ParseTopologyProperties(path string, re *regexp.Regexp) (int64, error) {
293293
return v, e
294294
}
295295

296+
// ParseTopologyProperties parse for a property value in kfd topology file as string
297+
// The format is usually one entry per line <name> <value>. Examples in
298+
// testdata/topology-parsing/.
299+
func ParseTopologyPropertiesString(path string, re *regexp.Regexp) (string, error) {
300+
f, e := os.Open(path)
301+
if e != nil {
302+
return "", e
303+
}
304+
305+
e = errors.New("Topology property not found. Regex: " + re.String())
306+
v := ""
307+
scanner := bufio.NewScanner(f)
308+
for scanner.Scan() {
309+
m := re.FindStringSubmatch(scanner.Text())
310+
if m == nil {
311+
continue
312+
}
313+
314+
v = m[1]
315+
e = nil
316+
break
317+
}
318+
f.Close()
319+
320+
return v, e
321+
}
322+
296323
var fwVersionRe = regexp.MustCompile(`(\w+) feature version: (\d+), firmware version: (0x[0-9a-fA-F]+)`)
297324

298325
func parseDebugFSFirmwareInfo(path string) (map[string]uint32, map[string]uint32) {

internal/pkg/amdgpu/amdgpu_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ func TestParseTopologyProperties(t *testing.T) {
161161
}
162162

163163
}
164+
165+
func TestParseTopologyPropertiesString(t *testing.T) {
166+
var v string
167+
var re *regexp.Regexp
168+
var path string
169+
170+
re = regexp.MustCompile(`unique_id\s(\d+)`)
171+
path = "../../../testdata/topology-parsing/topology/nodes/2/properties"
172+
v, _ = ParseTopologyPropertiesString(path, re)
173+
if v != "14073402507705256557" {
174+
t.Errorf("Error parsing %s for `%s`: expect %s", path, re.String(), "14073402507705256557")
175+
}
176+
177+
}
178+
164179
func TestParseDebugFSFirmwareInfo(t *testing.T) {
165180
expFeat := map[string]uint32{
166181
"VCE": 0,

testdata/topology-parsing/topology/nodes/1/properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ local_mem_size 17163091968
2323
fw_version 392
2424
capability 8832
2525
sdma_fw_version 421
26+
unique_id 14073402507705256556
2627
max_engine_clk_ccompute 3200

testdata/topology-parsing/topology/nodes/2/properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ local_mem_size 17163091968
2323
fw_version 392
2424
capability 8832
2525
sdma_fw_version 421
26+
unique_id 14073402507705256557
2627
max_engine_clk_ccompute 3200

0 commit comments

Comments
 (0)