quil-lang / magicl

Matrix Algebra proGrams In Common Lisp.
BSD 3-Clause "New" or "Revised" License
238 stars 44 forks source link

load fail with `register-matrix-matrix-multiply' for matrix/int32 on macos (m1) #203

Closed li-yiyang closed 3 months ago

li-yiyang commented 7 months ago

My machine: macbook air m1, 2020, Sonoma 14.3, sbcl 2.4.3 (homebrew), lapack 3.12.0 (homebrew).

When trying to load magicl, raise The value 17314 is not of type (INTEGER -8192 16383) when binding SB-ASSEM:LABEL error ((SB-ARM64-ASM::EMIT-TEST-BRANCH-IMM #<SB-ASSEM:SEGMENT {70098F1AF3}> 0 1 0 17314 14) [external]).

Could locate the error to src/high-level/matrix-functions/mult-methods.lisp at line 12:

(register-matrix-matrix-multiply matrix/int32 (signed-byte 32))

After commit the line, there's no error and could load magicl. But would fail one test for ((:METHOD NO-APPLICABLE-METHOD (T)) #<STANDARD-GENERIC-FUNCTION MAGICL:NROWS (1)> #S(MAGICL::VECTOR/INT32 :SIZE 2 :STORAGE #(1 4))) [fast-method] (other test would pass though).

Not know whether if for the apple's arm fault. (could load on amd64 machine)

Load code:

> rm ~/.cache/common-lisp/sbcl-* # cleared the cache
> sbcl --dynamic-space-size 4096 # would fail if not providing enough heap space
This is SBCL 2.4.1, an implementation of ANSI Common Lisp.
...
* (ql:quickload :magicl)
...
#<THREAD "main thread" RUNNING {70055206B3}>:
  The value
    17480
  is not of type
    (INTEGER -8192 16383)
  when binding SB-ASSEM:LABEL

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY                        ] Retry compiling
   #<CL-SOURCE-FILE "magicl/core" "high-level" "matrix-functions" "mult-methods">.
  1: [ACCEPT                       ] Continue, treating compiling
   #<CL-SOURCE-FILE "magicl/core" "high-level" "matrix-functions" "mult-methods">
                                     as having been successful.
  2:                                 Retry ASDF operation.
  3: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the
                                     configuration.
  4:                                 Retry ASDF operation.
  5:                                 Retry ASDF operation after resetting the
                                     configuration.
  6: [ABORT                        ] Give up on "magicl"
  7: [REGISTER-LOCAL-PROJECTS      ] Register local projects and try again.
  8:                                 Exit debugger, returning to top level.

(SB-ARM64-ASM::EMIT-TEST-BRANCH-IMM #<SB-ASSEM:SEGMENT {700E5A99F3}> 0 1 0 17480 14) [external]
0] 0

Test code:

* (ql:quickload :fiasco)
* (asdf:test-system :magicl)
...
debugger invoked on a SB-PCL::NO-APPLICABLE-METHOD-ERROR in thread
#<THREAD tid=259 "main thread" RUNNING {70052F0E83}>:
  There is no applicable method for the generic function
    #<STANDARD-GENERIC-FUNCTION MAGICL:NROWS (1)>
  when called with arguments
    (#S(MAGICL::VECTOR/INT32 :SIZE 2 :STORAGE #(1 4))).
See also:
  The ANSI Standard, Section 7.6.6

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY                                ] Retry calling the generic function.
  1: [CONTINUE                             ] Skip the rest of the test
                                             TEST-MATRIX-STACKING and continue
                                             by returning (values)
  2: [RETEST                               ] Rerun the test TEST-MATRIX-STACKING
  3:                                         Skip the rest of the test
                                             FIASCO-SUITES::MAGICL-TESTS and
                                             continue by returning (values)
  4:                                         Rerun the test
                                             FIASCO-SUITES::MAGICL-TESTS
  5: [CONTINUE-WITHOUT-DEBUGGING           ] Turn off debugging for this test
                                             session and invoke the first
                                             CONTINUE restart
  6: [CONTINUE-WITHOUT-DEBUGGING-ERRORS    ] Do not stop at unexpected errors
                                             for the rest of this test session
                                             and continue by invoking the first
                                             CONTINUE restart
  7: [CONTINUE-WITHOUT-DEBUGGING-ASSERTIONS] Do not stop at failed assertions
                                             for the rest of this test session
                                             and continue by invoking the first
                                             CONTINUE restart
  8: [ABORT-TESTING                        ] Abort the entire test session
  9: [RETRY                                ] Retry
                                             #<TEST-OP > on #<SYSTEM "magicl-tests">.
 10: [ACCEPT                               ] Continue, treating
                                             #<TEST-OP > on #<SYSTEM "magicl-tests">
                                             as having been successful.
 11:                                         Retry ASDF operation.
 12: [CLEAR-CONFIGURATION-AND-RETRY        ] Retry ASDF operation after
                                             resetting the configuration.
 13:                                         Retry ASDF operation.
 14:                                         Retry ASDF operation after
                                             resetting the configuration.
 15: [ABORT                                ] Exit debugger, returning to top
                                             level.

((:METHOD NO-APPLICABLE-METHOD (T)) #<STANDARD-GENERIC-FUNCTION MAGICL:NROWS (1)> #S(MAGICL::VECTOR/INT32 :SIZE 2 :STORAGE #(1 4))) [fast-method]
0] 1
...
stylewarning commented 7 months ago

I will be getting an Apple Silicon machine soon and then I will be able to test.

stylewarning commented 7 months ago

(This potentially looks like an SBCL bug too.)

krfantasy commented 4 months ago

I have tested it on an M1 Mac mini with macOS Sonoma 14.5 and SBCL 2.4.7 & 2.4.6, and neither of them has the loading issue. It may just be a bug in SBCL that has already been fixed.

The failed test test-matrix-stacking is not related to this loading issue. It was introduced in commit 07edc0f7a17ac77ccae9cbd4506dfc51b58800d5 and can be fixed by:

diff --git a/tests/matrix-tests.lisp b/tests/matrix-tests.lisp
index 32a6f60..5ea3800 100644
--- a/tests/matrix-tests.lisp
+++ b/tests/matrix-tests.lisp
@@ -183,11 +183,11 @@
     (is (magicl:= expected
                   (magicl:hstack
                    (loop :for j :below 3
-                         :collect (magicl:column expected j)))))
+                         :collect (magicl:vector->column-matrix (magicl:column expected j))))))
     (is (magicl:= expected
                   (magicl:vstack
                    (loop :for i :below 2
-                         :collect (magicl:row expected i)))))))
+                         :collect (magicl:vector->row-matrix (magicl:row expected i))))))))

 (deftest test-block-matrix-construction ()
li-yiyang commented 3 months ago

Yes, thank you. After updating SBCL and it could be loaded successfully.