Skip to contentSkip to conversation

app/mldev: fix build with debug

PATCH Superseded David Marchand 3 participants 7 messages Mar 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 app/mldev: fix build with debug

Compiling with -O0 and -g triggers these warnings:

../app/test-mldev/test_inference_common.c: In function
‘ml_request_finish’:
../app/test-mldev/test_inference_common.c:946:51:
error: ‘.q.’ directive output may be truncated writing 3 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
946 | snprintf(str, sizeof(str) - 1, "%s.q.%d",

      |                                                   ^~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:946:48: note: using the range
	[-2147483648, 2147483647] for directive argument
  946 |                 snprintf(str, sizeof(str) - 1, "%s.q.%d",
      |                                                ^~~~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:946:17: note: ‘snprintf’
	output between 5 and 4110 bytes into a destination of size 4095
  946 |                 snprintf(str, sizeof(str) - 1, "%s.q.%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);

../app/test-mldev/test_inference_common.c:952:51: error: ‘.’ directive
output may be truncated writing 1 byte into a region of size between 0 and 4095 [-Werror=format-truncation=]
952 | snprintf(str, sizeof(str) - 1, "%s.%d",

      |                                                   ^
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:48: note: using the range
	[-2147483648, 2147483647] for directive argument
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                                                ^~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:17: note: ‘snprintf’
	output between 3 and 4108 bytes into a destination of size 4095
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);

../app/test-mldev/test_inference_common.c:929:51: error: ‘.q’ directive
output may be truncated writing 2 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
929 | snprintf(str, sizeof(str) - 1, "%s.q",

      |                                                   ^~
	t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:929:17: note: ‘snprintf’
	output between 3 and 4098 bytes into a destination of size 4095
  929 |                 snprintf(str, sizeof(str) - 1, "%s.q",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output);

../app/test-mldev/test_inference_common.c:935:51: error: ‘snprintf’
output may be truncated before the last format character [-Werror=format-truncation=]
935 | snprintf(str, sizeof(str) - 1, "%s",

      |                                                   ^
	t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:935:17: note: ‘snprintf’
	output between 1 and 4096 bytes into a destination of size 4095
  935 |                 snprintf(str, sizeof(str) - 1, "%s",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output);

Fix unsigned integer format, and switch to dynamic allocations.

Fixes da6793390596 ("app/mldev: support inference validation")
---
 app/test-mldev/test_inference_common.c | 29 ++++++++++++++++++--------
 1 file changed, 20 insertions(+), 9 deletions(-)
app/test-mldev/test_inference_common.c +20 -9
index e85f32be60..f7ce732d9a 100644
@@ -3,6 +3,7 @@
  */
 
 #include <errno.h>
+#include <stdio.h>
 #include <unistd.h>
 
 #include <rte_common.h>
@@ -901,8 +902,8 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 	struct test_inference *t = ml_test_priv((struct ml_test *)opaque);
 	struct ml_request *req = (struct ml_request *)obj;
 	struct ml_model *model = &t->model[req->fid];
-	char str[PATH_MAX];
 	bool error = false;
+	char *dump_path;
 
 	RTE_SET_USED(mp);
 
@@ -926,14 +927,18 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 dump_output_pass:
 	if (obj_idx == 0) {
 		/* write quantized output */
-		snprintf(str, PATH_MAX, "%s.q", t->cmn.opt->filelist[req->fid].output);
-		ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+		if (asprintf(&dump_path, "%s.q", t->cmn.opt->filelist[req->fid].output) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+		free(dump_path);
 		if (error)
 			return;
 
 		/* write dequantized output */
-		snprintf(str, PATH_MAX, "%s", t->cmn.opt->filelist[req->fid].output);
-		ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error);
+		if (asprintf(&dump_path, "%s", t->cmn.opt->filelist[req->fid].output) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, model->output, model->out_dsize, error);
+		free(dump_path);
 		if (error)
 			return;
 	}
@@ -943,14 +948,20 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 dump_output_fail:
 	if (t->cmn.opt->debug) {
 		/* dump quantized output buffer */
-		snprintf(str, PATH_MAX, "%s.q.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
-		ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+		if (asprintf(&dump_path, "%s.q.%d", t->cmn.opt->filelist[req->fid].output,
+				obj_idx) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+		free(dump_path);
 		if (error)
 			return;
 
 		/* dump dequantized output buffer */
-		snprintf(str, PATH_MAX, "%s.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
-		ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error);
+		if (asprintf(&dump_path, "%s.%d", t->cmn.opt->filelist[req->fid].output,
+				obj_idx) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, model->output, model->out_dsize, error);
+		free(dump_path);
 		if (error)
 			return;
 	}
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 ci: test compilation with debug

We often miss compilation issues with -O0 -g.
Add a test in GHA.

---
 .ci/linux-build.sh          | 8 +++++++-
 .github/workflows/build.yml | 4 ++++
 2 files changed, 11 insertions(+), 1 deletion(-)
.ci/linux-build.sh +7 -1
index ab0994388a..150b38bd7a 100755
@@ -65,6 +65,12 @@ if [ "$RISCV64" = "true" ]; then
     cross_file=config/riscv/riscv64_linux_gcc
 fi
 
+buildtype=debugoptimized
+
+if [ "$BUILD_DEBUG" = "true" ]; then
+    buildtype=debug
+fi
+
 if [ "$BUILD_DOCS" = "true" ]; then
     OPTS="$OPTS -Denable_docs=true"
 fi
@@ -85,7 +91,7 @@ fi
 
 OPTS="$OPTS -Dplatform=generic"
 OPTS="$OPTS -Ddefault_library=$DEF_LIB"
-OPTS="$OPTS -Dbuildtype=debugoptimized"
+OPTS="$OPTS -Dbuildtype=$buildtype"
 OPTS="$OPTS -Dcheck_includes=true"
 if [ "$MINI" = "true" ]; then
     OPTS="$OPTS -Denable_drivers=net/null"
.github/workflows/build.yml +4 -0
index 154be70cc1..d90ecfc6f0 100644
@@ -18,6 +18,7 @@ jobs:
       ABI_CHECKS: ${{ contains(matrix.config.checks, 'abi') }}
       ASAN: ${{ contains(matrix.config.checks, 'asan') }}
       BUILD_32BIT: ${{ matrix.config.cross == 'i386' }}
+      BUILD_DEBUG: ${{ contains(matrix.config.checks, 'debug') }}
       BUILD_DOCS: ${{ contains(matrix.config.checks, 'doc') }}
       CC: ccache ${{ matrix.config.compiler }}
       DEF_LIB: ${{ matrix.config.library }}
@@ -37,6 +38,9 @@ jobs:
           - os: ubuntu-20.04
             compiler: gcc
             mini: mini
+          - os: ubuntu-20.04
+            compiler: gcc
+            checks: debug
           - os: ubuntu-20.04
             compiler: gcc
             checks: abi+doc+tests
Signature · 1 line
2.39.2
#2 lore raw
In reply to David Marchand
Quoted 10 lines · David Marchand

../app/test-mldev/test_inference_common.c:952:48: note: using the range

        [-2147483648, 2147483647] for directive argument
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                                                ^~~~~~~
        t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:17: note: ‘snprintf’
        output between 3 and 4108 bytes into a destination of size 4095
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        t->cmn.opt->filelist[req->fid].output, obj_idx);

[...]

Quoted 3 lines

Fix unsigned integer format, and switch to dynamic allocations.

[...]

app/test-mldev/test_inference_common.c ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int · line 951

Quoted 7 lines
app/test-mldev/test_inference_common.c +1 -2
@@ -943,14 +948,20 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 dump_output_fail:
        if (t->cmn.opt->debug) {
                /* dump quantized output buffer */
-               snprintf(str, PATH_MAX, "%s.q.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
-               ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+               if (asprintf(&dump_path, "%s.q.%d", t->cmn.opt->filelist[req->fid].output,

Sent the wrong patch... I forgot to add the change (fixing with %u) when amending the commitlog.

Quoted 7 lines
app/test-mldev/test_inference_common.c +4 -0
+                               obj_idx) == -1)
+                       return;
+               ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+               free(dump_path);
                if (error)
                        return;
 
Signature · 1 line
David Marchand
#3 lore raw
Quoted 41 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: 20 March 2023 16:11
To: [email protected]
Cc: Srikanth Yalavarthi <[email protected]>; Anup Prabhu <[email protected]>
Subject: [EXT] Re: [PATCH 1/2] app/mldev: fix build with debug

External Email

----------------------------------------------------------------------

Quoted 10 lines · David Marchand

../app/test-mldev/test_inference_common.c:952:48: note: using the range

        [-2147483648, 2147483647] for directive argument
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                                                ^~~~~~~
        t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:17: note: ‘snprintf’
        output between 3 and 4108 bytes into a destination of size 4095
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        t->cmn.opt->filelist[req->fid].output, obj_idx);

[...]

Quoted 3 lines

Fix unsigned integer format, and switch to dynamic allocations.

[...]

Review ml_request_finish(struct rte_mempool *mp, void · line 949

Quoted 8 lines
(quoted diff) +0 -2
@@ -943,14 +948,20 @@ ml_request_finish(struct rte_mempool *mp, void
 *opaque, void *obj, unsigned int
 dump_output_fail:
        if (t->cmn.opt->debug) {
                /* dump quantized output buffer */
-               snprintf(str, PATH_MAX, "%s.q.%d", t->cmn.opt->filelist[req-
 fid].output, obj_idx);
-               ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize,

error);

Quoted 5 lines

Review ml_request_finish(struct rte_mempool *mp, void · line 954

Quoted 2 lines
(quoted diff) +2 -0
+               if (asprintf(&dump_path, "%s.q.%d",
+ t->cmn.opt->filelist[req->fid].output,

Sent the wrong patch... I forgot to add the change (fixing with %u) when amending the commitlog.

Acked with the format specifier changes. %d to be replaced with %u.

Quoted 14 lines

app/test-mldev/test_inference_common.c ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int · line 958

Quoted 10 lines
app/test-mldev/test_inference_common.c +4 -0
+                               obj_idx) == -1)
+                       return;
+               ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model-
 out_qsize, error);
+               free(dump_path);
                if (error)
                        return;
 

--
David Marchand

#4 lore raw

PATCH v2 1/2 app/mldev: fix build with debug

In reply to David Marchand

Compiling with -O0 and -g triggers these warnings:

../app/test-mldev/test_inference_common.c: In function
‘ml_request_finish’:
../app/test-mldev/test_inference_common.c:946:51:
error: ‘.q.’ directive output may be truncated writing 3 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
946 | snprintf(str, sizeof(str) - 1, "%s.q.%d",

      |                                                   ^~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:946:48: note: using the range
	[-2147483648, 2147483647] for directive argument
  946 |                 snprintf(str, sizeof(str) - 1, "%s.q.%d",
      |                                                ^~~~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:946:17: note: ‘snprintf’
	output between 5 and 4110 bytes into a destination of size 4095
  946 |                 snprintf(str, sizeof(str) - 1, "%s.q.%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);

../app/test-mldev/test_inference_common.c:952:51: error: ‘.’ directive
output may be truncated writing 1 byte into a region of size between 0 and 4095 [-Werror=format-truncation=]
952 | snprintf(str, sizeof(str) - 1, "%s.%d",

      |                                                   ^
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:48: note: using the range
	[-2147483648, 2147483647] for directive argument
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                                                ^~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:17: note: ‘snprintf’
	output between 3 and 4108 bytes into a destination of size 4095
  952 |                 snprintf(str, sizeof(str) - 1, "%s.%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output, obj_idx);

../app/test-mldev/test_inference_common.c:929:51: error: ‘.q’ directive
output may be truncated writing 2 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
929 | snprintf(str, sizeof(str) - 1, "%s.q",

      |                                                   ^~
	t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:929:17: note: ‘snprintf’
	output between 3 and 4098 bytes into a destination of size 4095
  929 |                 snprintf(str, sizeof(str) - 1, "%s.q",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output);

../app/test-mldev/test_inference_common.c:935:51: error: ‘snprintf’
output may be truncated before the last format character [-Werror=format-truncation=]
935 | snprintf(str, sizeof(str) - 1, "%s",

      |                                                   ^
	t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:935:17: note: ‘snprintf’
	output between 1 and 4096 bytes into a destination of size 4095
  935 |                 snprintf(str, sizeof(str) - 1, "%s",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	t->cmn.opt->filelist[req->fid].output);

Fix unsigned integer format, and switch to dynamic allocations.

Fixes da6793390596 ("app/mldev: support inference validation")

---
Changes since v1:
- updated integer format as mentionned in v1 commitlog,

---
 app/test-mldev/test_inference_common.c | 29 ++++++++++++++++++--------
 1 file changed, 20 insertions(+), 9 deletions(-)
app/test-mldev/test_inference_common.c +20 -9
index e85f32be60..eba37c50e9 100644
@@ -3,6 +3,7 @@
  */
 
 #include <errno.h>
+#include <stdio.h>
 #include <unistd.h>
 
 #include <rte_common.h>
@@ -901,8 +902,8 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 	struct test_inference *t = ml_test_priv((struct ml_test *)opaque);
 	struct ml_request *req = (struct ml_request *)obj;
 	struct ml_model *model = &t->model[req->fid];
-	char str[PATH_MAX];
 	bool error = false;
+	char *dump_path;
 
 	RTE_SET_USED(mp);
 
@@ -926,14 +927,18 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 dump_output_pass:
 	if (obj_idx == 0) {
 		/* write quantized output */
-		snprintf(str, PATH_MAX, "%s.q", t->cmn.opt->filelist[req->fid].output);
-		ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+		if (asprintf(&dump_path, "%s.q", t->cmn.opt->filelist[req->fid].output) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+		free(dump_path);
 		if (error)
 			return;
 
 		/* write dequantized output */
-		snprintf(str, PATH_MAX, "%s", t->cmn.opt->filelist[req->fid].output);
-		ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error);
+		if (asprintf(&dump_path, "%s", t->cmn.opt->filelist[req->fid].output) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, model->output, model->out_dsize, error);
+		free(dump_path);
 		if (error)
 			return;
 	}
@@ -943,14 +948,20 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
 dump_output_fail:
 	if (t->cmn.opt->debug) {
 		/* dump quantized output buffer */
-		snprintf(str, PATH_MAX, "%s.q.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
-		ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+		if (asprintf(&dump_path, "%s.q.%u", t->cmn.opt->filelist[req->fid].output,
+				obj_idx) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+		free(dump_path);
 		if (error)
 			return;
 
 		/* dump dequantized output buffer */
-		snprintf(str, PATH_MAX, "%s.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
-		ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error);
+		if (asprintf(&dump_path, "%s.%u", t->cmn.opt->filelist[req->fid].output,
+				obj_idx) == -1)
+			return;
+		ML_OPEN_WRITE_GET_ERR(dump_path, model->output, model->out_dsize, error);
+		free(dump_path);
 		if (error)
 			return;
 	}
Signature · 1 line
2.39.2
#5 lore raw

PATCH v2 2/2 ci: test compilation with debug in GHA

We often miss compilation issues with -O0 -g.
Switch to debug in GHA for the gcc job.

---
Changes since v1:
- rather than introduce a new job, updated the ABI check job to build with debug,

---
 .ci/linux-build.sh          | 8 +++++++-
 .github/workflows/build.yml | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
.ci/linux-build.sh +7 -1
index ab0994388a..150b38bd7a 100755
@@ -65,6 +65,12 @@ if [ "$RISCV64" = "true" ]; then
     cross_file=config/riscv/riscv64_linux_gcc
 fi
 
+buildtype=debugoptimized
+
+if [ "$BUILD_DEBUG" = "true" ]; then
+    buildtype=debug
+fi
+
 if [ "$BUILD_DOCS" = "true" ]; then
     OPTS="$OPTS -Denable_docs=true"
 fi
@@ -85,7 +91,7 @@ fi
 
 OPTS="$OPTS -Dplatform=generic"
 OPTS="$OPTS -Ddefault_library=$DEF_LIB"
-OPTS="$OPTS -Dbuildtype=debugoptimized"
+OPTS="$OPTS -Dbuildtype=$buildtype"
 OPTS="$OPTS -Dcheck_includes=true"
 if [ "$MINI" = "true" ]; then
     OPTS="$OPTS -Denable_drivers=net/null"
.github/workflows/build.yml +2 -1
index 154be70cc1..bbcb535afb 100644
@@ -18,6 +18,7 @@ jobs:
       ABI_CHECKS: ${{ contains(matrix.config.checks, 'abi') }}
       ASAN: ${{ contains(matrix.config.checks, 'asan') }}
       BUILD_32BIT: ${{ matrix.config.cross == 'i386' }}
+      BUILD_DEBUG: ${{ contains(matrix.config.checks, 'debug') }}
       BUILD_DOCS: ${{ contains(matrix.config.checks, 'doc') }}
       CC: ccache ${{ matrix.config.compiler }}
       DEF_LIB: ${{ matrix.config.library }}
@@ -39,7 +40,7 @@ jobs:
             mini: mini
           - os: ubuntu-20.04
             compiler: gcc
-            checks: abi+doc+tests
+            checks: abi+debug+doc+tests
           - os: ubuntu-20.04
             compiler: clang
             checks: asan+doc+tests
Signature · 1 line
2.39.2
#6 lore raw

Re: [PATCH v2 2/2] ci: test compilation with debug in GHA

20/03/2023 13:18, David Marchand:

Quoted 4 lines

We often miss compilation issues with -O0 -g.
Switch to debug in GHA for the gcc job.

Series applied, thanks.