chsasank / llama.lisp

Lisp dialect designed for HPC and AI
GNU Lesser General Public License v2.1
15 stars 6 forks source link

'nan' returned for the last few positions of the first 10 position of an array of size 100. #47

Closed adi-lb-phoenix closed 4 months ago

adi-lb-phoenix commented 4 months ago

Command executed :

guile ../../utils/sexp-json.scm < matrix_multiplication.sexp | python3 ../../c-lisp.py | python3 ../../brilisp.py |python3 ../../llvm.py | bash ../brilisp/run.sh 

This is the code that was written in c-lisp (matrix_multiplication.sexp) :


(c-lisp

    (define ((mat-cons void) (arr (ptr float)) (len int))
        ()

    (define ((fprint float) (n  float) ))

    (define ((matmul_print void) (arr (ptr float)) (len int))
        (declare (i int))
        (for ((set i 0) (lt i len) (set i (add i 1))) 
            (call fprint (load (ptradd arr i)))
        )
        (ret) 
    ) 

 ;x is 10 , xout and w is 100 . d is 10 . n is 10
    (define ((mat_mul void) (xout (ptr float)) (x (ptr float)) (w (ptr float)) (n int) (d int)) 
        (declare (i int))
        (for ( (set i 4) (lt i d) (set i (add i 1)) )
            (declare (val float))
            (set val 0.0)
            (declare (j int))
            (for ((set j 0) (lt j n) (set j (add j 1)))
               (set val (fadd val (fmul (load (ptradd w (add (mul i n) j))) (load (ptradd x j)))))
            )
            (store (ptradd xout i) val)
        )
        (ret)  
    )

    (define ((main void))
        (declare (xout (ptr float)))
        (declare (x (ptr float)))
        (declare (w (ptr float)))
        (declare (n int ))
        (declare (d int))

        (set xout (alloc float 100))
        (set x (alloc float 10))
        (set w (alloc float 100))
        (set n 10)
        (set d 10)
        (call mat-cons w 100)
        (call mat-cons x 10)
        (call mat_mul xout x w n d)
        (call matmul_print xout 100)
        ;(call fprint xout)
        (ret) 
    )
)

So in the statement (for ( (set i 4) (lt i d) (set i (add i 1)) ) which is in the third line of the the function mat_mul void . We receive output for first 4 places, the next 6 positions are 'nan'. The rest of positions from 11 to 100 has shown a value.

0.000000
0.000000
0.000000
0.000000
nan
nan
nan
nan
nan
nan
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-32684814336.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-32740376576.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-145883421574501833904646391177808969728.000000
0.000000
-32724295680.000000
0.000000
0.000000
0.000000
-2171437523135452134426804224.000000
0.000000
-2258273431040127298351136768.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-1.843628
0.000000
-2171439884318693569249411072.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-145925122208646941739038026726453018624.000000
0.000000

When (set i 2) , the first 2 positions has a value, the next 8 positions are 'nan', followed by values present for the next 90.

0.000000
0.000000
nan
nan
nan
nan
nan
nan
nan
nan
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-7362206240281924307255296.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-1.843628
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
-7364576646895395984637952.000000
0.000000

This behavior is shown only within first 10 positions of the array.

GlowingScrewdriver commented 4 months ago

Duplicate of #46