Skip to content

Commit 52541e8

Browse files
authored
Fix #1410. (#1412)
The libdrm replacement for ROCm images will first search the typical location for the amdgpu.ids file. If failed, it will search as it did before in the python install location.
1 parent 60c79a8 commit 52541e8

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

common/install_rocm_drm.sh

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ pushd drm
3232
###########################
3333
patch -p1 <<'EOF'
3434
diff --git a/amdgpu/amdgpu_asic_id.c b/amdgpu/amdgpu_asic_id.c
35-
index a5007ffc..a3627529 100644
35+
index a5007ffc..13fa07fc 100644
3636
--- a/amdgpu/amdgpu_asic_id.c
3737
+++ b/amdgpu/amdgpu_asic_id.c
3838
@@ -22,6 +22,13 @@
3939
*
4040
*/
41-
41+
4242
+#define _XOPEN_SOURCE 700
4343
+#define _LARGEFILE64_SOURCE
4444
+#define _FILE_OFFSET_BITS 64
@@ -49,20 +49,18 @@ index a5007ffc..a3627529 100644
4949
#include <ctype.h>
5050
#include <stdio.h>
5151
#include <stdlib.h>
52-
@@ -34,6 +41,21 @@
52+
@@ -34,6 +41,19 @@
5353
#include "amdgpu_drm.h"
5454
#include "amdgpu_internal.h"
55-
55+
5656
+static char *amdgpuids_path = NULL;
57+
+static const char* amdgpuids_path_msg = NULL;
5758
+
5859
+static int check_for_location_of_amdgpuids(const char *filepath, const struct stat *info, const int typeflag, struct FTW *pathinfo)
5960
+{
6061
+ if (typeflag == FTW_F && strstr(filepath, "amdgpu.ids")) {
61-
+ if (NULL != amdgpuids_path) {
62-
+ free(amdgpuids_path);
63-
+ }
6462
+ amdgpuids_path = strdup(filepath);
65-
+ return 0;
63+
+ return 1;
6664
+ }
6765
+
6866
+ return 0;
@@ -71,16 +69,20 @@ index a5007ffc..a3627529 100644
7169
static int parse_one_line(struct amdgpu_device *dev, const char *line)
7270
{
7371
char *buf, *saveptr;
74-
@@ -113,13 +135,48 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
72+
@@ -113,10 +133,46 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
7573
int line_num = 1;
7674
int r = 0;
77-
78-
- fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
75+
76+
+ // attempt to find typical location for amdgpu.ids file
77+
fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
78+
+
79+
+ // if it doesn't exist, search
80+
+ if (!fp) {
81+
+
7982
+ char self_path[ PATH_MAX ];
8083
+ ssize_t count;
8184
+ ssize_t i;
8285
+
83-
+ fp = NULL;
8486
+ count = readlink( "/proc/self/exe", self_path, PATH_MAX );
8587
+ if (count > 0) {
8688
+ self_path[count] = '\0';
@@ -97,30 +99,43 @@ index a5007ffc..a3627529 100644
9799
+ }
98100
+ self_path[i] = '\0';
99101
+
100-
+ if (0 == nftw(self_path, check_for_location_of_amdgpuids, 5, FTW_PHYS)) {
101-
+ if (amdgpuids_path) {
102-
+ fp = fopen(amdgpuids_path, "r");
103-
+ if (!fp) {
104-
+ fprintf(stderr, "%s: %s\n", amdgpuids_path, strerror(errno));
105-
+ }
106-
+ }
102+
+ if (1 == nftw(self_path, check_for_location_of_amdgpuids, 5, FTW_PHYS)) {
103+
+ fp = fopen(amdgpuids_path, "r");
104+
+ amdgpuids_path_msg = amdgpuids_path;
107105
+ }
108106
+ }
109107
+
110-
+ if (!fp) {
108+
+ }
109+
+ else {
110+
+ amdgpuids_path_msg = AMDGPU_ASIC_ID_TABLE;
111+
+ }
111112
+
112-
+ fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
113+
+ // both hard-coded location and search have failed
113114
if (!fp) {
114-
fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
115-
strerror(errno));
115+
- fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
116+
- strerror(errno));
117+
+ fprintf(stderr, "amdgpu.ids: No such file or directory\n");
116118
return;
117119
}
118-
119-
+ }
120-
+
121-
/* 1st valid line is file version */
122-
while ((n = getline(&line, &len, fp)) != -1) {
123-
/* trim trailing newline */
120+
121+
@@ -132,7 +188,7 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
122+
continue;
123+
}
124+
125+
- drmMsg("%s version: %s\n", AMDGPU_ASIC_ID_TABLE, line);
126+
+ drmMsg("%s version: %s\n", amdgpuids_path_msg, line);
127+
break;
128+
}
129+
130+
@@ -150,7 +206,7 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
131+
132+
if (r == -EINVAL) {
133+
fprintf(stderr, "Invalid format: %s: line %d: %s\n",
134+
- AMDGPU_ASIC_ID_TABLE, line_num, line);
135+
+ amdgpuids_path_msg, line_num, line);
136+
} else if (r && r != -EAGAIN) {
137+
fprintf(stderr, "%s: Cannot parse ASIC IDs: %s\n",
138+
__func__, strerror(-r));
124139
EOF
125140

126141
###########################

0 commit comments

Comments
 (0)