guix_mirror_bot pushed a commit to branch master
in repository guix.

commit 32795f39a4cfc314dbc1bb26449ef34583a5c637
Author: Nicolas Graves <ngra...@ngraves.fr>
AuthorDate: Sun Aug 10 00:31:02 2025 +0200

    gnu: xnnpack: Improve package.
    
    This rework was done for updating xxnpack-for-r-torch to its next
    version.  The refactor is done to avoid copying the huge snippet and
    generate-files phase for it.
    
    * gnu/packages/machine-learning.scm (xnnpack)
    [source]<snippet>: Guard against potentially non-existing files in
    another source. Improve generated files removal.
    [configure-flags]: Rewrite using gepxs.
    [arguments]<#:phases>: Handle multilines and guard against potentially
    non-existing files in phase 'generate-files.
    
    Change-Id: If97cadf5ed0b34a68d99fb73bd3ea99411820aaa
    Reviewed-by: David Elsing <david.els...@posteo.net> @dtelsing
    Signed-off-by: Sharlatan Hellseher <sharlata...@gmail.com>
---
 gnu/packages/machine-learning.scm | 66 +++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/gnu/packages/machine-learning.scm 
b/gnu/packages/machine-learning.scm
index 73155e62fd..015451f4a7 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -4514,7 +4514,8 @@ on quantized 8-bit tensors.")
                     (srfi srfi-26)))
          (snippet
           '(begin
-             (delete-file-recursively "bench/models")
+             (when (directory-exists? "bench/models")
+               (delete-file-recursively "bench/models"))
              ;; Remove autogenerated files, which contain the string
              ;; "Auto-generated file"
              (for-each
@@ -4528,30 +4529,26 @@ on quantized 8-bit tensors.")
                                 (get-string-all port)
                                 "Auto-generated file")))
                        (delete-file path))))
-                 (scandir dir (negate (cut member <> '("." ".." "simd"))))))
+                 (or (scandir dir (negate (cut member <> '("." ".." "simd"))))
+                     '())))
               (cons*
-               "test" "bench" "src/enums" "src/xnnpack"
-               "gen" "cmake/gen"
-               (filter
-                identity
-                (map
-                 (lambda (dir)
-                   (let ((path
-                          (string-append "src/" dir "/gen")))
-                     (and (file-exists? path) path)))
-                 (scandir "src" (negate (cut member <> '("." ".."))))))))))))
+               "test" "bench" "src/enums" "src/xnnpack" "gen" "cmake/gen"
+               (filter file-exists?
+                       (map (cut string-append "src/" <> "/gen")
+                            (scandir "src")))))))))
       (build-system cmake-build-system)
       (arguments
        (list
         #:build-type "Release" ;; Debugging symbols require a lot of disk space
-        #:configure-flags ''("-DXNNPACK_USE_SYSTEM_LIBS=YES"
-                             "-DBUILD_SHARED_LIBS=ON"
-                             "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
-                             "-DXNNPACK_LIBRARY_TYPE=shared"
-                             "-DXNNPACK_BUILD_BENCHMARKS=FALSE"
-                             ;; Tests fail to build with 
-DXNNPACK_LIBRARY_TYPE=shared:
-                             ;; https://github.com/google/XNNPACK/issues/6285
-                             "-DXNNPACK_BUILD_TESTS=OFF")
+        #:configure-flags
+        #~(list "-DXNNPACK_USE_SYSTEM_LIBS=YES"
+                "-DBUILD_SHARED_LIBS=ON"
+                "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
+                "-DXNNPACK_LIBRARY_TYPE=shared"
+                "-DXNNPACK_BUILD_BENCHMARKS=FALSE"
+                ;; Tests fail to build with -DXNNPACK_LIBRARY_TYPE=shared:
+                ;; https://github.com/google/XNNPACK/issues/6285
+                "-DXNNPACK_BUILD_TESTS=OFF")
         #:tests? #f
         #:modules '((ice-9 ftw)
                     (guix build cmake-build-system)
@@ -4577,14 +4574,18 @@ on quantized 8-bit tensors.")
                               (string-suffix? ".sh" name))
                      (let ((file (string-append "scripts/" name)))
                        (substitute* file
-                         ;; Turn the commands into targets and remove trailing
-                         ;; '&' characters
-                         (("(.*(\\.sh|\\.py|-o 
|--output)[^&]*)&?[[:space:]]*$" _ command)
+                         ;; Turn the commands into targets. Avoid comments and
+                         ;; lines starting with - (rest of multilines).
+                         (("\
+^[[:space:]]*([^ #-].*/.*(\\.sh|\\.py|-o |--output)[^&]*).*$"
+                           _ command)
                           (begin
                             (set! counter (+ counter 1))
-                            (string-append "target" (number->string counter)
+                            (string-append "\ntarget" (number->string counter)
                                            ":" target-deps
-                                           "\n\t" command "\n")))
+                                           "\n\t" command)))
+                         ;; Remove trailing '&' characters.
+                         (("&?[[:space:]]*$") "\n")
                          (("[[:space:]]*wait[[:space:]]*") "")
                          ;; The commands after this line depend on the
                          ;; previous commands in the file.
@@ -4610,12 +4611,15 @@ on quantized 8-bit tensors.")
                 (invoke "python3" "tools/generate-lut-norm-test.py"
                         "--spec" "test/u8-lut32norm.yaml"
                         "--output" "test/u8-lut32norm.cc")
-                (invoke "python3" "tools/generate-gemm-test.py"
-                        "--spec" "test/qd8-f16-qb4w-gemm-minmax.yaml"
-                        "--output-test" "test/qd8-f16-qb4w-gemm-minmax.cc")
-                (invoke "python3" "tools/generate-gemm-test.py"
-                        "--spec" "test/qd8-f32-qb4w-gemm-minmax.yaml"
-                        "--output-test" 
"test/qd8-f32-qb4w-gemm-minmax.cc"))))))
+                ;; Check existence to avoid doubling the phase for r-torch.
+                (when (file-exists? "test/qd8-f16-qb4w-gemm-minmax.yaml")
+                  (invoke "python3" "tools/generate-gemm-test.py"
+                          "--spec" "test/qd8-f16-qb4w-gemm-minmax.yaml"
+                          "--output-test" "test/qd8-f16-qb4w-gemm-minmax.cc"))
+                (when (file-exists? "test/qd8-f32-qb4w-gemm-minmax.yaml")
+                  (invoke "python3" "tools/generate-gemm-test.py"
+                          "--spec" "test/qd8-f32-qb4w-gemm-minmax.yaml"
+                          "--output-test" 
"test/qd8-f32-qb4w-gemm-minmax.cc")))))))
       (inputs
        (list clog
              cpuinfo

Reply via email to