chsasank / llama.lisp

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

TypeError: unhashable type: 'list' #59

Closed adi-lb-phoenix closed 2 months ago

adi-lb-phoenix commented 3 months ago

command executed :

guile ../../utils/sexp-json.scm < llama2.c/mat_mul.sexp | python ../../c-lisp.py 

output :

Error in statement: ['call', 'fprint', ['load', [['ptradd', 'xout', 'i']]]]
Error in statement: [['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'], ['call', 'fprint', ['load', [['ptradd', 'xout', 'i']]]]]
Error in statement: ['for', [['set', 'i', 0], ['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'], ['call', 'fprint', ['load', [['ptradd', 'xout', 'i']]]]]
Traceback (most recent call last):
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 430, in <module>
    json.dump(brilisp_code_generator.c_lisp(json.loads(sys.stdin.read())), sys.stdout)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 58, in c_lisp
    return ["brilisp"] + [self.gen_function(fn) for fn in prog[1:]]
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 58, in <listcomp>
    return ["brilisp"] + [self.gen_function(fn) for fn in prog[1:]]
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 93, in gen_function
    *self.gen_compound_stmt(func[2:], new_scope=False),
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 256, in gen_compound_stmt
    instr_list += self.gen_stmt(s)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 119, in gen_stmt
    raise e
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 110, in gen_stmt
    return self.gen_for_stmt(stmt)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 169, in gen_for_stmt
    loop_stmt_instr = self.gen_stmt(stmt[2:])
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 119, in gen_stmt
    raise e
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 102, in gen_stmt
    return self.gen_compound_stmt(stmt)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 256, in gen_compound_stmt
    instr_list += self.gen_stmt(s)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 119, in gen_stmt
    raise e
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 114, in gen_stmt
    return self.gen_expr(stmt)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 411, in gen_expr
    return self.gen_call_expr(expr, res_sym)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 301, in gen_call_expr
    instr_list += self.gen_expr(arg, res_sym=arg_sym)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 419, in gen_expr
    return self.gen_load_expr(expr, res_sym)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 367, in gen_load_expr
    *self.gen_expr(expr[1], res_sym=ptr_sym),
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 414, in gen_expr
    elif self.is_fixed_type_expr(expr):
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/c-lisp/../../c-lisp.py", line 323, in is_fixed_type_expr
    return expr[0] in self.fixed_op_types
TypeError: unhashable type: 'list'

C-lisp code executed.

(c-lisp
        (define ((fprint float) (n  float) ))

        (define ((putchar int) (n int)))

        (define ((initialise void) (xout (ptr float)) (x (ptr float)) (w (ptr float)) (column int) (row int)) ;void initialise(float *xout, float *x, float *w, int column , int row)
                (declare row_float float)
                (declare column_float float)
                (declare i int)
                (declare j int)
                (set row_float 0.0)
                (set column_float 0.0)
                (for ((set i 0) (lt i row) (set i (add i 1)) )
                        (store (ptradd x i) row_float)
                        (for ((set j 0) (lt j column) (set j (add j 1)))
                            (store (ptradd w (add j (mul i row))) (fadd column_float row_float ))
                            (set column_float (fadd column_float 1.0))
                            (call fprint (load (ptradd w (add j (mul i row)))))
                        )
                        (call putchar 10)
                        (set row_float (fadd row_float 1.0))
                        (set column_float 0.0)
                )
                (ret)
        )

        (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 0) (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)
                    (call fprint (load((ptradd xout i))))
                )
                (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 10))
                (set x (alloc float 10))
                (set w (alloc float 100))
                (set n 10)
                (set d 10)
                (call initialise xout x w n d)
                (call mat_mul xout x w n d)
                (ret) 
        )
)
adi-lb-phoenix commented 3 months ago

Error in statement:['call', 'fprint', ['load', [['ptradd', 'xout', 'i']]]] . Updated from (call (fprint (load((ptradd xout i)))) to (call fprint (load((ptradd xout i))))). The syntax to call fprint is (call fprint args), where as my instruction before updating had an extra () before call instruction which would make the compiler interpret the function call as (call (some_function)). This syntax would not be able to pass arguments to the function print. Hence we remove the () around fprint.

GlowingScrewdriver commented 2 months ago

This can be closed, right?